Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / River / RiverChiefController.java
package com.newfiber.api.pc.controller.River;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.plugins.Page;
import com.newfiber.api.core.annotation.SysLog;
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.RiverChiefDao;
import com.newfiber.api.pc.dao.RiverManage.RiverInfoBasisDao;
import com.newfiber.api.pc.model.River.RiverChief;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wmj
 * @version 创建时间:2017/11/25
 * @description 河长基础信息控制器
 */
@Controller
public class RiverChiefController {

    @Autowired
    private RiverChiefDao riverChiefDao;
    @Autowired
    private RiverInfoBasisDao riverInfoBasisDao;

    /**
     * 查询河长基础信息列表
     * @return
     */
    @PostMapping(value = "river/selectRiverChiefList", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj selectRiverChiefList(@RequestBody ReqBodyObj<Map<String,Object>> param){

        Integer page = param.getCurrent();
        Integer rows = param.getSize();
        Integer chiefGrade = (Integer) param.getData().get("chiefGrade");
        String chiefUserNo = (String) param.getData().get("chiefUserNo");
        try{
            Integer pageNo = null;
            Integer pageSize = rows;
            if(page != null){
                pageNo = (page-1)*pageSize;
            }
            List<RiverChief> riverChiefList = riverChiefDao.selectRiverChiefList(pageNo,pageSize,chiefGrade,chiefUserNo);
            int count = riverChiefDao.countRiverChiefList(chiefGrade,chiefUserNo);
            Page page1 = new Page();
            page1.setRecords(riverChiefList);
            page1.setTotal(count);
            return RespBodyObj.ok(page1);
        }catch(Exception e){
            e.printStackTrace();
        }
        return RespBodyObj.ok();
    }

    /**
     * 新增河长
     * @param request
     * @return
     */
    @PostMapping(value = "river/addRiverChief", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj addRiverChief(HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,Object>> param){

        String chiefUserNo = (String) param.getData().get("chiefUserNo");
        Integer riverGrade = (Integer) param.getData().get("riverGrade");
        String chiefDuty = (String) param.getData().get("chiefDuty");
        String riverNo = (String) param.getData().get("riverNo");
                JSONObject json = new JSONObject();
        //riverNo = UUIDPK.UUIDGenerator.getUUID();
        //String chiefUserNo = "";
        try{
            /*if (chiefUserNo == null || chiefUserNo == "") {
                chiefUserNo = request.getHeader("userNo");
            }*/
            String riverGradeZn = "";
            if(riverGrade==1){
                riverGradeZn = "省级河长";
            }else if(riverGrade==2){
                riverGradeZn = "市级河长";
            }else if(riverGrade==3){
                riverGradeZn = "县级河长";
            }else if(riverGrade==4){
                riverGradeZn = "镇级河长";
            }else if(riverGrade==5){
                riverGradeZn = "村级河长";
            }
            int a = riverChiefDao.addRiverChief(chiefUserNo,riverGrade,riverGradeZn,chiefDuty,riverNo);
            if(a>0){

                return RespBodyObj.ok("新增成功");
            }else{

                return RespBodyObj.ok("新增失败");
            }
        }catch(Exception e){
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 修改河长基本信息
     * @param request
     * @return
     */
    @PostMapping(value = "river/updateRiverChief", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj updateRiverChief( HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,Object>> param){

        String userNo = (String) param.getData().get("userNo");
        Integer riverGrade = (Integer) param.getData().get("riverGrade");
        String chiefDuty = (String) param.getData().get("chiefDuty");
        String riverNo = (String) param.getData().get("riverNo");
        String chiefUserNo = "";
        try{
            /*if (chiefUserNo == null || chiefUserNo == "") {
                chiefUserNo = request.getHeader("userNo");
            }*/
            String riverGradeZn = "";
            if(riverGrade==1){
                riverGradeZn = "省级河长";
            }else if(riverGrade==2){
                riverGradeZn = "市级河长";
            }else if(riverGrade==3){
                riverGradeZn = "县级河长";
            }else if(riverGrade==4){
                riverGradeZn = "镇级河长";
            }else if(riverGrade==5){
                riverGradeZn = "村级河长";
            }
            int a = riverChiefDao.updateRiverChief(userNo,riverGrade,riverGradeZn,chiefDuty,riverNo);
            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/deleteRiverChief", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj deleteRiverChief(@RequestBody ReqBodyObj<Map<String,String>> param){

        String riverNo = (String) param.getData().get("riverNo");
        try{
            int a = riverChiefDao.deleteRiverChief(riverNo);
            if(a>0){
                return RespBodyObj.ok("删除成功");
            }else {
                return RespBodyObj.ok("删除失败");
            }
        }catch(Exception e){
            e.printStackTrace();
            return RespBodyObj.error();

        }
    }

    /**
     * 统计分析--河道信息--各级河长分布
     * @return
     */
    @PostMapping(value = "river/countRiverChiefTotal", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj countRiverChiefTotal(){
        JSONObject json = new JSONObject();
        try{
            //市级河长
            int proviceCount = riverChiefDao.countRiverChiefTotal(3);
            //镇级河长
            int townCount = riverChiefDao.countRiverChiefTotal(4);
            //村级河长
            int villageCount = riverChiefDao.countRiverChiefTotal(5);
            String [][] distributed = {{"市级分布","镇级分布","村级分布"},{String.valueOf(proviceCount),String.valueOf(townCount),String.valueOf(villageCount)}};
            return RespBodyObj.ok(distributed);
        }catch(Exception e){
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 统计分析模块--查询所有河道及河长
     * @return
     */
    @PostMapping(value = "river/countRiverMessageTotal", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj countRiverMessageTotal(){
        JSONObject json = new JSONObject();
        try{
            int a = riverInfoBasisDao.countRiverMessageTotal();
            int b = riverInfoBasisDao.countRiverInfoMessageTotal();
            json.put("totalRiver",b);
            json.put("totalRiverUser",a);
            return RespBodyObj.ok(json);
        }catch(Exception e){
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 查询时用到的下拉框
     * @param request
     * @return
     */
    @PostMapping(value = "river/countRiverGradeTotal", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj countRiverGradeTotal(HttpServletRequest request,@RequestBody ReqBodyObj<Map<String,String>> param){
        String chiefUserNo = param.getData().get("chiefUserNo");
        try{
            if (chiefUserNo == null || chiefUserNo == "") {
                chiefUserNo = request.getHeader("userNo");
            }
            RiverChief riverChief = riverChiefDao.selectGradeByUserNo(chiefUserNo);
            List<Object> list = new ArrayList<Object>();
            if(riverChief != null){
                Integer chiefGrade = riverChief.getChiefGrade();
                if(chiefGrade == 3){
                    for (int i=0;i<4;i++){
                        Map<Object,Object> map = new HashMap<Object,Object>();
                        if(i == 0){
                            map.put("chiefGrade",i+3);
                            map.put("chiefGradeZn","县级河长");
                            list.add(map);
                        }else if(i == 1){
                            map.put("chiefGrade",i+3);
                            map.put("chiefGradeZn","镇级河长");
                            list.add(map);
                        }else if(i == 2){
                            map.put("chiefGrade",i+3);
                            map.put("chiefGradeZn","村级河长");
                            list.add(map);
                        }else if(i==3){
                            map.put("chiefGrade",0);
                            map.put("chiefGradeZn","---全部---");
                            list.add(map);
                        }
                    }
                }else if(chiefGrade == 4){
                    for (int i=0;i<3;i++){
                        Map<Object,Object> map = new HashMap<Object,Object>();
                        if(i == 0){
                            map.put("chiefGrade",i+4);
                            map.put("chiefGradeZn","镇级河长");
                            list.add(map);
                        }else if(i == 1){
                            map.put("chiefGrade",i+4);
                            map.put("chiefGradeZn","村级河长");
                            list.add(map);
                        }else if(i==2){
                            map.put("chiefGrade",0);
                            map.put("chiefGradeZn","---全部---");
                            list.add(map);
                        }
                    }
                }else if(chiefGrade == 5){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",5);
                    map.put("chiefGradeZn","村级河长");
                    list.add(map);
                }else{
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("查询出错",0);
                    list.add(map);
                }
            }else{
                Map<Object,Object> map = new HashMap<Object,Object>();
                map.put("查询出错",0);
                list.add(map);
            }
            return RespBodyObj.ok(list);
        }catch(Exception e){
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 查询无权限的河长等级下拉框
     * @return
     */
    @PostMapping(value = "river/selectRiverChiefRiverGrade", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj selectRiverChiefRiverGrade(){
        List<Object> list = new ArrayList<Object>();
        try{
            for(int i = 1;i < 5;i++){
                if(i == 1){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",i);
                    map.put("chiefGradeZn","县级河长");
                    list.add(map);
                }else if(i == 2){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",i);
                    map.put("chiefGradeZn","镇级河长");
                    list.add(map);
                }else if(i == 3){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",i);
                    map.put("chiefGradeZn","村级河长");
                    list.add(map);
                }else if(i == 4){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",0);
                    map.put("chiefGradeZn","---全部---");
                    list.add(map);
                }
            }
            return RespBodyObj.ok(list);
        }catch(Exception e){
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }

    /**
     * 查询无权限的河长等级下拉框
     * @return
     */
    @PostMapping(value = "river/selectRiverChiefRiverGradeOk", produces = "application/json;charset=utf-8")
    @ResponseBody
    public RespBodyObj selectRiverChiefRiverGradeOk(){
        List<Object> list = new ArrayList<Object>();
        try{
            for(int i = 1;i < 6;i++){
                if(i == 3){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",i);
                    map.put("chiefGradeZn","县级河长");
                    list.add(map);
                }else if(i == 4){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",i);
                    map.put("chiefGradeZn","镇级河长");
                    list.add(map);
                }else if(i == 5){
                    Map<Object,Object> map = new HashMap<Object,Object>();
                    map.put("chiefGrade",i);
                    map.put("chiefGradeZn","村级河长");
                    list.add(map);
                }
            }
            return RespBodyObj.ok(list);
        }catch(Exception e){
            e.printStackTrace();
            return RespBodyObj.error();
        }
    }


}