From 23e43d94105c6f3676e879d2cc271d0bec63f081 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Tue, 31 Aug 2021 13:13:41 +0800 Subject: [PATCH] screen-manage kafka消费者更换主题名称 --- screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java | 185 +++++++++++++++++++++++++-------------------- 1 files changed, 103 insertions(+), 82 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 5886add..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) { @@ -99,10 +100,7 @@ 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; } @@ -145,7 +143,7 @@ organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); //������������������ - insertUpdateLog(organizationUpdateForm, organization, oldOrganization); + updateLog(oldOrganization,organization); return organizationDTO; } @@ -166,6 +164,14 @@ //������ 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); @@ -179,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)) {//��������������������� @@ -199,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 @@ -220,18 +226,26 @@ } } + //������������������ + 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()); //������������������ - 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; } @@ -373,62 +387,6 @@ /** - * @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: ������������������������������������ * @Param: [] * @return: java.util.List<com.moral.api.entity.Organization> @@ -463,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