| | |
| | | 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.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.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * </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: 添加客户组织 |
| | |
| | | } |
| | | //插入组织 |
| | | 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; |
| | | } |
| | | |
| | |
| | | //更新组织 |
| | | organizationMapper.updateById(organization); |
| | | |
| | | //获取更新后的组合 |
| | | //获取更新后的组织 |
| | | organization = organizationMapper.selectById(organization.getId()); |
| | | |
| | | //封装DTO信息 |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | Integer provinceCode = organizationQueryForm.getProvinceCode(); |
| | | Integer cityCode = organizationQueryForm.getCityCode(); |
| | | Integer areaCode = organizationQueryForm.getAreaCode(); |
| | | Long townCode = organizationQueryForm.getTownCode(); |
| | | Long villageCode = organizationQueryForm.getVillageCode(); |
| | | String phone = organizationQueryForm.getPhone(); |
| | | String email = organizationQueryForm.getEmail(); |
| | | String wechat = organizationQueryForm.getWechat(); |
| | |
| | | queryWrapper.eq("province_code", provinceCode); |
| | | queryWrapper.eq("city_code", cityCode); |
| | | queryWrapper.eq("area_code", areaCode); |
| | | queryWrapper.eq("town_code", townCode); |
| | | queryWrapper.eq("village_code", villageCode); |
| | | queryWrapper.like("phone", phone); |
| | | queryWrapper.like("email", email); |
| | | queryWrapper.like("wechat", wechat); |
| | |
| | | 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()); |
| | | Organization parent = organizationMapper.selectById(child.getParentId());//查找父组织 |
| | | //拼接地址字符串 |
| | | changeAddressByOrganization(child); |
| | | resultDto.setOrganization(child); |
| | | resultDto.setParentOrganization(parent); |
| | | organizationDTOS.add(resultDto); |
| | |
| | | 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()); |
| | | } |
| | | } |