广州市综治平台后端
xusd
2025-06-07 36306491396230522fa20585c2621a7fc899849a
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package cn.huge.module.ctuser.controller.client;
 
import cn.huge.base.common.utils.ObjectUtils;
import cn.huge.base.common.utils.ReturnFailUtils;
import cn.huge.base.common.utils.ReturnSucUtils;
import cn.huge.base.config.CurrentUser;
import cn.huge.module.ctuser.domain.po.CtDept;
import cn.huge.module.ctuser.domain.po.CtUnit;
import cn.huge.module.ctuser.domain.po.CtUser;
import cn.huge.module.ctuser.service.CtDeptService;
import cn.huge.module.ctuser.service.CtUnitService;
import cn.huge.module.ctuser.service.CtUserService;
import cn.huge.module.cust.constant.UserBaseConsts;
import cn.huge.module.cust.dto.CtUnitDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartHttpServletRequest;
 
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * @title: 客户组织信息表接口api-微服务调用
 * @description: 客户组织信息表接口api-微服务调用
 * @company: hugeinfo
 * @author: liyj
 * @time: 2024-08-19 20:04:19
 * @version: 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/api/client/ctUnit")
public class CtUnitClientController {
 
    @Autowired(required = false)
    private HttpServletRequest request;
 
    @Autowired
    private CtUnitService service;
    @Autowired
    private CtUserService ctUserService;
    @Autowired
    private CtDeptService ctDeptService;
 
    /**
     * 根据id查询组织信息
     * @url {ctx}/api/client/ctUnit/getUnitById
     * @param unitId 组织编号
     * @return Object
     */
    @GetMapping("/getUnitById")
    public Object getUnitById(@RequestParam(value = "unitId") String unitId) {
        try {
            CtUnit ctUnit = service.getById(unitId);
            if (ObjectUtils.isNotEmpty(ctUnit)){
                CtUnitDTO ctUnitDTO = new CtUnitDTO();
                BeanUtils.copyProperties(ctUnit, ctUnitDTO);
                return ReturnSucUtils.getRepInfo(ctUnitDTO);
            }else {
                return ReturnFailUtils.getRepInfo("查询组织不存在!");
            }
        } catch (Exception e) {
            log.error("Controller接口[CtUnitClientController.getUnitById]请求异常:"+e, e);
            return ReturnFailUtils.getRepInfo();
        }
    }
 
    /**
     * 获取上级综治中心
     * @url {ctx}/api/client/ctUnit/getParentZzzxUnit
     * @param unitId 组织编号
     * @return Object
     */
    @GetMapping("/getParentZzzxUnit")
    public Object getParentZzzxUnit(@RequestParam(value = "unitId")  String unitId) {
        try {
            return ReturnSucUtils.getRepInfo(service.getParentZzzx(unitId));
        } catch (Exception e) {
            return ReturnFailUtils.getRepInfo(e.getMessage());
        }
    }
 
    /**
     * 获取本级综治中心
     * @url {ctx}/api/client/ctUnit/getBjZzzx
     * @param unitId 组织编号
     * @return Object
     */
    @GetMapping("/getBjZzzx")
    public Object getBjZzzx(@RequestParam(value = "unitId")  String unitId) {
        try {
            return ReturnSucUtils.getRepInfo(service.getBjZzzx(unitId));
        } catch (Exception e) {
            return ReturnFailUtils.getRepInfo(e.getMessage());
        }
    }
 
    /**
     * 查询用户所在的单位信息
     * @url {ctx}/api/client/ctUnit/getUnitByUserId
     * @param userId 用户编号
     * @return Object
     */
    @GetMapping("/getUnitByUserId")
    public Object getUnitByUserId(@RequestParam(value = "userId") String userId) {
        try {
            CtUser ctUser = ctUserService.getById(userId);
            CtUnit ctUnit = service.getById(ctUser.getUnitId());
            if (ObjectUtils.isNotEmpty(ctUnit)){
                CtUnitDTO ctUnitDTO = new CtUnitDTO();
                BeanUtils.copyProperties(ctUnit, ctUnitDTO);
                return ReturnSucUtils.getRepInfo(ctUnitDTO);
            }else {
                return ReturnFailUtils.getRepInfo("查询组织不存在!");
            }
        } catch (Exception e) {
            return ReturnFailUtils.getRepInfo();
        }
    }
 
    /**
     * 更新镇街的部门变为直属部门组织
     * @url {ctx}/api/client/ctUnit/upZjDeptToUnit
     * @return Object
     */
    @GetMapping("/upZjDeptToUnit")
    public Object upZjDeptToUnit() {
        try {
            Date newDate = new Date();
            QueryWrapper<CtUnit> ctUnitQueryWrapper = new QueryWrapper<>();
            ctUnitQueryWrapper.eq("unit_grade", UserBaseConsts.UNIT_GRADE_3).eq("unit_type", UserBaseConsts.UNIT_TYPE_101);
            List<CtUnit> zjCtUnitList = service.list(ctUnitQueryWrapper);
            int i = 0;
            for (CtUnit zjCtUnit: zjCtUnitList){
                QueryWrapper<CtDept> ctDeptQueryWrapper = new QueryWrapper<>();
                ctDeptQueryWrapper.eq("unit_id", zjCtUnit.getId());
                List<CtDept> ctDeptList = ctDeptService.list(ctDeptQueryWrapper);
                for (CtDept ctDept: ctDeptList){
                    if (StringUtils.isNotEmpty(ctDept.getParentId()) && "root".equals(ctDept.getParentId())){
                        i++;
                    }else {
                        CtUnit ctUnit = new CtUnit();
                        ctUnit.setId(ctDept.getId());
                        ctUnit.setLevel(zjCtUnit.getLevel() + 1);
                        ctUnit.setParentId(zjCtUnit.getId());
                        ctUnit.setUnitGrade(UserBaseConsts.UNIT_GRADE_3);
                        ctUnit.setUnitFun(UserBaseConsts.UNIT_FUN_1);
                        ctUnit.setUnitType(UserBaseConsts.UNIT_TYPE_102);
                        ctUnit.setCourtStatus(UserBaseConsts.COURT_STATUS_0);
                        ctUnit.setUnitName(ctDept.getName());
                        ctUnit.setUnitDes(zjCtUnit.getUnitName() + "-" + ctDept.getName());
                        ctUnit.setJoinWay(UserBaseConsts.JOIN_WAY_1);
                        ctUnit.setProv(zjCtUnit.getProv());
                        ctUnit.setProvName(zjCtUnit.getProvName());
                        ctUnit.setCity(zjCtUnit.getCity());
                        ctUnit.setCityName(zjCtUnit.getCityName());
                        ctUnit.setArea(zjCtUnit.getArea());
                        ctUnit.setAreaName(zjCtUnit.getAreaName());
                        ctUnit.setRoad(zjCtUnit.getRoad());
                        ctUnit.setRoadName(zjCtUnit.getRoadName());
                        ctUnit.setVillage(zjCtUnit.getVillage());
                        ctUnit.setVillageName(zjCtUnit.getVillageName());
                        ctUnit.setAddr(zjCtUnit.getAddr());
                        ctUnit.setLng(zjCtUnit.getLng());
                        ctUnit.setLat(zjCtUnit.getLat());
                        ctUnit.setFindStatus(UserBaseConsts.FIND_STATUS_0);
                        ctUnit.setDispStatus(UserBaseConsts.DISP_STATUS_0);
                        ctUnit.setDeleteStatus(zjCtUnit.getDeleteStatus());
                        ctUnit.setCustId(zjCtUnit.getCustId());
                        ctUnit.setCreateTime(newDate);
                        ctUnit.setUpdateTime(newDate);
                        service.save(ctUnit);
                        // 更新人
                        QueryWrapper<CtUser> ctUserQueryWrapper = new QueryWrapper<>();
                        ctUserQueryWrapper.eq("dept_id", ctDept.getId());
                        List<CtUser> ctUserList = ctUserService.list(ctUserQueryWrapper);
                        for (CtUser ctUser : ctUserList) {
                            ctUser.setUnitId(ctUnit.getId());
                            ctUser.setUnitName(ctUnit.getUnitName());
                            ctUser.setDeptId(null);
                            ctUser.setDeptName(null);
                            ctUserService.saveOrUpdate(ctUser);
                        }
                    }
                }
            }
            log.info("过滤"+i+"部门");
            return ReturnSucUtils.getRepInfo(zjCtUnitList);
        } catch (Exception e) {
            log.error("[CtUnitClientController.upZjDeptToUnit]请求失败,异常信息:"+e, e);
            return ReturnFailUtils.getRepInfo();
        }
    }
 
    /**
     * 根据条件查询单位信息
     * @url {ctx}/api/client/ctUnit/listByTerms
     * @return Object
     */
    @PostMapping("/listByTerms")
    public Object listByTerms(@RequestBody Map<String, Object> terms) {
        try {
            return ReturnSucUtils.getRepInfo(service.listTerms(terms));
        } catch (Exception e) {
            log.error("[CtUnitClientController.listByTerms]请求失败,异常信息:"+e, e);
            return ReturnFailUtils.getRepInfo();
        }
    }
}