package com.huimv.receive.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.FlowUtil;
import com.huimv.receive.common.utils.Result;
import com.huimv.receive.common.utils.ResultCode;
import com.huimv.receive.common.utils.UploadImage;
import com.huimv.receive.entity.*;
import com.huimv.receive.entity.vo.BillSamplingVo;
import com.huimv.receive.mapper.*;
import com.huimv.receive.service.IBillSamplingService;
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.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * <p>
 * 洗消表 服务实现类
 * </p>
 *
 * @author author
 * @since 2024-03-11
 */
@Service
public class BillSamplingServiceImpl extends ServiceImpl<BillSamplingMapper, BillSampling> implements IBillSamplingService {

    @Autowired
    private BillSamplingMapper billSamplingMapper;
    @Autowired
    private UploadImage uploadImage;
    @Autowired
    private BaseProcessMapper processMapper;
    @Autowired
    private BaseLocationMapper locationMapper;
    @Autowired
    private BillPcrMapper pcrMapper;
    @Autowired
    private BillCleanMapper cleanMapper;
    @Autowired
    private BillIsolateMapper isolateMapper;
    @Autowired
    private BillDryMapper dryMapper;
    @Autowired
    private BillCleanBeforeMapper billCleanBeforeMapper;
    @Autowired
    private BillGoodsInventoryMapper inventoryMapper;
    @Autowired
    private PeopleListMapper peopleListMapper;
    @Autowired
    private DeviceListMapper deviceListMapper;
    @Autowired
    private SysAccountMultilevelMapper multilevelMapper;

    @Override
    public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");//展示类型
        String data = paramsMap.get("data");
        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<BillSampling> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        QueryWrapper<BillSampling> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date").eq("vistit_type", type);
        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);
        }
        if ("3".equals(data)) {
            queryWrapper.in("bill_status", 2, 3);
        }
        QueryWrapper<BillSampling> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("vistit_type", type);
        queryWrapper2.in("test_location_id", TokenSign.getWorkIdByJwtToken(httpServletRequest)).orderByDesc("sub_date");
        queryWrapper2.eq("bill_status", 0);
        return new Result(ResultCode.SUCCESS, billSamplingMapper.selectPage(page, queryWrapper), billSamplingMapper.selectCount(queryWrapper2));
    }

    @Override
    public Result listById(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        BillSampling billSampling = billSamplingMapper.selectById(id);
        BillSamplingVo billSamplingVo = new BillSamplingVo();
        BeanUtil.copyProperties(billSampling, billSamplingVo);
        BillPcr billPcr = pcrMapper.selectOne(new QueryWrapper<BillPcr>().lambda().eq(BillPcr::getSamplingId, id));
        if (ObjectUtil.isNotEmpty(billPcr)) {
            billSamplingVo.setPcrType(billPcr.getPcrType());
            billSamplingVo.setStatus(billPcr.getBillStatus());
        }
        return new Result(ResultCode.SUCCESS, billSamplingVo);
    }

    @Override
    public Result listPersonalSample(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String pageNo = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        String vistitType = paramsMap.get("vistitType");
        Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
        Page<BillSampling> page = new Page<>(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        LambdaQueryWrapper<BillSampling> queryWrapper = new QueryWrapper<BillSampling>().lambda()
                .eq(BillSampling::getFarmId, farmId)
                .eq(BillSampling::getAdmissionUserId, userId)
                .eq(ObjectUtil.isNotEmpty(vistitType), BillSampling::getVistitType, vistitType)
                .orderByDesc(BillSampling::getSubDate);
        Page<BillSampling> billSamplingPage = billSamplingMapper.selectPage(page, queryWrapper);
        Integer count = billSamplingMapper.selectCount(queryWrapper);
        return new Result(ResultCode.SUCCESS, billSamplingPage, count);
    }


    @Override
    public Result edit(HttpServletRequest httpServletRequest, String farmId, String id, String date,
                       String video1, String video2, String video3, String video4, String video5, String video6
            , String video7, String video8, MultipartFile picture1, MultipartFile picture2, MultipartFile picture3) throws ParseException, IOException {
        String s = "";
        if (ObjectUtil.isNotEmpty(video1)) {
            s = video1;
        }
        if (ObjectUtil.isNotEmpty(video2)) {
            s = s + "," + video2;
        }
        if (ObjectUtil.isNotEmpty(video3)) {
            s = s + "," + video3;
        }
        if (ObjectUtil.isNotEmpty(video4)) {
            s = s + "," + video4;
        }
        if (ObjectUtil.isNotEmpty(video5)) {
            s = s + "," + video5;
        }
        if (ObjectUtil.isNotEmpty(video6)) {
            s = s + "," + video6;
        }
        if (ObjectUtil.isNotEmpty(video7)) {
            s = s + "," + video7;
        }
        if (ObjectUtil.isNotEmpty(video8)) {
            s = s + "," + video8;
        }

        String picUrl = null;

        if (ObjectUtil.isNotEmpty(picture1)) {
            String pic1 = uploadImage.getImageCom(picture1);
            if (pic1.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "物品照片1上传失败", false);
            } else {
                picUrl = pic1;
            }
        }
        if (ObjectUtil.isNotEmpty(picture2)) {
            String pic2 = uploadImage.getImageCom(picture2);
            if (pic2.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "物品照片2上传失败", false);
            } else {
                picUrl = picUrl + "," + pic2;
            }
        }
        if (ObjectUtil.isNotEmpty(picture3)) {
            String pic3 = uploadImage.getImageCom(picture3);
            if (pic3.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "物品照片3上传失败", false);
            } else {
                picUrl = picUrl + "," + pic3;
            }
        }


        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");

        BillSampling sampling = billSamplingMapper.selectById(id);
        if (sampling.getBillStatus() != 0) {
            return new Result(10001, "此条记录已被他人修改，请退出刷新查看！", false);
        }
        sampling.setImgUrl(s);
        sampling.setImgStatus(1);
        if (sampling.getVistitType() == 0) {
            if (ObjectUtil.isNotEmpty(picUrl)) {
                sampling.setIsCarry(1);
                sampling.setPicUrl(picUrl);
            } else {
                sampling.setIsCarry(0);
            }
        }

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

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

        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[] split = substring1.split(",");
        Integer nextId = Integer.parseInt(split[0]);


        sampling.setBillStatus(1);
        sampling.setPassUserName(TokenSign.getUserNameByJwtToken(httpServletRequest));
        sampling.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
        sampling.setTestLocation(baseLocation.getLocationName());
        sampling.setTestLocationId(baseLocation.getId());
        sampling.setCheckDate(LocalDateTime.parse(date, dateTimeFormatter));
        sampling.setPassDate(LocalDateTime.now());


        Object newObject = BillPcrServiceImpl.getNewObject(nextId, sampling.getDestName(), sampling.getDestId(), sampling.getAdmissionUserName(),
                sampling.getAdmissionUserId(), sampling.getVistitDate(), sampling.getSubDate(),
                sampling.getProcessId(), Integer.parseInt(sampling.getFarmId()), sampling.getTestLocation(), sampling.getTestLocationId(),
                sampling.getVistitType(), sampling.getPhone(), sampling.getDepartureName(), sampling.getDepartureId(), sampling.getMidId()
                , sampling.getMidName(),sampling.getFarmName());
        if (nextId == 0) {
            if (split.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(split[1]), sampling.getVistitType(), sampling.getDestName()
                        , sampling.getDestId(), sampling.getAdmissionUserId(), sampling.getAdmissionUserName(), sampling.getPhone(),
                        sampling.getVistitDate(), location.getId(), location.getLocationName(), Integer.parseInt(sampling.getFarmId())
                        , baseProcess.getId(), sampling.getDepartureName(), sampling.getDepartureId(), sampling.getMidId()
                        , sampling.getMidName(),sampling.getFarmName());
                if (Integer.parseInt(split[1]) == 1) {
                    //新增采样
                    BillSampling billSampling = (BillSampling) entity;
                    if (sampling.getVistitType() != 0) {
                        billSampling.setCarNum(sampling.getCarNum());
                    }
                    if (sampling.getVistitType() == 5) {
                        billSampling.setResource(sampling.getResource());
                        billSampling.setFeedImgUrl(sampling.getFeedImgUrl());
                        billSampling.setRemark(sampling.getRemark());
                    }
                    billSamplingMapper.insert(billSampling);
                } else if (Integer.parseInt(split[1]) == 2) {
                    //新增pcr
                    BillPcr billClean = (BillPcr) entity;
                    if (sampling.getVistitType() != 0) {
                        billClean.setCarNum(sampling.getCarNum());
                    }
                    if (sampling.getVistitType() == 5) {
                        billClean.setResource(sampling.getResource());
                        billClean.setFeedImgUrl(sampling.getFeedImgUrl());
                        billClean.setRemark(sampling.getRemark());
                    }
                    billClean.setSamplingId(Integer.parseInt(id));
                    pcrMapper.insert(billClean);
                    //下发人脸门禁白名单
                    /*if (sampling.getVistitType() == 0) {
                        DeviceList deviceList = deviceListMapper.selectOne(new QueryWrapper<DeviceList>().eq("farm_id", 1));
                        PeopleList peopleList = new PeopleList();
                        peopleList.setFarmId("1");
                        peopleList.setDeviceCode(deviceList.getDeviceCode());
                        peopleList.setUserId(sampling.getProcessId().toString());
                        peopleList.setUserName(sampling.getAdmissionUserName());
                        peopleList.setPassword("123456");
                        peopleList.setType(0);
                        peopleList.setCreateTime(new Date());
                        Date now = new Date();
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(now);
                        calendar.add(Calendar.HOUR_OF_DAY, 4);
                        Date date1 = calendar.getTime();
                        peopleList.setOutTime(date1);
                        SysAccountMultilevel sysAccountMultilevel = multilevelMapper.selectById(sampling.getAdmissionUserId());
                        peopleList.setImgUrl(sysAccountMultilevel.getImgUrl());
                        peopleListMapper.insert(peopleList);
                    }*/
                } else if (Integer.parseInt(split[1]) == 3) {
                    //新增洗澡
                    BillClean billClean = (BillClean) entity;
                    if (sampling.getVistitType() != 0) {
                        billClean.setCarNum(sampling.getCarNum());
                    }
                    if (sampling.getVistitType() == 5) {
                        billClean.setResource(sampling.getResource());
                        billClean.setFeedImgUrl(sampling.getFeedImgUrl());
                        billClean.setRemark(sampling.getRemark());
                    }
                    cleanMapper.insert(billClean);
                } else if (Integer.parseInt(split[1]) == 4) {
                    //新增隔离
                    BillIsolate pcr = (BillIsolate) entity;
                    if (sampling.getVistitType() != 0) {
                        pcr.setCarNum(sampling.getCarNum());
                    }
                    if (sampling.getVistitType() == 5) {
                        pcr.setResource(sampling.getResource());
                        pcr.setFeedImgUrl(sampling.getFeedImgUrl());
                        pcr.setRemark(sampling.getRemark());
                    }
                    isolateMapper.insert(pcr);
                } else if (Integer.parseInt(split[1]) == 5) {
                    BillDry billClean = (BillDry) entity;
                    if (sampling.getVistitType() != 0) {
                        billClean.setCarNum(sampling.getCarNum());
                    }
                    if (sampling.getVistitType() == 5) {
                        billClean.setResource(sampling.getResource());
                        billClean.setFeedImgUrl(sampling.getFeedImgUrl());
                        billClean.setRemark(sampling.getRemark());
                    }
                    dryMapper.insert(billClean);
                    //新增烘干
                } else if (Integer.parseInt(split[1]) == 6) {
                    //新增洗澡前拍照
                    BillCleanBefore before = (BillCleanBefore) entity;
                    if (sampling.getVistitType() != 0) {
                        before.setCarNum(sampling.getCarNum());
                    }
                    if (sampling.getVistitType() == 5) {
                        before.setResource(sampling.getResource());
                        before.setFeedImgUrl(sampling.getFeedImgUrl());
                        before.setRemark(sampling.getRemark());
                    }
                    billCleanBeforeMapper.insert(before);
                } else if (Integer.parseInt(split[1]) == 7) {
                    //新增洗澡前拍照
                    BillGoodsInventory before = (BillGoodsInventory) entity;
                    if (sampling.getVistitType() != 0) {
                        before.setCarNum(sampling.getCarNum());
                    }
                    if (sampling.getVistitType() == 5) {
                        before.setResource(sampling.getResource());
                        before.setFeedImgUrl(sampling.getFeedImgUrl());
                        before.setRemark(sampling.getRemark());
                    }
                    inventoryMapper.insert(before);
                }
                baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId + "," + split[1]);
                Integer locationId = sampling.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 (sampling.getVistitType() != 0) {
                billSampling.setCarNum(sampling.getCarNum());
            }
            if (sampling.getVistitType() == 5) {
                billSampling.setResource(sampling.getResource());
                billSampling.setFeedImgUrl(sampling.getFeedImgUrl());
                billSampling.setRemark(sampling.getRemark());
            }
            billSamplingMapper.insert(billSampling);
            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
        } else if (nextId == 2) {
            //新增pcr
            BillPcr billClean = (BillPcr) newObject;
            if (sampling.getVistitType() != 0) {
                billClean.setCarNum(sampling.getCarNum());
            }
            if (sampling.getVistitType() == 5) {
                billClean.setResource(sampling.getResource());
                billClean.setFeedImgUrl(sampling.getFeedImgUrl());
                billClean.setRemark(sampling.getRemark());
            }
            billClean.setSamplingId(Integer.parseInt(id));
            pcrMapper.insert(billClean);
            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
            //下发人脸门禁白名单
            /*if (sampling.getVistitType() == 0) {
                DeviceList deviceList = deviceListMapper.selectOne(new QueryWrapper<DeviceList>().eq("farm_id", 1));
                PeopleList peopleList = new PeopleList();
                peopleList.setFarmId("1");
                peopleList.setDeviceCode(deviceList.getDeviceCode());
                peopleList.setUserId(sampling.getProcessId().toString());
                peopleList.setUserName(sampling.getAdmissionUserName());
                peopleList.setPassword("123456");
                peopleList.setType(0);
                peopleList.setCreateTime(new Date());
                Date now = new Date();
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(now);
                calendar.add(Calendar.HOUR_OF_DAY, 4);
                Date date1 = calendar.getTime();
                peopleList.setOutTime(date1);
                SysAccountMultilevel sysAccountMultilevel = multilevelMapper.selectById(sampling.getAdmissionUserId());
                peopleList.setImgUrl(sysAccountMultilevel.getImgUrl());
                peopleListMapper.insert(peopleList);
            }*/
        } else if (nextId == 3) {
            //新增洗澡
            BillClean billClean = (BillClean) newObject;
            if (sampling.getVistitType() != 0) {
                billClean.setCarNum(sampling.getCarNum());
            }
            if (sampling.getVistitType() == 5) {
                billClean.setResource(sampling.getResource());
                billClean.setFeedImgUrl(sampling.getFeedImgUrl());
                billClean.setRemark(sampling.getRemark());
            }
            cleanMapper.insert(billClean);
            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
        } else if (nextId == 4) {
            //新增隔离
            BillIsolate pcr = (BillIsolate) newObject;
            if (sampling.getVistitType() != 0) {
                pcr.setCarNum(sampling.getCarNum());
            }
            if (sampling.getVistitType() == 5) {
                pcr.setResource(sampling.getResource());
                pcr.setFeedImgUrl(sampling.getFeedImgUrl());
                pcr.setRemark(sampling.getRemark());
            }
            isolateMapper.insert(pcr);
            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
        } else if (nextId == 5) {
            BillDry billClean = (BillDry) newObject;
            if (sampling.getVistitType() != 0) {
                billClean.setCarNum(sampling.getCarNum());
            }
            if (sampling.getVistitType() == 5) {
                billClean.setResource(sampling.getResource());
                billClean.setFeedImgUrl(sampling.getFeedImgUrl());
                billClean.setRemark(sampling.getRemark());
            }
            dryMapper.insert(billClean);
            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
            //新增烘干
        } else if (nextId == 6) {
            //新增洗澡前拍照
            BillCleanBefore before = (BillCleanBefore) newObject;
            if (sampling.getVistitType() != 0) {
                before.setCarNum(sampling.getCarNum());
            }
            if (sampling.getVistitType() == 5) {
                before.setResource(sampling.getResource());
                before.setFeedImgUrl(sampling.getFeedImgUrl());
                before.setRemark(sampling.getRemark());
            }
            billCleanBeforeMapper.insert(before);
            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
        } else if (nextId == 7) {
            //新增洗澡前拍照
            BillGoodsInventory before = (BillGoodsInventory) newObject;
            if (sampling.getVistitType() != 0) {
                before.setCarNum(sampling.getCarNum());
            }
            if (sampling.getVistitType() == 5) {
                before.setResource(sampling.getResource());
                before.setFeedImgUrl(sampling.getFeedImgUrl());
                before.setRemark(sampling.getRemark());
            }
            inventoryMapper.insert(before);
            baseProcess.setCurrentFlowId(baseProcess.getCurrentFlowId() + "," + nextId);
        }
        baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + LocalDateTime.now().format(dateTimeFormatter));
        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);
        billSamplingMapper.updateById(sampling);
        return new Result(10000, "修改成功!", true);
    }

    @Override
    public Result listAll(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
        String farmId = paramsMap.get("farmId");
        String type = paramsMap.get("type");//展示类型
        String data = paramsMap.get("data");
        String pageNum = paramsMap.get("pageNum");
        String pageSize = paramsMap.get("pageSize");
        Page<BillSampling> page = new Page<>(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        QueryWrapper<BillSampling> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("farm_id", farmId).orderByDesc("sub_date").eq("vistit_type", type);
        if ("0".equals(data)) {
            queryWrapper.in("bill_status", 0, 1, 2, 3);
        }
        if ("1".equals(data)) {
            queryWrapper.in("bill_status", 0, 3);
        }
        if ("2".equals(data)) {
            queryWrapper.eq("bill_status", 1);
        }
        return new Result(ResultCode.SUCCESS, billSamplingMapper.selectPage(page, queryWrapper));
    }

    @Override
    public Result getVideo(MultipartFile video) throws IOException {
        String s = "";
        if (ObjectUtil.isNotEmpty(video)) {
            String pic1 = uploadImage.getVideoCom(video);
            if (pic1.equals("上传失败")) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return new Result(10001, "车辆视频上传失败", false);
            } else {
                s = pic1;
            }
        }
        return new Result(ResultCode.SUCCESS, s);
    }

    public static void main(String[] args) {
        String s = "0,35,0,36,0,38,0";
        String[] split1 = s.split(",");
        int a = 0;
        for (int i = 0; i < split1.length; i++) {
            if ("36".equals(split1[i])) {
                a = i + 1;
            }
        }
        int i = 2 * (a - 2);
        System.out.println(i);
        String s1 = "2,2,2,1,0,0,0";
        String s2 = s1.substring(0, i + 3);
        System.out.println("s2:" + s2);
        String[] split = s2.split(",");
        String sb2 = "";
        for (int j = 0; j < split.length; j++) {
            if (j == split.length - 1) {
                sb2 = sb2 + split[j].replaceAll(split[j], "2");
            } else {
                sb2 = split[j].replaceAll(split[j], "2") + "," + sb2;
            }
        }
        sb2 = sb2 + s1.substring(i + 3);
        StringBuilder sb = new StringBuilder(sb2);
        sb.replace(i + 4, i + 5, "2");
        sb.replace(i + 6, i + 7, "1");
        System.out.println(sb.toString());

    }
}
