package com.huimv.receive.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huimv.receive.common.token.TokenSign;
import com.huimv.receive.common.utils.*;
import com.huimv.receive.entity.*;
import com.huimv.receive.entity.vo.CleanAndDryVo;
import com.huimv.receive.entity.vo.CleanAndDryVo2;
import com.huimv.receive.entity.vo.CleanDryGoodsVo;
import com.huimv.receive.entity.vo.CleanVo;
import com.huimv.receive.mapper.*;
import com.huimv.receive.service.IBillCleanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;
import sun.applet.Main;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.*;

/**
 * <p>
 * 洗消表 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-07-21
 */
@Service
public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean> implements IBillCleanService {

    @Autowired
    private BillCleanMapper cleanMapper;
    @Autowired
    private BillIsolateMapper isolateMapper;
    @Autowired
    private BillPcrMapper pcrMapper;
    @Autowired
    private BaseProcessMapper processMapper;
    @Autowired
    private BaseLocationMapper locationMapper;
    @Autowired
    private BaseWashoutPointMapper baseWashoutPointMapper;
    @Autowired
    private UploadImage uploadImage;
    @Autowired
    private BillDryMapper dryMapper;
    @Autowired
    private BillPersonnelAdmissionMapper admissionMapper;
    @Autowired
    private ConfigurationMapper configurationMapper;
    @Autowired
    private ExistMapper existMapper;
    @Autowired
    private BillGoodsInventoryMapper inventoryMapper;

    @Override
    public Result listAll(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String type = paramsMap.get("type");//展示类型 0-6
        String data = paramsMap.get("data");//状态
        String farmId = paramsMap.get("farmId");
        String pageNum = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        if ("".equals(pageNum) || null == pageNum) {
            pageNum = "1";
        }
        if ("".equals(pageSize) || null == pageSize) {
            pageSize = "20";
        }
        if ("".equals(type) || null == type) {
            type = "1";
        }
        if ("".equals(data) || null == data) {
            data = "0";
        }
        if (type.equals("0")) {
            BaseLocation baseLocation = locationMapper.selectById(TokenSign.getWorkIdByJwtToken(httpServletRequest));
            Page<BillClean> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
            QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("vistit_type", type).orderByDesc("sub_date").eq("test_location_id", baseLocation.getId());

            if ("0".equals(data)) {
                queryWrapper.in("bill_status", 0, 1, 2,3);
            }
            if ("1".equals(data)) {
                queryWrapper.eq("bill_status", 0);
            }
            if ("2".equals(data)) {
                queryWrapper.eq("bill_status", 1);
            }
            QueryWrapper<BillClean> queryWrapper2 = new QueryWrapper<>();
            if (baseLocation.getId() == 47) {
            } else {
                queryWrapper.eq("farm_id", farmId);
                queryWrapper2.eq("farm_id", farmId);
            }
            queryWrapper2.eq("vistit_type", type).orderByDesc("sub_date")
                    .eq("test_location_id", baseLocation.getId()).eq("bill_status", 0);

            return new Result(ResultCode.SUCCESS, cleanMapper.selectPage(page, queryWrapper), cleanMapper.selectCount(queryWrapper2));
        } else if ("5".equals(type)) {
            Page<CleanDryGoodsVo> cleanDryGoodPage = null;
            Page<CleanDryGoodsVo> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
            QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("vistit_type", type);
            QueryWrapper<BillDry> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("vistit_type", type);
            QueryWrapper<BillGoodsInventory> queryWrapper3 = new QueryWrapper<>();
            if ("0".equals(data)) {
                String[] s = {TokenSign.getWorkIdByJwtToken(httpServletRequest)};
                System.out.println("传入自定义sql的位置参数形式：" + s);
                if (Integer.parseInt(TokenSign.getWorkIdByJwtToken(httpServletRequest)) == 47) {
                    cleanDryGoodPage = cleanMapper.listCleanDryGoodsNo(page, type, "0,1,2,3".split(","), s);
                } else {
                    cleanDryGoodPage = cleanMapper.listCleanDryGoods(page, farmId, type, "0,1,2,3".split(","), s);
                }
                queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper3.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
            }
            if ("1".equals(data)) {
                String[] ids = {TokenSign.getWorkIdByJwtToken(httpServletRequest)};
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.add("0");
                String[] s = arrayList.toArray(new String[arrayList.size()]);
                if (Integer.parseInt(TokenSign.getWorkIdByJwtToken(httpServletRequest)) == 47) {
                    cleanDryGoodPage = cleanMapper.listCleanDryGoodsNo(page, type, s, ids);
                } else {
                    cleanDryGoodPage = cleanMapper.listCleanDryGoods(page, farmId, type, s, ids);
                }
                queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper3.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
            }
            if ("2".equals(data)) {
                String[] ids = {TokenSign.getWorkIdByJwtToken(httpServletRequest)};
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.add("1");
                String[] s = arrayList.toArray(new String[arrayList.size()]);
                if (Integer.parseInt(TokenSign.getWorkIdByJwtToken(httpServletRequest)) == 47) {
                    cleanDryGoodPage = cleanMapper.listCleanDryGoodsNo(page, type, s, ids);
                } else {
                    cleanDryGoodPage = cleanMapper.listCleanDryGoods(page, farmId, type, s, ids);
                }
                if (Integer.parseInt(TokenSign.getWorkIdByJwtToken(httpServletRequest)) == 47) {

                } else {
                    queryWrapper.eq("farm_id", farmId);
                    queryWrapper2.eq("farm_id", farmId);
                    queryWrapper3.eq("farm_id", farmId);
                }
                queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper3.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
            }

            queryWrapper.eq("bill_status", 0);
            queryWrapper2.eq("bill_status", 0);
            queryWrapper3.eq("bill_status", 0);
            Integer integer = cleanMapper.selectCount(queryWrapper);
            Integer integer1 = dryMapper.selectCount(queryWrapper2);
            Integer integer2 = inventoryMapper.selectCount(queryWrapper3);
            return new Result(ResultCode.SUCCESS, cleanDryGoodPage, integer + integer1 + integer2);
        } else {
            Page<CleanAndDryVo2> cleanAndDryVo2Page = null;
            Page<CleanAndDryVo2> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
            QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("vistit_type", type);
            QueryWrapper<BillDry> queryWrapper2 = new QueryWrapper<>();
            queryWrapper2.eq("vistit_type", type);
            if ("0".equals(data)) {
                String[] s = {TokenSign.getWorkIdByJwtToken(httpServletRequest)};
                System.out.println("传入自定义sql的位置参数形式：" + s);
                if (Integer.parseInt(TokenSign.getWorkIdByJwtToken(httpServletRequest)) == 47) {
                    cleanAndDryVo2Page = cleanMapper.CleanAndDryNo(page, type, "0,1".split(","), s);
                } else {
                    cleanAndDryVo2Page = cleanMapper.CleanAndDry(page, farmId, type, "0,1".split(","), s);
                    queryWrapper.eq("farm_id",farmId);
                    queryWrapper2.eq("farm_id", farmId);
                }
                queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
            }
            if ("1".equals(data)) {
                String[] ids = {TokenSign.getWorkIdByJwtToken(httpServletRequest)};
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.add("0");
                String[] s = arrayList.toArray(new String[arrayList.size()]);
                if (Integer.parseInt(TokenSign.getWorkIdByJwtToken(httpServletRequest)) == 47) {
                    cleanAndDryVo2Page = cleanMapper.CleanAndDryNo(page, type, s, ids);
                } else {
                    cleanAndDryVo2Page = cleanMapper.CleanAndDry(page, farmId, type, s, ids);
                    queryWrapper.eq("farm_id",farmId);
                    queryWrapper2.eq("farm_id", farmId);
                }
                queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
            }
            if ("2".equals(data)) {
                String[] ids = {TokenSign.getWorkIdByJwtToken(httpServletRequest)};
                ArrayList<String> arrayList = new ArrayList<>();
                arrayList.add("1");
                String[] s = arrayList.toArray(new String[arrayList.size()]);
                if (Integer.parseInt(TokenSign.getWorkIdByJwtToken(httpServletRequest)) == 47) {
                    cleanAndDryVo2Page = cleanMapper.CleanAndDryNo(page, type, s, ids);
                } else {
                    cleanAndDryVo2Page = cleanMapper.CleanAndDry(page, farmId, type, s, ids);
                    queryWrapper.eq("farm_id",farmId);
                    queryWrapper2.eq("farm_id", farmId);
                }
                queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
                queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
            }
            queryWrapper.eq("bill_status", 0);
            queryWrapper2.eq("bill_status", 0);
            Integer integer = cleanMapper.selectCount(queryWrapper);
            Integer integer1 = dryMapper.selectCount(queryWrapper2);
            return new Result(ResultCode.SUCCESS, cleanAndDryVo2Page, integer + integer1);
        }

    }

    @Override
    public Result listPersonCleanAndDryAndGoods(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String pageNum = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        Page<CleanDryGoodsVo> cleanDryGoodPage = null;
        Page<CleanDryGoodsVo> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).eq("vistit_type", 5);
        QueryWrapper<BillDry> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("farm_id", farmId).eq("vistit_type", 5);
        QueryWrapper<BillGoodsInventory> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.eq("farm_id", farmId);

        String[] s = {TokenSign.getMemberIdByJwtToken(httpServletRequest).toString()};
        System.out.println("传入自定义sql的位置参数形式：" + s);
        cleanDryGoodPage = cleanMapper.listCleanDryGoods(page, farmId, "5", "0,1".split(","), s);
//        queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
//        queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));
//        queryWrapper3.in("current_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest));

        queryWrapper.eq("img_status", 0);
        queryWrapper2.eq("img_status", 0);
        queryWrapper3.eq("bill_status", 0);
        Integer integer = cleanMapper.selectCount(queryWrapper);
        Integer integer1 = dryMapper.selectCount(queryWrapper2);
        Integer integer2 = inventoryMapper.selectCount(queryWrapper3);
        return new Result(ResultCode.SUCCESS, cleanDryGoodPage, integer + integer1 + integer2);
    }

    @Override
    public Result listById(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        BillClean billClean = cleanMapper.selectById(id);
        return new Result(ResultCode.SUCCESS, billClean);
    }

    @Override
    public Result listByIdDry(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return new Result(ResultCode.SUCCESS, dryMapper.selectById(id));
    }

    @Override
    @Transactional
    public Result commitClean(HttpServletRequest httpServletRequest, String farmId, String id, String date, String result
            , MultipartFile img1, MultipartFile img2, MultipartFile img3) throws ParseException, IOException {

        String s1 = "";
        String s2 = "";
        String s3 = "";
        if (ObjectUtil.isNotEmpty(img1)) {
            if (uploadImage.getImageCom(img1).equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片1上传失败", false);
            }
            s1 = uploadImage.uploadImg(img1);
        }
        if (ObjectUtil.isNotEmpty(img2)) {
            if (uploadImage.getImageCom(img2).equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片2上传失败", false);
            }
            s2 = "," + uploadImage.uploadImg(img2);
        }
        if (ObjectUtil.isNotEmpty(img3)) {
            if (uploadImage.getImageCom(img3).equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片3上传失败", false);
            }
            s3 = "," + uploadImage.uploadImg(img3);
        }
        String s = s1 + s2 + s3;

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        if (StringUtils.isBlank(date)) {
            date = sdf.format(new Date());
        }
        BillClean billClean = cleanMapper.selectById(id);//某条洗消记录
        billClean.setImgUrl(s);
        billClean.setImgStatus(1);

        QueryWrapper<BaseProcess> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).eq("id", billClean.getProcessId());
        BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程

        QueryWrapper<BaseLocation> locationQueryWrapper = new QueryWrapper<>();
        locationQueryWrapper.eq("id", billClean.getTestLocationId());
        BaseLocation baseLocation = locationMapper.selectOne(locationQueryWrapper);//当前所在的位置

        QueryWrapper<Configuration> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.eq("farm_id", farmId);
        Configuration configuration = configurationMapper.selectOne(queryWrapper3);

        QueryWrapper<Exist> existQueryWrapper = new QueryWrapper<>();
        existQueryWrapper.eq("farm_id", farmId);
        Exist exist = existMapper.selectOne(existQueryWrapper);//判断是否有二级洗消站


        if (billClean.getBillStatus() != 0) {
            return new Result(10001, "该订单已通过，无需再次提交！", false);
        }
        if (billClean.getDestId() >= billClean.getTestLocationId()) { //不是目的地

            if ("1".equals(result)) {
                billClean.setBillStatus(1);
                billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                billClean.setTestLocation(baseLocation.getLocationName());
                billClean.setTestLocationId(baseLocation.getId());
                billClean.setCheckDate(sdf.parse(date));
                billClean.setPassDate(sdf.parse(sdf.format(new Date())));
                billClean.setCleanTime("20");

                if (exist.getExist() == 0) {
                    if (baseLocation.getId() == 1 && baseProcess.getDestId() > 2) {
                        //生成pcr检测申请
                        BillPcr billPcr = new BillPcr();
                        billPcr.setPcrType(0);
                        billPcr.setPhone(billClean.getPhone());
                        billPcr.setVistitType(billClean.getVistitType());
                        billPcr.setDestName(billClean.getDestName());
                        billPcr.setDestId(billClean.getDestId());
                        billPcr.setAdmissionUserName(billClean.getAdmissionUserName());
                        billPcr.setAdmissionUserId(billClean.getAdmissionUserId());
                        billPcr.setVistitDate(billClean.getVistitDate());
                        billPcr.setSubDate(LocalDateTime.now());
                        billPcr.setBillStatus(0);
                        billPcr.setProcessId(billClean.getProcessId());
                        billPcr.setFarmId(billClean.getFarmId());
                        billPcr.setTestLocation("人员二级洗消站");
                        billPcr.setTestLocationId(3);
                        billPcr.setQualifiedDate(configuration.getPcr());
                        pcrMapper.insert(billPcr);

                        String status = baseProcess.getAllLocationStatus();
                        String[] split1 = status.split(",");
                        split1[0] = "2";
                        split1[1] = "2";
                        split1[2] = "2";
                        split1[3] = "1";
                        baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + status.substring(7));
                    }
                    if (baseLocation.getId() == 3) {
                        //生成隔离申请
                        BillIsolate isolate = new BillIsolate();
                        isolate.setPhone(billClean.getPhone());
                        isolate.setVistitType(billClean.getVistitType());
                        isolate.setDestName(billClean.getDestName());
                        isolate.setDestId(billClean.getDestId());
                        isolate.setAdmissionUserName(billClean.getAdmissionUserName());
                        isolate.setAdmissionUserId(billClean.getAdmissionUserId());
                        isolate.setVistitDate(billClean.getVistitDate());
                        isolate.setSubDate(billClean.getSubDate());
                        isolate.setFarmId(billClean.getFarmId());
                        isolate.setBillStatus(0);
                        isolate.setIsolateDayNum("");
                        isolate.setProcessId(billClean.getProcessId());
                        isolate.setIsolateLocation(baseLocation.getLocationName());
                        isolate.setIsolateLocationId(baseLocation.getId());
                        isolateMapper.insert(isolate);

                        String status = baseProcess.getAllLocationStatus();
                        String[] split1 = status.split(",");
                        split1[0] = "2";
                        split1[1] = "2";
                        split1[2] = "2";
                        split1[3] = "1";
                        baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + status.substring(7));
                    }
                }
                if (exist.getExist() == 1 && billClean.getDestId() >= 4 && baseLocation.getId() == 1) {
                    BillClean billClean1 = new BillClean();
                    billClean1.setVistitType(billClean.getVistitType());
                    billClean1.setDestName(billClean.getDestName());
                    billClean1.setDestId(billClean.getDestId());
                    billClean1.setAdmissionUserId(billClean.getAdmissionUserId());
                    billClean1.setAdmissionUserName(billClean.getAdmissionUserName());
                    billClean1.setVistitDate(billClean.getVistitDate());
                    billClean1.setSubDate(LocalDateTime.now());
                    billClean1.setFarmId(billClean.getFarmId());
                    billClean1.setBillStatus(0);
                    billClean1.setProcessId(billClean.getProcessId());
                    billClean1.setPhone(billClean.getPhone());
                    billClean1.setTestLocation("场内");
                    billClean1.setTestLocationId(4);
                    billCleanMapper.insert(billClean1);
                    String status = baseProcess.getAllLocationStatus();
                    String[] split1 = status.split(",");
                    split1[0] = "2";
                    split1[1] = "2";
                    split1[2] = "2";
                    split1[3] = "1";
                    baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + status.substring(7));
                }


                if (baseLocation.getId() == 4) {
                    QueryWrapper<BillPcr> queryWrapper1 = new QueryWrapper<>();
                    queryWrapper1.eq("farm_id", farmId).eq("process_id", baseProcess.getId()).eq("test_location_id", 4);
                    if (ObjectUtil.isEmpty(pcrMapper.selectOne(queryWrapper1))) {
                        //生成pcr检测申请
                        BillPcr billPcr = new BillPcr();
                        billPcr.setPcrType(0);
                        billPcr.setPhone(billClean.getPhone());
                        billPcr.setVistitType(billClean.getVistitType());
                        billPcr.setDestName(billClean.getDestName());
                        billPcr.setDestId(billClean.getDestId());
                        billPcr.setAdmissionUserName(billClean.getAdmissionUserName());
                        billPcr.setAdmissionUserId(billClean.getAdmissionUserId());
                        billPcr.setVistitDate(billClean.getVistitDate());
                        billPcr.setSubDate(LocalDateTime.now());
                        billPcr.setBillStatus(0);
                        billPcr.setProcessId(billClean.getProcessId());
                        billPcr.setFarmId(billClean.getFarmId());
                        billPcr.setTestLocation("场内");
                        billPcr.setTestLocationId(4);
                        billPcr.setQualifiedDate(configuration.getPcr());
                        pcrMapper.insert(billPcr);

                        if (exist.getExist() == 0) {
                            String status = baseProcess.getAllLocationStatus();
                            String[] split1 = status.split(",");
                            split1[0] = "2";
                            split1[1] = "2";
                            split1[2] = "2";
                            split1[3] = "2";
                            split1[4] = "1";
                            baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + "," + split1[4] + status.substring(9));
                        } else {
                            String status = baseProcess.getAllLocationStatus();
                            String[] split1 = status.split(",");
                            split1[0] = "2";
                            split1[1] = "2";
                            split1[2] = "2";
                            split1[3] = "1";
                            baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + status.substring(7));
                        }

                    } else {
                        //生成隔离申请
                        BillIsolate isolate = new BillIsolate();
                        isolate.setPhone(billClean.getPhone());
                        isolate.setVistitType(billClean.getVistitType());
                        isolate.setDestName(billClean.getDestName());
                        isolate.setDestId(billClean.getDestId());
                        isolate.setAdmissionUserName(billClean.getAdmissionUserName());
                        isolate.setAdmissionUserId(billClean.getAdmissionUserId());
                        isolate.setVistitDate(billClean.getVistitDate());
                        isolate.setSubDate(LocalDateTime.now());
                        isolate.setFarmId(billClean.getFarmId());
                        isolate.setBillStatus(0);
                        isolate.setIsolateDayNum("");
                        isolate.setProcessId(billClean.getProcessId());
//                        isolate.setIsolateLocation(baseLocation.getNextLocation());
//                        isolate.setIsolateLocationId(baseLocation.getNextId());
                        isolateMapper.insert(isolate);

                        if (exist.getExist() == 0) {
                            String status = baseProcess.getAllLocationStatus();
                            String[] split1 = status.split(",");
                            split1[0] = "2";
                            split1[1] = "2";
                            split1[2] = "2";
                            split1[3] = "2";
                            split1[4] = "2";
                            baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + "," + split1[4] + "," + "1");
                        } else {
                            String status = baseProcess.getAllLocationStatus();
                            String[] split1 = status.split(",");
                            split1[0] = "2";
                            split1[1] = "2";
                            split1[2] = "2";
                            split1[3] = "2";
                            baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + "," + "1");
                        }


                    }
                }


                if (baseProcess.getDestId() == 1) {
                    baseProcess.setAllLocationStatus("2,2");
                }

                if (baseProcess.getDestId() == 4 && baseLocation.getId() == 1) {

                    baseProcess.setAllLocationStatus("2,2,2,1,0");
                }

                if (baseProcess.getDestId() == 2) {
                    baseProcess.setAllLocationStatus("2,2,2");
                }

                baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
                baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + "," + baseLocation.getLocationName());
                baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + "," + baseLocation.getId());
                String status = baseProcess.getCurrentStatus();
                String substring = status.substring(0, status.length() - 1);
                baseProcess.setCurrentStatus(substring + "1," + 0);
            } else {
                billClean.setBillStatus(2);
                billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                billClean.setTestLocation(baseLocation.getLocationName());
                billClean.setTestLocationId(baseLocation.getId());
                billClean.setCheckDate(sdf.parse(date));
                billClean.setPassDate(sdf.parse(sdf.format(new Date())));
                billClean.setCleanTime("20");


                if (baseProcess.getDestId() == 1) {
                    baseProcess.setAllLocationStatus("2,3");
                }
                if (baseProcess.getDestId() == 2) {
                    baseProcess.setAllLocationStatus("2,3,0");
                }
                if (baseProcess.getDestId() >= 3 && baseLocation.getId() == 3) {
                    String status = baseProcess.getAllLocationStatus();
                    String[] split1 = status.split(",");
                    split1[0] = "2";
                    split1[1] = "2";
                    split1[2] = "2";
                    split1[3] = "3";
                    baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + status.substring(7));
                }


                if (baseLocation.getId() == 1 && baseProcess.getDestId() > 2) {
                    String status = baseProcess.getAllLocationStatus();
                    String[] split1 = status.split(",");
                    split1[0] = "2";
                    split1[1] = "3";
                    split1[2] = "0";
                    split1[3] = "0";
                    baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + status.substring(7));
                }
                if (baseLocation.getId() == 4 && exist.getExist() == 0) {
                    String status = baseProcess.getAllLocationStatus();
                    String[] split1 = status.split(",");
                    split1[0] = "2";
                    split1[1] = "2";
                    split1[2] = "2";
                    split1[3] = "2";
                    split1[4] = "3";
                    baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + "," + split1[4] + status.substring(9));
                }
                if (exist.getExist() == 1 && baseProcess.getDestId() > 2 && baseLocation.getId() == 4) {
                    String status = baseProcess.getAllLocationStatus();
                    String[] split1 = status.split(",");
                    split1[0] = "2";
                    split1[1] = "2";
                    split1[2] = "2";
                    split1[3] = "3";
                    baseProcess.setAllLocationStatus(split1[0] + "," + split1[1] + "," + split1[2] + "," + split1[3] + status.substring(7));
                }

                baseProcess.setProcessType(2);
                baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
                baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
                baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
                String status = baseProcess.getCurrentStatus();
                String substring = status.substring(0, status.length() - 1);
                baseProcess.setCurrentStatus(substring + "2");
            }
            cleanMapper.updateById(billClean);
            processMapper.updateById(baseProcess);
            return new Result(10000, "修改成功！", true);
        } else {
            //当前是目的地
            if ("1".equals(result)) {
                billClean.setBillStatus(1);
                baseProcess.setProcessType(1);
            } else {
                billClean.setBillStatus(2);
                baseProcess.setProcessType(2);
            }
            billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
            billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
            billClean.setTestLocation(baseLocation.getLocationName());
            billClean.setTestLocationId(baseLocation.getId());
            billClean.setCheckDate(sdf.parse(date));
            billClean.setPassDate(sdf.parse(sdf.format(new Date())));
            billClean.setCleanTime("20");

            baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
            baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
            baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
            String status = baseProcess.getCurrentStatus();
            String substring = status.substring(0, status.length() - 1);
            baseProcess.setCurrentStatus(substring + "1");

            String ids = baseProcess.getAllLocationId();
            String[] split = ids.split(",");
            Integer s22 = 0;
            for (int i = 0; i < split.length; i++) {
                if (Integer.parseInt(split[i]) == baseLocation.getId()) {
                    s22 = i;
                }
            }
            String status1 = baseProcess.getAllLocationStatus();
            StringBuilder split1 = new StringBuilder(status1);
            split1.replace(s22, s22 + 1, "3");
            baseProcess.setAllLocationStatus(split1.toString());

            if (baseProcess.getDestId() == 1) {
                baseProcess.setAllLocationStatus("2,3");
            }

            if (baseProcess.getDestId() == 3) {
                baseProcess.setAllLocationStatus("2,2,3");
            }
            if (baseProcess.getDestId() == 4) {
                baseProcess.setAllLocationStatus("2,2,2,3");
            }

            processMapper.updateById(baseProcess);
            cleanMapper.updateById(billClean);
            return new Result(10000, "修改成功！", true);
        }

    }

    @Resource
    private BillCleanMapper billCleanMapper;
    @Autowired
    private BillCleanBeforeMapper beforeMapper;
    @Autowired
    private BillSamplingMapper samplingMapper;


    @Override
    public Result listPersonalClean(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String pageNo = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        String vistitType = paramsMap.get("vistitType");
        Page<BillClean> page = new Page<>(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(vistitType), "vistit_type", vistitType).eq("admission_user_id", TokenSign.getMemberIdByJwtToken(httpServletRequest)).orderByDesc("sub_date");
        return new Result(ResultCode.SUCCESS, billCleanMapper.selectPage(page, new QueryWrapper<BillClean>().eq(StringUtils.isNotBlank(vistitType), "vistit_type", vistitType).eq("admission_user_id", TokenSign.getMemberIdByJwtToken(httpServletRequest)).orderByDesc("sub_date")), billCleanMapper.selectCount(queryWrapper));
    }

    @Override
    @Transactional
    public Result carClean(HttpServletRequest httpServletRequest, String farmId, String id, String data, MultipartFile img1, MultipartFile img2, MultipartFile img3, MultipartFile img4, MultipartFile img5, String type) throws ParseException, IOException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        if (StringUtils.isBlank(data)) {
            data = sdf.format(new Date());
        }


        if ("1".equals(type)) {
            BillClean billClean1 = cleanMapper.selectById(id);//某条洗消记录
            if (billClean1.getBillStatus() != 0) {
                return new Result(10001, "该订单已通过，无需再次提交！", false);
            }
            //洗消上传
            BillClean billClean = cleanMapper.selectById(id);//某条洗消记录
            System.out.println("洗消记录的id:" + billClean.getTestLocationId());
            Integer testId = billClean.getTestLocationId();
            QueryWrapper<BaseLocation> locationQueryWrapper = new QueryWrapper<>();
            locationQueryWrapper.eq("id", testId);
            BaseLocation baseLocation = locationMapper.selectOne(locationQueryWrapper);//当前所在的位置

            QueryWrapper<BaseProcess> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("farm_id", farmId).eq("id", billClean.getProcessId());
//            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程

            billClean.setBillStatus(0);
            billClean.setImgStatus(1);
            billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
            billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
            billClean.setTestLocation(baseLocation.getLocationName());
            billClean.setTestLocationId(baseLocation.getId());
            billClean.setCheckDate(sdf.parse(data));
            billClean.setPassDate(sdf.parse(sdf.format(new Date())));
            billClean.setCleanTime("20");
            String s1 = "";
            String s2 = "";
            String s3 = "";
            String s4 = "";
            String s5 = "";
            if (ObjectUtil.isNotEmpty(img1)) {
                if (uploadImage.getImageCom(img1).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片1上传失败", false);
                }
                s1 = uploadImage.uploadImg(img1);
            }
            if (ObjectUtil.isNotEmpty(img2)) {
                if (uploadImage.getImageCom(img2).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片2上传失败", false);
                }
                s2 = "," + uploadImage.uploadImg(img2);
            }
            if (ObjectUtil.isNotEmpty(img3)) {
                if (uploadImage.getImageCom(img3).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片3上传失败", false);
                }
                s3 = "," + uploadImage.uploadImg(img3);
            }
            if (ObjectUtil.isNotEmpty(img4)) {
                if (uploadImage.getImageCom(img4).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片4上传失败", false);
                }
                s4 = "," + uploadImage.uploadImg(img4);
            }
            if (ObjectUtil.isNotEmpty(img5)) {
                if (uploadImage.getImageCom(img5).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片5上传失败", false);
                }
                s5 = "," + uploadImage.uploadImg(img5);
            }
            String s = s1 + s2 + s3 + s4 + s5;
            billClean.setImgUrl(s);
            cleanMapper.updateById(billClean);
            //物资车生成二次申请

        } else {
            BillDry billClean = dryMapper.selectById(id);//某条烘干记录
            if (billClean.getBillStatus() != 0) {
                return new Result(10001, "该订单已通过，无需再次提交！", false);
            }
            System.out.println("洗消记录的id:" + billClean.getTestLocationId());
            Integer testId = billClean.getTestLocationId();
            QueryWrapper<BaseLocation> locationQueryWrapper = new QueryWrapper<>();
            locationQueryWrapper.eq("id", testId);
            BaseLocation baseLocation = locationMapper.selectOne(locationQueryWrapper);//当前所在的位置

            QueryWrapper<BaseProcess> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("farm_id", farmId).eq("id", billClean.getProcessId());
//            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程

            billClean.setBillStatus(0);
            billClean.setImgStatus(1);
            billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
            billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
            billClean.setTestLocation(baseLocation.getLocationName());
            billClean.setTestLocationId(baseLocation.getId());
            billClean.setCheckDate(sdf.parse(data));
            billClean.setPassDate(sdf.parse(sdf.format(new Date())));
            billClean.setDryTem("70");
            billClean.setDryTime("40");
            String s1 = "";
            String s2 = "";
            String s3 = "";
            String s4 = "";
            String s5 = "";
            if (ObjectUtil.isNotEmpty(img1)) {
                if (uploadImage.getImageCom(img1).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片1上传失败", false);
                }
                s1 = uploadImage.uploadImg(img1);
            }
            if (ObjectUtil.isNotEmpty(img2)) {
                if (uploadImage.getImageCom(img2).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片2上传失败", false);
                }
                s2 = "," + uploadImage.uploadImg(img2);
            }
            if (ObjectUtil.isNotEmpty(img3)) {
                if (uploadImage.getImageCom(img3).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片3上传失败", false);
                }
                s3 = "," + uploadImage.uploadImg(img3);
            }
            if (ObjectUtil.isNotEmpty(img4)) {
                if (uploadImage.getImageCom(img4).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片4上传失败", false);
                }
                s4 = "," + uploadImage.uploadImg(img4);
            }
            if (ObjectUtil.isNotEmpty(img5)) {
                if (uploadImage.getImageCom(img5).equals("上传失败")) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return new Result(10001, "图片5上传失败", false);
                }
                s5 = "," + uploadImage.uploadImg(img5);
            }
            String s = s1 + s2 + s3 + s4 + s5;
            billClean.setImgUrl(s);
            dryMapper.updateById(billClean);
        }

        return new Result(10000, "提交成功！", true);
    }

    @Override
    public Result listCleanAndDry(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String type = paramsMap.get("type");
        String pageNo = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        Page<CleanAndDryVo> page = new Page<>(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        Page<CleanAndDryVo> cleanAndDryVoPage;
        switch (type) {
            case "1":
                cleanAndDryVoPage = billCleanMapper.listCleanAndDry(page, Integer.parseInt(TokenSign.getFarmIds(httpServletRequest)), 0);
                break;
            case "2":
                cleanAndDryVoPage = billCleanMapper.listCleanAndDry(page, Integer.parseInt(TokenSign.getFarmIds(httpServletRequest)), 1);
                break;
            case "3":
                cleanAndDryVoPage = billCleanMapper.listCleanAndDry(page, Integer.parseInt(TokenSign.getFarmIds(httpServletRequest)), 2);
                break;
            default:
                cleanAndDryVoPage = billCleanMapper.listCleanAndDry(page, Integer.parseInt(TokenSign.getFarmIds(httpServletRequest)));
                break;
        }

        return new Result(ResultCode.SUCCESS, cleanAndDryVoPage, cleanAndDryVoPage.getSize());
    }

    @Override
    public Result listPersonalCleanAndDry(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String pageNo = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        String vistitType = paramsMap.get("vistitType");
        Page<CleanAndDryVo> page = new Page<>(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
        Page<CleanAndDryVo> cleanAndDryVoPage = cleanMapper.listPersonalCleanAndDry(page, userId, vistitType);
        return new Result(ResultCode.SUCCESS, cleanAndDryVoPage, cleanAndDryVoPage.getSize());
    }

    @Override
    @Transactional
    public Result goodsCarClean(HttpServletRequest httpServletRequest, String farmId, String id, String date, MultipartFile img1,
                                MultipartFile img2, MultipartFile img3, MultipartFile img4, MultipartFile img5, String type, String result
    ) throws ParseException, IOException {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        if (StringUtils.isBlank(date)) {
            date = sdf.format(new Date());
        }
        String s1 = "";
        String s2 = "";
        String s3 = "";
        String s4 = "";
        String s5 = "";
        if (ObjectUtil.isNotEmpty(img1)) {
            String imageCom = uploadImage.getImageCom(img1);
            if (imageCom.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片1上传失败", false);
            }
            s1 = imageCom;
        }
        if (ObjectUtil.isNotEmpty(img2)) {
            String imageCom = uploadImage.getImageCom(img2);
            if (imageCom.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片2上传失败", false);
            }
            s2 = "," + imageCom;
        }
        if (ObjectUtil.isNotEmpty(img3)) {
            String imageCom = uploadImage.getImageCom(img3);
            if (imageCom.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片3上传失败", false);
            }
            s3 = "," + imageCom;
        }
        if (ObjectUtil.isNotEmpty(img4)) {
            String imageCom = uploadImage.getImageCom(img4);
            if (imageCom.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片4上传失败", false);
            }
            s4 = "," + imageCom;
        }
        if (ObjectUtil.isNotEmpty(img5)) {
            String imageCom = uploadImage.getImageCom(img5);
            if (imageCom.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "图片5上传失败", false);
            }
            s5 = "," + imageCom;
        }
        String s = s1 + s2 + s3 + s4 + s5;

        if ("1".equals(type)) {
            BillClean billClean = cleanMapper.selectById(id);//某条洗消记录
            if (billClean.getBillStatus() != 0) {
                return new Result(10001, "此条记录已被他人修改，请退出刷新查看！", false);
            }
            QueryWrapper<BaseProcess> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", billClean.getProcessId());
            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程
            QueryWrapper<BaseLocation> locationQueryWrapper = new QueryWrapper<>();
            locationQueryWrapper.eq("id", billClean.getTestLocationId());
            BaseLocation baseLocation = locationMapper.selectOne(locationQueryWrapper);//当前所在的位置

            String allLocationId = baseProcess.getAllLocationId();//所有的位置id
            String allFlowId = baseProcess.getAllFlowId();//所有的流程id
            String currentFlowId = baseProcess.getCurrentFlowId();//当前已经完成的流程id
            String substring1 = allFlowId.substring(currentFlowId.length() + 1, allFlowId.length());
            String[] splits = substring1.split(",");
            Integer nextId = Integer.parseInt(splits[0]);

            if ("1".equals(result)) {
                billClean.setBillStatus(1);
                billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                billClean.setTestLocation(baseLocation.getLocationName());
                billClean.setTestLocationId(baseLocation.getId());
                billClean.setCheckDate(sdf.parse(date));
                billClean.setPassDate(sdf.parse(sdf.format(new Date())));
                billClean.setImgUrl(s);
                billClean.setImgStatus(1);
                billClean.setCleanTime("20");
                cleanMapper.updateById(billClean);

                Object newObject = BillPcrServiceImpl.getNewObject(nextId, billClean.getDestName(), billClean.getDestId(), billClean.getAdmissionUserName(),
                        billClean.getAdmissionUserId(), billClean.getVistitDate(), billClean.getSubDate(),
                        billClean.getProcessId(), billClean.getFarmId(), billClean.getTestLocation(), billClean.getTestLocationId(),
                        billClean.getVistitType(), billClean.getPhone(), billClean.getDepartureName(), billClean.getDepartureId(),
                        billClean.getMidId(),billClean.getMidName(),billClean.getFarmName());
                if (nextId == 0) {
                    if (splits.length == 1) {
                        baseProcess.setProcessType(1);
                        String[] strings = allLocationId.split(",");
                        String ss2 = "";
                        for (int i = 0; i < strings.length; i++) {
                            strings[i].replaceAll(strings[i], "2");
                            if (i == strings.length - 1) {
                                ss2 = ss2 + strings[i].replaceAll(strings[i], "2");
                            } else {
                                ss2 = strings[i].replaceAll(strings[i], "2") + "," + ss2;
                            }
                        }
                        baseProcess.setAllLocationStatus(ss2);
                    }  else {
                        String[] strings = allLocationId.split(",");
                        Integer index = 0;
                        for (int i = 0; i < strings.length; i++) {
                            if ((baseLocation.getId().toString()).equals(strings[i])) {
                                index = i;
                            }
                        }
                        QueryWrapper<BaseLocation> queryWrapper1 = new QueryWrapper();
                        queryWrapper1.eq("id", strings[index + 2]);
                        BaseLocation location = locationMapper.selectOne(queryWrapper1);
                        FlowUtil flowUtil = new FlowUtil();
                        Object entity = flowUtil.getEntity(Integer.parseInt(splits[1]), billClean.getVistitType(), billClean.getDestName()
                                , billClean.getDestId(), billClean.getAdmissionUserId(), billClean.getAdmissionUserName(), billClean.getPhone(),
                                billClean.getVistitDate(), location.getId(), location.getLocationName(),  billClean.getFarmId()
                                , baseProcess.getId(), billClean.getDepartureName(), billClean.getDepartureId(),
                                billClean.getMidId(),billClean.getMidName(),billClean.getFarmName());
                        if (Integer.parseInt(splits[1]) == 1) {
                            //新增采样
                            BillSampling billSampling = (BillSampling) entity;
                            if (billClean.getVistitType() != 0) {
                                billSampling.setCarNum(billClean.getCarNum());
                            }
                            if (billClean.getVistitType() == 5) {
                                billSampling.setResource(billClean.getResource());
                                billSampling.setFeedImgUrl(billClean.getFeedImgUrl());
                                billSampling.setRemark(billClean.getRemark());
                            }
                            samplingMapper.insert(billSampling);
                        } else if (Integer.parseInt(splits[1]) == 2) {
                            //新增pcr
                            BillPcr billClean1 = (BillPcr) entity;
                            if (billClean.getVistitType() != 0) {
                                billClean1.setCarNum(billClean.getCarNum());
                            }
                            if (billClean.getVistitType() == 5) {
                                billClean1.setResource(billClean.getResource());
                                billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                                billClean1.setRemark(billClean.getRemark());
                            }
                            pcrMapper.insert(billClean1);
                        } else if (Integer.parseInt(splits[1]) == 3) {
                            //新增洗澡
                            BillClean billClean1 = (BillClean) entity;
                            if (billClean.getVistitType() != 0) {
                                billClean1.setCarNum(billClean.getCarNum());
                            }
                            if (billClean.getVistitType() == 5) {
                                billClean1.setResource(billClean.getResource());
                                billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                                billClean1.setRemark(billClean.getRemark());
                            }
                            cleanMapper.insert(billClean1);
                        } else if (Integer.parseInt(splits[1]) == 4) {
                            //新增隔离
                            BillIsolate pcr = (BillIsolate) entity;
                            if (billClean.getVistitType() != 0) {
                                pcr.setCarNum(billClean.getCarNum());
                            }
                            if (billClean.getVistitType() == 5) {
                                pcr.setResource(billClean.getResource());
                                pcr.setFeedImgUrl(billClean.getFeedImgUrl());
                                pcr.setRemark(billClean.getRemark());
                            }
                            isolateMapper.insert(pcr);
                        } else if (Integer.parseInt(splits[1]) == 5) {
                            BillDry billClean1 = (BillDry) entity;
                            if (billClean.getVistitType() != 0) {
                                billClean1.setCarNum(billClean.getCarNum());
                            }
                            if (billClean.getVistitType() == 5) {
                                billClean1.setResource(billClean.getResource());
                                billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                                billClean1.setRemark(billClean.getRemark());
                            }
                            dryMapper.insert(billClean1);
                            //新增烘干
                        } else if (Integer.parseInt(splits[1]) == 6) {
                            //新增洗澡前拍照
                            BillCleanBefore before = (BillCleanBefore) entity;
                            if (billClean.getVistitType() != 0) {
                                before.setCarNum(billClean.getCarNum());
                            }
                            if (billClean.getVistitType() == 5) {
                                before.setResource(billClean.getResource());
                                before.setFeedImgUrl(billClean.getFeedImgUrl());
                                before.setRemark(billClean.getRemark());
                            }
                            beforeMapper.insert(before);
                        } else if (Integer.parseInt(splits[1]) == 7) {
                            //新增洗澡前拍照
                            BillGoodsInventory before = (BillGoodsInventory) entity;
                            if (billClean.getVistitType() != 0) {
                                before.setCarNum(billClean.getCarNum());
                            }
                            if (billClean.getVistitType() == 5) {
                                before.setResource(billClean.getResource());
                                before.setFeedImgUrl(billClean.getFeedImgUrl());
                                before.setRemark(billClean.getRemark());
                            }
                            inventoryMapper.insert(before);
                        }
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId + "," + splits[1]);
                        Integer locationId = billClean.getTestLocationId();
                        String[] split2 = allLocationId.split(",");
                        int a=0;
                        for (int i = 0; i < split2.length; i++) {
                            if (locationId.toString().equals(split2[i])) {
                                a = i + 1;
                            }
                        }
                        int indexOf = 2 * (a - 2);//当前位置在所有流程位置中的下标
                        String substring = baseProcess.getAllLocationStatus().substring(0, indexOf + 3);//截取已经过的位置状态
                        String[] split1 = substring.split(",");
                        String sb2 = "";
                        for (int i = 0; i < split1.length; i++) {
                            if (i == split1.length - 1) {
                                sb2 = sb2 + split1[i].replaceAll(split1[i], "2");
                            } else {
                                sb2 = split1[i].replaceAll(split1[i], "2") + "," + sb2;
                            }
                        }
                        sb2 = sb2 + baseProcess.getAllLocationStatus().substring(indexOf + 3);
                        StringBuilder sb = new StringBuilder(sb2);
                        sb.replace(indexOf + 4, indexOf + 5, "2");
                        sb.replace(indexOf + 6, indexOf + 7, "1");
                        baseProcess.setAllLocationStatus(sb.toString());
                    }
                } else if (nextId == 1) {
                    //新增采样
                    BillSampling billSampling = (BillSampling) newObject;
                    if (billClean.getVistitType() != 0) {
                        billSampling.setCarNum(billClean.getCarNum());
                    }
                    if (billClean.getVistitType() == 5) {
                        billSampling.setResource(billClean.getResource());
                        billSampling.setFeedImgUrl(billClean.getFeedImgUrl());
                        billSampling.setRemark(billClean.getRemark());
                    }
                    samplingMapper.insert(billSampling);
                    baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                } else if (nextId == 2) {
                    //新增pcr
                    BillPcr billClean1 = (BillPcr) newObject;
                    if (billClean.getVistitType() != 0) {
                        billClean1.setCarNum(billClean.getCarNum());
                    }
                    if (billClean.getVistitType() == 5) {
                        billClean1.setResource(billClean.getResource());
                        billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                        billClean1.setRemark(billClean.getRemark());
                    }
                    pcrMapper.insert(billClean1);
                    baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                } else if (nextId == 3) {
                    //新增洗澡
                    BillClean billClean2 = (BillClean) newObject;
                    if (billClean.getVistitType() != 0) {
                        billClean2.setCarNum(billClean.getCarNum());
                    }
                    if (billClean.getVistitType() == 5) {
                        billClean2.setResource(billClean.getResource());
                        billClean2.setFeedImgUrl(billClean.getFeedImgUrl());
                        billClean2.setRemark(billClean.getRemark());
                    }
                    cleanMapper.insert(billClean2);
                    baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                } else if (nextId == 4) {
                    //新增隔离
                    BillIsolate pcr = (BillIsolate) newObject;
                    if (billClean.getVistitType() != 0) {
                        pcr.setCarNum(billClean.getCarNum());
                    }
                    if (billClean.getVistitType() == 5) {
                        pcr.setResource(billClean.getResource());
                        pcr.setFeedImgUrl(billClean.getFeedImgUrl());
                        pcr.setRemark(billClean.getRemark());
                    }
                    isolateMapper.insert(pcr);
                    baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                } else if (nextId == 5) {
                    BillDry billClean2 = (BillDry) newObject;
                    if (billClean.getVistitType() != 0) {
                        billClean2.setCarNum(billClean.getCarNum());
                    }
                    if (billClean.getVistitType() == 5) {
                        billClean2.setResource(billClean.getResource());
                        billClean2.setFeedImgUrl(billClean.getFeedImgUrl());
                        billClean2.setRemark(billClean.getRemark());
                    }
                    dryMapper.insert(billClean2);
                    baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                    //新增烘干
                } else if (nextId == 6) {
                    //新增洗澡前拍照
                    BillCleanBefore before = (BillCleanBefore) newObject;
                    if (billClean.getVistitType() != 0) {
                        before.setCarNum(billClean.getCarNum());
                    }
                    if (billClean.getVistitType() == 5) {
                        before.setResource(billClean.getResource());
                        before.setFeedImgUrl(billClean.getFeedImgUrl());
                        before.setRemark(billClean.getRemark());
                    }
                    beforeMapper.insert(before);
                    baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                } else if (nextId == 7) {
                    //新增洗澡前拍照
                    BillGoodsInventory before = (BillGoodsInventory) newObject;
                    if (billClean.getVistitType() != 0) {
                        before.setCarNum(billClean.getCarNum());
                    }
                    if (billClean.getVistitType() == 5) {
                        before.setResource(billClean.getResource());
                        before.setFeedImgUrl(billClean.getFeedImgUrl());
                        before.setRemark(billClean.getRemark());
                    }
                    inventoryMapper.insert(before);
                    baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                }
                baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
                baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + "," + baseLocation.getLocationName());
                baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + "," + baseLocation.getId());
                String status = baseProcess.getCurrentStatus();
                String substring = status.substring(0, status.length() - 1);
                baseProcess.setCurrentStatus(substring + "1," + 0);
                processMapper.updateById(baseProcess);
            } else {
                billClean.setImgStatus(1);
                billClean.setImgUrl(s);
                billClean.setBillStatus(2);
                billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                billClean.setTestLocation(baseLocation.getLocationName());
                billClean.setTestLocationId(baseLocation.getId());
                billClean.setCheckDate(sdf.parse(date));
                billClean.setPassDate(sdf.parse(sdf.format(new Date())));
                billClean.setCleanTime("20");

                baseProcess.setProcessType(2);
                baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
                baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
                baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
                String status = baseProcess.getCurrentStatus();
                String substring = status.substring(0, status.length() - 1);
                baseProcess.setCurrentStatus(substring + "2");


                int i = allLocationId.indexOf(billClean.getTestLocationId().toString());
                String status1 = baseProcess.getAllLocationStatus();
                System.out.println(status1);
                StringBuilder sb = new StringBuilder(status1);
                sb.setCharAt(i-1, '3');
                baseProcess.setAllLocationStatus(sb.toString());

                cleanMapper.updateById(billClean);
                processMapper.updateById(baseProcess);
            }
            return new Result(10000, "修改成功！", true);


        } else {
            BillDry billClean = dryMapper.selectById(id);//某条烘干记录
            if (billClean.getBillStatus() != 0) {
                return new Result(10001, "此条记录已被他人修改，请退出刷新查看！", false);
            }
            QueryWrapper<BaseProcess> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id", billClean.getProcessId());
            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程
            QueryWrapper<BaseLocation> locationQueryWrapper = new QueryWrapper<>();
            locationQueryWrapper.eq("id", billClean.getTestLocationId());
            BaseLocation baseLocation = locationMapper.selectOne(locationQueryWrapper);//当前所在的位置

            String allLocationId = baseProcess.getAllLocationId();//所有的位置id
            String allFlowId = baseProcess.getAllFlowId();//所有的流程id
            String currentFlowId = baseProcess.getCurrentFlowId();//当前已经完成的流程id
            String substring1 = allFlowId.substring(currentFlowId.length() + 1, allFlowId.length());
            String[] splits = substring1.split(",");
            Integer nextId = Integer.parseInt(splits[0]);
            if (baseProcess.getProcessType() == 2 || baseProcess.getProcessType() == 1) {
                return new Result(10001, "修改失败！该申请已提前结束或者被拒绝", false);
            } else {
                if ("1".equals(result)) {
                    //烘干通过
                    billClean.setImgUrl(s);
                    billClean.setBillStatus(1);
                    billClean.setPassDate(new Date());
                    billClean.setCheckDate(new Date());
                    billClean.setPhone(billClean.getPhone());
                    billClean.setCarNum(billClean.getCarNum());
                    billClean.setImgStatus(1);
                    billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                    billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                    billClean.setTestLocation(baseLocation.getLocationName());
                    billClean.setTestLocationId(baseLocation.getId());
                    billClean.setDryTime("40");
                    billClean.setDryTem("70");
                    dryMapper.updateById(billClean);

                    Object newObject = BillPcrServiceImpl.getNewObject(nextId, billClean.getDestName(), billClean.getDestId(), billClean.getAdmissionUserName(),
                            billClean.getAdmissionUserId(), billClean.getVistitDate(), billClean.getSubDate(),
                            billClean.getProcessId(), billClean.getFarmId(), billClean.getTestLocation(), billClean.getTestLocationId(),
                            billClean.getVistitType(), billClean.getPhone(), billClean.getDepartureName(),
                            billClean.getDepartureId(),billClean.getMidId(),billClean.getMidName(),billClean.getFarmName());
                    if (nextId == 0) {
                        if (splits.length == 1) {
                            baseProcess.setProcessType(1);
                            String[] strings = allLocationId.split(",");
                            String ss2 = "";
                            for (int i = 0; i < strings.length; i++) {
                                strings[i].replaceAll(strings[i], "2");
                                if (i == strings.length - 1) {
                                    ss2 = ss2 + strings[i].replaceAll(strings[i], "2");
                                } else {
                                    ss2 = strings[i].replaceAll(strings[i], "2") + "," + ss2;
                                }
                            }
                            baseProcess.setAllLocationStatus(ss2);
                        }  else {
                            String[] strings = allLocationId.split(",");
                            Integer index = 0;
                            for (int i = 0; i < strings.length; i++) {
                                if ((baseLocation.getId().toString()).equals(strings[i])) {
                                    index = i;
                                }
                            }
                            QueryWrapper<BaseLocation> queryWrapper1 = new QueryWrapper();
                            queryWrapper1.eq("id", strings[index + 2]);
                            BaseLocation location = locationMapper.selectOne(queryWrapper1);
                            FlowUtil flowUtil = new FlowUtil();
                            Object entity = flowUtil.getEntity(Integer.parseInt(splits[1]), billClean.getVistitType(), billClean.getDestName()
                                    , billClean.getDestId(), billClean.getAdmissionUserId(), billClean.getAdmissionUserName(), billClean.getPhone(),
                                    billClean.getVistitDate(), location.getId(), location.getLocationName(),  billClean.getFarmId()
                                    , baseProcess.getId(), billClean.getDepartureName(),
                                    billClean.getDepartureId(),billClean.getMidId(),billClean.getMidName(),billClean.getFarmName());
                            if (Integer.parseInt(splits[1]) == 1) {
                                //新增采样
                                BillSampling billSampling = (BillSampling) entity;
                                if (billClean.getVistitType() != 0) {
                                    billSampling.setCarNum(billClean.getCarNum());
                                }
                                if (billClean.getVistitType() == 5) {
                                    billSampling.setResource(billClean.getResource());
                                    billSampling.setFeedImgUrl(billClean.getFeedImgUrl());
                                    billSampling.setRemark(billClean.getRemark());
                                }
                                samplingMapper.insert(billSampling);
                            } else if (Integer.parseInt(splits[1]) == 2) {
                                //新增pcr
                                BillPcr billClean1 = (BillPcr) entity;
                                if (billClean.getVistitType() != 0) {
                                    billClean1.setCarNum(billClean.getCarNum());
                                }
                                if (billClean.getVistitType() == 5) {
                                    billClean1.setResource(billClean.getResource());
                                    billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                                    billClean1.setRemark(billClean.getRemark());
                                }
                                pcrMapper.insert(billClean1);
                            } else if (Integer.parseInt(splits[1]) == 3) {
                                //新增洗澡
                                BillClean billClean1 = (BillClean) entity;
                                if (billClean.getVistitType() != 0) {
                                    billClean1.setCarNum(billClean.getCarNum());
                                }
                                if (billClean.getVistitType() == 5) {
                                    billClean1.setResource(billClean.getResource());
                                    billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                                    billClean1.setRemark(billClean.getRemark());
                                }
                                cleanMapper.insert(billClean1);
                            } else if (Integer.parseInt(splits[1]) == 4) {
                                //新增隔离
                                BillIsolate pcr = (BillIsolate) entity;
                                if (billClean.getVistitType() != 0) {
                                    pcr.setCarNum(billClean.getCarNum());
                                }
                                if (billClean.getVistitType() == 5) {
                                    pcr.setResource(billClean.getResource());
                                    pcr.setFeedImgUrl(billClean.getFeedImgUrl());
                                    pcr.setRemark(billClean.getRemark());
                                }
                                isolateMapper.insert(pcr);
                            } else if (Integer.parseInt(splits[1]) == 5) {
                                BillDry billClean1 = (BillDry) entity;
                                if (billClean.getVistitType() != 0) {
                                    billClean1.setCarNum(billClean.getCarNum());
                                }
                                if (billClean.getVistitType() == 5) {
                                    billClean1.setResource(billClean.getResource());
                                    billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                                    billClean1.setRemark(billClean.getRemark());
                                }
                                dryMapper.insert(billClean1);
                                //新增烘干
                            } else if (Integer.parseInt(splits[1]) == 6) {
                                //新增洗澡前拍照
                                BillCleanBefore before = (BillCleanBefore) entity;
                                if (billClean.getVistitType() != 0) {
                                    before.setCarNum(billClean.getCarNum());
                                }
                                if (billClean.getVistitType() == 5) {
                                    before.setResource(billClean.getResource());
                                    before.setFeedImgUrl(billClean.getFeedImgUrl());
                                    before.setRemark(billClean.getRemark());
                                }
                                beforeMapper.insert(before);
                            } else if (Integer.parseInt(splits[1]) == 7) {
                                //新增洗澡前拍照
                                BillGoodsInventory before = (BillGoodsInventory) entity;
                                if (billClean.getVistitType() != 0) {
                                    before.setCarNum(billClean.getCarNum());
                                }
                                if (billClean.getVistitType() == 5) {
                                    before.setResource(billClean.getResource());
                                    before.setFeedImgUrl(billClean.getFeedImgUrl());
                                    before.setRemark(billClean.getRemark());
                                }
                                inventoryMapper.insert(before);
                            }
                            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId + "," + splits[1]);

                            Integer locationId = billClean.getTestLocationId();
                            String[] split2 = allLocationId.split(",");
                            int a=0;
                            for (int i = 0; i < split2.length; i++) {
                                if (locationId.toString().equals(split2[i])) {
                                    a = i + 1;
                                }
                            }
                            int indexOf = 2 * (a - 2);//当前位置在所有流程位置中的下标
                            String substring = baseProcess.getAllLocationStatus().substring(0, indexOf + 3);//截取已经过的位置状态
                            String[] split1 = substring.split(",");
                            String sb2 = "";
                            for (int i = 0; i < split1.length; i++) {
                                if (i == split1.length - 1) {
                                    sb2 = sb2 + split1[i].replaceAll(split1[i], "2");
                                } else {
                                    sb2 = split1[i].replaceAll(split1[i], "2") + "," + sb2;
                                }
                            }
                            sb2 = sb2 + baseProcess.getAllLocationStatus().substring(indexOf + 3);
                            StringBuilder sb = new StringBuilder(sb2);
                            sb.replace(indexOf + 4, indexOf + 5, "2");
                            sb.replace(indexOf + 6, indexOf + 7, "1");
                            baseProcess.setAllLocationStatus(sb.toString());
                        }
                    } else if (nextId == 1) {
                        //新增采样
                        BillSampling billSampling = (BillSampling) newObject;
                        if (billClean.getVistitType() != 0) {
                            billSampling.setCarNum(billClean.getCarNum());
                        }
                        if (billClean.getVistitType() == 5) {
                            billSampling.setResource(billClean.getResource());
                            billSampling.setFeedImgUrl(billClean.getFeedImgUrl());
                            billSampling.setRemark(billClean.getRemark());
                        }
                        samplingMapper.insert(billSampling);
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                    } else if (nextId == 2) {
                        //新增pcr
                        BillPcr billClean1 = (BillPcr) newObject;
                        if (billClean.getVistitType() != 0) {
                            billClean1.setCarNum(billClean.getCarNum());
                        }
                        if (billClean.getVistitType() == 5) {
                            billClean1.setResource(billClean.getResource());
                            billClean1.setFeedImgUrl(billClean.getFeedImgUrl());
                            billClean1.setRemark(billClean.getRemark());
                        }
                        pcrMapper.insert(billClean1);
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                    } else if (nextId == 3) {
                        //新增洗澡
                        BillClean billClean2 = (BillClean) newObject;
                        if (billClean.getVistitType() != 0) {
                            billClean2.setCarNum(billClean.getCarNum());
                        }
                        if (billClean.getVistitType() == 5) {
                            billClean2.setResource(billClean.getResource());
                            billClean2.setFeedImgUrl(billClean.getFeedImgUrl());
                            billClean2.setRemark(billClean.getRemark());
                        }
                        cleanMapper.insert(billClean2);
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                    } else if (nextId == 4) {
                        //新增隔离
                        BillIsolate pcr = (BillIsolate) newObject;
                        if (billClean.getVistitType() != 0) {
                            pcr.setCarNum(billClean.getCarNum());
                        }
                        if (billClean.getVistitType() == 5) {
                            pcr.setResource(billClean.getResource());
                            pcr.setFeedImgUrl(billClean.getFeedImgUrl());
                            pcr.setRemark(billClean.getRemark());
                        }
                        isolateMapper.insert(pcr);
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                    } else if (nextId == 5) {
                        BillDry billClean2 = (BillDry) newObject;
                        if (billClean.getVistitType() != 0) {
                            billClean2.setCarNum(billClean.getCarNum());
                        }
                        if (billClean.getVistitType() == 5) {
                            billClean2.setResource(billClean.getResource());
                            billClean2.setFeedImgUrl(billClean.getFeedImgUrl());
                            billClean2.setRemark(billClean.getRemark());
                        }
                        dryMapper.insert(billClean2);
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                        //新增烘干
                    } else if (nextId == 6) {
                        //新增洗澡前拍照
                        BillCleanBefore before = (BillCleanBefore) newObject;
                        if (billClean.getVistitType() != 0) {
                            before.setCarNum(billClean.getCarNum());
                        }
                        if (billClean.getVistitType() == 5) {
                            before.setResource(billClean.getResource());
                            before.setFeedImgUrl(billClean.getFeedImgUrl());
                            before.setRemark(billClean.getRemark());
                        }
                        beforeMapper.insert(before);
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                    } else if (nextId == 7) {
                        //新增洗澡前拍照
                        BillGoodsInventory before = (BillGoodsInventory) newObject;
                        if (billClean.getVistitType() != 0) {
                            before.setCarNum(billClean.getCarNum());
                        }
                        if (billClean.getVistitType() == 5) {
                            before.setResource(billClean.getResource());
                            before.setFeedImgUrl(billClean.getFeedImgUrl());
                            before.setRemark(billClean.getRemark());
                        }
                        inventoryMapper.insert(before);
                        baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
                    }

                    baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
                    baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + "," + baseLocation.getLocationName());
                    baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + "," + baseLocation.getId());
                    String status = baseProcess.getCurrentStatus();
                    String substring = status.substring(0, status.length() - 1);
                    baseProcess.setCurrentStatus(substring + "1," + 0);

                    processMapper.updateById(baseProcess);
                } else {
                    billClean.setImgStatus(1);
                    billClean.setImgUrl(s);
                    billClean.setBillStatus(2);
                    billClean.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                    billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                    billClean.setTestLocation(baseLocation.getLocationName());
                    billClean.setTestLocationId(baseLocation.getId());
                    billClean.setCheckDate(sdf.parse(date));
                    billClean.setPassDate(sdf.parse(sdf.format(new Date())));
                    billClean.setDryTime("40");
                    billClean.setDryTem("70");
                    dryMapper.updateById(billClean);

                    baseProcess.setProcessType(2);
                    baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
                    baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
                    baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
                    String status = baseProcess.getCurrentStatus();
                    String substring = status.substring(0, status.length() - 1);
                    baseProcess.setCurrentStatus(substring + "2");

                    int i = allLocationId.indexOf(billClean.getTestLocationId().toString());
                    String status1 = baseProcess.getAllLocationStatus();
                    StringBuilder sb = new StringBuilder(status1);
                    sb.setCharAt(i-1, '3');
                    baseProcess.setAllLocationStatus(sb.toString());

                    processMapper.updateById(baseProcess);
                }
                return new Result(10000, "修改成功！", true);
            }

        }


    }


    @Override
    public Result listCount(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        Date timesmorning = DataUill.getTimesmorning();
        QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).ge("sub_date", timesmorning);
        queryWrapper.eq("bill_status", 1);
        Integer count = billCleanMapper.selectCount(queryWrapper);//合格
        QueryWrapper<BillClean> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("farm_id", farmId).ge("sub_date", timesmorning);
        queryWrapper1.eq("bill_status", 2);
        Integer count1 = billCleanMapper.selectCount(queryWrapper1);//异常
        Integer allCount = count + count1;
        DecimalFormat def = new DecimalFormat("0.00");
        String rank;
        if (allCount == 0 || allCount == null) {
            Double ranks = Double.valueOf("0.00");
            rank = ranks.toString();
        } else {
            Double ranks = (Double.valueOf(count.toString()) / Double.valueOf(allCount.toString())) * 100;
            rank = def.format(ranks);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count", allCount);
        jsonObject.put("count1", count);
        jsonObject.put("count2", count1);
        jsonObject.put("rank", rank);
        return new Result(ResultCode.SUCCESS, jsonObject);
    }

    @Override
    public Result AllClean(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String personType = paramsMap.get("personType");
        String type = paramsMap.get("type");
        if ("".equals(type) || null == type) {
            type = "1";
        }
        List<CleanVo> pcrVos = null;
        QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).in("bill_status", 1, 2);
        if ("".equals(personType) || null == personType) {

        } else {
            queryWrapper.eq("vistit_type", personType);
        }
        if ("1".equals(type)) {
            Date timesmorning = DataUill.getTimesmorning();
            queryWrapper.ge("sub_date", timesmorning);
        } else if ("2".equals(type)) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 7);
            queryWrapper.ge("sub_date", calendar.getTime());
        } else if ("3".equals(type)) {
            Date monthmorning = DataUill.getTimesMonthmorning();
            queryWrapper.ge("sub_date", monthmorning);
        }
        pcrVos = billCleanMapper.listAll(queryWrapper);
        for (CleanVo pcrVo : pcrVos) {
            pcrVo.setAllCount(pcrVo.getPassCount() + pcrVo.getRefuseCount());
        }
        return new Result(ResultCode.SUCCESS, pcrVos);
    }

    @Override
    public Result CleanSelect(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");//来访类型
        String startTime = paramsMap.get("startTime");
        String endTime = paramsMap.get("endTime");
        String pageNum = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        if ("".equals(pageNum) || null == pageNum) {
            pageNum = "1";
        }
        if ("".equals(pageSize) || null == pageSize) {
            pageSize = "10";
        }
        QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotEmpty(startTime)) {
            startTime = startTime + " 00:00:00";
            endTime = endTime + " 23:59:59";
            queryWrapper.between("check_date", startTime, endTime);
        }
        queryWrapper.lambda().orderByDesc(BillClean::getId);
        queryWrapper.eq("farm_id", farmId);
        if ("".equals(type) || null == type) {
        } else {
            queryWrapper.eq("vistit_type", type);
        }
        Page<BillClean> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        return new Result(ResultCode.SUCCESS, billCleanMapper.selectPage(page, queryWrapper));
    }

    @Override
    public void printClean(HttpServletResponse httpServletRequest, Map<String, String> paramsMap) throws Exception {
        String ids = paramsMap.get("ids");
        String[] split = ids.split(",");
        List<BillClean> list = new ArrayList<>();
        for (String s : split) {
            BillClean admission = billCleanMapper.selectById(s);
            list.add(admission);
        }
        Print.printClean(list);
    }

    @Override
    public Result listScreen(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");
        if ("".equals(type) || null == type) {
            type = "1";
        }
        QueryWrapper<BillClean> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("pass_date");
        if ("21".equals(farmId)) {
            queryWrapper.eq("farm_id", 26);
        }else {
            queryWrapper.eq("farm_id", farmId);
        }
        if (type.equals("1")) {
            queryWrapper.eq("vistit_type", 0).ne("bill_status", 0);
        } else {
            queryWrapper.ne("vistit_type", 0).ne("bill_status", 0);
        }

        return new Result(ResultCode.SUCCESS, billCleanMapper.selectList(queryWrapper));
    }
}
