lizijie
2022-01-14 9147ac833536f581c4ce8ff7504d7daf4a20cd9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package com.moral.api.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.entity.Organization;
import com.moral.api.entity.ServicesScope;
import com.moral.api.mapper.OrganizationMapper;
import com.moral.api.mapper.ServicesScopeMapper;
import com.moral.api.service.ServicesScopeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.util.LogUtils;
import com.moral.constant.Constants;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author moral
 * @since 2022-01-12
 */
@Service
public class ServicesScopeServiceImpl extends ServiceImpl<ServicesScopeMapper, ServicesScope> implements ServicesScopeService {
 
    @Autowired
    private ServicesScopeMapper servicesScopeMapper;
 
    @Autowired
    private OrganizationMapper organizationMapper;
 
    @Override
    public Map<String, Object> getDataByCondition(Map<String, Object> map) {
        Map<String,Object> resultMap = new HashMap<>();
        int current = Integer.parseInt(map.get("current").toString());
        int size = Integer.parseInt(map.get("size").toString());
        Page<ServicesScope> page = new Page<>(current, size);
        QueryWrapper<ServicesScope> servicesScopeWrapper = new QueryWrapper<>();
        servicesScopeWrapper.eq("is_delete",Constants.NOT_DELETE);
        if (!ObjectUtils.isEmpty(map.get("orgId"))){
            servicesScopeWrapper.eq("organization_id",Integer.parseInt(map.get("orgId").toString()));
        }
        if (!ObjectUtils.isEmpty(map.get("name"))){
            if (map.get("name") != ""){
                servicesScopeWrapper.like("name",map.get("name").toString());
            }
        }
        Page<ServicesScope> resultPage = servicesScopeMapper.selectPage(page, servicesScopeWrapper);
        List<ServicesScope> servicesScopes = resultPage.getRecords();
        SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<Map<String,Object>> servicesScopesList = new ArrayList<>();
        for (ServicesScope servicesScope:servicesScopes) {
            Map servicesScopeMap = JSON.parseObject(JSON.toJSONString(servicesScope),Map.class);
            if (ObjectUtils.isEmpty(servicesScopeMap.get("centerLongitude"))){
                servicesScopeMap.put("centerLongitude",null);
            }
            if (ObjectUtils.isEmpty(servicesScopeMap.get("centerLatitude"))){
                servicesScopeMap.put("centerLatitude",null);
            }
            if (ObjectUtils.isEmpty(servicesScopeMap.get("boundary"))){
                servicesScopeMap.put("boundary",null);
            }
            String createTime = SDF.format(servicesScope.getCreateTime());
            String updateTime = SDF.format(servicesScope.getUpdateTime());
            servicesScopeMap.put("createTime",createTime);
            servicesScopeMap.put("updateTime",updateTime);
            int organization_id = servicesScope.getOrganizationId();
            Organization organization = organizationMapper.selectById(organization_id);
            servicesScopeMap.put("organization_name",organization.getName());
            servicesScopesList.add(servicesScopeMap);
        }
        resultMap.put("servicesScopes",servicesScopesList);
        int totalNumber = servicesScopeMapper.selectCount(servicesScopeWrapper);
        resultMap.put("totalNumber",totalNumber);
        resultMap.put("current",current);
        int totalPageNumber = totalNumber/size;
        if(totalNumber%size != 0){
            totalPageNumber += 1;
        }
        resultMap.put("totalPageNumber",totalPageNumber);
        return resultMap;
    }
 
    @Transactional
    @Override
    public void insert(ServicesScope servicesScope) {
        int count = servicesScopeMapper.insert(servicesScope);
        if (count > 0) {
            //操作日志记录
            HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
            StringBuilder content = new StringBuilder();
            content.append("添加了服务范围:").append("id:").append(servicesScope.getId() + ";").append("name:").append(servicesScope.getName() + ";").append(":").append("organization_id:").append(servicesScope.getOrganizationId() + ";");
            LogUtils.saveOperationForManage(request, content.toString(), Constants.INSERT_OPERATE_TYPE);
        }
    }
 
    @Override
    @Transactional
    public void update(ServicesScope servicesScope) {
        ServicesScope oldServicesScope = servicesScopeMapper.selectById(servicesScope.getId());
        servicesScopeMapper.updateById(servicesScope);
        ServicesScope newServicesScope = servicesScopeMapper.selectById(servicesScope.getId());
        //操作日志记录
        HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("修改了政府站点:").append("id:").append(servicesScope.getId() + ";");
        if (!com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isEmpty(servicesScope.getOrganizationId())) {
            content.append("organization_id:").append(oldServicesScope.getOrganizationId()).append("->").append(newServicesScope.getOrganizationId()).append(";");
        }
        if (!com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isEmpty(servicesScope.getName())) {
            content.append("name:").append(oldServicesScope.getName()).append("->").append(newServicesScope.getName()).append(";");
        }
        if (!com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isEmpty(servicesScope.getCenterLongitude())) {
            content.append("center_longitude:").append(oldServicesScope.getCenterLongitude()).append("->").append(newServicesScope.getCenterLongitude()).append(";");
        }
        if (!com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isEmpty(servicesScope.getCenterLatitude())) {
            content.append("center_latitude:").append(oldServicesScope.getCenterLatitude()).append("->").append(newServicesScope.getCenterLatitude()).append(";");
        }
        if (!com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isEmpty(servicesScope.getBoundary())) {
            content.append("boundary:").append("数据过长").append(";");
        }
        LogUtils.saveOperationForManage(request, content.toString(), Constants.UPDATE_OPERATE_TYPE);
    }
 
    @Override
    @Transactional
    public void delete(int id) {
        ServicesScope servicesScope = new ServicesScope();
        servicesScope.setId(id);
        servicesScope.setIsDelete(Constants.DELETE);
        servicesScopeMapper.updateById(servicesScope);
        //操作日志记录
        HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
        StringBuilder content = new StringBuilder();
        content.append("删除了服务范围:").append("id:").append(id).append(";");
        LogUtils.saveOperationForManage(request, content.toString(), Constants.DELETE_OPERATE_TYPE);
    }
}