package com.newfiber.api.pc.controller.River; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.plugins.Page; import com.newfiber.api.core.bean.ReqBodyObj; import com.newfiber.api.core.bean.RespBodyObj; import com.newfiber.api.pc.dao.EventsManage.AdministrativeDivisionDao; import com.newfiber.api.pc.dao.RiverManage.PatrolDaysConfigDao; import com.newfiber.api.pc.dao.RiverManage.RiverChiefLogDao; import com.newfiber.api.pc.dao.RiverManage.RiverInfoBasisDao; import com.newfiber.api.pc.dao.RiverManage.RiverPatrolDao; import com.newfiber.api.pc.model.EventsManage.AdministrativeDivision; import com.newfiber.api.pc.model.River.PatrolDaysConfig; import com.newfiber.api.pc.model.River.RiverChiefLog; import com.newfiber.api.pc.model.River.RiverInfoBasis; import com.newfiber.api.pc.model.River.RiverPatrol; import java.net.URLDecoder; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; /** * @author wmj * @Date: 2017/12/21 15:16 * @description */ @Controller public class PatrolDaysConfigController { @Autowired private PatrolDaysConfigDao patrolDaysConfigDao; @Autowired private RiverChiefLogDao riverChiefLogDao; @Autowired private AdministrativeDivisionDao administrativeDivisionDao; @Autowired private RiverPatrolDao riverPatrolDao; @Autowired private RiverInfoBasisDao riverInfoBasisDao; /** * 业务管理--巡查管理--巡查次数配置 * * @param request * @return */ @PostMapping(value = "river/selectPatrolDaysConfigList", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj selectPatrolDaysList(@RequestBody ReqBodyObj<Map<String, Object>> param, HttpServletRequest request) { String chiefUserNo = (String) param.getData().get("chiefUserNo"); String startSearchTime = (String) param.getData().get("startSearchTime"); String endSearchTime = (String) param.getData().get("endSearchTime"); String riverName = (String) param.getData().get("riverName"); Integer riverGrade = (Integer) param.getData().get("riverGrade"); Integer page = param.getCurrent(); Integer rows = param.getSize(); try { if (chiefUserNo == null || chiefUserNo == "") { chiefUserNo = request.getHeader("userNo"); } if (riverName != null && riverName.equals("") != true) { riverName = URLDecoder.decode(riverName, "UTF-8"); } Date startTime = null; Date endTime = null; Integer pageNo = null; Integer pageSize = rows; if (page != null && page != 0) { pageNo = (page - 1) * pageSize; }else{ pageNo = null; pageSize = null; } if (riverGrade == 0) { riverGrade = null; } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (startSearchTime != null && startSearchTime.equals("") != true) { startTime = sdf1.parse(startSearchTime); endTime = sdf1.parse(endSearchTime); } List<String> list1 = new ArrayList<String>(); //查询当前登录用户的行政区划编号 RiverChiefLog riverChiefLog = riverChiefLogDao.selectRiverChiefLogByUserNo(chiefUserNo); if (riverChiefLog != null) { String divisionNo = riverChiefLog.getDivisionNo(); if (divisionNo != null && divisionNo.equals("") != true) { //根据divisionNo查询出parentDivisionNo AdministrativeDivision administrativeDivision = administrativeDivisionDao.selectParentDivisionNo(divisionNo); if (administrativeDivision != null) { String divisionName = administrativeDivision.getDivisionName(); String parentDivisionNo = administrativeDivision.getParentDivisionNo(); //查询下级所有行政区划 List<AdministrativeDivision> administrativeDivisionList = administrativeDivisionDao.selectParentDivisionNoList(divisionNo); if (administrativeDivisionList != null && administrativeDivisionList.size() > 0) { for (AdministrativeDivision administrativeDivisions : administrativeDivisionList) { List<String> list = new ArrayList<String>(); List<String> listUser = new ArrayList<String>(); Map<Object, Object> map1 = new HashMap<Object, Object>(); String divisionNames = administrativeDivisions.getDivisionName(); String divisionNos = administrativeDivisions.getDivisionNo(); //查询本级在内的人员 List<RiverPatrol> listPatrol = riverPatrolDao.selectPatrolUserTotal(divisionNos); if (listPatrol != null && listPatrol.size() > 0) { for (RiverPatrol riverPatrol : listPatrol) { String userNo = riverPatrol.getRiverChiefNo(); listUser.add(userNo); } } //查询下级的巡河人员 list = getUserNo(divisionNos); if (listUser != null && listUser.size() > 0 && list != null) { for (int i = 0; i < listUser.size(); i++) { list.add(listUser.get(i)); } } if(!CollectionUtils.isEmpty(list)){ //对list去处重复 for (int i = 0; i < list.size() - 1; i++) { for (int j = list.size() - 1; j > i; j--) { if (list.get(j).equals(list.get(i))) { list.remove(j); } } } //添加到另一个list中 for (int i = 0; i < list.size(); i++) { list1.add(list.get(i)); } } } } } } } if (list1 != null && list1.size() > 0) { } else { list1 = null; } List<PatrolDaysConfig> patrolDaysConfigList = patrolDaysConfigDao.selectPatrolDaysConfigList(riverName, pageNo, pageSize, list1, riverGrade, startTime, endTime); int count = patrolDaysConfigDao.countPatrolDaysConfig(riverName, list1, riverGrade, startTime, endTime); Page page1 = new Page(); page1.setTotal(count); page1.setRecords(patrolDaysConfigList); return RespBodyObj.ok(page1); } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 递归查询 * * @param divisionNo * @return */ public List<String> getUserNo(String divisionNo) { List<AdministrativeDivision> administrativeDivisionList = administrativeDivisionDao.selectuserNoListByDivisionNo(divisionNo); List<String> list = null; if(!CollectionUtils.isEmpty(administrativeDivisionList)){ list = administrativeDivisionList.stream() .map(AdministrativeDivision::getUserNo) .collect(Collectors.toList()); } return list; } /** * 业务管理--巡查管理--新增巡查次数配置 * * @return */ @PostMapping(value = "river/addPatrolDaysConfig", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj addPatrolDaysConfig(HttpServletRequest request, @RequestBody ReqBodyObj<Map<String, Object>> param) { String riverNo = (String) param.getData().get("riverNo"); String chiefUserNo = (String) param.getData().get("chiefUserNo"); Integer patrolDays = (Integer) param.getData().get("patrolDays"); String createUserNo = (String) param.getData().get("createUserNo"); JSONObject json = new JSONObject(); try { if (createUserNo == null || createUserNo.equals("") == true) { createUserNo = request.getHeader("userNo"); } //查询是否已经配置过巡查次数 List<PatrolDaysConfig> patrolDaysConfigList = patrolDaysConfigDao.selectPatrolDaysConfigByRiverNo(riverNo, chiefUserNo); if (patrolDaysConfigList != null && patrolDaysConfigList.size() > 0) { return RespBodyObj.ok("该河道已配置巡查天数,无需再配置了"); } else { int a = patrolDaysConfigDao.addPatrolDaysConfig(riverNo, chiefUserNo, patrolDays, createUserNo); if (a > 0) { return RespBodyObj.ok("新增成功"); } else { boolean result = false; return RespBodyObj.ok("新增失败"); } } } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--巡查管理--修改巡查次数配置 * @return */ @PostMapping(value = "river/updatePatrolDaysConfig", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj updatePatrolDaysConfig(HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,Object>> param) { Integer patrolDays = (Integer) param.getData().get("patrolDays"); String updateUserNo = (String) param.getData().get("updateUserNo"); Integer serial = (Integer) param.getData().get("serial"); try { if (updateUserNo == null || updateUserNo.equals("") == true) { updateUserNo = request.getHeader("userNo"); } Date updateTime = new Date(); int a = patrolDaysConfigDao.updatePatrolDaysConfig(patrolDays, updateUserNo, updateTime, serial); if (a > 0) { boolean result = true; return RespBodyObj.ok("修改成功"); } else { boolean result = false; return RespBodyObj.ok("修改失败"); } } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--巡查管理--删除巡查次数配置 * * @return */ @PostMapping(value = "river/deletePatrolDaysConfig", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj deletePatrolDaysConfig(@RequestBody ReqBodyObj<Map<String,Integer>> param) { Integer serial = param.getData().get("serial"); JSONObject json = new JSONObject(); try { int a = patrolDaysConfigDao.deletePatrolDaysConfig(serial); if (a > 0) { boolean result = true; return RespBodyObj.ok("删除成功"); } else { boolean result = false; return RespBodyObj.ok("删除失败"); } } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--巡查管理--巡查次数配置--查询我的下级所有河长用户编号以及姓名 * * @param request * @return */ @PostMapping(value = "river/addPatrolDaysConfigRiverNo", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj addPatrolDaysConfigRiverNo( HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,String>> param){ String chiefUserNo = param.getData().get("chiefUserNo"); JSONObject json = new JSONObject(); List<Object> listObject = new ArrayList<Object>(); try { if (chiefUserNo == null || chiefUserNo.equals("") == true) { chiefUserNo = request.getHeader("userNo"); } List<String> list1 = new ArrayList<String>(); //查询当前登录用户的行政区划编号 RiverChiefLog riverChiefLog = riverChiefLogDao.selectRiverChiefLogByUserNo(chiefUserNo); if (riverChiefLog != null) { String divisionNo = riverChiefLog.getDivisionNo(); if (divisionNo != null && divisionNo.equals("") != true) { //根据divisionNo查询出parentDivisionNo AdministrativeDivision administrativeDivision = administrativeDivisionDao.selectParentDivisionNo(divisionNo); if (administrativeDivision != null) { String divisionName = administrativeDivision.getDivisionName(); String parentDivisionNo = administrativeDivision.getParentDivisionNo(); //查询下级所有行政区划 List<AdministrativeDivision> administrativeDivisionList = administrativeDivisionDao.selectParentDivisionNoList(divisionNo); if (administrativeDivisionList != null && administrativeDivisionList.size() > 0) { for (AdministrativeDivision administrativeDivisions : administrativeDivisionList) { List<String> list = new ArrayList<String>(); List<String> listUser = new ArrayList<String>(); Map<Object, Object> map1 = new HashMap<Object, Object>(); String divisionNames = administrativeDivisions.getDivisionName(); String divisionNos = administrativeDivisions.getDivisionNo(); //查询本级在内的人员 List<RiverPatrol> listPatrol = riverPatrolDao.selectPatrolUserTotal(divisionNos); if (listPatrol != null && listPatrol.size() > 0) { for (RiverPatrol riverPatrol : listPatrol) { String userNo = riverPatrol.getRiverChiefNo(); listUser.add(userNo); } } //查询下级的巡河人员 list = getUserNo(divisionNos); if (listUser != null && listUser.size() > 0 && list != null) { for (int i = 0; i < listUser.size(); i++) { list.add(listUser.get(i)); } } if(!CollectionUtils.isEmpty(list)){ //对list去处重复 for (int i = 0; i < list.size() - 1; i++) { for (int j = list.size() - 1; j > i; j--) { if (list.get(j).equals(list.get(i))) { list.remove(j); } } } //添加到另一个list中 for (int i = 0; i < list.size(); i++) { list1.add(list.get(i)); } } } } } } } if (list1 != null && list1.size() > 0) { List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverUserNameo(list1); if (riverInfoBasisList != null && riverInfoBasisList.size() > 0) { for (RiverInfoBasis riverInfoBasis : riverInfoBasisList) { Map<String, Object> map = new HashMap<String, Object>(); String chiefUserNo1 = riverInfoBasis.getChiefUserNo(); String chiefUserName = riverInfoBasis.getUserName(); map.put("chiefUserNo", chiefUserNo1); map.put("chiefUserName", chiefUserName); listObject.add(map); } } else { json.put("message", "当前暂无河长可分配"); return RespBodyObj.ok("当前暂无河长可分配"); } } return RespBodyObj.ok(listObject); } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--巡查管理--巡查次数配置--根据河长编号查询河道编号以及河道名称 * * @return */ @PostMapping(value = "river/selectPatrolDaysConfigUserNo", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj selectPatrolDaysConfigUserNo( HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,String>> param) { String chiefUserNo = param.getData().get("chiefUserNo"); JSONObject json = new JSONObject(); List<Object> list = new ArrayList<Object>(); try { if (chiefUserNo == null || chiefUserNo.equals("") == true) { chiefUserNo = request.getHeader("userNo"); } List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverNoRiverNameByUserNo(chiefUserNo); if (riverInfoBasisList != null && riverInfoBasisList.size() > 0) { for (RiverInfoBasis riverInfoBasis : riverInfoBasisList) { Map<String, Object> map = new HashMap<String, Object>(); String riverName = riverInfoBasis.getRiverName(); String riverNo = riverInfoBasis.getRiverNo(); map.put("riverNo", riverNo); map.put("riverName", riverName); list.add(map); } } return RespBodyObj.ok(list); } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--巡查管理--巡查次数配置--根据河长编号查询河道编号以及河道名称 * * @return */ @PostMapping(value = "river/selectAddPatrolDaysConfigUserNo", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj selectAddPatrolDaysConfigUserNo( HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,String>> param) { String chiefUserNo = param.getData().get("chiefUserNo"); JSONObject json = new JSONObject(); List<Object> list = new ArrayList<Object>(); try { if (chiefUserNo == null || chiefUserNo.equals("") == true) { chiefUserNo = request.getHeader("userNo"); } List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectAddRiverNoRiverNameByUserNo(); if (riverInfoBasisList != null && riverInfoBasisList.size() > 0) { for (RiverInfoBasis riverInfoBasis : riverInfoBasisList) { Map<String, Object> map = new HashMap<String, Object>(); String riverName = riverInfoBasis.getRiverName(); String riverNo = riverInfoBasis.getRiverNo(); String chiefUserNos = riverInfoBasis.getChiefUserNo(); String chiefUserName = riverInfoBasis.getChiefUserName(); map.put("riverNo", riverNo); map.put("riverName", riverName); map.put("chiefUserNo", chiefUserNos); map.put("chiefUserName", chiefUserName); list.add(map); } } return RespBodyObj.ok(list); } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } }