From b888331b6ba56caeeab12a4543fe81bac8854794 Mon Sep 17 00:00:00 2001 From: lizijie <lzjiiie@163.com> Date: Tue, 31 Aug 2021 17:09:46 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java | 227 +++++++++++++++++++++++++++----------------------------- 1 files changed, 108 insertions(+), 119 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 bd2db85..e351875 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 @@ -6,20 +6,25 @@ 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.MonitorPointMapper; 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; @@ -31,6 +36,8 @@ import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.*; import java.util.function.Predicate; @@ -43,7 +50,6 @@ * @since 2021-04-06 */ @Service -@ConfigurationProperties(prefix = "log-aspect") public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService { @Autowired @@ -58,11 +64,8 @@ @Autowired UserMapper userMapper; - Map<String, String> organizationFormMap; - - public void setOrganizationFormMap(Map<String, String> organizationFormMap) { - this.organizationFormMap = organizationFormMap; - } + @Autowired + MonitorPointService monitorPointService; /** * @Description: ������������������ @@ -71,8 +74,6 @@ * @Author: ��������� * @Date: 2021/3/22 */ - - @Override @Transactional public OrganizationDTO insertOrganization(OrganizationInsertForm organizationInsertForm) { @@ -91,34 +92,15 @@ organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST.getMsg()); return organizationDTO; } - //��������������������������� - Integer parentId = organization.getParentId(); - Organization parentOrganization = new Organization(); - if (!ObjectUtils.isEmpty(parentId)) { - parentOrganization.setId(parentId); - parentOrganization.setIsDelete(Constants.NOT_DELETE); - queryWrapper.setEntity(parentOrganization); - parentOrganization = organizationMapper.selectOne(queryWrapper); - if (ObjectUtils.isEmpty(parentOrganization)) { - organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getCode()); - organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getMsg()); - return organizationDTO; - } - } //������������ organizationMapper.insert(organization); //������DTO������ - organizationDTO.setParentOrganization(parentOrganization); - organizationDTO.setOrganization(organization); organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); //������������������ - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - StringBuilder content = new StringBuilder(); - content.append("������������������").append(organization.getName() + ";"); - logUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE); + insertLog(organization); return organizationDTO; } @@ -149,21 +131,6 @@ return organizationDTO; } - //������������������������������������������������������ - Integer parentId = organization.getParentId(); - Organization parentOrganization = new Organization(); - if (!ObjectUtils.isEmpty(parentId) && parentId != 0) { - QueryWrapper<Organization> existParentWrapper = new QueryWrapper<>(); - parentOrganization.setId(parentId); - parentOrganization.setIsDelete(Constants.NOT_DELETE); - existParentWrapper.setEntity(parentOrganization); - parentOrganization = organizationMapper.selectOne(existParentWrapper); - if (ObjectUtils.isEmpty(parentOrganization)) { - organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getCode()); - organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_PARENT_NOT_EXIST.getMsg()); - return organizationDTO; - } - } //������������ organizationMapper.updateById(organization); @@ -172,16 +139,16 @@ organization = organizationMapper.selectById(organization.getId()); //������DTO������ - organizationDTO.setParentOrganization(parentOrganization); - organizationDTO.setOrganization(organization); organizationDTO.setCode(ResponseCodeEnum.SUCCESS.getCode()); organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); //������������������ - insertUpdateLog(organizationUpdateForm, organization, oldOrganization); + updateLog(oldOrganization,organization); return organizationDTO; } + + /** * @Description: ������������������ @@ -197,7 +164,15 @@ //������ 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); @@ -210,18 +185,9 @@ return dto; } - //������������������ - UpdateWrapper deleteWrapper = new UpdateWrapper(); - deleteWrapper.eq("id", id); - deleteWrapper.set("is_delete", Constants.DELETE); - organizationMapper.update(null, deleteWrapper); - - //������������������ - userService.deleteUserByOrganizationId(id); - //��������������������������� List<Organization> children = getAllChildrenOrganization(existOrganization.getId()); - if (!ObjectUtils.isEmpty(children)) {//��������������������� + if (!ObjectUtils.isEmpty(children)) { //��������������������������������������������������������������������������������������������������������������������������� UpdateWrapper updateWrapper = new UpdateWrapper(); if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) {//��������������������� @@ -230,12 +196,21 @@ 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.deleteUserByOrganizationId(value)); + childrenId.forEach(value->userService.deleteUsersByOrganizationId(value)); } else {//��������� //���������������������������id @@ -251,19 +226,26 @@ } } + //������������������ + UpdateWrapper deleteWrapper = new UpdateWrapper(); + deleteWrapper.eq("id", id); + deleteWrapper.set("is_delete", Constants.DELETE); + organizationMapper.update(null, deleteWrapper); + + //������������������ + userService.deleteUsersByOrganizationId(id); + //������������������ - dto.setOrganization(existOrganization); dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); //������������������ - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); StringBuilder content = new StringBuilder(); content.append("������������������").append(existOrganization.getName()); if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) content.append("���������������������;"); else content.append(";"); - logUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE); + logUtils.saveOperationForManage(content.toString(), Constants.DELETE_OPERATE_TYPE); return dto; } @@ -355,7 +337,7 @@ dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); dto.setOrganizationDTOS(organizationDTOS); dto.setCurrent(page.getCurrent()); - dto.setPage(page.getPages()); + dto.setPages(page.getPages()); dto.setSize(page.getSize()); dto.setTotal(page.getTotal()); return dto; @@ -379,7 +361,7 @@ queryWrapper.eq("is_delete", Constants.NOT_DELETE); //������������������ List<Organization> organizations = organizationMapper.selectList(queryWrapper); - //������form������������id,��������������������������������������� + //������form������������id,��������������������������������������������� if(!ObjectUtils.isEmpty(id)){ List<Organization> children = getAllChildrenOrganization(id); List<Integer> thisAndchildrenIds = new ArrayList<>();//���id���������������������������id������ @@ -403,62 +385,6 @@ return dto; } - - /** - * @Description: ��������������������������� - * @Param: [updateForm, newOrganization, oldOrganization] - * @return: void - * @Author: ��������� - * @Date: 2021/4/8 - */ - private void insertUpdateLog(OrganizationUpdateForm updateForm, Organization newOrganization, Organization oldOrganization) { - //������������������ - HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); - StringBuilder content = new StringBuilder(); - content.append("������������������").append(oldOrganization.getName()).append(";"); - //������������Map,��������������������������������� - Map<String, Object> newParameters = JSONObject.parseObject(JSON.toJSONString(updateForm), Map.class); - Map<String, Object> oldParameters = JSONObject.parseObject(JSON.toJSONString(oldOrganization), Map.class); - //������������������������Map��������������������������� - Set<String> keys = organizationFormMap.keySet(); - for (String key : keys) { - String value = organizationFormMap.get(key);//��������������������� - if ("parentName".equals(key)) {//��������������������������� - if (updateForm.getParentId() != null) {//������������������������������������ - String oldParentName = "���"; - String newParentName = "���"; - if (!oldOrganization.getParentId().equals(0)) { - oldParentName = organizationMapper.selectById(oldOrganization.getParentId()).getName(); - } - if (!newOrganization.getParentId().equals(0)) { - newParentName = organizationMapper.selectById(newOrganization.getParentId()).getName(); - } - content.append(value + ":" + oldParentName + "->" + newParentName + ";"); - } - } else if ("expireTime".equals(key)) {//expireTime������������������������ - if (updateForm.getExpireTime() != null) { - Date oldExpireTime = oldOrganization.getExpireTime(); - Date newExpireTime = newOrganization.getExpireTime(); - String oldExpireTimeStr = DateUtils.dateToDateString(oldExpireTime, "yyyy-MM-dd"); - String newExpireTimeStr = DateUtils.dateToDateString(newExpireTime, "yyyy-MM-dd"); - content.append(value + ":" + oldExpireTimeStr + "->" + newExpireTimeStr + ";"); - } - } else {//������������������ - if (newParameters.get(key) != null) { - String newValue = "���"; - String oldValue = "���"; - if (newParameters.get(key) != null && !newParameters.get(key).equals(" ")) { - newValue = String.valueOf(newParameters.get(key)); - } - if (oldParameters.get(key) != null && !oldParameters.get(key).equals(" ")) { - oldValue = String.valueOf(oldParameters.get(key)); - } - content.append(value + ":" + oldValue + "->" + newValue + ";"); - } - } - } - logUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE); - } /** * @Description: ������������������������������������ @@ -495,5 +421,68 @@ } } + /** + * @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