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.core.support.HttpCode; import com.newfiber.api.pc.dao.EventsManage.AdministrativeDivisionDao; import com.newfiber.api.pc.dao.RiverManage.*; import com.newfiber.api.pc.model.EventsManage.AdministrativeDivision; import com.newfiber.api.pc.model.UserManager.Data_User_Info; import com.newfiber.api.pc.model.River.*; import com.newfiber.api.pc.service.RestTemplateService; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import java.net.URLDecoder; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; /** * @author wmj * @Date: 2017/12/16 14:28 * @description 业务管理--文案管理--我的文案以及下级文案 */ @Controller public class OfficialManageController { @Autowired private OfficialManageDao officialManageDao; @Autowired private OfficialFileDao officialFileDao; @Autowired private AdministrativeDivisionDao administrativeDivisionDao; @Autowired private RiverChiefLogDao riverChiefLogDao; @Autowired private RiverPatrolDao riverPatrolDao; @Autowired private RiverChiefDao riverChiefDao; @Resource private RestTemplateService restTemplateService; /** * 业务管理--文案管理--查询我的文案 */ @PostMapping(value = "river/selectOfficialManageList", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj selectOfficialManageList(HttpServletRequest request, @RequestBody ReqBodyObj<Map<String,Object>> param) { Map<String,Object> map = param.getData(); String createUserNo = (String) map.get("createUserNo"); String officialName = (String) map.get("officialName"); Integer officialType = (Integer) map.get("officialType"); String searchStartTime = (String) map.get("searchStartTime"); String searchEndTime = (String) map.get("searchEndTime"); Integer page = (Integer)map.get("current"); Integer rows = (Integer)map.get("size"); Integer serial = (Integer) map.get("serial"); String order = (String) map.get("order"); String sort = (String) map.get("sort"); JSONObject json = new JSONObject(); try { if (createUserNo == null || createUserNo == "") { createUserNo = request.getHeader("userNo"); } if (officialName != null && officialName.equals("") != true) { officialName = URLDecoder.decode(officialName, "UTF-8"); } Integer pageNo = null; Integer pageSize = rows; if (page != null && page != 0) { pageNo = (page - 1) * pageSize; }else{ pageNo = null; pageSize = null; } Date startTime = null; Date endTime = null; SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (searchStartTime != null && searchStartTime.equals("") != true) { startTime = sdf1.parse(searchStartTime); endTime = sdf1.parse(searchEndTime); } Data_User_Info currentUser =restTemplateService.getUserInfo(createUserNo); if(currentUser.getHighestAuthority() != null && currentUser.getHighestAuthority().equals("yes")){ createUserNo = null; } if (serial != null) { createUserNo = null; } List<OfficialManage> officialManageList = officialManageDao.selectOfficialManageList(officialName, officialType, createUserNo, startTime, endTime, pageNo, pageSize, serial, order, sort); if (officialManageList != null && officialManageList.size() > 0) { for (OfficialManage officialManage : officialManageList) { String officialFileNo = officialManage.getOfficialFileNo(); int countSize = officialFileDao.countOfficialFile(officialFileNo); List<OfficialFile> officialFileList = officialFileDao.selectOfficialFileList(officialFileNo); officialManage.setCountSize(countSize); officialManage.setList(officialFileList); } } int count = officialManageDao.countOfficialManage(officialName, officialType, createUserNo, startTime, endTime, serial); if (serial != null) { //修改浏览次数 OfficialManage officialManage = officialManageDao.selectOfficialManageByNumber(serial); if (officialManage != null) { Integer countA = officialManage.getBrowseNumber(); countA = countA + 1; int a = officialManageDao.updateOfficialManageByNumber(countA, serial); } } Page page1 = new Page(); page1.setTotal(count); page1.setRecords(officialManageList); return RespBodyObj.ok(page1); } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--文案管理--新增文案 * @return */ @PostMapping(value = "river/addOfficialManage", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj addOfficialManage(HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,Object>> param ) { String officialName = (String) param.getData().get("officialName"); Integer officialType = (Integer) param.getData().get("officialType"); String officialContent = (String) param.getData().get("officialContent"); Integer officialSecrecy = (Integer) param.getData().get("officialSecrecy"); String officialFileNo = (String) param.getData().get("officialFileNo"); String createUserNo = (String) param.getData().get("createUserNo"); try { if (createUserNo == null || createUserNo == "") { createUserNo = request.getHeader("userNo"); } RiverChief riverChief = riverChiefDao.selectGradeByUserNo(createUserNo); String riverNo = riverChief.getRiverNo(); int a = officialManageDao.addOfficialManage(officialName, riverNo, officialType, officialContent, officialFileNo, officialSecrecy, createUserNo, 0); if (a > 0) { return RespBodyObj.ok("新增成功"); } else { return RespBodyObj.ok("新增失败"); } } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--文案管理--修改文案 * @return */ @PostMapping(value = "river/updateOfficialManage", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj updateOfficialManage(HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,Object>> param) { String officialName = (String) param.getData().get("officialName"); Integer officialType = (Integer) param.getData().get("officialType"); String officialContent = (String) param.getData().get("officialContent"); Integer officialSecrecy = (Integer) param.getData().get("officialSecrecy"); String officialFileNo = (String) param.getData().get("officialFileNo"); String updateUserNo = (String) param.getData().get("updateUserNo"); Integer serial = (Integer) param.getData().get("serial"); try { if (updateUserNo == null || updateUserNo == "") { updateUserNo = request.getHeader("userNo"); } Date updateTime = new Date(); int a = officialManageDao.updateOfficialManage(officialName, officialType, officialContent, officialFileNo, officialSecrecy, updateUserNo, updateTime, serial); if (a > 0) { return RespBodyObj.ok("修改成功"); } else { return RespBodyObj.ok("修改失败"); } } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--文案管理--删除文案 * * @return */ @PostMapping(value = "river/deleteOfficialManage", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj deleteOfficialManage(@RequestBody ReqBodyObj<Map<String,Object>> param) { List<Integer> serials = (List<Integer>) param.getData().get("serials"); try { int a = 0; if (serials != null){ for (int i=0;i<serials.size();i++){ Integer serial = serials.get(i); a += officialManageDao.deleteOfficialManage(serial); } if (a >= serials.size()) { boolean result = true; return RespBodyObj.ok("删除成功"); } else { return RespBodyObj.error("删除失败"); } }else { return RespBodyObj.error(HttpCode.BAD_REQUEST); } } catch (Exception e) { e.printStackTrace(); return RespBodyObj.error(); } } /** * 业务管理--文案管理--我的下级文案 * * @param request * @return */ @PostMapping(value = "river/selectNextOfficial", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj selectNextOfficial(HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,Object>>param) { Integer page = param.getCurrent(); Integer rows = param.getSize(); Integer riverGrade = (Integer) param.getData().get("riverGrade"); String chiefUserNo = (String) param.getData().get("chiefUserNo"); String year = (String) param.getData().get("year"); String month = (String) param.getData().get("month"); try { if (chiefUserNo == null || chiefUserNo == "") { chiefUserNo = request.getHeader("userNo"); } 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; } Date startTime = null; Date endTime = null; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); if (year != null && year.equals("") != true) { if (month != null && month.equals("") != true) { startTime = sdf1.parse(year + "-" + month + "-01 00:00:00"); Calendar c = Calendar.getInstance(); //设置年份 c.set(Calendar.YEAR, Integer.valueOf(year)); //设置月份 c.set(Calendar.MONTH, Integer.valueOf(month) - 1); //获取某月最大天数 int monthMax = c.getActualMaximum(Calendar.DAY_OF_MONTH); String monthMaxDay = String.valueOf(monthMax); endTime = sdf1.parse(year + "-" + month + "-" + monthMaxDay + " 23:59:59"); } } else { //获取当前时间 Calendar now = Calendar.getInstance(); year = String.valueOf(now.get(Calendar.YEAR)); month = String.valueOf(now.get(Calendar.MONTH) + 1); startTime = sdf1.parse(year + "-" + month + "-01 00:00:00"); Calendar c = Calendar.getInstance(); //设置年份 c.set(Calendar.YEAR, Integer.valueOf(year)); //设置月份 c.set(Calendar.MONTH, Integer.valueOf(month) - 1); //获取某月最大天数 int monthMax = c.getActualMaximum(Calendar.DAY_OF_MONTH); String monthMaxDay = String.valueOf(monthMax); endTime = sdf1.parse(year + "-" + month + "-" + monthMaxDay + " 23:59:59"); } //查询当前登录用户的行政区划编号 RiverChiefLog riverChiefLog = riverChiefLogDao.selectRiverChiefLogByUserNo(chiefUserNo); List<String> list1 = new ArrayList<String>(); 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)); } } } } } } } List<OfficialManage> officialManageList = officialManageDao.selectNextOfficialManage(list1, startTime, endTime, riverGrade, pageNo, pageSize); if (officialManageList != null && officialManageList.size() > 0) { for (OfficialManage officialManage : officialManageList) { String officialFileNo = officialManage.getOfficialFileNo(); int countSize = officialFileDao.countOfficialFile(officialFileNo); List<OfficialFile> officialFileList = officialFileDao.selectOfficialFileList(officialFileNo); officialManage.setCountSize(countSize); officialManage.setList(officialFileList); } } int count = officialManageDao.selectNextOfficialManageCount(list1, startTime, endTime, riverGrade); Page page1 = new Page(); page1.setRecords(officialManageList); page1.setTotal(count); 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; } }