e8f42d01f88e43bf0036c6516bbdb99d2aa22228.svn-base 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. package cn.com.goldenwater.dcproj.controller.ducha;
  2. import cn.com.goldenwater.core.web.BaseController;
  3. import cn.com.goldenwater.core.web.BaseResponse;
  4. import cn.com.goldenwater.dcproj.dto.*;
  5. import cn.com.goldenwater.dcproj.model.OlBisInspOrg;
  6. import cn.com.goldenwater.dcproj.param.InGroupResParam;
  7. import cn.com.goldenwater.dcproj.param.InspObjParam;
  8. import cn.com.goldenwater.dcproj.service.OlBisInspOrgService;
  9. import cn.com.goldenwater.dcproj.service.SupervisionPlanService;
  10. import cn.com.goldenwater.dcproj.util.CheckUtil;
  11. import cn.com.goldenwater.dcproj.utils.AdLevelUtil;
  12. import cn.com.goldenwater.dcproj.utils.TimeRangeUtil;
  13. import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
  14. import com.alibaba.fastjson.JSON;
  15. import com.github.pagehelper.PageInfo;
  16. import io.swagger.annotations.Api;
  17. import io.swagger.annotations.ApiOperation;
  18. import io.swagger.annotations.ApiParam;
  19. import org.apache.commons.lang.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.scheduling.annotation.Async;
  23. import org.springframework.web.bind.annotation.*;
  24. import org.springframework.web.multipart.MultipartFile;
  25. import javax.servlet.http.HttpServletRequest;
  26. import javax.servlet.http.HttpServletResponse;
  27. import java.io.File;
  28. import java.text.SimpleDateFormat;
  29. import java.util.ArrayList;
  30. import java.util.HashMap;
  31. import java.util.List;
  32. import java.util.Map;
  33. /**
  34. * Created by 61618 on 2019/4/17.
  35. */
  36. @Api(value = "督查计划相关接口", tags = "督查计划相关接口")
  37. @RestController
  38. @RequestMapping("/supervision/plan")
  39. public class SupervisionPlanController extends BaseController {
  40. @Autowired
  41. private SupervisionPlanService supervisionPlanService;
  42. @Value("${export.templatePath}")
  43. private String templatePath;
  44. @Value("${impExcel.basePath}")
  45. private String impExcelPath;
  46. @Autowired
  47. private OlBisInspOrgService olBisInspOrgService;
  48. private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  49. @ApiOperation(value = "根据用户信息与督查计划类型获取该用户可示可管理的单一机构的所有批次")
  50. @RequestMapping(value = "getNodeByPersid", method = RequestMethod.GET)
  51. public BaseResponse<List<AllNodeDto>> getNodeByPersid(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid,
  52. @ApiParam(name = "ptype", value = "ptype", required = true) @RequestParam String ptype) {
  53. List<AllNodeDto> allNodeDtoList = this.supervisionPlanService.getNodeByPersid(persid, ptype, getCurrentOrgId());
  54. return buildSuccessResponse(allNodeDtoList);
  55. }
  56. @ApiOperation(value = "获取督查组相关的对象、人员、区域信息(新)")
  57. @RequestMapping(value = "getAllInfoByPersidAndOrgId", method = RequestMethod.GET)
  58. public BaseResponse<List<PersAllInfoDto>> getAllInfoByPersidAndOrgId(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid,
  59. @ApiParam(name = "inspYear", value = "inspYear", required = false) @RequestParam(required = false) String inspYear,
  60. @ApiParam(name = "inspMnth", value = "inspMnth", required = false) @RequestParam(required = false) String inspMnth,
  61. @ApiParam(name = "orgId", value = "机构id", required = true) @RequestParam String orgId,
  62. @ApiParam(name = "yearPlanId", value = "年度id", required = true) @RequestParam String yearPlanId) {
  63. List<PersAllInfoDto> allNodeDtoList = this.supervisionPlanService.getAllInfoByPersidAndOrgId(persid, inspYear, inspMnth, orgId, yearPlanId);
  64. return buildSuccessResponse(allNodeDtoList);
  65. }
  66. @ApiOperation(value = "根据组id查询督查区域")
  67. @RequestMapping(value = "/getPersAllAreaDtoList", method = RequestMethod.POST)
  68. public BaseResponse<List<PersAllAreaDto>> getPersAllAreaDtoList(@PathVariable String id) {
  69. List<PersAllAreaDto> dtos = this.supervisionPlanService.getPersAllAreaDtoList(id, getCurrentOrgId());
  70. return buildSuccessResponse(dtos);
  71. }
  72. @ApiOperation(value = "获取督查组相关的对象、人员、区域信息")
  73. @RequestMapping(value = "getAllInfoByPersid", method = RequestMethod.GET)
  74. public BaseResponse<List<PersAllInfoDto>> getAllInfoByPersid(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid,
  75. @ApiParam(name = "ptype", value = "ptype", required = true) @RequestParam String ptype,
  76. @ApiParam(name = "id", value = "id", required = true) @RequestParam String id) {
  77. List<PersAllInfoDto> allNodeDtoList = this.supervisionPlanService.getAllInfoByPersid(persid, ptype, id, getCurrentOrgId());
  78. return buildSuccessResponse(allNodeDtoList);
  79. }
  80. @ApiOperation(value = "查询不在该督查组下的水库", notes = "查询不在该督查组下的水库")
  81. @RequestMapping(value = "/getSupResByGroup", method = RequestMethod.POST)
  82. public BaseResponse<PageInfo<AttSupResBase>> getSupResByGroup(@RequestBody InGroupResParam inGroupResParam) {
  83. inGroupResParam.setProvince(olBisInspOrgService.getProvinceFlag(getCurrentOrgId()));
  84. inGroupResParam.setOrgId(getCurrentOrgId());
  85. PageInfo<AttSupResBase> list = supervisionPlanService.getSupResByGroup(inGroupResParam);
  86. return buildSuccessResponse(list);
  87. }
  88. @ApiOperation(value = "查询不在督查组督查范围内的督查对象")
  89. @RequestMapping(value = "/getSupObjListNotInspGroupId", method = RequestMethod.GET)
  90. public BaseResponse<Object> getSupObjListNotInspGroupId(@ApiParam(name = "InspObjParam", value = "InspObjParam") InspObjParam inspObjParam) {
  91. OlBisInspOrg org = olBisInspOrgService.get(getCurrentOrgId());
  92. CheckUtil.notNull(org, "机构ID错误", getCurrentOrgId());
  93. inspObjParam.setProvince(AdLevelUtil.getAddvcd(org.getAdCode()));
  94. inspObjParam.setOrgId(getCurrentOrgId());
  95. if (StringUtils.isNotBlank(inspObjParam.getOrderBy()) && inspObjParam.getOrderBy().contains("undefined")) {
  96. inspObjParam.setOrderBy("");
  97. }
  98. PageInfo pageInfo = supervisionPlanService.getSupObjListNotInspGroupId(inspObjParam);
  99. return buildSuccessResponse(pageInfo);
  100. }
  101. @ApiOperation(value = "添加督查人员、督查对象、督查区域")
  102. @RequestMapping(value = "/insertSupervisionObj", method = RequestMethod.POST)
  103. public BaseResponse<Object> insertSupervisionObj(@ApiParam(name = "PersAllInfoDto", value = "PersAllInfoDto") @RequestBody PersAllInfoDto persAllInfoDto) {
  104. if ((StringUtils.isNotBlank(persAllInfoDto.getSttm()) || StringUtils.isNotBlank(persAllInfoDto.getEntm())) && StringUtils.isBlank(persAllInfoDto.getIsInsert())) {
  105. Map<String, Object> map = isValiTm(persAllInfoDto);
  106. if (map.get("msg") != null) {
  107. return buildSuccessResponse(map);
  108. }
  109. }
  110. persAllInfoDto.setOrgId(getCurrentOrgId());
  111. persAllInfoDto.setPersid(getCurrentPersId());
  112. persAllInfoDto.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId()));
  113. SupInsertResult supInsertResult = supervisionPlanService.insertSupervisionObj(persAllInfoDto);
  114. return buildSuccessResponse(supInsertResult);
  115. }
  116. @ApiOperation(value = "添加督查人员、督查对象、督查区域")
  117. @RequestMapping(value = "/insertAllSupervisionObj", method = RequestMethod.POST)
  118. public BaseResponse<Object> insertAllSupervisionObj(@ApiParam(name = "InspObjParam", value = "InspObjParam") InspObjParam inspObjParam) {
  119. batchInsert(inspObjParam);
  120. return buildSuccessResponse("添加成功!");
  121. }
  122. @Async
  123. protected void batchInsert(InspObjParam inspObjParam) {
  124. OlBisInspOrg org = olBisInspOrgService.get(getCurrentOrgId());
  125. CheckUtil.notNull(org, "机构ID错误", getCurrentOrgId());
  126. inspObjParam.setProvince(AdLevelUtil.getAddvcd(org.getAdCode()));
  127. inspObjParam.setOrgId(getCurrentOrgId());
  128. if (StringUtils.isNotBlank(inspObjParam.getOrderBy()) && inspObjParam.getOrderBy().contains("undefined")) {
  129. inspObjParam.setOrderBy("");
  130. }
  131. List<SupervisionPlanDto> pageInfo = supervisionPlanService.getObjListNotGroupId(inspObjParam);
  132. PersAllInfoDto persAllInfoDto = new PersAllInfoDto();
  133. persAllInfoDto.setId(inspObjParam.getInspGroupId());
  134. List<PersAllObjDto> objList = new ArrayList<>();
  135. for (int i = 0; i < pageInfo.size(); i++) {
  136. PersAllObjDto persAllObjDto = new PersAllObjDto();
  137. persAllObjDto.setPtype(inspObjParam.getObjType());
  138. persAllObjDto.setCode(pageInfo.get(i).getCode());
  139. persAllObjDto.setName(pageInfo.get(i).getNm());
  140. objList.add(persAllObjDto);
  141. }
  142. persAllInfoDto.setPersAllObjDtoList(objList);
  143. persAllInfoDto.setPersAllAreaDtoList(new ArrayList<>());
  144. persAllInfoDto.setPersAllDtoList(new ArrayList<>());
  145. persAllInfoDto.setOrgId(getCurrentOrgId());
  146. persAllInfoDto.setPersid(getCurrentPersId());
  147. persAllInfoDto.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId()));
  148. supervisionPlanService.insertSupervisionObj(persAllInfoDto);
  149. }
  150. public Map<String, Object> isValiTm(PersAllInfoDto persAllInfoDto) {
  151. String msg = "";
  152. Map<String, Object> map = new HashMap<>();
  153. Map<String, String> mapGroup = supervisionPlanService.getYearMonth(persAllInfoDto.getId());
  154. if (StringUtils.isNotBlank(persAllInfoDto.getSttm())) {
  155. mapGroup.put("STTM", persAllInfoDto.getSttm());
  156. }
  157. if (StringUtils.isNotBlank(persAllInfoDto.getEntm())) {
  158. mapGroup.put("ENTM", persAllInfoDto.getEntm());
  159. }
  160. List<String> adCodeList = new ArrayList<String>();
  161. List<String> errorList = new ArrayList<String>();
  162. List<PersAllInfoDto> allNodeDtoList = this.supervisionPlanService.getAllInfoByPersidAndOrgId(getCurrentPersId(), mapGroup.get("INSP_YEAR"), mapGroup.get("INSP_MNTH"), getCurrentOrgId(), null);
  163. if (allNodeDtoList != null && allNodeDtoList.size() > 0 && (StringUtils.isNotBlank(mapGroup.get("STTM")) || StringUtils.isNotBlank(mapGroup.get("ENTM")))) {
  164. allNodeDtoList.forEach(item -> {
  165. if (persAllInfoDto.getId().equals(item.getId()) && item.getPersAllAreaDtoList() != null && item.getPersAllAreaDtoList().size() > 0) {
  166. item.getPersAllAreaDtoList().forEach(item1 -> {
  167. adCodeList.add(item1.getAdCode());
  168. });
  169. }
  170. });
  171. if (adCodeList.size() > 0) {
  172. allNodeDtoList.forEach(item -> {
  173. long count = 0;
  174. if (!persAllInfoDto.getId().equals(item.getId()) && item.getPersAllAreaDtoList() != null && item.getPersAllAreaDtoList().size() > 0) {
  175. count = item.getPersAllAreaDtoList().stream().filter(item1 -> adCodeList.indexOf(item1.getAdCode()) > -1).count();
  176. }
  177. try {
  178. if (count > 0 && TimeRangeUtil.isTimeRange(item, mapGroup)) {
  179. errorList.add("(检查计划事项:" + item.getChkName() + "-组名:" + item.getNm() + ")");
  180. }
  181. } catch (Exception e) {
  182. e.printStackTrace();
  183. }
  184. });
  185. }
  186. }
  187. if (errorList.size() > 0) {
  188. msg = "(检查计划事项:" + mapGroup.get("CHK_NAME") + "-当前组:" + mapGroup.get("PNM") + ")与其他组" + String.join(",", errorList) + "重叠";
  189. map.put("msg", msg);
  190. }
  191. return map;
  192. }
  193. @ApiOperation(value = "督查组人员分配角色")
  194. @RequestMapping(value = "/assignmentRole", method = RequestMethod.POST)
  195. public BaseResponse assignmentRole(@ApiParam(name = "objIdDto", value = "ObjIdDto") ObjIdDto objIdDto) {
  196. int i = supervisionPlanService.assignmentRole(objIdDto);
  197. return buildSuccessResponse();
  198. }
  199. @ApiOperation(value = "获取人员类型")
  200. @GetMapping(value = "/getPersType")
  201. public BaseResponse<List<PersTypeDto>> getPersType(@RequestParam String persid, @RequestParam(value = "yearId", required = false) String yearId) {
  202. List<PersTypeDto> persTypeDtoList = supervisionPlanService.getPersType(persid, getCurrentOrgId(), yearId);
  203. return buildSuccessResponse(persTypeDtoList);
  204. }
  205. @ApiOperation(value = "获取人员类型(根据接收单位)")
  206. @GetMapping(value = "/getPersTypeByPersid")
  207. public BaseResponse<List<PersTypeDto>> getPersTypeByPersid(@RequestParam String persid) {
  208. List<PersTypeDto> persTypeDtoList = supervisionPlanService.getPersTypeByPersid(persid, getCurrentOrgId());
  209. return buildSuccessResponse(persTypeDtoList);
  210. }
  211. @ApiOperation(value = "清空督查对象")
  212. @RequestMapping(value = "/cleanObjData", method = RequestMethod.GET)
  213. public BaseResponse cleanObjData(@ApiParam(name = "objType", value = "督查对象类型", required = true) @RequestParam(required = true) String objType,
  214. @ApiParam(name = "id", value = "登记表id", required = true) @RequestParam(required = true) String id) {
  215. supervisionPlanService.cleanObjData(objType, id);
  216. return buildSuccessResponse();
  217. }
  218. @ApiOperation(value = "清空督查对象(根据obj_id)")
  219. @RequestMapping(value = "/cleanObjDataByObjId", method = RequestMethod.GET)
  220. public BaseResponse cleanObjDataByObjId(@ApiParam(name = "objType", value = "督查对象类型", required = true) @RequestParam(required = true) String objType,
  221. @ApiParam(name = "objId", value = "objId", required = true) @RequestParam(required = true) String objId) {
  222. supervisionPlanService.cleanObjDataByObjId(objType, objId);
  223. return buildSuccessResponse();
  224. }
  225. @ApiOperation(value = "批量清空督查对象(根据obj_id)")
  226. @PostMapping(value = "/cleanObjDataByObjIds/{objType}")
  227. public BaseResponse cleanObjDataByObjIds(@PathVariable String objType,
  228. @RequestBody String objIds) {
  229. Map<String, Object> objIdMaps = (Map<String, Object>) JSON.parse(objIds);
  230. List<String> objIdList = (List<String>) objIdMaps.get("objIds");
  231. if (null == objIdList || objIdList.size() == 0) {
  232. buildFailResponse("获取参数失败");
  233. }
  234. supervisionPlanService.cleanObjDataByObjIds(objType, objIdList);
  235. return buildSuccessResponse();
  236. }
  237. @ApiOperation(value = "添加督查小组,不存在批次时同时添加批次")
  238. @RequestMapping(value = "/insertGroupInfo", method = RequestMethod.POST)
  239. public BaseResponse<String> insertGroupInfo(@ApiParam(name = "GroupInfoDto", value = "groupInfoDto") @RequestBody GroupInfoDto groupInfoDto) {
  240. groupInfoDto.setOrgId(getCurrentOrgId());
  241. String groupId = supervisionPlanService.insertGroupInfo(groupInfoDto);
  242. return buildSuccessResponse(groupId);
  243. }
  244. @ApiOperation(value = "根据id修改节点")
  245. @RequestMapping(value = "/updateNode", method = RequestMethod.POST)
  246. public BaseResponse updateNode(@ApiParam(name = "BisInspAllDto", value = "bisInspAllDto") @RequestBody BisInspAllDto bisInspAllDto) {
  247. bisInspAllDto.setOrgId(getCurrentOrgId());
  248. supervisionPlanService.updateNode(bisInspAllDto);
  249. return buildSuccessResponse();
  250. }
  251. @ApiOperation(value = "清空督查组信息")
  252. @RequestMapping(value = "/cleanGroupInfo", method = RequestMethod.GET)
  253. public BaseResponse cleanGroupInfo(@ApiParam(name = "groupId", value = "组id") @RequestParam String groupId) {
  254. supervisionPlanService.cleanGroupInfo(groupId, getCurrentOrgId());
  255. return buildSuccessResponse();
  256. }
  257. @ApiOperation(value = "复用督查组信息")
  258. @RequestMapping(value = "/copyGroupInfo", method = RequestMethod.POST)
  259. public BaseResponse copyGroupInfo(@RequestBody AllGroupInfoDto allGroupInfoDto) {
  260. allGroupInfoDto.setOrgId(getCurrentOrgId());
  261. supervisionPlanService.copyGroupInfo(allGroupInfoDto);
  262. return buildSuccessResponse();
  263. }
  264. @ApiOperation(value = "导入督查组列表")
  265. @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  266. public BaseResponse importExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request, GroupInfoDto dto) {
  267. String persId = request.getHeader("persId");
  268. Map<String, Object> map = supervisionPlanService.importExcel(file, persId, dto.getOrgId());
  269. return buildSuccessResponse(map);
  270. }
  271. @ApiOperation(value = "下载模板")
  272. @RequestMapping(value = "/dowmTemplate/{fileName}", method = RequestMethod.GET)
  273. public BaseResponse dowmTemplate(HttpServletResponse response, @PathVariable String fileName) {
  274. try {
  275. ExpAndImpUtil.downloadFile(response, templatePath + File.separator + fileName + ".xls", "督查计划列表");
  276. } catch (Exception e) {
  277. return buildFailResponse(e);
  278. }
  279. return buildSuccessResponse();
  280. }
  281. @ApiOperation(value = "根据年度计划添加批次和组信息")
  282. @RequestMapping(value = "/insertByYearMonth", method = RequestMethod.POST)
  283. public BaseResponse insertByYearMonth(@RequestBody BisInspYearAllDto bisInspYearAllDto) {
  284. bisInspYearAllDto.setOrgId(getCurrentOrgId());
  285. supervisionPlanService.insertByYearMonth(bisInspYearAllDto);
  286. return buildSuccessResponse();
  287. }
  288. }