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.dto.PcrDto;
import com.huimv.receive.entity.vo.PcrVo;
import com.huimv.receive.entity.vo.PcrVo1;
import com.huimv.receive.mapper.*;
import com.huimv.receive.service.IBillPcrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.multipart.MultipartFile;

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.*;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * <p>
 * pcr 表 服务实现类
 * </p>
 *
 * @author author
 * @since 2023-07-21
 */
@Service
public class BillPcrServiceImpl extends ServiceImpl<BillPcrMapper, BillPcr> implements IBillPcrService {

    @Resource
    private BillPcrMapper billPcrMapper;

    @Override
    public Result listPersonalPcr(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String pageNo = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        String vistitType = paramsMap.get("vistitType");
        Page<BillPcr> page = new Page<>(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        Page<BillPcr> billPcrPage = billPcrMapper.selectPage(page, new QueryWrapper<BillPcr>().eq(StringUtils.isNotBlank(vistitType), "vistit_type", vistitType).eq("admission_user_id", TokenSign.getMemberIdByJwtToken(httpServletRequest)).orderByDesc("sub_date"));
        QueryWrapper<BillPcr> 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, billPcrPage, billPcrMapper.selectCount(queryWrapper));
    }

    @Override
    public Result pcrWhole(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        Date timesmorning = DataUill.getTimesmorning();
        QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).eq("bill_status", 1).ge("sub_date", timesmorning);//今日合格
        Integer count = billPcrMapper.selectCount(queryWrapper);
        QueryWrapper<BillPcr> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("farm_id", farmId).eq("bill_status", 2).ge("sub_date", timesmorning);//今日异常
        Integer count1 = billPcrMapper.selectCount(queryWrapper1);
        QueryWrapper<BillPcr> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("farm_id", farmId).eq("bill_status", 3).ge("sub_date", timesmorning);//今日失效
        Integer count2 = billPcrMapper.selectCount(queryWrapper2);
        PcrDto dto = new PcrDto();
        dto.setWholeCount(count + count1);
        dto.setPassCount(count);
        dto.setRefuseCount(count1);
        dto.setLoseCount(count2);
        return new Result(ResultCode.SUCCESS, dto);
    }

    @Override
    public Result listType(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");
        if ("".equals(type) || null == type) {
            type = "1";
        }
        List<PcrVo> pcrVos = null;
        QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).in("bill_status", 1, 2);
        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 = billPcrMapper.listPcr(queryWrapper);
        for (PcrVo pcrVo : pcrVos) {
            if (pcrVo.getType().equals("0")) {
                pcrVo.setType("人员");
            } else if (pcrVo.getType().equals("1")) {
                pcrVo.setType("环保车");
            } else if (pcrVo.getType().equals("2")) {
                pcrVo.setType("拉猪车");
            } else if (pcrVo.getType().equals("3")) {
                pcrVo.setType("饲料车");
            } else if (pcrVo.getType().equals("4")) {
                pcrVo.setType("送猪车");
            } else if (pcrVo.getType().equals("5")) {
                pcrVo.setType("物资车");
            }
        }
        return new Result(ResultCode.SUCCESS, pcrVos);
    }

    @Override
    public Result listLocation(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");
        if ("".equals(type) || null == type) {
            type = "1";
        }
        List<PcrVo> pcrVos = null;
        QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).in("bill_status", 1, 2);
        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 = billPcrMapper.listLocation(queryWrapper);
        return new Result(ResultCode.SUCCESS, pcrVos);
    }

    @Override
    public Result listAll(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<PcrVo1> pcrVos = null;
        QueryWrapper<BillPcr> 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 = billPcrMapper.listAll(queryWrapper);
        for (PcrVo1 pcrVo : pcrVos) {
            pcrVo.setAllCount(pcrVo.getPassCount() + pcrVo.getRefuseCount());
        }
        return new Result(ResultCode.SUCCESS, pcrVos);
    }

    @Override
    public Result selectList(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");//来访类型
        String destId = paramsMap.get("destId");//目的地
        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<BillPcr> queryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotEmpty(startTime)) {
            startTime = startTime + " 00:00:00";
            endTime = endTime + " 23:59:59";
            queryWrapper.between("check_date", startTime, endTime);
        }
        queryWrapper.in("bill_status", 1, 2);
        queryWrapper.lambda().orderByDesc(BillPcr::getId);
        queryWrapper.eq("farm_id", farmId).eq(StringUtils.isNotBlank(destId), "dest_id", destId).eq(StringUtils.isNotBlank(type), "vistit_type", type);
        Page<BillPcr> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        return new Result(ResultCode.SUCCESS, billPcrMapper.selectPage(page, queryWrapper));
    }

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

    @Override
    public Result PcrList(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId);
        Integer integer = pcrMapper.selectCount(queryWrapper);//检测总数
        queryWrapper.in("bill_status", 1,3);
        Integer integer1 = pcrMapper.selectCount(queryWrapper);//合格总数
        queryWrapper.orderByDesc("sub_date").last(" limit 10");
        DecimalFormat def = new DecimalFormat("0.00");
        String rank;
        if (integer == 0 || integer == null) {
            Double ranks  = Double.valueOf("0.00");
            rank = ranks.toString();
        } else {
            Double ranks = (Double.valueOf(integer1.toString()) / Double.valueOf(integer.toString())) * 100;
            rank = def.format(ranks);
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("allCount", integer);
        jsonObject.put("passCount", integer1);
        jsonObject.put("rank", rank);
        jsonObject.put("pcrList", pcrMapper.selectList(queryWrapper));
        return new Result(ResultCode.SUCCESS, jsonObject);
    }

    @Autowired
    private BillPcrMapper pcrMapper;
    @Autowired
    private BaseProcessMapper processMapper;
    @Autowired
    private BaseLocationMapper locationMapper;
    @Autowired
    private BillCleanMapper cleanMapper;
    @Autowired
    private BillGoodsInventoryMapper goodsInventoryMapper;
    @Autowired
    private ConfigurationMapper configurationMapper;
    @Autowired
    private UploadImage uploadImage;
    @Autowired
    private ExistMapper existMapper;

    @Override
    public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");//展示类型
        String pageNum = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        if ("".equals(pageNum) || null == pageNum) {
            pageNum = "1";
        }
        if ("".equals(pageSize) || null == pageSize) {
            pageSize = "20";
        }
        Page<BillPcr> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        QueryWrapper<BaseLocation> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("location_type", TokenSign.getWorkIdByJwtToken(httpServletRequest));
        List<BaseLocation> baseLocations = locationMapper.selectList(queryWrapper1);
        List<Integer> ids = new ArrayList<>();
        for (BaseLocation baseLocation : baseLocations) {
            ids.add(baseLocation.getId());
        }
        QueryWrapper<BillPcr> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).in("test_location_id", ids).orderByDesc("sub_date");
        if ("0".equals(type)) {
            queryWrapper.in("bill_status", 0, 1, 2, 3);
        }
        if ("1".equals(type)) {
            queryWrapper.eq("bill_status", 0);
        }
        if ("2".equals(type)) {
            queryWrapper.eq("bill_status", 1);
        }
        if ("3".equals(type)) {
            queryWrapper.in("bill_status", 2, 3);
        }
        QueryWrapper<BillPcr> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("farm_id", farmId).in("test_location_id", ids).orderByDesc("sub_date");
        queryWrapper2.eq("bill_status", 0);
        return new Result(ResultCode.SUCCESS, pcrMapper.selectPage(page, queryWrapper), pcrMapper.selectCount(queryWrapper2));
    }

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

    @Override
    public Result edit(HttpServletRequest httpServletRequest,String farmId, String id, String date, String result,
                       MultipartFile img1, MultipartFile img2, MultipartFile img3) throws ParseException, IOException {
      //1为合格2为异常
        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());
        }
        BillPcr billPcr = pcrMapper.selectById(id);
        billPcr.setImgUrl(s);
        billPcr.setImgStatus(1);


        QueryWrapper<BaseProcess> processQueryWrapper = new QueryWrapper<>();
        processQueryWrapper.eq("farm_id", farmId).eq("id", billPcr.getProcessId());
        BaseProcess baseProcess = processMapper.selectOne(processQueryWrapper);//进程

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

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

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

        if (billPcr.getBillStatus() != 0) {
            return new Result(10001, "该订单已通过，无需再次提交！", false);
        }
        if (baseProcess.getProcessType() == 2 || baseProcess.getProcessType() == 1) {
            return new Result(10001, "修改失败！该申请已提前结束或者被拒绝", false);
        } else {
            if (billPcr.getDestId() >= billPcr.getTestLocationId() || billPcr.getTestLocationId() == 9 || billPcr.getTestLocationId() == 10 || billPcr.getTestLocationId() == 11 || billPcr.getTestLocationId() == 6) { //说明当前不是目的地

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


                    //通过生成洗消记录
                    BillClean billClean = new BillClean();
                    billClean.setVistitType(billPcr.getVistitType());
                    billClean.setDestName(billPcr.getDestName());
                    billClean.setDestId(billPcr.getDestId());
                    billClean.setAdmissionUserName(billPcr.getAdmissionUserName());
                    billClean.setAdmissionUserId(billPcr.getAdmissionUserId());
                    billClean.setVistitDate(billPcr.getVistitDate());
                    billClean.setSubDate(LocalDateTime.now());
                    billClean.setFarmId(billPcr.getFarmId());
                    billClean.setPassUserName(billPcr.getPassUserName());
                    billClean.setPassDate(billPcr.getPassDate());
                    billClean.setPassUserId(billPcr.getPassUserId());
                    billClean.setProcessId(billPcr.getProcessId());
                    billClean.setTestLocation(baseLocation.getLocationName());
                    billClean.setTestLocationId(baseLocation.getId());
                    billClean.setPhone(billPcr.getPhone());
                    billClean.setImgStatus(0);
                    billClean.setCarNum(billPcr.getCarNum());
                    cleanMapper.insert(billClean);

                    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);

                    if (billPcr.getDestId() == 11) {
                        baseProcess.setAllLocationStatus("2,1");
                    }
                    if (billPcr.getDestId() == 10) {
                        baseProcess.setAllLocationStatus("2,1");
                    }
                    if (billPcr.getDestId() == 9) {
                        baseProcess.setAllLocationStatus("2,1");
                    }

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

                    billPcr.setBillStatus(2);
                    billPcr.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                    billPcr.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));

                    billPcr.setTestLocation(baseLocation.getLocationName());
                    billPcr.setTestLocationId(baseLocation.getId());
                    billPcr.setCheckDate(sdf.parse(date));
                    billPcr.setPassDate(sdf.parse(sdf.format(new Date())));
                    baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));

                    String status = baseProcess.getCurrentStatus();
                    String substring = status.substring(0, status.length() - 1);

                    baseProcess.setCurrentStatus(substring + "2," + 0);
                    if (baseLocation.getId() == 1) {
                        //第一次检测不合格
                        billPcr.setPcrType(1);
                        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + ",初级洗消站污区");
                        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + ",2");
                    }
                    if (baseLocation.getId() == 12) {
                        //环保车第一次不合格
                        billPcr.setPcrType(1);
                        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + ",销售中转站");
                        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + ",2");
                    }
                    if (baseLocation.getId() == 15) {
                        //拉猪车第一次不合格
                        billPcr.setPcrType(1);
                        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + ",销售中转站");
                        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + ",2");
                    }
                    if (baseLocation.getId() == 6) {
                        //饲料车第一次不合格
                        billPcr.setPcrType(1);
                        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + ",车辆初级洗消站");
                        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + ",2");
                    }
                    if (baseLocation.getId() == 3) {
                        //第二次检测不合格
                        baseProcess.setProcessType(2);
                        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
                        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "2";
                        split[2] = "2";
                        split[3] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1] + "," + split[2] + "," + split[3] + status1.substring(7));
                    }
                    if (baseLocation.getId() == 4&&exist.getExist()==0) {
                        //第三次不合格
                        baseProcess.setProcessType(2);
                        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
                        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "2";
                        split[2] = "2";
                        split[3] = "2";
                        split[4] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1] + "," + split[2] + "," + split[3] + "," + split[4] + status1.substring(9));
                    }
                    if (baseLocation.getId() == 4&&exist.getExist()==1) {
                        //第三次不合格
                        baseProcess.setProcessType(2);
                        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation());
                        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId());
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "2";
                        split[2] = "2";
                        split[3] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1] + "," + split[2] + "," + split[3] + status1.substring(7));
                    }

                    if (baseLocation.getId() == 17) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1]  + status1.substring(3));
                    }
                    if (baseLocation.getId() == 15) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1]  + status1.substring(3));
                    }
                    if (baseLocation.getId() == 9) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1]  + status1.substring(3));
                    }
                    if (baseLocation.getId() == 10) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1] + status1.substring(3));
                    }
                    if (baseLocation.getId() == 11) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1] + status1.substring(3));
                    }

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

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

                    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");
                    baseProcess.setProcessType(1);

                    if (baseLocation.getId() == 9) {
                        baseProcess.setAllLocationStatus("2,2");
                    }
                    if (baseLocation.getId() == 10) {

                        baseProcess.setAllLocationStatus("2,2");
                    }
                    if (baseLocation.getId() == 11) {
                        baseProcess.setAllLocationStatus("2,2");
                    }

                    processMapper.updateById(baseProcess);
                    pcrMapper.updateById(billPcr);
                    return new Result(10000, "修改成功！", true);
                } else {
                    if (baseLocation.getId() == 1) {
                        //第一次检测不合格
                        billPcr.setPcrType(1);
                        baseProcess.setProcessType(2);
                    } else if (baseLocation.getId() == 12) {
                        //环保车检测不合格
                        billPcr.setPcrType(1);
                        baseProcess.setProcessType(2);
                    } else if (baseLocation.getId() == 15) {
                        //拉猪车检测不合格
                        billPcr.setPcrType(1);
                        baseProcess.setProcessType(2);
                    } else if (baseLocation.getId() == 6) {
                        //饲料车检测不合格
                        billPcr.setPcrType(1);
                        baseProcess.setProcessType(2);
                    } else {
                        baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
                        baseProcess.setProcessType(2);
                    }

                    if (baseLocation.getId() == 15) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1]  + status1.substring(3));
                    }
                    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," + 0);

                    if (baseLocation.getId() == 9) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1]  + status1.substring(3));
                    }
                    if (baseLocation.getId() == 10) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1] + status1.substring(3));
                    }
                    if (baseLocation.getId() == 11) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1] + status1.substring(3));
                    }
                    if (baseLocation.getId() == 17) {
                        String status1 = baseProcess.getAllLocationStatus();
                        String[] split = status1.split(",");
                        split[0] = "2";
                        split[1] = "3";
                        baseProcess.setAllLocationStatus(split[0] + "," + split[1]  + status1.substring(3));
                    }

                    billPcr.setBillStatus(2);
                    billPcr.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
                    billPcr.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                    billPcr.setTestLocation(baseLocation.getLocationName());
                    billPcr.setTestLocationId(baseLocation.getId());
                    billPcr.setCheckDate(sdf.parse(date));
                    billPcr.setPassDate(sdf.parse(sdf.format(new Date())));
                    processMapper.updateById(baseProcess);
                    pcrMapper.updateById(billPcr);
                    return new Result(10000, "修改成功！", true);
                }

            }

        }

    }

    private void xiugaiPro(BaseProcess baseProcess, BillPcr billPcr) {
        baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + new Date());
        baseProcess.setCurrentLocation(baseProcess.getCurrentLocation() + "," + billPcr.getTestLocation());
        baseProcess.setCurrentLocationId(baseProcess.getCurrentLocationId() + "," + billPcr.getTestLocationId());
        baseProcess.setCurrentStatus(baseProcess.getCurrentStatus() + "," + 2);
    }

    public String add() {
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10);
        Runnable task = new Runnable() {
            @Override
            public void run() {

                //这里写业务
                System.out.println();
            }
        };

        // 设定延迟时间（两小时后执行，单位为秒）
        long delay = 3;

        // 执行定时任务
        scheduler.schedule(task, delay, TimeUnit.SECONDS);
        System.out.println("完结");
        return "成功";
    }
}
