package com.gci.boot.modules.vehicles.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gci.boot.common.util.StringUtil;
import com.gci.boot.modules.msg.enums.SenderTypeEnum;
import com.gci.boot.modules.msg.enums.WorkOrderType;
import com.gci.boot.modules.msg.service.MsgPushService;
import com.gci.boot.modules.msg.vo.MsgRedisVO;
import com.gci.boot.modules.projects.entity.Projects;
import com.gci.boot.modules.projects.service.IProjectsService;
import com.gci.boot.modules.system.service.*;
import com.gci.boot.modules.system.vo.LoginUser;
import com.gci.boot.modules.vehicles.entity.*;
import com.gci.boot.modules.vehicles.enums.UpkeepPlanStatusEnumEmployee;
import com.gci.boot.modules.vehicles.enums.UpkeepPlanStatusEnumLeader;
import com.gci.boot.modules.vehicles.mapper.TbRepairInfoMapper;
import com.gci.boot.modules.vehicles.mapper.TbUpkeepBillMapper;
import com.gci.boot.modules.vehicles.mapper.TbUpkeepPlanMapper;
import com.gci.boot.modules.vehicles.service.*;
import com.gci.boot.modules.vehicles.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.Duration;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

@Service
@Slf4j
public class TbUpkeepPlanServiceImpl extends ServiceImpl<TbUpkeepPlanMapper, TbUpkeepPlan> implements ITbUpkeepPlanService {

    @Autowired
    private ITbUpkeepPlanCheckService upkeepPlanCheckService;
    @Autowired
    private ITbUpkeepRuleService upkeepRuleService;
    @Autowired
    private TbRepairInfoMapper repairInfoMapper;
    @Autowired
    private TbUpkeepPlanMapper upkeepPlanMapper;
    @Autowired
    private TbUpkeepBillMapper upkeepBillMapper;
    @Autowired
    private CommonService commonService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private ISysUserRoleService sysUserRoleService;
    @Autowired
    private ISysRoleService sysRoleService;
    @Autowired
    private MsgPushService msgPushService;
    @Autowired
    private IProjectsService projectsService;
    @Autowired
    private ITbUpkeepCheckService upkeepCheckService;

    @Transactional
    @Override
    public String submitUpkeepPlan(UpkeepPlanObjectVO vo) {
        List<String> planIds = Arrays.asList(vo.getId().split(","));
        //无需审核数据不给审核操作
        if(CollectionUtil.isNotEmpty(planIds)){
            LambdaQueryWrapper<TbUpkeepPlan> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.in(TbUpkeepPlan::getId,planIds).in(TbUpkeepPlan::getAuditStatus,"2","3","4","5");
            List<TbUpkeepPlan> list = this.list(queryWrapper);
            if(CollectionUtil.isNotEmpty(list)){
                return ("存在已审核、作废或归档数据,请重新操作!");
            }
        }
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //批量提交
        for(String planId : planIds){
            //更新维修单流程状态、流程节点
            TbUpkeepPlan upkeepPlan = this.getById(planId);
            TbUpkeepPlanCheck upkeepPlanCheck = vo.getCurrentUpkeepCheck();
            if("2".equals(upkeepPlanCheck.getCheckResult())){
                if(StrUtil.isNotBlank(StringUtil.checkString(upkeepPlanCheck.getCheckIdea(),200))){
                    return ("审核意见 " + StringUtil.checkString(upkeepPlanCheck.getCheckIdea(),200));
                }
            }else{
                if(StrUtil.isNotBlank(StringUtil.checkString2(upkeepPlanCheck.getCheckIdea(),200))){
                    return ("审核意见 " + StringUtil.checkString2(upkeepPlanCheck.getCheckIdea(),200));
                }
            }
            if(vo.getCheckFlag() == 1){
                //审核通过
                upkeepPlan.setAuditStatus("2");
                this.updateById(upkeepPlan);
                //同步数据到台账
                TbUpkeepBill upkeepBill = new TbUpkeepBill();
                BeanUtil.copyProperties(upkeepPlan,upkeepBill);
                upkeepBill.setFlowStatus(2);
                upkeepBill.setFlowNode(1);
                //走流程的
                upkeepBill.setAddType(2);
                upkeepBillMapper.insert(upkeepBill);
                //补充节点操作人
                TbUpkeepCheck upkeepCheck = new TbUpkeepCheck();
                if(Objects.nonNull(sysUser)){
                    upkeepCheck.setCheckPeople(sysUser.getRealname());
                }
                upkeepCheck.setUpkeepBillId(upkeepBill.getId());
                upkeepCheck.setCheckPeopleType("4");
                upkeepCheck.setCheckTime(new Date());
                upkeepCheckService.save(upkeepCheck);

                //推送微信消息
                ThreadUtil.execAsync(()->{
                    Projects projects = projectsService.getById(upkeepBill.getProjectId());
                    msgPushService.pushMsgToRedis(new MsgRedisVO(
                            SenderTypeEnum.YYWB.getSendType(),upkeepBill.getId(),
                            upkeepBill.getProjectId(), WorkOrderType.UPKEEP_BILL.getType(),"待派单",
                            DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"),projects.getProjectName() + "工单更新，请及时查看"));
                });
            }
            if(vo.getCheckFlag() == 2){
                //审核未通过
                upkeepPlan.setAuditStatus("3");
                this.updateById(upkeepPlan);
            }

            String realName = "";
            if(Objects.nonNull(sysUser)){
                realName = sysUser.getRealname();
            }
            //审核信息
            if(StrUtil.isBlank(upkeepPlanCheck.getCheckPeople())){
                upkeepPlanCheck.setCheckPeople(realName);
            }
            upkeepPlanCheck.setCheckType("2");
            upkeepPlanCheck.setCheckPeopleType("2");
            upkeepPlanCheck.setCheckTime(new Date());
            upkeepPlanCheck.setUpkeepPlanId(planId);
            upkeepPlanCheckService.save(upkeepPlanCheck);
        }
        return null;
    }

    @Override
    public UpkeepPlanObjectVO getUpkeepPlanObjectById(String id) {
        UpkeepPlanObjectVO vo = new UpkeepPlanObjectVO();
        TbUpkeepPlan tbUpkeepPlan = this.getById(id);
        vo.setId(id);
        vo.setUpkeepPlan(tbUpkeepPlan);
        if(StrUtil.isNotBlank(tbUpkeepPlan.getAttachmentJson())){
            tbUpkeepPlan.setAttachmentList(JSONUtil.toList(tbUpkeepPlan.getAttachmentJson(), AttachmentDetailVO.class));
        }
        vo.setAuditStatus(tbUpkeepPlan.getAuditStatus());
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //暂只做单一”司机、维修厂、维保员工、领导” 身份的处理。取最高身份
        String authorityType = commonService.getAuthority(sysUser.getUsername());
        if("6".equals(authorityType)){
            authorityType = "5";
        }
        vo.setUserType(authorityType);

        //补充作废信息
        if("4".equals(tbUpkeepPlan.getAuditStatus())){
            CancelObjectVO cancelObjectVO = new CancelObjectVO();
            cancelObjectVO.setCancelIdea(tbUpkeepPlan.getCancelIdea());
            cancelObjectVO.setCancelPeople(tbUpkeepPlan.getCancelPeople());
            cancelObjectVO.setCancelTime(tbUpkeepPlan.getCancelTime());
            vo.setCancelObject(cancelObjectVO);
        }

        LambdaQueryWrapper<TbUpkeepPlanCheck> checkQueryWrapper = new LambdaQueryWrapper<>();
        checkQueryWrapper.eq(TbUpkeepPlanCheck::getUpkeepPlanId,id);
        List<TbUpkeepPlanCheck> tbRepairCheckList = upkeepPlanCheckService.list(checkQueryWrapper);
        vo.setUpkeepCheckList(tbRepairCheckList);

        return vo;
    }

    /**
     * 一个“或”规则，多次触发。后续触发需要屏蔽掉。仅生成一次
     * 同一次定时多个规则圈中同一辆车只生成一份
     */
    @Override
    public String ruleCreatePlan() {
        //当前批次
        Integer createNo = upkeepPlanMapper.findMaxPlanCreateNo() + 1;
        //1、查启用的规则
        LambdaQueryWrapper<TbUpkeepRule> ruleQuery = new LambdaQueryWrapper<>();
        ruleQuery.eq(TbUpkeepRule::getRuleStatus,"1");
        List<TbUpkeepRule> upkeepRuleList = upkeepRuleService.list(ruleQuery);
        //按时间、里程、时间或里程
        List<TbUpkeepRule> ruleTimes = upkeepRuleList.stream().filter(s->"1".equals(s.getRuleType())).collect(Collectors.toList());
        List<TbUpkeepRule> ruleMiles = upkeepRuleList.stream().filter(s->"2".equals(s.getRuleType())).collect(Collectors.toList());
        List<TbUpkeepRule> ruleTimeOrMiles = upkeepRuleList.stream().filter(s->"3".equals(s.getRuleType())).collect(Collectors.toList());
        //按时间生成保养单  规则设置的时间间隔-上次保养时间<=30
        int timeCount = ruleCreatePlanByTime(ruleTimes,createNo);
        //按里程生成保养单  (当前车辆的总里程数+本月的累计里程数)>=设置的里程数*90%则生成保养计划
        int mileCount = ruleCreatePlanByMile(ruleMiles, createNo);
        //按时间或里程生成保养计划单，同一规则车仅会存在一条
        int timeOrMileCount = ruleCreatePlanByTimeOrMiles(ruleTimeOrMiles,createNo);

        String str = "按时间生成保养单: " + timeCount + "条； " +
                "按里程生成保养单: " + mileCount + "条； " +
                "按时间或里程生成保养计划单: " + timeOrMileCount + "条。";
        log.info("保养规则生成计划 {}，{}" ,DateUtil.formatDateTime(new Date()), str);
        return  str;
    }

    @Override
    public Page getUpkeepPlanList(Page page, TbUpkeepPlan upkeepPlan) {
        List<TbUpkeepPlan> list = new ArrayList<>();
        list = upkeepPlanMapper.findUpkeepPlanList(page,upkeepPlan);
        //todo 做按钮权限处理
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //1-司机，2-维修厂，3-司机&维修厂，4-维保管理员，5-维保领导，6-维保管理员&维保领导
        String authorityType = commonService.getAuthority(sysUser.getUsername());
        handlerButtonAndType(list, authorityType);
        page.setRecords(list);

        return page;
    }

    public Integer ruleCreatePlanByTime(List<TbUpkeepRule> ruleTimes,Integer createNo) {
        AtomicInteger saveCount = new AtomicInteger();
        ruleTimes.stream().forEach(rule->{
            //按时间规则查车，没有上次里程的车取交车时间
            List<VehicleInfoVO> vehicleInfoVOList = repairInfoMapper.findVehicleInfoByTime(rule.getVehicleType(),rule.getVehicleModel(),rule.getVehicleBrand());
            if(Objects.nonNull(vehicleInfoVOList) && vehicleInfoVOList.size()>0){
                for(VehicleInfoVO vo : vehicleInfoVOList){
                    //查有无进行中的计划或台账
                    int unFinishcount = upkeepPlanMapper.findUnfinishCount(vo.getPlateNumber());
                    if(unFinishcount>0){
                        continue;
                    }
                    
                    //查有无已生成的当前批次计划
                    LambdaQueryWrapper<TbUpkeepPlan> planQuery = new LambdaQueryWrapper<>();
                    planQuery.eq(TbUpkeepPlan::getPlateNumber,vo.getPlateNumber())
                            .eq(TbUpkeepPlan::getCreateNo,createNo);
                    int count = this.count(planQuery);
                    if(count > 0){
                        continue;
                    }else{
                        //规则设置的时间间隔-上次保养时间<=30
                        log.info(DateUtil.formatDateTime(vo.getLastTime()) + "-----" + rule.getTime());
                        log.info(DateUtil.formatDateTime(DateUtil.offsetDay(vo.getLastTime(),rule.getTime())));
                        long days = DateUtil.between(DateUtil.offsetDay(vo.getLastTime(),rule.getTime()), new Date(), DateUnit.DAY,false);
                        if(days <= 30 && days >= 0){
                            //生成该车保养计划
                            TbUpkeepPlan plan = new TbUpkeepPlan();
                            BeanUtil.copyProperties(vo,plan,"id");
                            //未审核
                            plan.setAuditStatus("1");
                            //自动、规则id、批次号、生成日期
                            plan.setSaveType(1);
                            plan.setRuleId(rule.getId());
                            plan.setCreateNo(createNo);
                            plan.setPlanSaveTime(new Date());
                            //预计保养里程、时间。。。时间为这次上次保养时间+时间间隔
                            plan.setPredictMileage(rule.getMileage());
                            if(Objects.nonNull(rule.getTime())){
                                plan.setPredictTime(DateUtil.offsetDay(vo.getLastTime(),rule.getTime()));
                            }
                            //工单号
                            String format = DateUtil.format(new Date(),"yyyyMMddHHmmssSSS");
                            plan.setOrderNo(format);
                            plan.setContent(rule.getName());
                            this.save(plan);
                            //推送微信消息
                            ThreadUtil.execAsync(()->{
                                Projects projects = projectsService.getById(plan.getProjectId());
                                msgPushService.pushMsgToRedis(new MsgRedisVO(
                                        SenderTypeEnum.YYWB.getSendType(),plan.getId(),
                                        plan.getProjectId(), WorkOrderType.UPKEEP_PLAN.getType(),"未审批",
                                        DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"),projects.getProjectName() + "工单更新，请及时查看"));
                            });
                            saveCount.getAndIncrement();
                        }
                    }
                }
            }
        });

        return saveCount.get();
    }

    public Integer ruleCreatePlanByMile(List<TbUpkeepRule> ruleMiles,Integer createNo) {
        AtomicInteger saveCount = new AtomicInteger();
        ruleMiles.stream().forEach(rule->{
            //按时间规则查车，没有上次里程的车取交车时间
            List<VehicleInfoVO> vehicleInfoVOList = repairInfoMapper.findVehicleInfoByMile(rule.getVehicleType(),rule.getVehicleModel(),rule.getVehicleBrand());
            if(Objects.nonNull(vehicleInfoVOList) && vehicleInfoVOList.size()>0){
                for(VehicleInfoVO vo : vehicleInfoVOList){
                    //查有无进行中的计划或台账
                    int unFinishcount = upkeepPlanMapper.findUnfinishCount(vo.getPlateNumber());
                    if(unFinishcount>0){
                        continue;
                    }
                    //查有无已生成的当前批次计划
                    LambdaQueryWrapper<TbUpkeepPlan> planQuery = new LambdaQueryWrapper<>();
                    planQuery.eq(TbUpkeepPlan::getPlateNumber,vo.getPlateNumber())
                            .eq(TbUpkeepPlan::getCreateNo,createNo);
                    int count = this.count(planQuery);
                    if(count > 0){
                        continue;
                    }else{
                        //按里程生成保养单  (当前车辆的总里程数+本月的累计里程数)>=（设置的里程数间隔 + 上次保养里程）*90%则生成保养计划
                        if((vo.getTotalMileage() + vo.getMonthlyTotalMileage())>= ((rule.getMileage() + vo.getLastMileage())*0.9)){
                            //生成该车保养计划
                            TbUpkeepPlan plan = new TbUpkeepPlan();
                            BeanUtil.copyProperties(vo,plan,"id");
                            //未审核
                            plan.setAuditStatus("1");
                            //自动、规则id、批次号、生成日期
                            plan.setSaveType(1);
                            plan.setRuleId(rule.getId());
                            plan.setCreateNo(createNo);
                            plan.setPlanSaveTime(new Date());
                            //预计保养里程、时间。。。时间为这次上次保养时间+时间间隔
                            plan.setPredictMileage(rule.getMileage() + vo.getLastMileage());
                            if(Objects.nonNull(rule.getTime())){
                                plan.setPredictTime(DateUtil.offsetDay(vo.getLastTime(),rule.getTime()));
                            }
                            //工单号
                            String format = DateUtil.format(new Date(),"yyyyMMddHHmmssSSS");
                            plan.setOrderNo(format);
                            plan.setContent(rule.getName());
                            this.save(plan);
                            //推送微信消息
                            ThreadUtil.execAsync(()->{
                                Projects projects = projectsService.getById(plan.getProjectId());
                                msgPushService.pushMsgToRedis(new MsgRedisVO(
                                        SenderTypeEnum.YYWB.getSendType(),plan.getId(),
                                        plan.getProjectId(), WorkOrderType.UPKEEP_PLAN.getType(),"未审批",
                                        DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"),projects.getProjectName() + "工单更新，请及时查看"));
                            });
                            saveCount.getAndIncrement();
                        }
                    }
                }
            }
        });
        return saveCount.get();
    }

    public Integer ruleCreatePlanByTimeOrMiles(List<TbUpkeepRule> ruleTimeOrMiles,Integer createNo) {
        AtomicInteger saveCount = new AtomicInteger();
        //“或”工单仅有一条
        ruleTimeOrMiles.stream().forEach(rule->{
            //按时间规则查车，没有上次里程的车取交车时间
            List<VehicleInfoVO> vehicleInfoVOList = repairInfoMapper.findVehicleInfoByMile(rule.getVehicleType(),rule.getVehicleModel(),rule.getVehicleBrand());
            if(Objects.nonNull(vehicleInfoVOList) && vehicleInfoVOList.size()>0) {
                for (VehicleInfoVO vo : vehicleInfoVOList) {
                    //查有无进行中的计划或台账
                    int unFinishcount = upkeepPlanMapper.findUnfinishCount(vo.getPlateNumber());
                    if(unFinishcount>0){
                        continue;
                    }
                    //查有无已生成的当前批次计划
                    LambdaQueryWrapper<TbUpkeepPlan> curPlanQuery = new LambdaQueryWrapper<>();
                    curPlanQuery.eq(TbUpkeepPlan::getPlateNumber,vo.getPlateNumber())
                            .eq(TbUpkeepPlan::getCreateNo,createNo);
                    int curCount = this.count(curPlanQuery);
                    if(curCount > 0){
                        continue;
                    }
                    //查有无已经有生成过一次的“或”工单
                    LambdaQueryWrapper<TbUpkeepPlan> planQuery = new LambdaQueryWrapper<>();
                    planQuery.eq(TbUpkeepPlan::getRuleId,rule.getId()).eq(TbUpkeepPlan::getPlateNumber,vo.getPlateNumber());
                    int count = this.count(planQuery);
                    if(count > 0){
                        continue;
                    }else{
                        //时间或里程，满足其一即可
                        long days = DateUtil.between(DateUtil.offsetDay(vo.getLastTime(),rule.getTime()), new Date(), DateUnit.DAY,false);
                        if(days <= 30 && days >= 0){
                            //生成该车保养计划
                            TbUpkeepPlan plan = new TbUpkeepPlan();
                            BeanUtil.copyProperties(vo,plan,"id");
                            //未审核
                            plan.setAuditStatus("1");
                            //自动、规则id、批次号、生成日期
                            plan.setSaveType(1);
                            plan.setRuleId(rule.getId());
                            plan.setCreateNo(createNo);
                            plan.setPlanSaveTime(new Date());
                            //预计保养里程、时间。。。时间为这次上次保养时间+时间间隔
                            plan.setPredictMileage(rule.getMileage());
                            if(Objects.nonNull(rule.getTime())){
                                plan.setPredictTime(DateUtil.offsetDay(vo.getLastTime(),rule.getTime()));
                            }
                            //工单号
                            String format = DateUtil.format(new Date(),"yyyyMMddHHmmssSSS");
                            plan.setOrderNo(format);
                            plan.setContent(rule.getName());
                            this.save(plan);
                            saveCount.getAndIncrement();
                            //推送微信消息
                            ThreadUtil.execAsync(()->{
                                Projects projects = projectsService.getById(plan.getProjectId());
                                msgPushService.pushMsgToRedis(new MsgRedisVO(
                                        SenderTypeEnum.YYWB.getSendType(),plan.getId(),
                                        plan.getProjectId(), WorkOrderType.UPKEEP_PLAN.getType(),"未审批",
                                        DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"),projects.getProjectName() + "工单更新，请及时查看"));
                            });
                            continue;
                        }

                        if((vo.getTotalMileage() + vo.getMonthlyTotalMileage())>= ((rule.getMileage() + vo.getLastMileage())*0.9)){
                            //生成该车保养计划
                            TbUpkeepPlan plan = new TbUpkeepPlan();
                            BeanUtil.copyProperties(vo,plan,"id");
                            //未审核
                            plan.setAuditStatus("1");
                            //自动、规则id、批次号、生成日期
                            plan.setSaveType(1);
                            plan.setRuleId(rule.getId());
                            plan.setCreateNo(createNo);
                            plan.setPlanSaveTime(new Date());
                            //预计保养里程、时间。。。时间为这次上次保养时间+时间间隔
                            plan.setPredictMileage(rule.getMileage() + vo.getLastMileage());
                            if(Objects.nonNull(rule.getTime())){
                                plan.setPredictTime(DateUtil.offsetDay(vo.getLastTime(),rule.getTime()));
                            }
                            //工单号
                            String format = DateUtil.format(new Date(),"yyyyMMddHHmmssSSS");
                            plan.setOrderNo(format);
                            plan.setContent(rule.getName());
                            this.save(plan);
                            saveCount.getAndIncrement();
                            //推送微信消息
                            ThreadUtil.execAsync(()->{
                                Projects projects = projectsService.getById(plan.getProjectId());
                                msgPushService.pushMsgToRedis(new MsgRedisVO(
                                        SenderTypeEnum.YYWB.getSendType(),plan.getId(),
                                        plan.getProjectId(), WorkOrderType.UPKEEP_PLAN.getType(),"未审批",
                                        DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"),projects.getProjectName() + "工单更新，请及时查看"));
                            });
                            continue;
                        }
                    }
                }
            }
        });
        return saveCount.get();
    }

    //补充按钮权限
    public void handlerButtonAndType(List<TbUpkeepPlan> list, String authorityType){
        //1-司机，2-维修厂，3-司机&维修厂，4-维保管理员，5-维保领导，6-维保管理员&维保领导
        if("4".equals(authorityType)){
            list.stream().forEach(item->{
                UpkeepPlanStatusEnumEmployee statusEnum = UpkeepPlanStatusEnumEmployee.getEnum(item.getAuditStatus());
                if(Objects.nonNull(statusEnum)){
                    item.setCheckButton(statusEnum.getCheckButton());
                    item.setDeleteButton(statusEnum.getDeleteButton());
                    item.setAuditButton(statusEnum.getAuditButton());
                    //手动生成才有编辑
                    if(2 == item.getSaveType()){
                        item.setEditButton(statusEnum.getEditButton());
                    }
                    //没编辑就补充查看按钮
                    if(Objects.isNull(item.getEditButton()) || item.getEditButton()==2){
                        item.setCheckButton(1);
                    }
                    item.setUserType(authorityType);
                }
            });
        }

        if("6".equals(authorityType) || "5".equals(authorityType)){
            list.stream().forEach(item->{
                UpkeepPlanStatusEnumLeader statusEnum = UpkeepPlanStatusEnumLeader.getEnum(item.getAuditStatus());
                if(Objects.nonNull(statusEnum)){
                    item.setCheckButton(statusEnum.getCheckButton());
                    item.setDeleteButton(statusEnum.getDeleteButton());
                    item.setAuditButton(statusEnum.getAuditButton());
                    //手动生成才有编辑
                    if(2 == item.getSaveType()){
                        item.setEditButton(statusEnum.getEditButton());
                    }
                    //没编辑就补充查看按钮
                    if(Objects.isNull(item.getEditButton()) || item.getEditButton()==2){
                        item.setCheckButton(1);
                    }
                    item.setUserType("5");
                }
            });
        }
    }
}
