From 19b72fbd2e6b30a23a06dd284619784a096bc896 Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Thu, 26 Aug 2021 11:33:56 +0800 Subject: [PATCH] screen-manage 单位转换插入添加日志功能 修复organization插入Bug --- screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java | 142 +++++++++++++++++++++++------------------------ 1 files changed, 70 insertions(+), 72 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 5e40443..0aa31ac 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 @@ -20,9 +20,11 @@ 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; @@ -34,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; @@ -46,7 +50,6 @@ * @since 2021-04-06 */ @Service -@ConfigurationProperties(prefix = "log-aspect") public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService { @Autowired @@ -64,12 +67,6 @@ @Autowired MonitorPointService monitorPointService; - Map<String, String> organizationFormMap; - - public void setOrganizationFormMap(Map<String, String> organizationFormMap) { - this.organizationFormMap = organizationFormMap; - } - /** * @Description: ������������������ * @Param: [organizationInsertForm] @@ -77,8 +74,6 @@ * @Author: ��������� * @Date: 2021/3/22 */ - - @Override @Transactional public OrganizationDTO insertOrganization(OrganizationInsertForm organizationInsertForm) { @@ -105,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; } @@ -151,7 +143,7 @@ organizationDTO.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); //������������������ - insertUpdateLog(organizationUpdateForm, organization, oldOrganization); + updateLog(oldOrganization,organization); return organizationDTO; } @@ -247,14 +239,13 @@ 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; } @@ -396,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> @@ -486,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, "���������������"); + logUtils.saveOperationForManage(content, Constants.UPDATE_OPERATE_TYPE); + } + } -- Gitblit v1.8.0