Newer
Older
huludao / src / main / java / com / newfiber / api / mobile / service / PatrolProblemService.java
package com.newfiber.api.mobile.service;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import com.newfiber.api.core.base.BaseService;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.core.utils.NumberUtil;
import com.newfiber.api.core.utils.UUIDPK;
import com.newfiber.api.mobile.dao.PatrolProblemDao;
import com.newfiber.api.mobile.dao.ProcessProblemDao;
import com.newfiber.api.mobile.dao.RiverBusinessPicsDao;
import com.newfiber.api.mobile.model.domain.*;
import com.newfiber.api.pc.model.River.RiverUserRelation;
import com.newfiber.api.pc.service.RiverUserRelationService;
import com.newfiber.api.pc.service.impl.RiverChiefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 *  Service
 * @author xcc
 * @date 2018-12-04 16:21:59
 */
@Service("patrolProblemService")
public class PatrolProblemService extends BaseService<PatrolProblemDao,PatrolProblem> {
	@Autowired
	private PatrolProblemDao patrolProblemDao;

    @Autowired
    private RiverBusinessPicsDao riverBusinessPicsDao;

    @Autowired
    private ProcessProblemDao processProblemDao;

    @Autowired
    private RiverChiefService riverChiefService;

    @Autowired
    private RiverUserRelationService riverUserRelationService;

    @Autowired
    private PatrolProblemStateService patrolProblemStateService;

    @Autowired
    private RiverUserRelationService relationService;
	/** 根据条件获取列表(分页) */
	public List<PatrolProblem> queryList(Map<String, Object> map,Page<PatrolProblem> page){
		return patrolProblemDao.queryList(map,page);
	}
	
	/** 根据条件获取列表(无分页) */
	public List<PatrolProblem> queryList(Map<String, Object> map){
		return patrolProblemDao.queryList(map);
	}
    
	/** 
	 * @Description: 按照巡查编号查询所有巡河问题
	 * @param  
	 * @return: java.util.List<com.newfiber.api.mobile.model.domain.PatrolProblem>
	 * @Author: Wmj 
	 * @Date: 2018/12/22 16:24 
	 */ 
    public List<Map<String,Object>> selectAllProblemList(){
        List<PatrolProblem> patrolProblemList = Optional.ofNullable(patrolProblemDao.selectAllProblemList())
                .orElse(Lists.newArrayList());
        if(CollectionUtil.isEmpty(patrolProblemList)){
            return null;
        }
        List<Map<String,Object>> list = new ArrayList<>();
        for (PatrolProblem patrolProblem : patrolProblemList) {
            Map<String,Object> map = new HashMap<>();
            map.put("patrolProblemNo",patrolProblem.getPatrolProblemNo());
            map.put("coordinate",patrolProblem.getCoordinate());
            map.put("complainTypeName",patrolProblem.getComplainTypeName());
            list.add(map);
        }
        return list;
    }

	/** 
	 * @Description: 按照巡查编号查询巡河问题详情
	 * @param map 
	 * @return: java.util.List<com.newfiber.api.mobile.model.domain.PatrolProblem>
	 * @Author: Wmj 
	 * @Date: 2018/12/19 13:25 
	 */ 
    public List<PatrolProblem> queryListByPatrolNo(Map<String, Object> map){
        List<PatrolProblem> patrolProblemList = Optional.ofNullable(patrolProblemDao.queryListByPatrolNo(map))
                .orElse(Lists.newArrayList());
        return patrolProblemList;
    }



    /**
     * @Description: 查询巡查问题分类
     * @param param
     * @return: java.util.List<com.newfiber.api.mobile.model.domain.PatrolProblem>
     * @Author: Wmj
     * @Date: 2018/12/8 17:19
     */
    public List<PatrolProblem> queryProblemListByUserNo(Map<String, Object> param){
        return patrolProblemDao.queryProblemListByUserNo(param);
    }

    /**
     * @Description: 按照用户编号获取巡查问题列表(分类统计待处理)
     * @param
     * @return: java.util.List<com.newfiber.api.mobile.model.domain.PatrolProblem>
     * @Author: Wmj
     * @Date: 2018/12/19 19:34
     */
    public List<PatrolProblem> queryProblemListByUserNoToBeProcessed(String userNo){
        List<ProcessProblem> processProblemList = processProblemDao.selectProcessNoByUserNo(userNo);
        if(!CollectionUtil.isEmpty(processProblemList)){
            List<String> processPicsList = new ArrayList<>();
            for (ProcessProblem processProblem:processProblemList) {
                String processNo = processProblem.getProcessNo();
                processPicsList.add(processNo);
            }
            List<PatrolProblem> patrolProblemList = patrolProblemDao.queryProblemListByUserNoToBeProcessed(processPicsList);
            return patrolProblemList;
        }
        return new ArrayList<>();
    };

    /**
     * @Description: 按照用户编号获取巡查问题列表(分类统计已处理)
     * @param userNo
     * @return: java.util.List<com.newfiber.api.mobile.model.domain.PatrolProblem>
     * @Author: Wmj
     * @Date: 2018/12/19 19:32
     */
    public List<PatrolProblem> queryProblemListByUserNoProcessed(String userNo){
        return patrolProblemDao.queryProblemListByUserNoProcessed(userNo);
    }

    /**
     * @Description: 按照用户编号获取巡查问题列表(分类统计已结案)
     * @param userNo
     * @return: java.util.List<com.newfiber.api.mobile.model.domain.PatrolProblem>
     * @Author: Wmj
     * @Date: 2018/12/19 19:32
     */
    public List<PatrolProblem> queryProblemListByUserNoClosed(String userNo){
        return patrolProblemDao.queryProblemListByUserNoClosed(userNo);
    }

    /**
     * @Description: 修改巡查问题状态以及巡查问题进程状态
     * @param map
     * @return: com.newfiber.api.core.bean.RespBodyObj<java.lang.Object>
     * @Author: Wmj
     * @Date: 2018/12/12 17:06
     */
    public RespBodyObj<Object> updateData(Map<String, Object> map, HttpServletRequest request){
        //往问题进程表中添加数据
        ProcessProblem processProblem = new ProcessProblem();
        processProblem.setProcessNo((String)map.get("problemProcessNo"));
        processProblem.setUserNo(request.getHeader("userNo"));
        processProblem.setUserOrg((String)map.get("userOrg"));
        if((String)map.get("nextUserNo") != null){
            processProblem.setProcessNextUserno((String)map.get("nextUserNo"));
        }
        processProblem.setProcessNextOrg((String)map.get("processNextOrg"));
        processProblem.setProcessOption((String)map.get("processOption"));
        processProblem.setProcessTime(new Date());
        //上传巡河问题处理图片
        /*String pics = (String)map.get("picsList");
        pics = pics.substring(1,pics.length()-1);
        String[] processPic = pics.split(";");
        if (processPic != null && processPic.length > 0) {
            List<String> processPics = new ArrayList<>();
            for (int i = 0; i < processPic.length; i++) {
                processPics.add(processPic[i]);
            }
            String processPicsNo = UUIDPK.UUIDGenerator.getUUID();
            processPics.forEach(file -> {
                try {
                    String path = file;//文件路径
                    String fileName = "问题处理进程图片";//文件名
                    RiverBusinessPics riverBusinessPics = new RiverBusinessPics();
                    riverBusinessPics.setRiverPicsNo(processPicsNo);
                    riverBusinessPics.setRiverPicsName(fileName);
                    riverBusinessPics.setRiverPicsAddress(path);
                    riverBusinessPics.setCreateUserNo((String)map.get("userNo"));
                    riverBusinessPics.setCreateTime(new Date());
                    riverBusinessPicsDao.insert(riverBusinessPics);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
            processProblem.setProcessPicsNo(processPicsNo);
        }*/
        processProblemDao.insert(processProblem);
        //修改巡查问题表
        PatrolProblem patrolProblem = new PatrolProblem();
        patrolProblem.setProblemState((Integer)map.get("problemState"));
        if((int)map.get("problemState") == 1){
            patrolProblem.setProblemStateStr("已处理");
        }
        if((int)map.get("problemState") == 2){
            patrolProblem.setProblemStateStr("已结案");
        }
        EntityWrapper<PatrolProblem> wrapper = new EntityWrapper<>();
        wrapper.eq("Patrol_Problem_No", (String)map.get("patrolProblemNo"));
        patrolProblemDao.update(patrolProblem,wrapper);
        return RespBodyObj.ok();
    }


    /**根据时间条件和当前用户sid获取本级河流不同类型问题个数*/
	public List<ProblemStatistical> problemStatistics(Map<String, Object> map){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            map.put("st",sdf.parse((String)map.get("startTime")));
            map.put("et",sdf.parse((String)map.get("endTime")));
            //每种问题个数集合
            List<ProblemStatistical> list = patrolProblemDao.problemStatisticalInfo(map);
            //总问题个数
            int total = patrolProblemDao.problemTotal(map);
            if(total != 0){
                for(int i=0;i<list.size();i++){
                    list.get(i).setTotal(total);
                    list.get(i).setPercentage(NumberUtil.getRoundingNum((list.get(i).getNum()/(double)total),4)*100+"%");
                }
            }
            return list;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
	}


    /**根据时间条件和当前用户sid获取下级河流不同类型问题个数*/
    public List<ProblemStatistical> problenStatisticsSubordinate(Map<String, Object> map){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            map.put("st",sdf.parse((String)map.get("startTime")));
            map.put("et",sdf.parse((String)map.get("endTime")));
            //每种问题个数集合
            List<ProblemStatistical> list = patrolProblemDao.problemStatisticalSubordinate(map);
            //总问题个数
            int total = patrolProblemDao.problemTotalSubordinate(map);
            if(total != 0){
                for(int i=0;i<list.size();i++){
                    list.get(i).setTotal(total);
                    list.get(i).setPercentage(NumberUtil.getRoundingNum((list.get(i).getNum()/(double)total),4)*100+"%");
                }
            }
            return list;
        }catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**本级河长巡查事件统计(根据每条河流计数)*/
    public Map<String,Object> InspectEvent(Map<String, Object> map){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String,Object> result = new HashMap<>();
        try {
            //巡查事件结案总个数
            int totalFinish = 0;
            map.put("st",sdf.parse((String)map.get("startTime")));
            map.put("et",sdf.parse((String)map.get("endTime")));
            //巡查问题总数
            int total= patrolProblemDao.problemTotal(map);
            Integer page = (Integer)map.get("page");
            Integer rows = (Integer)map.get("rows");
            if(page != null && rows != null){
                map.put("startPage",(page-1)*rows);
                map.put("pageSize",rows);
            }
            //本级每条河流问题总数
            List<ProblemStatistical> list1 = patrolProblemDao.InspectEvent(map);
            map.put("problemState",2);
            //本级每条河流结案总数
            List<ProblemStatistical> list2 = patrolProblemDao.InspectEvent(map);
            for(int i=0;i<list1.size();i++){
                totalFinish += list2.get(i).getNum();
                list2.get(i).setTotal(list1.get(i).getNum());
                if(list1.get(i).getNum() >0){
                    list2.get(i).setPercentage(NumberUtil.getRoundingNum((list2.get(i).getNum()/(double)list1.get(i).getNum()),4)*100+"%");
                }
            }
            result.put("dataList",list2);
            result.put("total",total);
            result.put("totalFinish",totalFinish);
            result.put("unfinished",total-totalFinish);
            result.put("finishingRate",total>0?(NumberUtil.getRoundingNum(totalFinish/(double)total,4)*100+"%"):"0.0%");
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**下级区域巡查事件统计(根据每个区域计数)*/
    public Map<String,Object> InspectEventSubordinate(Map<String, Object> map){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Map<String,Object> result = new HashMap<>();
        try {
            //下级区域巡查事件结案总个数
            int totalFinish = 0;
            map.put("st",sdf.parse((String)map.get("startTime")));
            map.put("et",sdf.parse((String)map.get("endTime")));
            //下级区域巡查问题总数
            int total= patrolProblemDao.problemTotalSubordinate(map);
            Integer page = (Integer)map.get("page");
            Integer rows = (Integer)map.get("rows");
            if(page != null && rows != null){
                map.put("startPage",(page-1)*rows);
                map.put("pageSize",rows);
            }
            //下级每个区域问题总数
            List<ProblemStatistical> list1 = patrolProblemDao.InspectEventSubordinate(map);
            map.put("problemState",2);
            //下级每个区域结案总数
            List<ProblemStatistical> list2 = patrolProblemDao.InspectEventSubordinate(map);
            for(int i=0;i<list1.size();i++){
                totalFinish += list2.get(i).getNum();
                list2.get(i).setTotal(list1.get(i).getNum());
                if(list1.get(i).getNum() >0){
                    list2.get(i).setPercentage(NumberUtil.getRoundingNum((list2.get(i).getNum()/(double)list1.get(i).getNum()),4)*100+"%");
                }
            }
            result.put("dataList",list2);
            result.put("total",total);
            result.put("totalFinish",totalFinish);
            result.put("unfinished",total-totalFinish);
            result.put("finishingRate",total>0?(NumberUtil.getRoundingNum(totalFinish/(double)total,4)*100+"%"):"0.0%");
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**查询河流问题列表*/
    public List<PatrolProblem> queryListByRiver(Map<String, Object> map){
        List<PatrolProblem> result = new ArrayList<>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            map.put("st",sdf.parse((String)map.get("startTime")));
            map.put("et",sdf.parse((String)map.get("endTime")));
            result = patrolProblemDao.queryListByRiver(map);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**查询区域问题统计*/
    public List<ProblemStatistical> problemTotalOfArea(Map<String,Object> map) throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        map.put("st",sdf.parse((String)map.get("startTime")));
        map.put("et",sdf.parse((String)map.get("endTime")));
        //一个区域下每条河流的问题总数
        List<ProblemStatistical> pList = patrolProblemDao.problemTotalOfArea(map);
        //一个区域下每条河流的问题结案数量
        map.put("problemState",2);
        List<ProblemStatistical> finishList = patrolProblemDao.problemTotalOfArea(map);
        for(int i=0;i<finishList.size();i++){
            finishList.get(i).setTotal(pList.get(i).getNum());
            if(finishList.get(i).getUserName() == null) finishList.get(i).setUserName("无");
            if(pList.get(i).getNum() >0){
                finishList.get(i).setPercentage(NumberUtil.getRoundingNum((finishList.get(i).getNum()/(double)pList.get(i).getNum()),4)*100+"%");
            }
        }
        return finishList;
    }

    public PageInfo problemNew(String userNo, String problemState, Integer pageNo, Integer size) {
        PageInfo<PatrolProblem> result = new PageInfo<>();
        if("Admin".equalsIgnoreCase(userNo)){
            PageHelper.startPage(pageNo,size);
            List<PatrolProblem> list = patrolProblemDao.selectByRiver(null, problemState);
            if (!list.isEmpty()) {
                result = new PageInfo<PatrolProblem>(list);
            }
            return result;
        }
        //List<String> river = riverChiefService.getNextRiver(userNo);
        //if(river.size() != 0){
            PageHelper.startPage(pageNo,size);
            List<PatrolProblem> list = patrolProblemDao.selectByRiver(userNo, problemState);
            if (!list.isEmpty()) {
                result = new PageInfo<PatrolProblem>(list);
            }
        //}
        return result;
    }

    /**
     * 添加或编辑任务状态
     * @param userName
     * @param patrolProblemNo
     * @param patrolProblemState
     */
    private void insertOrUpdateState(String userName,String patrolProblemNo,Integer patrolProblemState){
        Boolean aBoolean = patrolProblemStateService.existData(userName, patrolProblemNo);
        if(aBoolean){
            //update
            patrolProblemStateService.updateByUserNameAndNo(userName,patrolProblemNo,patrolProblemState);
        }else{
            //insert
            PatrolProblemState state = new PatrolProblemState();
            state.setUserNo(userName);
            state.setPatrolProblemNo(patrolProblemNo);
            state.setProblemState(patrolProblemState);
            state.setCreateTime(new Date());
            patrolProblemStateService.insert(state);
        }

    }

    /**
     * 修改任务状态
     * @param patrolProblem
     * @param relation
     * @param state
     * @param stateStr
     */
    private void updateProblemState(PatrolProblem patrolProblem, RiverUserRelation relation,Integer state,String stateStr) {
        PatrolProblem nPatrol = new PatrolProblem();
        nPatrol.setPatrolProblemNo(patrolProblem.getPatrolProblemNo());
        nPatrol.setProblemState(state);
        nPatrol.setProblemStateStr(stateStr);
        EntityWrapper<PatrolProblem> wrapper = new EntityWrapper<>();
        wrapper.eq("Patrol_Problem_No",patrolProblem.getPatrolProblemNo());
        patrolProblemDao.update(nPatrol,wrapper);
    }

    /**
     * 任务指派
     * @param patrolProblem
     * @param request
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public RespBodyObj appoint(PatrolProblem patrolProblem, HttpServletRequest request) {
        RiverUserRelation relation = riverUserRelationService.selectByRiverNo(patrolProblem.getRiverNo());
        //存在关联关系
        if(relation!=null) {
            //编辑任务状态
            updateProblemState(patrolProblem, relation,3,"待处理");
            //生成流程
            String chiefUserNo = request.getHeader("userNo");
            ProcessProblem processProblem = new ProcessProblem();
            processProblem.setProcessNo(patrolProblem.getProblemProcessNo());
            processProblem.setUserNo(chiefUserNo);
            processProblem.setProcessNextUserno(patrolProblem.getPatrolUserNo());
            processProblem.setProcessState(3);
            processProblem.setProcessStateName("待处理");
            processProblem.setProcessOption(patrolProblem.getProcessOption());
            processProblem.setProcessTime(new Date());
            processProblemDao.insert(processProblem);
            //1.负责人状态 设置为3
            insertOrUpdateState(relation.getDutyUserNo(),patrolProblem.getPatrolProblemNo(),3);
            //2.处理人状态 设置为2
            insertOrUpdateState(patrolProblem.getPatrolUserNo(),patrolProblem.getPatrolProblemNo(),2);
            //3.保存处理人
            relation.setHandlerNo(patrolProblem.getPatrolUserNo());
            relation.setHandlerName(patrolProblem.getPatrolUserName());
            riverUserRelationService.updateById(relation);
        }else {
            //没关联
        }
       return RespBodyObj.ok();
    }


    /**
     * 处理人员提交任务
     * @param patrolProblem
     * @param request
     */
    @Transactional(rollbackFor = Exception.class)
    public RespBodyObj check(PatrolProblem patrolProblem, HttpServletRequest request) {

        RiverUserRelation relation = riverUserRelationService.selectByRiverNo(patrolProblem.getRiverNo());
        //存在关联关系
       if(relation!=null){
            //编辑任务状态
            updateProblemState(patrolProblem, relation,4,"待审核");
            String chiefUserNo = request.getHeader("userNo");
            //生成流程
            ProcessProblem processProblem = new ProcessProblem();
            processProblem.setProcessNo(patrolProblem.getProblemProcessNo());
            processProblem.setUserNo(chiefUserNo);
            processProblem.setProcessNextUserno(patrolProblem.getCurrentUserNo());
            processProblem.setProcessState(4);
            processProblem.setProcessStateName("待审核");
            //保存流程图片
            saveProcessImg(patrolProblem,processProblem, chiefUserNo);
            processProblem.setProcessOption(patrolProblem.getProcessOption());
            processProblem.setProcessTime(new Date());
            processProblemDao.insert(processProblem);
            //1.处理人状态 状态设置为3
           insertOrUpdateState(relation.getHandlerNo(),patrolProblem.getPatrolProblemNo(),3);
           //2.巡河人员状态
           insertOrUpdateState(patrolProblem.getCurrentUserNo(),patrolProblem.getPatrolProblemNo(),2);
        }else{
            //todo
        }
        return RespBodyObj.ok();
    }

    /**
     * 巡河人员处理
     * @param patrolProblem
     * @param request
     */
    @Transactional(rollbackFor = Exception.class)
    public RespBodyObj chiefCheck(PatrolProblem patrolProblem, HttpServletRequest request) {

        //存在关联关系
        RiverUserRelation relation = riverUserRelationService.selectByRiverNo(patrolProblem.getRiverNo());
        if(relation!=null){
            //编辑任务状态
            updateProblemState(patrolProblem, relation,5,"待审核");
            //生成流程
            String chiefUserNo = request.getHeader("userNo");
            ProcessProblem processProblem = new ProcessProblem();
            processProblem.setProcessNo(patrolProblem.getProblemProcessNo());
            processProblem.setUserNo(chiefUserNo);
            processProblem.setProcessNextUserno(relation.getDutyUserNo());
            processProblem.setProcessState(5);
            processProblem.setProcessStateName("待审核");
            //保存流程图片
            saveProcessImg(patrolProblem,processProblem, chiefUserNo);
            processProblem.setProcessOption(patrolProblem.getProcessOption());
            processProblem.setProcessTime(new Date());
            processProblemDao.insert(processProblem);
            //1.处理人状态 设置为2
            insertOrUpdateState(relation.getDutyUserNo(),patrolProblem.getPatrolProblemNo(),2);
            //2.巡河人员状态 设置为3
            insertOrUpdateState(patrolProblem.getCurrentUserNo(),patrolProblem.getPatrolProblemNo(),3);
        }else{
            //todo
        }
        return RespBodyObj.ok();
    }

    /**
     * 处理人处理
     * @param patrolProblem
     * @param request
     */
    @Transactional(rollbackFor = Exception.class)
    public RespBodyObj handlerCheck(PatrolProblem patrolProblem, HttpServletRequest request) {
        //存在关联关系
        RiverUserRelation relation = riverUserRelationService.selectByRiverNo(patrolProblem.getRiverNo());
        if(relation!=null){
            ProcessProblem processProblem = new ProcessProblem();
            //编辑任务状态
            if(patrolProblem.getNeedleader() == null || patrolProblem.getNeedleader() != 1){
                updateProblemState(patrolProblem, relation,7,"已完成");
                processProblem.setProcessState(7);
                processProblem.setProcessStateName("已完成");
            }else{
                updateProblemState(patrolProblem, relation,6,"待审查");
                processProblem.setProcessState(6);
                processProblem.setProcessStateName("待审查");
            }
            //生成流程
            String chiefUserNo = request.getHeader("userNo");

            processProblem.setProcessNo(patrolProblem.getProblemProcessNo());
            processProblem.setUserNo(chiefUserNo);
            processProblem.setProcessNextUserno(relation.getLeaderNo());

            //保存流程图片
            saveProcessImg(patrolProblem,processProblem, chiefUserNo);
            processProblem.setProcessOption(patrolProblem.getProcessOption());
            processProblem.setProcessTime(new Date());
            processProblemDao.insert(processProblem);
            //1.处理人状态 设置为3
            insertOrUpdateState(relation.getDutyUserNo(),patrolProblem.getPatrolProblemNo(),3);

            //是否需要管理员操作 todo
            //2.管理员状态 是否需要管理员操作
            if(patrolProblem.getNeedleader() != null && patrolProblem.getNeedleader() == 1){
                insertOrUpdateState(relation.getLeaderNo(),patrolProblem.getPatrolProblemNo(),2);
            }

        }else{
            //todo
        }
        return RespBodyObj.ok();
    }

    /**
     * 处理人驳回
     * @param patrolProblem
     * @param request
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public RespBodyObj handlerRefuse(PatrolProblem patrolProblem, HttpServletRequest request) {
        //存在关联关系
        RiverUserRelation relation = riverUserRelationService.selectByRiverNo(patrolProblem.getRiverNo());
        if(relation!=null){
            //编辑任务状态
            updateProblemState(patrolProblem, relation,3,"待处理");
            //生成流程
            String chiefUserNo = request.getHeader("userNo");
            ProcessProblem processProblem = new ProcessProblem();
            processProblem.setProcessNo(patrolProblem.getProblemProcessNo());
            processProblem.setUserNo(chiefUserNo);
            processProblem.setProcessNextUserno(relation.getHandlerNo());
            processProblem.setProcessState(3);
            processProblem.setProcessStateName("负责人驳回");
            //保存流程图片
            saveProcessImg(patrolProblem,processProblem, chiefUserNo);
            processProblem.setProcessOption(patrolProblem.getProcessOption());
            processProblem.setProcessTime(new Date());
            processProblemDao.insert(processProblem);
            //1.处理人状态 设置为2
            insertOrUpdateState(relation.getHandlerNo(),patrolProblem.getPatrolProblemNo(),2);
            //2.负责人状态 设置为3
            insertOrUpdateState(relation.getDutyUserName(),patrolProblem.getPatrolProblemNo(),3);
        }else{
            //todo
        }
        return RespBodyObj.ok();
    }

    /**
     * 领导处理
     * @param patrolProblem
     * @param request
     */
    @Transactional(rollbackFor = Exception.class)
    public RespBodyObj leaderCheck(PatrolProblem patrolProblem, HttpServletRequest request) {
        //存在关联关系
        RiverUserRelation relation = riverUserRelationService.selectByRiverNo(patrolProblem.getRiverNo());
        if(relation!=null){
            //编辑任务状态
            updateProblemState(patrolProblem, relation,7,"完成");
            //生成流程
            String chiefUserNo = request.getHeader("userNo");
            ProcessProblem processProblem = new ProcessProblem();
            processProblem.setUserNo(chiefUserNo);
            processProblem.setProcessNextUserno("");
            processProblem.setProcessState(7);
            processProblem.setProcessStateName("完成");
            //保存流程图片
            saveProcessImg(patrolProblem,processProblem, chiefUserNo);
            processProblem.setProcessOption(patrolProblem.getProcessOption());
            processProblem.setProcessTime(new Date());
            processProblemDao.insert(processProblem);
            //3.管理员状态 设置为3
            insertOrUpdateState(relation.getLeaderNo(),patrolProblem.getPatrolProblemNo(),3);
        }else{
            //todo
        }
        return RespBodyObj.ok();
    }


    /**
     * 领导驳回
     * @param patrolProblem
     * @param request
     */
    @Transactional(rollbackFor = Exception.class)
    public RespBodyObj leaderRefuse(PatrolProblem patrolProblem, HttpServletRequest request) {

        //存在关联关系
        RiverUserRelation relation = riverUserRelationService.selectByRiverNo(patrolProblem.getRiverNo());
        if(relation!=null){
            //编辑任务状态
            updateProblemState(patrolProblem, relation,3,"待处理");
            //生成流程
            String chiefUserNo = request.getHeader("userNo");
            ProcessProblem processProblem = new ProcessProblem();
            processProblem.setProcessNo(patrolProblem.getProblemProcessNo());
            processProblem.setUserNo(chiefUserNo);
            processProblem.setProcessNextUserno(relation.getDutyUserNo());
            processProblem.setProcessState(3);
            processProblem.setProcessOption(patrolProblem.getProcessOption());
            processProblem.setProcessStateName("领导驳回");
            //保存流程图片
            saveProcessImg(patrolProblem,processProblem, chiefUserNo);
            processProblem.setProcessTime(new Date());
            processProblemDao.insert(processProblem);
            //1.负责人状态 设置为2
            insertOrUpdateState(relation.getHandlerNo(),patrolProblem.getPatrolProblemNo(),2);
            //2.管理员状态 设置为3
            insertOrUpdateState(relation.getLeaderNo(),patrolProblem.getPatrolProblemNo(),3);
        }else{
            //todo
        }
        return RespBodyObj.ok();
    }

    /**
     * 保存图片
     * @param patrolProblem
     * @param chiefUserNo
     */
    private void saveProcessImg(PatrolProblem patrolProblem,ProcessProblem processProblem, String chiefUserNo) {
        if(patrolProblem.getPicsList() != null){
            List<RiverBusinessPics> pics = patrolProblem.getPicsList();
            if (!pics.isEmpty()) {
                String problemPicsNo = UUIDPK.UUIDGenerator.getUUID();
                processProblem.setProcessPicsNo(problemPicsNo);
                savePatrolImg(problemPicsNo, chiefUserNo, pics, "巡河进程问题图片");
            }
        }

    }

    /**
     * 保存巡查图片
     * @param riverPicsNo
     * @param chiefUserNo
     * @param picsList
     */
    private void savePatrolImg(String riverPicsNo, String chiefUserNo, List<RiverBusinessPics> picsList,String fileName) {
        List<RiverBusinessPics> pic = JSON.parseArray(JSON.toJSONString(picsList),RiverBusinessPics.class);
        if (!pic.isEmpty()) {
            for (RiverBusinessPics file : pic) {
                try {
                    RiverBusinessPics riverBusinessPics = new RiverBusinessPics();
                    riverBusinessPics.setRiverPicsNo(riverPicsNo);
                    riverBusinessPics.setRiverPicsAddress(file.getRiverPicsAddress());
                    riverBusinessPics.setRiverPicsName(fileName);
                    riverBusinessPics.setCreateUserNo(chiefUserNo);
                    riverBusinessPics.setCreateTime(new Date());
                    riverBusinessPicsDao.insert(riverBusinessPics);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}