From 4d5eff3b824dac8e50400b2ec1114cba4ed6a87c Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Wed, 07 Apr 2021 17:05:43 +0800
Subject: [PATCH] screen-manage     完成sysarea模块查询     拦截器逻辑代码完成     修改organization和accountBug

---
 screen-manage/src/main/java/com/moral/api/service/impl/OrganizationServiceImpl.java |  258 +++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 216 insertions(+), 42 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 dc16393..705f087 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,8 +1,11 @@
 package com.moral.api.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 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.Organization;
 import com.moral.api.mapper.OrganizationMapper;
 import com.moral.api.pojo.dto.organization.OrganizationDTO;
@@ -13,14 +16,22 @@
 import com.moral.api.pojo.form.organization.OrganizationUpdateForm;
 import com.moral.api.service.OrganizationService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.api.util.LogUtils;
 import com.moral.constant.Constants;
 import com.moral.constant.ResponseCodeEnum;
+import com.moral.util.ConvertUtils;
+import com.moral.util.DateUtils;
+import lombok.Data;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.ObjectUtils;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
 
-import java.util.List;
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
 
 /**
  * <p>
@@ -28,13 +39,23 @@
  * </p>
  *
  * @author moral
- * @since 2021-03-09
+ * @since 2021-04-06
  */
 @Service
+@ConfigurationProperties(prefix = "log-aspect")
 public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService {
 
     @Autowired
     OrganizationMapper organizationMapper;
+
+    @Autowired
+    LogUtils logUtils;
+
+    Map<String, String> organizationFormMap;
+
+    public void setOrganizationFormMap(Map<String, String> organizationFormMap) {
+        this.organizationFormMap = organizationFormMap;
+    }
 
     /**
      * @Description: ������������������
@@ -55,8 +76,8 @@
         existOrganization.setName(organization.getName());
         existOrganization.setIsDelete(Constants.NOT_DELETE);
         queryWrapper.setEntity(existOrganization);
-        List<Organization> existOrganizations = organizationMapper.selectList(queryWrapper);
-        if (!ObjectUtils.isEmpty(existOrganizations)) {
+        Organization existOrganizationResult = organizationMapper.selectOne(queryWrapper);
+        if (!ObjectUtils.isEmpty(existOrganizationResult)) {
             organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_EXIST.getCode());
             organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_EXIST.getMsg());
             return organizationDTO;
@@ -77,27 +98,35 @@
         }
         //������������
         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());
         return organizationDTO;
     }
 
     /**
-    * @Description: ������������������
-            * @Param: [organizationUpdateForm]
-            * @return: com.moral.api.pojo.dto.organization.OrganizationDTO
-            * @Author: ���������
-            * @Date: 2021/3/24
-            */
+     * @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> existWrapper = new QueryWrapper<>();
         Organization existOrganization = new Organization();
@@ -105,15 +134,16 @@
         existOrganization.setIsDelete(Constants.NOT_DELETE);
         existWrapper.setEntity(existOrganization);
         existOrganization = organizationMapper.selectOne(existWrapper);
-        if(ObjectUtils.isEmpty(existOrganization)){
+        if (ObjectUtils.isEmpty(existOrganization)) {
             organizationDTO.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode());
             organizationDTO.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
             return organizationDTO;
         }
+
         //������������������������������������������������������
         Integer parentId = organization.getParentId();
         Organization parentOrganization = new Organization();
-        if (!ObjectUtils.isEmpty(parentId)&&parentId!=0) {
+        if (!ObjectUtils.isEmpty(parentId) && parentId != 0) {
             QueryWrapper<Organization> existParentWrapper = new QueryWrapper<>();
             parentOrganization.setId(parentId);
             parentOrganization.setIsDelete(Constants.NOT_DELETE);
@@ -125,9 +155,11 @@
                 return organizationDTO;
             }
         }
+
         //������������
         organizationMapper.updateById(organization);
-        //������������������������
+
+        //������������������������
         organization = organizationMapper.selectById(organization.getId());
 
         //������DTO������
@@ -135,16 +167,63 @@
         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()).append(";");
+        //������������������Map
+        Map<String, Object> newParameters = JSONObject.parseObject(JSON.toJSONString(organizationUpdateForm), Map.class);
+        Map<String, Object> oldParameters = JSONObject.parseObject(JSON.toJSONString(existOrganization), Map.class);
+        Set<String> keys = organizationFormMap.keySet();
+        for (String key : keys) {
+            String value = organizationFormMap.get(key);
+            if ("parentName".equals(key)) {//���������������������������
+                if (organizationUpdateForm.getParentId() != null) {//������������������������������������
+                    String oldParentName = "���";
+                    String newParentName = "���";
+                    if (!existOrganization.getParentId().equals(0)) {
+                        oldParentName = organizationMapper.selectById(existOrganization.getParentId()).getName();
+                    }
+                    if (!organization.getParentId().equals(0)) {
+                        newParentName = organizationMapper.selectById(organization.getParentId()).getName();
+                    }
+                    content.append(value + ":" + oldParentName + "->" + newParentName + ";");
+                }
+            } else if ("expireTime".equals(key)) {//expireTime������������������������
+                if (organizationUpdateForm.getExpireTime() != null) {
+                    Date oldExpireTime = existOrganization.getExpireTime();
+                    Date newExpireTime = organization.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());
+
         return organizationDTO;
     }
 
     /**
-    * @Description: ������������������
-            * @Param: [organizationDeleteForm]
-            * @return: com.moral.api.pojo.dto.organization.OrganizationDTO
-            * @Author: ���������
-            * @Date: 2021/3/25
-            */
+     * @Description: ������������������
+     * @Param: [organizationDeleteForm]
+     * @return: com.moral.api.pojo.dto.organization.OrganizationDTO
+     * @Author: ���������
+     * @Date: 2021/3/25
+     */
     @Override
     @Transactional
     public OrganizationDTO deleteOrganization(OrganizationDeleteForm form) {
@@ -158,57 +237,152 @@
         QueryWrapper queryExistWrapper = new QueryWrapper();
         queryExistWrapper.setEntity(existOrganization);
         existOrganization = organizationMapper.selectOne(queryExistWrapper);
-        if(ObjectUtils.isEmpty(existOrganization)){
+        if (ObjectUtils.isEmpty(existOrganization)) {
             dto.setCode(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getCode());
             dto.setMsg(ResponseCodeEnum.ORGANIZATION_NOT_EXIST.getMsg());
             return dto;
         }
         //������������������
         UpdateWrapper deleteWrapper = new UpdateWrapper();
-        deleteWrapper.eq("id",id);
-        deleteWrapper.set("is_delete",Constants.DELETE);
-        organizationMapper.update(null,deleteWrapper);
+        deleteWrapper.eq("id", id);
+        deleteWrapper.set("is_delete", Constants.DELETE);
+        organizationMapper.update(null, deleteWrapper);
         //������������������������������������������������������������������parentId���0
-        if(form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)){
+        if (form.getDeleteChildren().equals(Constants.DELETE_CHILDREN_ORG)) {
             UpdateWrapper deleteChildrenWrapper = new UpdateWrapper();
-            deleteChildrenWrapper.eq("parent_id",id);
-            deleteChildrenWrapper.set("is_delete",Constants.DELETE);
-            organizationMapper.update(null,deleteChildrenWrapper);
-        }else{
+            deleteChildrenWrapper.eq("parent_id", id);
+            deleteChildrenWrapper.set("is_delete", Constants.DELETE);
+            organizationMapper.update(null, deleteChildrenWrapper);
+        } else {
             UpdateWrapper updateChildrenWrapper = new UpdateWrapper();
-            updateChildrenWrapper.eq("parent_id",id);
-            updateChildrenWrapper.set("parent_id",0);
-            organizationMapper.update(null,updateChildrenWrapper);
+            updateChildrenWrapper.eq("parent_id", id);
+            updateChildrenWrapper.set("parent_id", 0);
+            organizationMapper.update(null, updateChildrenWrapper);
         }
 
+        //������������������
         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("���������������������");
+        logUtils.saveOperationForManage(request, content.toString());
+
         return dto;
     }
 
     /**
-    * @Description: ������������������
-            * @Param: [organizationQueryForm]
-            * @return: com.moral.api.pojo.dto.organization.OrganizationQueryDTO
-            * @Author: ���������
-            * @Date: 2021/3/25
-            */
+     * @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();
         //������
-        Organization organization = organizationQueryForm.formConvertEntity();
         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);
-        QueryWrapper<Organization> queryWrapper = new QueryWrapper<>();
-        return null;
+        //������������
+        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<>();
+        //������������������������������������������organization���DTO���
+        for (Organization child : organizations) {
+            OrganizationDTO resultDto = new OrganizationDTO();
+            Organization parent = organizationMapper.selectById(child.getParentId());//���������������
+            //���������������������
+            changeAddressByOrganization(child);
+            resultDto.setOrganization(child);
+            resultDto.setParentOrganization(parent);
+            organizationDTOS.add(resultDto);
+        }
+
+        dto.setCode(ResponseCodeEnum.SUCCESS.getCode());
+        dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg());
+        dto.setOrganizationDTOS(organizationDTOS);
+        dto.setCurrent(page.getCurrent());
+        dto.setPage(page.getPages());
+        dto.setSize(page.getSize());
+        dto.setTotal(page.getTotal());
+        return dto;
     }
 
+    /**
+     * @Description: ���organization���address���������provinceName cityName areaName������������
+     * @Param: [organization]
+     * @return: void
+     * @Author: ���������
+     * @Date: 2021/4/2
+     */
+    public void changeAddressByOrganization(Organization organization) {
+        String provinceName = organization.getProvinceName();
+        String cityName = organization.getCityName();
+        String areaName = organization.getAreaName();
+        String address = organization.getAddress();
 
+        StringBuilder newAddress = new StringBuilder();
+        if (provinceName != null)
+            newAddress.append(provinceName);
+        if (cityName != null)
+            newAddress.append(cityName);
+        if (areaName != null)
+            newAddress.append(areaName);
+        if (address != null)
+            newAddress.append(address);
+
+        organization.setAddress(newAddress.toString());
+    }
 }

--
Gitblit v1.8.0