package cn.com.goldenwater.dcproj.controller.ducha; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import cn.com.goldenwater.dcproj.dto.*; import cn.com.goldenwater.dcproj.model.OlBisInspOrg; import cn.com.goldenwater.dcproj.param.InGroupResParam; import cn.com.goldenwater.dcproj.param.InspObjParam; import cn.com.goldenwater.dcproj.service.OlBisInspOrgService; import cn.com.goldenwater.dcproj.service.SupervisionPlanService; import cn.com.goldenwater.dcproj.util.CheckUtil; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.TimeRangeUtil; import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil; import com.alibaba.fastjson.JSON; import com.github.pagehelper.PageInfo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Async; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Created by 61618 on 2019/4/17. */ @Api(value = "督查计划相关接口", tags = "督查计划相关接口") @RestController @RequestMapping("/supervision/plan") public class SupervisionPlanController extends BaseController { @Autowired private SupervisionPlanService supervisionPlanService; @Value("${export.templatePath}") private String templatePath; @Value("${impExcel.basePath}") private String impExcelPath; @Autowired private OlBisInspOrgService olBisInspOrgService; private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @ApiOperation(value = "根据用户信息与督查计划类型获取该用户可示可管理的单一机构的所有批次") @RequestMapping(value = "getNodeByPersid", method = RequestMethod.GET) public BaseResponse> getNodeByPersid(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid, @ApiParam(name = "ptype", value = "ptype", required = true) @RequestParam String ptype) { List allNodeDtoList = this.supervisionPlanService.getNodeByPersid(persid, ptype, getCurrentOrgId()); return buildSuccessResponse(allNodeDtoList); } @ApiOperation(value = "获取督查组相关的对象、人员、区域信息(新)") @RequestMapping(value = "getAllInfoByPersidAndOrgId", method = RequestMethod.GET) public BaseResponse> getAllInfoByPersidAndOrgId(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid, @ApiParam(name = "inspYear", value = "inspYear", required = false) @RequestParam(required = false) String inspYear, @ApiParam(name = "inspMnth", value = "inspMnth", required = false) @RequestParam(required = false) String inspMnth, @ApiParam(name = "orgId", value = "机构id", required = true) @RequestParam String orgId, @ApiParam(name = "yearPlanId", value = "年度id", required = true) @RequestParam String yearPlanId) { List allNodeDtoList = this.supervisionPlanService.getAllInfoByPersidAndOrgId(persid, inspYear, inspMnth, orgId, yearPlanId); return buildSuccessResponse(allNodeDtoList); } @ApiOperation(value = "根据组id查询督查区域") @RequestMapping(value = "/getPersAllAreaDtoList", method = RequestMethod.POST) public BaseResponse> getPersAllAreaDtoList(@PathVariable String id) { List dtos = this.supervisionPlanService.getPersAllAreaDtoList(id, getCurrentOrgId()); return buildSuccessResponse(dtos); } @ApiOperation(value = "获取督查组相关的对象、人员、区域信息") @RequestMapping(value = "getAllInfoByPersid", method = RequestMethod.GET) public BaseResponse> getAllInfoByPersid(@ApiParam(name = "persid", value = "persid", required = true) @RequestParam String persid, @ApiParam(name = "ptype", value = "ptype", required = true) @RequestParam String ptype, @ApiParam(name = "id", value = "id", required = true) @RequestParam String id) { List allNodeDtoList = this.supervisionPlanService.getAllInfoByPersid(persid, ptype, id, getCurrentOrgId()); return buildSuccessResponse(allNodeDtoList); } @ApiOperation(value = "查询不在该督查组下的水库", notes = "查询不在该督查组下的水库") @RequestMapping(value = "/getSupResByGroup", method = RequestMethod.POST) public BaseResponse> getSupResByGroup(@RequestBody InGroupResParam inGroupResParam) { inGroupResParam.setProvince(olBisInspOrgService.getProvinceFlag(getCurrentOrgId())); inGroupResParam.setOrgId(getCurrentOrgId()); PageInfo list = supervisionPlanService.getSupResByGroup(inGroupResParam); return buildSuccessResponse(list); } @ApiOperation(value = "查询不在督查组督查范围内的督查对象") @RequestMapping(value = "/getSupObjListNotInspGroupId", method = RequestMethod.GET) public BaseResponse getSupObjListNotInspGroupId(@ApiParam(name = "InspObjParam", value = "InspObjParam") InspObjParam inspObjParam) { OlBisInspOrg org = olBisInspOrgService.get(getCurrentOrgId()); CheckUtil.notNull(org, "机构ID错误", getCurrentOrgId()); inspObjParam.setProvince(AdLevelUtil.getAddvcd(org.getAdCode())); inspObjParam.setOrgId(getCurrentOrgId()); if (StringUtils.isNotBlank(inspObjParam.getOrderBy()) && inspObjParam.getOrderBy().contains("undefined")) { inspObjParam.setOrderBy(""); } PageInfo pageInfo = supervisionPlanService.getSupObjListNotInspGroupId(inspObjParam); return buildSuccessResponse(pageInfo); } @ApiOperation(value = "添加督查人员、督查对象、督查区域") @RequestMapping(value = "/insertSupervisionObj", method = RequestMethod.POST) public BaseResponse insertSupervisionObj(@ApiParam(name = "PersAllInfoDto", value = "PersAllInfoDto") @RequestBody PersAllInfoDto persAllInfoDto) { if ((StringUtils.isNotBlank(persAllInfoDto.getSttm()) || StringUtils.isNotBlank(persAllInfoDto.getEntm())) && StringUtils.isBlank(persAllInfoDto.getIsInsert())) { Map map = isValiTm(persAllInfoDto); if (map.get("msg") != null) { return buildSuccessResponse(map); } } persAllInfoDto.setOrgId(getCurrentOrgId()); persAllInfoDto.setPersid(getCurrentPersId()); persAllInfoDto.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); SupInsertResult supInsertResult = supervisionPlanService.insertSupervisionObj(persAllInfoDto); return buildSuccessResponse(supInsertResult); } @ApiOperation(value = "添加督查人员、督查对象、督查区域") @RequestMapping(value = "/insertAllSupervisionObj", method = RequestMethod.POST) public BaseResponse insertAllSupervisionObj(@ApiParam(name = "InspObjParam", value = "InspObjParam") InspObjParam inspObjParam) { batchInsert(inspObjParam); return buildSuccessResponse("添加成功!"); } @Async protected void batchInsert(InspObjParam inspObjParam) { OlBisInspOrg org = olBisInspOrgService.get(getCurrentOrgId()); CheckUtil.notNull(org, "机构ID错误", getCurrentOrgId()); inspObjParam.setProvince(AdLevelUtil.getAddvcd(org.getAdCode())); inspObjParam.setOrgId(getCurrentOrgId()); if (StringUtils.isNotBlank(inspObjParam.getOrderBy()) && inspObjParam.getOrderBy().contains("undefined")) { inspObjParam.setOrderBy(""); } List pageInfo = supervisionPlanService.getObjListNotGroupId(inspObjParam); PersAllInfoDto persAllInfoDto = new PersAllInfoDto(); persAllInfoDto.setId(inspObjParam.getInspGroupId()); List objList = new ArrayList<>(); for (int i = 0; i < pageInfo.size(); i++) { PersAllObjDto persAllObjDto = new PersAllObjDto(); persAllObjDto.setPtype(inspObjParam.getObjType()); persAllObjDto.setCode(pageInfo.get(i).getCode()); persAllObjDto.setName(pageInfo.get(i).getNm()); objList.add(persAllObjDto); } persAllInfoDto.setPersAllObjDtoList(objList); persAllInfoDto.setPersAllAreaDtoList(new ArrayList<>()); persAllInfoDto.setPersAllDtoList(new ArrayList<>()); persAllInfoDto.setOrgId(getCurrentOrgId()); persAllInfoDto.setPersid(getCurrentPersId()); persAllInfoDto.setProvince(olBisInspOrgService.getProvince(getCurrentOrgId())); supervisionPlanService.insertSupervisionObj(persAllInfoDto); } public Map isValiTm(PersAllInfoDto persAllInfoDto) { String msg = ""; Map map = new HashMap<>(); Map mapGroup = supervisionPlanService.getYearMonth(persAllInfoDto.getId()); if (StringUtils.isNotBlank(persAllInfoDto.getSttm())) { mapGroup.put("STTM", persAllInfoDto.getSttm()); } if (StringUtils.isNotBlank(persAllInfoDto.getEntm())) { mapGroup.put("ENTM", persAllInfoDto.getEntm()); } List adCodeList = new ArrayList(); List errorList = new ArrayList(); List allNodeDtoList = this.supervisionPlanService.getAllInfoByPersidAndOrgId(getCurrentPersId(), mapGroup.get("INSP_YEAR"), mapGroup.get("INSP_MNTH"), getCurrentOrgId(), null); if (allNodeDtoList != null && allNodeDtoList.size() > 0 && (StringUtils.isNotBlank(mapGroup.get("STTM")) || StringUtils.isNotBlank(mapGroup.get("ENTM")))) { allNodeDtoList.forEach(item -> { if (persAllInfoDto.getId().equals(item.getId()) && item.getPersAllAreaDtoList() != null && item.getPersAllAreaDtoList().size() > 0) { item.getPersAllAreaDtoList().forEach(item1 -> { adCodeList.add(item1.getAdCode()); }); } }); if (adCodeList.size() > 0) { allNodeDtoList.forEach(item -> { long count = 0; if (!persAllInfoDto.getId().equals(item.getId()) && item.getPersAllAreaDtoList() != null && item.getPersAllAreaDtoList().size() > 0) { count = item.getPersAllAreaDtoList().stream().filter(item1 -> adCodeList.indexOf(item1.getAdCode()) > -1).count(); } try { if (count > 0 && TimeRangeUtil.isTimeRange(item, mapGroup)) { errorList.add("(检查计划事项:" + item.getChkName() + "-组名:" + item.getNm() + ")"); } } catch (Exception e) { e.printStackTrace(); } }); } } if (errorList.size() > 0) { msg = "(检查计划事项:" + mapGroup.get("CHK_NAME") + "-当前组:" + mapGroup.get("PNM") + ")与其他组" + String.join(",", errorList) + "重叠"; map.put("msg", msg); } return map; } @ApiOperation(value = "督查组人员分配角色") @RequestMapping(value = "/assignmentRole", method = RequestMethod.POST) public BaseResponse assignmentRole(@ApiParam(name = "objIdDto", value = "ObjIdDto") ObjIdDto objIdDto) { int i = supervisionPlanService.assignmentRole(objIdDto); return buildSuccessResponse(); } @ApiOperation(value = "获取人员类型") @GetMapping(value = "/getPersType") public BaseResponse> getPersType(@RequestParam String persid, @RequestParam(value = "yearId", required = false) String yearId) { List persTypeDtoList = supervisionPlanService.getPersType(persid, getCurrentOrgId(), yearId); return buildSuccessResponse(persTypeDtoList); } @ApiOperation(value = "获取人员类型(根据接收单位)") @GetMapping(value = "/getPersTypeByPersid") public BaseResponse> getPersTypeByPersid(@RequestParam String persid) { List persTypeDtoList = supervisionPlanService.getPersTypeByPersid(persid, getCurrentOrgId()); return buildSuccessResponse(persTypeDtoList); } @ApiOperation(value = "清空督查对象") @RequestMapping(value = "/cleanObjData", method = RequestMethod.GET) public BaseResponse cleanObjData(@ApiParam(name = "objType", value = "督查对象类型", required = true) @RequestParam(required = true) String objType, @ApiParam(name = "id", value = "登记表id", required = true) @RequestParam(required = true) String id) { supervisionPlanService.cleanObjData(objType, id); return buildSuccessResponse(); } @ApiOperation(value = "清空督查对象(根据obj_id)") @RequestMapping(value = "/cleanObjDataByObjId", method = RequestMethod.GET) public BaseResponse cleanObjDataByObjId(@ApiParam(name = "objType", value = "督查对象类型", required = true) @RequestParam(required = true) String objType, @ApiParam(name = "objId", value = "objId", required = true) @RequestParam(required = true) String objId) { supervisionPlanService.cleanObjDataByObjId(objType, objId); return buildSuccessResponse(); } @ApiOperation(value = "批量清空督查对象(根据obj_id)") @PostMapping(value = "/cleanObjDataByObjIds/{objType}") public BaseResponse cleanObjDataByObjIds(@PathVariable String objType, @RequestBody String objIds) { Map objIdMaps = (Map) JSON.parse(objIds); List objIdList = (List) objIdMaps.get("objIds"); if (null == objIdList || objIdList.size() == 0) { buildFailResponse("获取参数失败"); } supervisionPlanService.cleanObjDataByObjIds(objType, objIdList); return buildSuccessResponse(); } @ApiOperation(value = "添加督查小组,不存在批次时同时添加批次") @RequestMapping(value = "/insertGroupInfo", method = RequestMethod.POST) public BaseResponse insertGroupInfo(@ApiParam(name = "GroupInfoDto", value = "groupInfoDto") @RequestBody GroupInfoDto groupInfoDto) { groupInfoDto.setOrgId(getCurrentOrgId()); String groupId = supervisionPlanService.insertGroupInfo(groupInfoDto); return buildSuccessResponse(groupId); } @ApiOperation(value = "根据id修改节点") @RequestMapping(value = "/updateNode", method = RequestMethod.POST) public BaseResponse updateNode(@ApiParam(name = "BisInspAllDto", value = "bisInspAllDto") @RequestBody BisInspAllDto bisInspAllDto) { bisInspAllDto.setOrgId(getCurrentOrgId()); supervisionPlanService.updateNode(bisInspAllDto); return buildSuccessResponse(); } @ApiOperation(value = "清空督查组信息") @RequestMapping(value = "/cleanGroupInfo", method = RequestMethod.GET) public BaseResponse cleanGroupInfo(@ApiParam(name = "groupId", value = "组id") @RequestParam String groupId) { supervisionPlanService.cleanGroupInfo(groupId, getCurrentOrgId()); return buildSuccessResponse(); } @ApiOperation(value = "复用督查组信息") @RequestMapping(value = "/copyGroupInfo", method = RequestMethod.POST) public BaseResponse copyGroupInfo(@RequestBody AllGroupInfoDto allGroupInfoDto) { allGroupInfoDto.setOrgId(getCurrentOrgId()); supervisionPlanService.copyGroupInfo(allGroupInfoDto); return buildSuccessResponse(); } @ApiOperation(value = "导入督查组列表") @RequestMapping(value = "/importExcel", method = RequestMethod.POST) public BaseResponse importExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request, GroupInfoDto dto) { String persId = request.getHeader("persId"); Map map = supervisionPlanService.importExcel(file, persId, dto.getOrgId()); return buildSuccessResponse(map); } @ApiOperation(value = "下载模板") @RequestMapping(value = "/dowmTemplate/{fileName}", method = RequestMethod.GET) public BaseResponse dowmTemplate(HttpServletResponse response, @PathVariable String fileName) { try { ExpAndImpUtil.downloadFile(response, templatePath + File.separator + fileName + ".xls", "督查计划列表"); } catch (Exception e) { return buildFailResponse(e); } return buildSuccessResponse(); } @ApiOperation(value = "根据年度计划添加批次和组信息") @RequestMapping(value = "/insertByYearMonth", method = RequestMethod.POST) public BaseResponse insertByYearMonth(@RequestBody BisInspYearAllDto bisInspYearAllDto) { bisInspYearAllDto.setOrgId(getCurrentOrgId()); supervisionPlanService.insertByYearMonth(bisInspYearAllDto); return buildSuccessResponse(); } }