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.utils.UUIDPK; import com.newfiber.api.pc.dao.RiverManage.RiverInfoBasisDao; import com.newfiber.api.pc.dao.RiverManage.RiverPolicyDao; import com.newfiber.api.pc.model.River.RiverInfoBasis; import com.newfiber.api.pc.model.River.RiverPolicy; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.ResponseBody; /** * @author wmj * @version 创建时间:2017/11/27 * @description 河道政策控制器 */ @Controller public class RiverPolicyController { @Autowired private RiverPolicyDao riverPolicyDao; @Autowired private RiverInfoBasisDao riverInfoBasisDao; /** * 查询政策列表 * @param page * @param rows * @param policyNo * @param request * @return */ @PostMapping(value = "river/selectRiverPolicyList", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj<Page<RiverPolicy>> selectRiverPolicyList(@RequestBody ReqBodyObj<RiverPolicy> params){ RiverPolicy rp = params.getData(); Page<RiverPolicy> result = new Page<>(); try{ Integer pageNo = null; Integer pageSize = null; if(params.getSize() != 0){ pageNo = (params.getCurrent()-1)*params.getSize(); pageSize = params.getSize(); } List<RiverPolicy> riverPolicyList = riverPolicyDao.selectRiverPolicyList(pageNo,pageSize,rp.getPolicyNo(),rp.getRiverNo()); int count = riverPolicyDao.countRiverPolicyList(rp.getPolicyNo(),rp.getRiverNo()); result.setTotal(count); result.setRecords(riverPolicyList); return RespBodyObj.ok(result); }catch(Exception e){ return RespBodyObj.error("查询异常"); } } /** * 查询我的政策 * @param page * @param rows * @param chiefUserNo * @param request * @return */ @PostMapping(value = "river/selectMyRiverPolicy", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj<Page<RiverPolicy>> selectMyRiverPolicy(@RequestBody ReqBodyObj<RiverPolicy> params,HttpServletRequest request){ RiverPolicy rp = params.getData(); Page<RiverPolicy> result = new Page<>(); String chiefUserNo = rp.getChiefUserNo(); try{ if (chiefUserNo == null || chiefUserNo == "") { chiefUserNo = request.getHeader("userNo"); } Integer pageNo = null; Integer pageSize = null; if(params.getSize() != 0){ pageNo = (params.getCurrent()-1)*params.getSize(); pageSize = params.getSize(); } List<String> list = new ArrayList<String>(); //根据当前河长编号查询所在的河道并且查询所对应的河道策略 List<RiverPolicy> riverPolicies = riverPolicyDao.selectRiverPolicyNos(chiefUserNo); if(riverPolicies != null && riverPolicies.size() > 0){ for(RiverPolicy riverPolicy : riverPolicies){ String policyNo = riverPolicy.getPolicyNo(); list.add(policyNo); } } List<RiverPolicy> riverPolicyList = new ArrayList<>(); if(list.size()>0){ riverPolicyList = riverPolicyDao.selectRiverPolicyNoByPolicyNos(pageNo,pageSize,list,chiefUserNo); } int count = 0; if(riverPolicyList !=null && riverPolicyList.size() > 0){ count = riverPolicyList.size(); } result.setTotal(count); result.setRecords(riverPolicyList); return RespBodyObj.ok(result); }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询异常"); } } /** * 新增政策 * @param createUserNo * @param policyContent * @param riverNo * @param request * @return */ @PostMapping(value = "river/addRiverPolicy", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj addRiverPolicy(@RequestBody ReqBodyObj<RiverPolicy> params,HttpServletRequest request){ RiverPolicy rp = params.getData(); String createUserNo = rp.getCreateUserNo(); try{ if (createUserNo == null || createUserNo == "") { createUserNo = request.getHeader("userNo"); } //根据当前河道编号查询是否有政策 List<RiverPolicy> riverPolicy = riverPolicyDao.selectPolicyByRiverNo(rp.getRiverNo()); if(riverPolicy != null && riverPolicy.size()>0){ return RespBodyObj.error("该河道已有政策,无法添加"); }else{ int a = riverPolicyDao.addRiverPolicy(rp.getPolicyContent(),rp.getRiverNo(),createUserNo, UUIDPK.UUIDGenerator.getUUID(),rp.getFileNo(),rp.getOfficalFileNo()); if(a>0){ return RespBodyObj.ok("新增成功"); }else{ return RespBodyObj.error("新增失败"); } } }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("新增失败"); } } /** * 修改河道政策 * @param policyContent * @param policyNo * @return */ @PostMapping(value = "river/updateRiverPolicy", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj updateRiverPolicy(@RequestBody ReqBodyObj<RiverPolicy> params){ RiverPolicy rp = params.getData(); try{ int a = riverPolicyDao.updateRiverPolicy(rp.getPolicyContent(),rp.getPolicyNo(),rp.getFileNo(),rp.getOfficalFileNo()); if(a>0){ return RespBodyObj.ok("修改成功"); }else{ return RespBodyObj.error("修改失败"); } }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("修改失败"); } } /** * 删除河道政策 * @param policyNos * @return */ @PostMapping(value = "river/deleteRiverPolicy", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj deleteRiverPolicy(@RequestBody ReqBodyObj<RiverPolicy> params){ List<String> policyNos = params.getData().getList(); try{ int a = riverPolicyDao.deleteRiverPolicy(policyNos); if(a>0){ return RespBodyObj.ok("删除成功"); }else{ return RespBodyObj.error("删除失败"); } }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("删除失败"); } } /** * 查询当前用户有哪些河道 * @param chiefUserNo * @param request * @return */ @PostMapping(value = "river/selectRiverNoRiverName", produces = "application/json;charset=utf-8") @ResponseBody public RespBodyObj<List<Object>> selectRiverNoRiverName(@RequestBody ReqBodyObj<RiverPolicy> params,HttpServletRequest request){ JSONObject json = new JSONObject(); String chiefUserNo = params.getData().getChiefUserNo(); try{ if (chiefUserNo == null || chiefUserNo == "") { chiefUserNo = request.getHeader("userNo"); } List<Object> list = new ArrayList<Object>(); //查询当前用户的所有河道 List<RiverInfoBasis> riverInfoBasisList = riverInfoBasisDao.selectRiverNoRiverName(chiefUserNo); if(riverInfoBasisList != null && riverInfoBasisList.size() > 0){ for(RiverInfoBasis riverInfoBasis : riverInfoBasisList){ Map<Object,Object> map = new HashMap<Object,Object>(); map.put("riverNo",riverInfoBasis.getRiverNo()); map.put("riverName",riverInfoBasis.getRiverName()); list.add(map); } return RespBodyObj.ok(list); }else{ return RespBodyObj.error("当前用户暂无河道可添加策略"); } }catch(Exception e){ e.printStackTrace(); return RespBodyObj.error("查询失败"); } } }