From c7dd4a195d8d893d92c49963447cdf6486844584 Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Fri, 20 Oct 2023 09:45:53 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/wb' into cjl
---
screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java | 458 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 457 insertions(+), 1 deletions(-)
diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
index 827683d..549adb9 100644
--- a/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
+++ b/screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java
@@ -1,10 +1,37 @@
package com.moral.api.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.moral.api.config.mybatis.wrapper.NullFilterWrapper;
+import com.moral.api.entity.MonitorPoint;
import com.moral.api.entity.Organization;
+import com.moral.api.entity.User;
import com.moral.api.mapper.OrganizationMapper;
+import com.moral.api.mapper.UserMapper;
+import com.moral.api.pojo.dto.organization.OrganizationDTO;
+import com.moral.api.pojo.dto.organization.OrganizationQueryDTO;
+import com.moral.api.pojo.dto.organization.OrganizationQueryNamesDTO;
+import com.moral.api.pojo.form.organization.*;
+import com.moral.api.service.MonitorPointService;
import com.moral.api.service.OrganizationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.api.service.UserService;
+import com.moral.api.util.CompareFieldUtils;
+import com.moral.api.util.LogUtils;
+import com.moral.constant.Constants;
+import com.moral.constant.ResponseCodeEnum;
+import com.moral.pojo.CompareFieldResult;
+import com.moral.util.ConvertUtils;
+import com.moral.util.DateUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
+
+import java.util.*;
+import java.util.function.Predicate;
/**
* <p>
@@ -12,9 +39,438 @@
* </p>
*
* @author moral
- * @since 2021-03-09
+ * @since 2021-04-06
*/
@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService {
+ @Autowired
+ OrganizationMapper organizationMapper;
+
+ @Autowired
+ UserService userService;
+
+ @Autowired
+ UserMapper userMapper;
+
+ @Autowired
+ MonitorPointService monitorPointService;
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationInsertForm]
+ * @return: void
+ * @Author: ���������
+ * @Date: 2021/3/22
+ */
+ @Override
+ @Transactional
+ public OrganizationDTO insertOrganization(OrganizationInsertForm organizationInsertForm) {
+ OrganizationDTO organizationDTO = new OrganizationDTO();
+ QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
+ //form������entity
+ Organization organization = organizationInsertForm.formConvertEntity();
+ //������������������������������������
+ Organization existOrganization = new Organization();
+ existOrganization.setName(organization.getName());
+ existOrganization.setIsDelete(Constants.NOT_DELETE);
+ queryWrapper.setEntity(existOrganization);
+ Organization existOrganizationResult = organizationMapper.selectOne(queryWrapper);
+ if (!ObjectUtils.isEmpty(existOrganizationResult)) {
+ organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_EXIST.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST.getMsg());
+ return organizationDTO;
+ }
+ //������������
+ organizationMapper.insert(organization);
+
+ //������DTO������
+ organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+
+ //������������������
+ insertLog(organization);
+ return organizationDTO;
+ }
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationUpdateForm]
+ * @return: com.moral.api.pojo.dto.organization.OrganizationDTO
+ * @Author: ���������
+ * @Date: 2021/3/24
+ */
+ @Override
+ @Transactional
+ public OrganizationDTO updateOrganization(OrganizationUpdateForm organizationUpdateForm) {
+ OrganizationDTO organizationDTO = new OrganizationDTO();
+ //form���entity
+ Organization organization = organizationUpdateForm.formConvertEntity();
+
+ //������������������������������������������
+ QueryWrapper<Organization> oldWrapper = new QueryWrapper<>();
+ Organization oldOrganization = new Organization();
+ oldOrganization.setId(organization.getId());
+ oldOrganization.setIsDelete(Constants.NOT_DELETE);
+ oldWrapper.setEntity(oldOrganization);
+ oldOrganization = organizationMapper.selectOne(oldWrapper);
+ if (ObjectUtils.isEmpty(oldOrganization)) {
+ organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
+ return organizationDTO;
+ }
+
+
+ //������������
+ organizationMapper.updateById(organization);
+
+ //������������������������
+ organization = organizationMapper.selectById(organization.getId());
+
+ //������DTO������
+ organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+
+ //������������������
+ updateLog(oldOrganization, organization);
+
+ return organizationDTO;
+ }
+
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationDeleteForm]
+ * @return: com.moral.api.pojo.dto.organization.OrganizationDTO
+ * @Author: ���������
+ * @Date: 2021/3/25
+ */
+ @Override
+ @Transactional
+ public OrganizationDTO deleteOrganization(OrganizationDeleteForm form) {
+ OrganizationDTO dto = new OrganizationDTO();
+ //������
+ Integer id = form.getOrganizationId();
+
+ //������������������������������
+ List<MonitorPoint> monitorPoints = monitorPointService.getMonitorPointsByOrganizationId(id);
+ if (!ObjectUtils.isEmpty(monitorPoints)) {
+ dto.setCode(ResponseCodeEnum.ORGANIZATION_EXIST_MONITORPOINT.getCode());
+ dto.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST_MONITORPOINT.getMsg());
+ return dto;
+ }
+
+ //������������������������������������������
+ Organization existOrganization = new Organization();
+ existOrganization.setIsDelete(Constants.NOT_DELETE);
+ existOrganization.setId(id);
+ QueryWrapper queryExistWrapper = new QueryWrapper();
+ queryExistWrapper.setEntity(existOrganization);
+ existOrganization = organizationMapper.selectOne(queryExistWrapper);
+ if (ObjectUtils.isEmpty(existOrganization)) {
+ dto.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode());
+ dto.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
+ return dto;
+ }
+
+ //���������������������������
+ List<Organization> children = getAllChildrenOrganization(existOrganization.getId());
+ if (!ObjectUtils.isEmpty(children)) {
+ //���������������������������������������������������������������������������������������������������������������������������
+ UpdateWrapper updateWrapper = new UpdateWrapper();
+ if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) {//���������������������
+ //������������������������id���������������
+ List<Integer> childrenId = new ArrayList<>();
+ children.forEach(value -> {
+ childrenId.add(value.getId());
+ });
+ //���������������������������������������������������������������������������������
+ for (Integer childId : childrenId) {
+ List<MonitorPoint> childMonitorPoints = monitorPointService.getMonitorPointsByOrganizationId(childId);
+ if (!ObjectUtils.isEmpty(childMonitorPoints)) {
+ dto.setCode(ResponseCodeEnum.CHILDREN_ORGANIZATION_EXIST_MONITORPOINT.getCode());
+ dto.setMsg(ResponseCodeEnum.CHILDREN_ORGANIZATION_EXIST_MONITORPOINT.getMsg());
+ return dto;
+ }
+ }
+ //������������
+ updateWrapper.in("id", childrenId);
+ updateWrapper.set("is_delete", Constants.DELETE);
+ organizationMapper.update(null, updateWrapper);
+ //���������������������������
+ childrenId.forEach(value -> userService.deleteUsersByOrganizationId(value));
+
+ } else {//���������
+ //���������������������������id
+ List<Integer> childrenId = new ArrayList<>();
+ children.forEach(value -> {
+ if (value.getParentId().equals(id))
+ childrenId.add(value.getId());
+ });
+ //������������
+ updateWrapper.in("id", childrenId);
+ updateWrapper.set("parent_id", 0);
+ organizationMapper.update(null, updateWrapper);
+ }
+ }
+
+ //������������������
+ UpdateWrapper deleteWrapper = new UpdateWrapper();
+ deleteWrapper.eq("id", id);
+ deleteWrapper.set("is_delete", Constants.DELETE);
+ organizationMapper.update(null, deleteWrapper);
+
+ //������������������
+ userService.deleteUsersByOrganizationId(id);
+
+ //������������������
+ dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ //������������������
+ StringBuilder content = new StringBuilder();
+ content.append("������������������").append(existOrganization.getName());
+ if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG))
+ content.append("���������������������;");
+ else
+ content.append(";");
+ LogUtils.saveOperationForManage(content.toString(), Constants.DELETE_OPERATE_TYPE);
+
+ return dto;
+ }
+
+ /**
+ * @Description: ������������������
+ * @Param: [organizationQueryForm]
+ * @return: com.moral.api.pojo.dto.organization.OrganizationQueryDTO
+ * @Author: ���������
+ * @Date: 2021/3/25
+ */
+ @Override
+ public OrganizationQueryDTO queryOrganization(OrganizationQueryForm organizationQueryForm) {
+ OrganizationQueryDTO dto = new OrganizationQueryDTO();
+ //������
+ Integer pageCount = organizationQueryForm.getPage();
+ Integer size = organizationQueryForm.getSize();
+ Integer parentId = organizationQueryForm.getParentId();
+ String name = organizationQueryForm.getName();
+ Integer provinceCode = organizationQueryForm.getProvinceCode();
+ Integer cityCode = organizationQueryForm.getCityCode();
+ Integer areaCode = organizationQueryForm.getAreaCode();
+ String phone = organizationQueryForm.getPhone();
+ String email = organizationQueryForm.getEmail();
+ String wechat = organizationQueryForm.getWechat();
+ String isDelete = organizationQueryForm.getIsDelete();
+ String order = organizationQueryForm.getOrder();
+ String orderType = organizationQueryForm.getOrderType();
+ Date createStartTime = organizationQueryForm.getCreateStartTime();
+ Date createEndTime = DateUtils.getDateOfDay(organizationQueryForm.getCreateEndTime(), 1);
+ Date expireStartTime = organizationQueryForm.getExpireStartTime();
+ Date expireEndTime = DateUtils.getDateOfDay(organizationQueryForm.getExpireEndTime(), 1);
+
+ //������������
+ Page<Organization> page = new Page<>(pageCount, size);
+ NullFilterWrapper<Organization> queryWrapper = new NullFilterWrapper<>();
+
+ queryWrapper.eq("parent_id", parentId);
+ queryWrapper.like("name", name);
+ queryWrapper.eq("province_code", provinceCode);
+ queryWrapper.eq("city_code", cityCode);
+ queryWrapper.eq("area_code", areaCode);
+ queryWrapper.like("phone", phone);
+ queryWrapper.like("email", email);
+ queryWrapper.like("wechat", wechat);
+ queryWrapper.between("create_time", createStartTime, createEndTime);
+ queryWrapper.between("expire_time", expireStartTime, expireEndTime);
+
+ if (!ObjectUtils.isEmpty(isDelete)) {
+ queryWrapper.eq("is_delete", isDelete);
+ } else {
+ queryWrapper.eq("is_delete", Constants.NOT_DELETE);
+ }
+
+ //������������
+ if (!ObjectUtils.isEmpty(order)) {
+ if (!ObjectUtils.isEmpty(orderType)) {
+ if (orderType.equals(Constants.ORDER_ASC))
+ queryWrapper.orderByAsc(ConvertUtils.toLine(order));
+ else
+ queryWrapper.orderByDesc(ConvertUtils.toLine(order));
+ }
+ }
+
+ //������������
+ Page<Organization> resultPage = organizationMapper.selectPage(page, queryWrapper);
+ List<Organization> organizations = resultPage.getRecords();
+ List<OrganizationDTO> organizationDTOS = new ArrayList<>();
+ //���������������������������������admin������������������organization���DTO���
+ for (Organization organization : organizations) {
+ OrganizationDTO resultDto = new OrganizationDTO();
+ //���������������
+ Organization parent = organizationMapper.selectById(organization.getParentId());
+ resultDto.setOrganization(organization);
+ resultDto.setParentOrganization(parent);
+ //������admin������
+ QueryWrapper userWrapper = new QueryWrapper();
+ User adminUser = new User();
+ adminUser.setIsAdmin(true);
+ adminUser.setOrganizationId(organization.getId());
+ adminUser.setIsDelete(Constants.NOT_DELETE);
+ userWrapper.setEntity(adminUser);
+ adminUser = userMapper.selectOne(userWrapper);
+ resultDto.setAdminUser(adminUser);
+ organizationDTOS.add(resultDto);
+ }
+
+ dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ dto.setOrganizationDTOS(organizationDTOS);
+ dto.setCurrent(page.getCurrent());
+ dto.setPages(page.getPages());
+ dto.setSize(page.getSize());
+ dto.setTotal(page.getTotal());
+ return dto;
+ }
+
+ /**
+ * @Description: ������form���id���������������������������������
+ * ������id������������������������id������id������������������������������������
+ * @Param: [from]
+ * @return: com.moral.api.pojo.dto.organization.OrganizationQueryNamesDTO
+ * @Author: ���������
+ * @Date: 2021/5/7
+ */
+ @Override
+ public OrganizationQueryNamesDTO queryNames(OrganizationQueryNamesForm form) {
+ OrganizationQueryNamesDTO dto = new OrganizationQueryNamesDTO();
+ //������
+ Integer id = form.getId();
+ //������������������
+ QueryWrapper<Organization> queryWrapper = new QueryWrapper();
+ queryWrapper.eq("is_delete", Constants.NOT_DELETE);
+ //������������������
+ List<Organization> organizations = organizationMapper.selectList(queryWrapper);
+ //������form������������id,���������������������������������������������
+ if (!ObjectUtils.isEmpty(id)) {
+ List<Organization> children = getAllChildrenOrganization(id);
+ List<Integer> thisAndchildrenIds = new ArrayList<>();//���id���������������������������id������
+ thisAndchildrenIds.add(id);
+ for (Organization child : children) {
+ thisAndchildrenIds.add(child.getId());
+ }
+ organizations.removeIf(new Predicate<Organization>() {//������
+ @Override
+ public boolean test(Organization organization) {
+ if (thisAndchildrenIds.contains(organization.getId()))
+ return true;
+ return false;
+ }
+ });
+ }
+ //������������������
+ dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+ dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+ dto.setOrganizations(organizations);
+ return dto;
+ }
+
+
+ /**
+ * @Description: ������������������������������������
+ * @Param: []
+ * @return: java.util.List<com.moral.api.entity.Organization>
+ * @Author: ���������
+ * @Date: 2021/4/14
+ */
+ @Override
+ public List<Organization> getAllChildrenOrganization(Integer parentId) {
+ List<Organization> children = new ArrayList<>();
+ recursionQueryChildren(parentId, children);
+ return children;
+ }
+
+ /**
+ * @Description: ���������������������������������������������������children���
+ * @Param: [parent, children]
+ * @return: void
+ * @Author: ���������
+ * @Date: 2021/4/14
+ */
+ private void recursionQueryChildren(Integer parentId, List<Organization> children) {
+ QueryWrapper<Organization> queryWrapper = new QueryWrapper();
+ queryWrapper.eq("is_delete", Constants.NOT_DELETE);
+ queryWrapper.eq("parent_id", parentId);
+ List<Organization> organizations = organizationMapper.selectList(queryWrapper);
+ if (!ObjectUtils.isEmpty(organizations)) {
+ children.addAll(organizations);
+ for (Organization organization : organizations) {
+ recursionQueryChildren(organization.getId(), children);
+ }
+ } else {
+ return;
+ }
+ }
+
+ /**
+ * @Description: ������������������������
+ * @Param: [organization]
+ * @return: void
+ * @Author: ���������
+ * @Date: 2021/8/25
+ */
+ private void insertLog(Organization organization) {
+ StringBuilder content = new StringBuilder();
+ content.append("������������������").append(organization.getName() + ";");
+ LogUtils.saveOperationForManage(content.toString(), Constants.INSERT_OPERATE_TYPE);
+ }
+
+ public void updateLog(Organization oldOrganization, Organization newOrganization) {
+ List<CompareFieldResult> results = CompareFieldUtils.compare(Organization.class, oldOrganization, newOrganization);
+ for (CompareFieldResult result : results) {
+ //���������������������������
+ if (result.getFieldName().equals("parentId")) {
+ //���������id���������������
+ String oldData = result.getOldData();
+ String newData = result.getNewData();
+
+ if (!oldData.equals("0"))
+ oldData = organizationMapper.selectById(Integer.parseInt(oldData)).getName();
+ else
+ oldData = "null";
+
+ if (!newData.equals("0"))
+ newData = organizationMapper.selectById(Integer.parseInt(newData)).getName();
+ else
+ newData = "null";
+
+ result.setNewData(newData);
+ result.setOldData(oldData);
+ result.setFieldAnnoName("���������");
+ }
+
+ //������������������������
+ if (result.getFieldName().equals("expireTime")) {
+ //DateToString���������������������yyyy-MM-dd
+ String oldData = result.getOldData();
+ String newData = result.getNewData();
+
+ if (oldData != null) {
+ Date oldDate = DateUtils.dateStringToDate(oldData);
+ oldData = DateUtils.dateToDateString(oldDate, "yyyy-MM-dd");
+ }
+
+ if (newData != null) {
+ Date newDate = DateUtils.dateStringToDate(newData);
+ newData = DateUtils.dateToDateString(newDate, "yyyy-MM-dd");
+ }
+
+ result.setNewData(newData);
+ result.setOldData(oldData);
+ result.setFieldAnnoName("������������");
+ }
+ }
+
+ String content = CompareFieldUtils.resultsConvertContent(results, "���������������;���������������" + oldOrganization.getName());
+ LogUtils.saveOperationForManage(content, Constants.UPDATE_OPERATE_TYPE);
+ }
+
}
--
Gitblit v1.8.0