package com.ruoyi.approvalFlow.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ruoyi.approvalFlow.domain.*;
import com.ruoyi.approvalFlow.domain.dto.AppAuditItemDTO;
import com.ruoyi.approvalFlow.domain.enums.AuditStateEnum;
import com.ruoyi.approvalFlow.domain.vo.AppAuditItemVO;
import com.ruoyi.approvalFlow.mapper.*;
import com.ruoyi.approvalFlow.service.IAuditPathsService;
import com.ruoyi.basicData.domain.TFees;
import com.ruoyi.basicData.mapper.TFeesMapper;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.exception.WarehouseException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.finance.domain.TFee;
import com.ruoyi.finance.mapper.TFeeMapper;
import com.ruoyi.finance.service.impl.TFeeServiceImpl;
import com.ruoyi.reportManagement.domain.TWhgenleg;
import com.ruoyi.reportManagement.mapper.TWhgenlegMapper;
import com.ruoyi.warehouseBusiness.component.CalculationWarehouseService;
import com.ruoyi.warehouseBusiness.domain.TWarehouseAgreement;
import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
import com.ruoyi.warehouseBusiness.domain.TWarehousebillsfees;
import com.ruoyi.warehouseBusiness.domain.TWarehousebillsitems;
import com.ruoyi.warehouseBusiness.domain.enums.WarehouseActIdEnum;
import com.ruoyi.warehouseBusiness.domain.enums.WarehouseTypeEnum;
import com.ruoyi.warehouseBusiness.mapper.TWarehouseAgreementMapper;
import com.ruoyi.warehouseBusiness.mapper.TWarehouseBillsMapper;
import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsfeesMapper;
import com.ruoyi.warehouseBusiness.mapper.TWarehousebillsitemsMapper;
import com.ruoyi.warehouseBusiness.service.impl.TWarehouseAgreementServiceImpl;
import com.ruoyi.warehouseBusiness.service.impl.TWarehouseBillsServiceImpl;
import com.ruoyi.warehouseBusiness.service.impl.TWarehousebillsModifyServiceImpl;
import org.apache.commons.compress.utils.Lists;
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 java.util.*;

import static java.util.stream.Collectors.toList;

/**
 * 审批流配置主Service业务层处理
 *
 * @author ruoyi
 * @date 2021-01-21
 */
@Service
public class AuditPathsServiceImpl implements IAuditPathsService {

    @Autowired
    private AuditPathsMapper auditPathsMapper;

    @Autowired
    private AuditItemsMapper auditItemsMapper;

    @Autowired
    private TWhgenlegMapper tWhgenlegMapper;

    @Autowired
    private AuditItemsUsersMapper auditItemsUsersMapper;

    @Autowired
    private AuditPathsActsMapper auditPathsActsMapper;

    @Autowired
    private AuditPathsLevelsMapper auditPathsLevelsMapper;

    @Autowired
    private TWarehouseBillsMapper tWarehouseBillsMapper;

    @Autowired
    private TWarehouseBillsServiceImpl tWarehouseBillsService;

    @Autowired
    private TWarehousebillsfeesMapper tWarehousebillsfeesMapper;

    @Autowired
    private TWarehousebillsitemsMapper tWarehousebillsitemsMapper;

    @Autowired
    private TFeeServiceImpl tFeeServiceImpl;

    @Autowired
    private TWarehouseAgreementServiceImpl tWarehouseAgreementService;

    @Autowired
    private TWarehousebillsModifyServiceImpl warehousebillsModifyService;

    @Autowired
    private TFeeMapper tFeeMapper;

    @Autowired
    private TFeesMapper feesMapper;

    @Autowired
    private TWarehouseAgreementMapper tWarehouseAgreementMapper;

    @Autowired
    private CalculationWarehouseService calculationWarehouseService;

    /**
     * 查询审批流配置主
     *
     * @param id 审批流配置主ID
     * @return 审批流配置主
     */
    @Override
    public AjaxResult selectAuditPathsById(Long id) {
        Map<String, Object> map = new HashMap<>();
        AuditPaths auditPaths = auditPathsMapper.selectAuditPathsById(id);
        if (StringUtils.isNull(auditPaths)) {
            return AjaxResult.error("该审批流不存在，请确认");
        }
        map.put("auditPaths", auditPaths);
        AuditPathsLevels auditPathsLevels = new AuditPathsLevels();
        auditPathsLevels.setPathId(id);
        List<AuditPathsLevels> pathsLevelsList = auditPathsLevelsMapper.selectAuditPathsLevelsList(auditPathsLevels);
        if (StringUtils.isNotNull(pathsLevelsList)) {
            List<List<Long>> longs = new ArrayList<>();
            for (AuditPathsLevels ap : pathsLevelsList) {
                List<Long> longList = new ArrayList<>();
                if (ap.getAuditUserId() != null) {
                    JSONArray jsonArray = JSONArray.parseArray(ap.getAuditUserId());
                    longList = JSONObject.parseArray(jsonArray.toJSONString(), Long.class);
                }
                longs.add(longList);
            }
            map.put("auditUserIds", longs);
            map.put("auditPathsLevels", pathsLevelsList);
        }
        return AjaxResult.success(map);
    }

    /**
     * 查询审批流配置主列表
     *
     * @param auditPaths 审批流配置主
     * @return 审批流配置主
     */
    @Override
    public List<AuditPaths> selectAuditPathsList(AuditPaths auditPaths) {
        return auditPathsMapper.selectAuditPathsList(auditPaths);
    }

    /**
     * 新增审批流配置主
     *
     * @param auditPaths 审批流配置主
     * @return 结果
     */
    @Override
    @Transactional
    public AjaxResult insertAuditPaths(String auditPaths, String auditPathsLevels, LoginUser loginUser) {
        AuditPaths apath = JSONArray.parseObject(auditPaths, AuditPaths.class);
        if ("A".equals(apath.getStatus()) && (StringUtils.isNull(auditPathsLevels) || "[]".equals(auditPathsLevels))) {
            return AjaxResult.error("未找到级次信息无法提交，请确认");
        }
        long fPid = 0L;
        if (StringUtils.isNotNull(apath.getId())) {
            if ("S".equals(apath.getStatus())) {
                AuditPathsActs auditPathsActs = new AuditPathsActs();
                auditPathsActs.setPathId(apath.getId());
                int sum = auditPathsActsMapper.selectCountAuditPathsActs(auditPathsActs);
                if (sum > 0) {
                    return AjaxResult.error("该审批配置已被使用，请取消使用后提交");
                }
            }
            auditPathsLevelsMapper.deleteAuditPathsLevelsBypathId(apath.getId());
            auditPathsMapper.updateAuditPaths(apath);
            fPid = apath.getId();
        } else {
            AuditPaths paths = new AuditPaths();
            paths.setPathName(apath.getPathName());
            List<AuditPaths> audiList = auditPathsMapper.selectAuditPathsList(paths);
            if (audiList.size() > 0) {
                return AjaxResult.error("审核路径名已存在，请确认");
            }
            apath.setOpUserId(loginUser.getUser().getUserId());
            apath.setOpDate(new Date());
            apath.setOpUserName(loginUser.getUsername());
            auditPathsMapper.insertAuditPaths(apath);
            fPid = apath.getId();
        }
        if (StringUtils.isNotNull(auditPathsLevels) && !"[]".equals(auditPathsLevels)) {
            JSONArray warehouseJSON = JSONArray.parseArray(auditPathsLevels);
            List<AuditPathsLevels> auditPathsLevelsList = JSONObject.parseArray(warehouseJSON.toJSONString(), AuditPathsLevels.class);
            if ("F".equals(auditPathsLevelsList.get(auditPathsLevelsList.size() - 1).getIffinalItem())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("操作失败：最后一级状态有误，请确认");
            }
            Long level = 0L;
            boolean last = false;
            for (AuditPathsLevels lev : auditPathsLevelsList) {
                if (StringUtils.isNull(lev.getAuditUserId())) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error("操作失败：请维护审核人");
                }
                if ("T".equals(lev.getIffinalItem()) && !last) {
                    last = true;
                } else if ("T".equals(lev.getIffinalItem()) && last) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    return AjaxResult.error("操作失败：最后一级只能存在一个");
                }
                level++;
                lev.setPathId(fPid);
                lev.setLevelId(level);
                auditPathsLevelsMapper.insertAuditPathsLevels(lev);
            }
        }
        return AjaxResult.success();
    }

    /**
     * 修改审批流配置主
     *
     * @param auditPaths 审批流配置主
     * @return 结果
     */
    @Override
    public int updateAuditPaths(AuditPaths auditPaths) {
        return auditPathsMapper.updateAuditPaths(auditPaths);
    }

    /**
     * 批量删除审批流配置主
     *
     * @param ids 需要删除的审批流配置主ID
     * @return 结果
     */
    @Override
    @Transactional
    public AjaxResult deleteAuditPathsByIds(Long[] ids) {
        int line = 0;
        for (Long lo : ids) {
            line++;
            AuditPathsActs auditPathsActs = new AuditPathsActs();
            auditPathsActs.setPathId(lo);
            int sum = auditPathsActsMapper.selectCountAuditPathsActs(auditPathsActs);
            if (sum > 0) {
                return AjaxResult.error("第" + line + "行，审批已被使用无法删除");
            }
        }
        auditPathsMapper.deleteAuditPathsByIds(ids);
        return AjaxResult.success();
    }

    /**
     * 删除审批流配置主信息
     *
     * @param id 审批流配置主ID
     * @return 结果
     */
    @Override
    public int deleteAuditPathsById(Long id) {
        return auditPathsMapper.deleteAuditPathsById(id);
    }

    /**
     * 单据点击查看审批流
     *
     * @param auditItems 条件
     * @return 结果
     */
    @Override
    public AjaxResult projectEndQueryPendingVal(AuditItems auditItems) {
        List<Map<String, Object>> mapList = auditItemsMapper.selectWarehouseApprover(auditItems);
        return AjaxResult.success(mapList);
    }

    /**
     * 首页点击查看审批流 获取对应数据
     *
     * @param auditItems 查询条件
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> selectAllAuditItems(AuditItems auditItems) {
        return auditItemsMapper.selectAuditItems(auditItems);
    }

    /**
     * 查询审批流配置主信息条数
     *
     * @return 结果
     */
    @Override
    public int selectCountAuditItems() {
        return auditItemsMapper.selectCountAuditItems();
    }

    /**
     * 审批通过
     *
     * @param auditItems 审核人、单据信息
     * @return 结果
     */
    @Override
    @Transactional
    public AjaxResult approved(AuditItems auditItems) {
        // 审核通过时间
        Date auditItemtem = auditItems.getAuditItem();
        long fettle = 0L;
        int number = 0;
        AuditItems item = new AuditItems();
        item.setBillId(auditItems.getId());
        item.setActId(auditItems.getActId());
        item.setFidStatus(auditItems.getFidStatus());
        List<AuditItems> auditItemsList = auditItemsMapper.selectAuditItemsList(item);
        if (CollectionUtils.isEmpty(auditItemsList)) {
            return AjaxResult.error("未找到审批信息，请确认");
        }
        for (AuditItems at : auditItemsList) {
            if (!"S".equals(at.getAuditStatus())) {
                continue;
            }
            AuditItemsUsers itemsUsers = new AuditItemsUsers();
            itemsUsers.setPid(at.getId());
            List<AuditItemsUsers> auditItemsUsers = auditItemsUsersMapper.selectAuditItemsUsersList(itemsUsers);
            for (AuditItemsUsers au : auditItemsUsers) {
                if (au.getUserId().equals(auditItems.getSendUserId()) && "S".equals(au.getAuditStatus())) {
                    number++;
                    if (StringUtils.isEmpty(auditItems.getAuditMsg())) {
                        at.setAuditMsg("同意");
                    } else {
                        at.setAuditMsg(auditItems.getAuditMsg());
                    }
                    at.setAuditStatus("A");
                    //at.setAuditItem(new Date());
                    at.setAuditOpTime(new Date());
                    at.setAuditUserId(au.getUserId());
                    at.setAuditItem(auditItemtem);
                    int updateAuditItems = auditItemsMapper.updateAuditItems(at);
                    if (updateAuditItems <= 0) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return AjaxResult.error("审批通过失败: 更新审批状态失败");
                    }
                    au.setAuditStatus("A");
                    int updateAuditItemsUsers = auditItemsUsersMapper.updateAuditItemsUsers(au);
                    if (updateAuditItemsUsers <= 0) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return AjaxResult.error("审批通过失败: 更新审批状态失败");
                    }
                    if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 仓库模块
                        if ("warehouse_status".equals(auditItems.getFidStatus())) {
                            tWarehouseBillsMapper.warehouseApprovalUpdate(auditItems, fettle);
                        } else {
                            tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
                        }
                        tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
                        if (Objects.equals(fettle, 6L)) {
                            if (Objects.equals(auditItems.getActId(), 120L)) {
                                List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
                                // 过滤出明细信息查询是否存在已计算仓储费
                                List<Long> ids = feesList.stream().filter(li -> !li.getfBilltype().equals(WarehouseTypeEnum.KCZZ.getType()))
                                        .map(TWarehousebillsfees::getSrcId).distinct().collect(toList());
                                if (CollectionUtils.isNotEmpty(ids) && tWarehousebillsitemsMapper.selectIsCalculateStorageFeesByIds(ids) > 0) {
                                    throw new WarehouseException("计算费用中存在已计算仓储费信息");
                                }
                                // 获取仓储费，并判断费用中是否存在仓储费
                                TFees ccf = feesMapper.seletFeesByCCF();
                                if (Objects.isNull(ccf)) {
                                    throw new WarehouseException("未找到仓储费费用信息");
                                }
                                // 过滤出费用类型等于仓储费并且有商机id，并取出来进行更新仓储费计费日期
                                long count = feesList.stream().filter(li -> Objects.equals(li.getfFeeid(), ccf.getfId()) && Objects.nonNull(li.getSrcId()))
                                        .count();
                                if (count > 0) {
                                    TWarehousebillsfees warehousebillsfees = feesList.stream().findFirst().orElseThrow(() -> new WarehouseException("未找到费用明细"));
                                    // 更新子表仓储费截止日期
                                    tWarehousebillsitemsMapper.updateItemStorageFeeDeadlineByPId(warehousebillsfees.getfPid(), warehousebillsfees.getfBillingDeadline());
                                }
                            } else if (Objects.equals(auditItems.getActId(), 150L)) {
                                tWarehouseBillsService.approvedStorageFee(auditItems.getBillId(), fettle, at.getAuditItem());
                            }
                        }
                    } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
                        // 财务模块
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                            // 更新费用明细
                            AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
                            String code = ajaxResult.get("code").toString();
                            if ("500".equals(code)) {
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                return ajaxResult;
                            }
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 变更财务状态
                        AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
                        String code = ajaxResult.get("code").toString();
                        if ("500".equals(code)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return ajaxResult;
                        }
                    } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
                        // 协议模块
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 变更财务状态
                        AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
                        String code = ajaxResult.get("code").toString();
                        if ("500".equals(code)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return ajaxResult;
                        }
                    } else if (auditItems.getActId() == 410) {
                        if (StringUtils.isEmpty(auditItems.getRefno3())) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return AjaxResult.error("提单号不能为空");
                        }
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        //变更凯和订单状态
                        AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, at.getAuditItem());
                        String code = ajaxResult.get("code").toString();
                        if ("500".equals(code)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return ajaxResult;
                        }
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfMblno(auditItems.getRefno3());
                        AjaxResult orderMessage = tWarehouseBillsService.updateOrderMessage(tWarehouseBills);
                        String orderMessageCode = orderMessage.get("code").toString();
                        if ("500".equals(orderMessageCode)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return orderMessage;
                        }
                    } else if (auditItems.getActId() == 420) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 11L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 10L;
                        }
                        //变更凯和订单状态
                        AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, at.getAuditItem());
                        String code = ajaxResult.get("code").toString();
                        if ("500".equals(code)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return ajaxResult;
                        }
                    } else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
                        // 财务模块
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                            // 更新费用明细
                            AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
                            String code = ajaxResult.get("code").toString();
                            if ("500".equals(code)) {
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                return ajaxResult;
                            }
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 变更财务状态
                        AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
                        String code = ajaxResult.get("code").toString();
                        if ("500".equals(code)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return ajaxResult;
                        }
                    } else if (auditItems.getActId() == 470) {
                        // 财务模块
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                            // 更新费用明细
                            AjaxResult ajaxResult = tFeeServiceImpl.billsfeesFollow(auditItems.getBillId());
                            String code = ajaxResult.get("code").toString();
                            if ("500".equals(code)) {
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                return ajaxResult;
                            }
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 变更财务状态
                        AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
                        String code = ajaxResult.get("code").toString();
                        if ("500".equals(code)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return ajaxResult;
                        }
                        //生成销项发票
                        AjaxResult invoiceFp = tFeeServiceImpl.copyInvoiceFp(auditItems.getBillId(), "INV");
                        String string = invoiceFp.get("code").toString();
                        if ("500".equals(string)) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return invoiceFp;
                        }
                    } else if (auditItems.getActId() == 460) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        //变更凯和订单状态
                        Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, at.getAuditItem());
                        if (i != null && i > 0) {
                        } else {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return AjaxResult.error("审核失败，更新费用状态失败");
                        }
                    } else if (auditItems.getActId() == 170) {
                        //入库明细审核
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        //变更仓库入库明细审核状态
                        Integer i = null;
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfItemstatus(fettle);
                        i = tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
                        i = tWarehousebillsitemsMapper.warehouseItemfItemstatus(auditItems.getBillId(), fettle);
                        if (i != null && i > 0) {
                        } else {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return AjaxResult.error("审核失败，更新费用状态失败");
                        }
                    } else if (auditItems.getActId() == 180) {
                        //入库明细审核
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        //变更仓库入库明细审核状态
                        Integer i = null;
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfItemstatus(fettle);
                        i = tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
                        i = tWarehousebillsitemsMapper.warehouseItemfItemstatus(auditItems.getBillId(), fettle);
                        if (i != null && i > 0) {
                        } else {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return AjaxResult.error("审核失败，更新费用状态失败");
                        }
                    } else if (auditItems.getActId() == 471) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                            AjaxResult orderMessage = tWarehouseBillsService.copyKhOrderMessage(auditItems.getBillId());
                            String string = orderMessage.get("code").toString();
                            if ("500".equals(string)) {
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                return orderMessage;
                            }
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 变更凯和申请修改订单状态
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfUpdeteStatus(fettle);
                        tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
                    } else if (auditItems.getActId() == 472) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 变更凯和申请修改订单状态
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfSubmitUpdate(fettle);
                        if (fettle == 6L) {
                            tWarehouseBills.setfUpdeteStatus(2L);
                            tWarehouseBills.setfSubmitUpdate(2L);
                        }
                        tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
                    } else if (auditItems.getActId() == 473) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                            // 删除申请审核通过修改订单的状态
                            TWarehouseBills tWarehouseBills = new TWarehouseBills();
                            tWarehouseBills.setfId(auditItems.getBillId());
                            tWarehouseBills.setDelFlag("1");
                            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        // 变更凯和申请修改订单状态
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfDeleteStatus(fettle);
                        tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
                    } else if (auditItems.getActId() == 474) {
                        if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        } else if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                            //修改原订单信息
                            AjaxResult ajaxResult = tWarehouseBillsService.approveDismount(auditItems.getBillId());
                            String string = ajaxResult.get("code").toString();
                            if ("500".equals(string)) {
                                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                                return ajaxResult;
                            }
                        }
                        //变更凯和订单状态
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfDismountStatus(fettle);
                        tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
                    } else if (auditItems.getActId() == 181) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        //业务处理
                    } else if (auditItems.getActId() == 190) {
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                        }
                        TWarehouseBills tWarehouseBills = new TWarehouseBills();
                        tWarehouseBills.setfId(auditItems.getBillId());
                        tWarehouseBills.setfBillstatus(fettle);
                        tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
                        tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
                    } else if (Objects.equals(auditItems.getActId(), WarehouseActIdEnum.FEE_CHANGES.getActId().longValue())) {
                        // 费用变更审核通过处理
                        if ("T".equals(at.getIffinalItem())) {
                            fettle = 6L;
                            warehousebillsModifyService.additionalFeeInformation(auditItems.getBillId(), WarehouseTypeEnum.APPROVE);
                        } else if ("F".equals(at.getIffinalItem())) {
                            fettle = 5L;
                            warehousebillsModifyService.additionalFeeInformation(auditItems.getBillId(), WarehouseTypeEnum.UNDER_REVIEW);
                        }
                    }
                    if ("F".equals(at.getIffinalItem())) {
                        at.setLevelId(at.getLevelId() + 1);
                        int updateNum = auditItemsMapper.updateAuditStatus(at);
                        if (updateNum <= 0) {
                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                            return AjaxResult.error("审批通过失败: 更新审批状态失败");
                        }
                    }
                    break;
                }
            }
        }

        TWarehouseBills warehouseBills = new TWarehouseBills();
        warehouseBills.setfId(auditItems.getBillId());
        calculationWarehouseService.calculationFeeStatus(warehouseBills);
        tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);

        if (number <= 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error("该审批已被操作");
        }
        return AjaxResult.success();
    }

    /**
     * 审批驳回
     *
     * @param auditItems 审核人、单据信息
     * @return 结果
     */
    @Override
    @Transactional
    public AjaxResult approvalRejected(AuditItems auditItems) {
        long fettle = 0L;
        if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
            fettle = 3L;
            if ("f_billstatus".equals(auditItems.getFidStatus())) {
                tWarehouseBillsMapper.warehouseFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            } else {
                tWarehouseBillsMapper.warehouseApprovalUpdate(auditItems, fettle);
            }
            tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            if (Objects.equals(auditItems.getActId(), 150L)) {
                List<TWarehousebillsfees> feesList = tWarehousebillsfeesMapper.selectWarehousebillsfeesByPId(auditItems.getBillId());
                for (TWarehousebillsfees wareItem : feesList) {
                    if (StringUtils.isNull(wareItem.getSrcId())) {
                        continue;
                    }
                    if ("KCZZ".equals(wareItem.getfBilltype())) {
                        TWhgenleg whgenleg = new TWhgenleg();
                        whgenleg.setfId(wareItem.getSrcId());
                        whgenleg.setfChargedate(wareItem.getfChargedate());
                        tWhgenlegMapper.updateTWhgenleg(whgenleg);
                    } else {
                        TWarehousebillsitems billsItem = new TWarehousebillsitems();
                        billsItem.setfId(wareItem.getSrcId());
                        billsItem.setfBilltype(wareItem.getfBilltype());
                        if (!"SJCK".equals(wareItem.getfBilltype())) {
                            billsItem.setfChargedate(wareItem.getfBillingDeadline());
                            tWarehousebillsitemsMapper.updateTWarehousebillsitems(billsItem);
                        } else {
                            billsItem.setIsCalculateStorageFees(WarehouseTypeEnum.NOT_CALCULATE.getType());
                            billsItem.setfChargedate(wareItem.getfChargedate());
                        }
                        tWarehousebillsitemsMapper.agreementApprovalRejected(billsItem);
                    }
                }
            }
        } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
            fettle = 3L;
            // 财务模块
            AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
            fettle = 3L;
            // 协议模块
            AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() == 410) {
            fettle = 3L;
            AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() == 420) {
            fettle = 8L;
            AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
            fettle = 3L;
            // 财务模块
            AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() == 460) {
            fettle = 3L;
            Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            if (i != null && i > 0) {
            } else {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批驳回失败,更新费用状态失败");
            }
        } else if (auditItems.getActId() == 470) {
            fettle = 3L;
            // 财务模块
            AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() == 170) {
            //入库明细审核
            fettle = 3L;
            //变更仓库入库明细审核状态
            Integer i = null;
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfItemstatus(fettle);
            i = tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
            i = tWarehousebillsitemsMapper.warehouseItemfItemstatus(auditItems.getBillId(), fettle);
            if (i != null && i > 0) {
            } else {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审核失败，更新费用状态失败");
            }
        } else if (auditItems.getActId() == 180) {
            //入库明细审核
            fettle = 3L;
            //变更仓库入库明细审核状态
            Integer i = null;
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfItemstatus(fettle);
            i = tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
            i = tWarehousebillsitemsMapper.warehouseItemfItemstatus(auditItems.getBillId(), fettle);
            if (i != null && i > 0) {
            } else {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审核失败，更新费用状态失败");
            }
        } else if (auditItems.getActId() == 471) {
            fettle = 3L;
            // 变更凯和申请修改订单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfUpdeteStatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 472) {
            fettle = 3L;
            // 变更凯和申请修改订单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfSubmitUpdate(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 473) {
            fettle = 3L;
            // 变更凯和申请修改订单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfDeleteStatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 474) {
            fettle = 3L;
            //变更凯和拆单单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfDismountStatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 181) {
            fettle = 3L;
            //业务处理
        } else if (auditItems.getActId() == 190) {
            fettle = 3L;
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfBillstatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
            tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
        } else if (Objects.equals(auditItems.getActId(), WarehouseActIdEnum.FEE_CHANGES.getActId().longValue())) {
            warehousebillsModifyService.additionalFeeInformation(auditItems.getBillId(), WarehouseTypeEnum.DISMISS);
        }
        AuditItems item = new AuditItems();
        item.setBillId(auditItems.getId());
        item.setActId(auditItems.getActId());
        item.setFidStatus(auditItems.getFidStatus());
        List<AuditItems> auditItem = auditItemsMapper.selectAuditItemsList(item);
        int number = 0;
        for (AuditItems at : auditItem) {
            if (!"S".equals(at.getAuditStatus())) {
                continue;
            }
            AuditItemsUsers itemsUsers = new AuditItemsUsers();
            itemsUsers.setPid(at.getId());
            List<AuditItemsUsers> auditItemsUsersList = auditItemsUsersMapper.selectAuditItemsUsersList(itemsUsers);
            for (AuditItemsUsers au : auditItemsUsersList) {
                if (Objects.equals(au.getUserId(), auditItems.getSendUserId())) {
                    number++;
                    at.setAuditStatus("B");
                    if (auditItems.getAuditMsg() == null || "".equals(auditItems.getAuditMsg())) {
                        at.setAuditMsg("不同意");
                    } else {
                        at.setAuditMsg(auditItems.getAuditMsg());
                    }
                    //at.setAuditItem(new Date());
                    at.setAuditOpTime(new Date());
                    at.setAuditUserId(au.getUserId());
                    int updateAuditItems = auditItemsMapper.updateAuditItems(at);
                    if (updateAuditItems <= 0) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return AjaxResult.error("审批驳回失败: 更新审批状态失败");
                    }
                    au.setAuditStatus("B");
                    int updateAuditItemUser = auditItemsUsersMapper.updateAuditItemsUsers(au);
                    if (updateAuditItemUser <= 0) {
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        return AjaxResult.error("审批驳回失败: 更新审批状态失败");
                    }
                    if ("F".equals(at.getIffinalItem())) {
                        int deleteNum = auditItemsMapper.deleteUpLevelId(at);
                        if (deleteNum <= 0) {
                            return AjaxResult.error("未找到后续除审批信息");
                        }
                    }
                }
            }
        }

        TWarehouseBills warehouseBills = new TWarehouseBills();
        warehouseBills.setfId(auditItems.getBillId());
        calculationWarehouseService.calculationFeeStatus(warehouseBills);
        tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);

        if (number <= 0) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error("该审批已被操作");
        }
        return AjaxResult.success();
    }

    /**
     * 审批撤销（我提交的 没人审核）
     *
     * @param auditItems 审核人、单据信息
     * @return
     */
    @Override
    @Transactional
    public AjaxResult revoke(AuditItems auditItems) {
        long fettle = 0L;
        if (auditItems.getActId() >= 110 && auditItems.getActId() <= 160) {
            fettle = 2L;
            // 查询仓库状态
            TWarehouseBills tWarehouseBills = tWarehouseBillsMapper.selectTWarehousebillsById(auditItems.getBillId());
            if ("f_billstatus".equals(auditItems.getFidStatus())) {
                if (!tWarehouseBills.getfBillstatus().equals(4L)) {
                    return AjaxResult.error("审批撤销失败: 已经过审批");
                }
            } else {
                if (!tWarehouseBills.getWarehouseStatus().equals(4L)) {
                    return AjaxResult.error("审批撤销失败: 已经过审批");
                }
            }
            tWarehouseBillsMapper.warehouseApprovalUpdate(auditItems, fettle);
            tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
        } else if (auditItems.getActId() >= 210 && auditItems.getActId() <= 230) {
            fettle = 2L;
            // 查询财务状态
            TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
            if (!"4".equals(tFee.getfBillstatus())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 已经过审批");
            }
            // 财务模块
            AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 更新审批状态失败");
            }
        } else if (auditItems.getActId() >= 310 && auditItems.getActId() <= 320) {
            fettle = 2L;
            // 查询协议状态
            TWarehouseAgreement tWarehouseAgreement = tWarehouseAgreementMapper.selectTWarehouseAgreementById(auditItems.getBillId());
            if (!"4".equals(tWarehouseAgreement.getfBillstatus())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 已经过审批");
            }
            // 协议模块
            AjaxResult ajaxResult = tWarehouseAgreementService.agreementFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 更新审批状态失败");
            }
        } else if (auditItems.getActId() == 410) {
            fettle = 2L;
            TWarehouseBills tWarehouseBills = tWarehouseBillsService.selectKaHeById(auditItems.getBillId());
            if (tWarehouseBills.getfBillstatus() != 4L) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 已经过审批");
            }
            AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() == 420) {
            fettle = 7L;
            TWarehouseBills tWarehouseBills = tWarehouseBillsService.selectKaHeById(auditItems.getBillId());
            if (tWarehouseBills.getfBillstatus() != 9L) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 已经过审批");
            }
            AjaxResult ajaxResult = tWarehouseBillsService.updateKaHeOrder(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return ajaxResult;
            }
        } else if (auditItems.getActId() >= 430 && auditItems.getActId() <= 450) {
            fettle = 2L;
            // 查询财务状态
            TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
            if (!"4".equals(tFee.getfBillstatus())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 已经过审批");
            }
            // 财务模块
            AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 更新审批状态失败");
            }
        } else if (auditItems.getActId() == 460) {
            fettle = 2L;
            TWarehousebillsfees warehousebillsfees = new TWarehousebillsfees();
            warehousebillsfees.setfPid(auditItems.getBillId());
            List<TWarehousebillsfees> tWarehousebillsfees = tWarehousebillsfeesMapper.selectTWarehousebillsfeesList(warehousebillsfees);
            if (CollectionUtils.isNotEmpty(tWarehousebillsfees) && tWarehousebillsfees.get(0).getfBillstatus() != 4L) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 已经过审批");
            }
            Integer i = tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
            if (i != null && i > 0) {
            } else {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审核失败，更新费用状态失败");
            }
        } else if (auditItems.getActId() == 470) {
            fettle = 2L;
            // 查询财务状态
            TFee tFee = tFeeMapper.selectTFeeById(auditItems.getBillId());
            if (!"4".equals(tFee.getfBillstatus())) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 已经过审批");
            }
            // 财务模块
            AjaxResult ajaxResult = tFeeServiceImpl.tfeeFollow(auditItems.getBillId(), fettle);
            String code = ajaxResult.get("code").toString();
            if ("500".equals(code)) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审批撤销失败: 更新审批状态失败");
            }
        } else if (auditItems.getActId() == 170) {
            //入库明细审核
            fettle = 2L;
            //变更仓库入库明细审核状态
            Integer i = null;
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfItemstatus(fettle);
            i = tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
            i = tWarehousebillsitemsMapper.warehouseItemfItemstatus(auditItems.getBillId(), fettle);
            if (i != null && i > 0) {
            } else {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审核失败，更新费用状态失败");
            }
        } else if (auditItems.getActId() == 180) {
            //入库明细审核
            fettle = 2L;
            //变更仓库入库明细审核状态
            Integer i = null;
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfItemstatus(fettle);
            i = tWarehouseBillsMapper.updateTWarehousebills(tWarehouseBills);
            i = tWarehousebillsitemsMapper.warehouseItemfItemstatus(auditItems.getBillId(), fettle);
            if (i != null && i > 0) {
            } else {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                return AjaxResult.error("审核失败，更新费用状态失败");
            }
        } else if (auditItems.getActId() == 471) {
            fettle = 2L;
            // 变更凯和申请修改订单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfUpdeteStatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 472) {
            fettle = 2L;
            // 变更凯和申请修改订单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfSubmitUpdate(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 473) {
            fettle = 2L;
            // 变更凯和申请修改订单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfDeleteStatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 474) {
            fettle = 2L;
            //变更凯和拆单单状态
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfDismountStatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
        } else if (auditItems.getActId() == 181) {
            fettle = 2L;
            //业务处理
        } else if (auditItems.getActId() == 190) {
            fettle = 2L;
            TWarehouseBills tWarehouseBills = new TWarehouseBills();
            tWarehouseBills.setfId(auditItems.getBillId());
            tWarehouseBills.setfBillstatus(fettle);
            tWarehouseBillsMapper.updateKaHeOrder(tWarehouseBills);
            tWarehousebillsfeesMapper.warehouseFeesFollowUpdate(auditItems.getBillId(), fettle, auditItems.getAuditItem());
        } else if (Objects.equals(auditItems.getActId(), WarehouseActIdEnum.FEE_CHANGES.getActId().longValue())) {
            warehousebillsModifyService.withdrawalApprovalById(auditItems.getBillId());
        }
        auditItemsMapper.deletePurchaseApproval(auditItems);

        TWarehouseBills warehouseBills = new TWarehouseBills();
        warehouseBills.setfId(auditItems.getBillId());
        calculationWarehouseService.calculationFeeStatus(warehouseBills);
        tWarehouseBillsMapper.updateTWarehousebills(warehouseBills);

        return AjaxResult.success();
    }

    /**
     * 仓库APP查看订单审批流
     *
     * @param auditItems 条件
     * @return 结果
     */
    @Override
    public List<AppAuditItemVO> selectOrderAuditItems(AppAuditItemDTO auditItems) {
        // 如果没有指定类型信息，则默认 赋值仓库类型
        if (StringUtils.isEmpty(auditItems.getBillType())) {
            auditItems.setBillTypeList(WarehouseTypeEnum.getWarehousingType());
        } else {
            List<String> strings = new ArrayList<>();
            strings.add(auditItems.getBillType());
            auditItems.setBillTypeList(strings);
        }
        if (StringUtils.isNotEmpty(auditItems.getSendTimeInterval())) {
            String[] split = auditItems.getSendTimeInterval().split(",");
            List<String> list = Lists.newArrayList();
            list.add(split[0] + " 00:00:00");
            list.add(split[1] + " 23:59:59");
            auditItems.setSendList(list);
        }
        auditItems.setActIdList(WarehouseActIdEnum.isWarehousingActList());
        // 查询
        List<AppAuditItemVO> appAuditItemVOList = auditItemsMapper.selectOrderAuditItems(auditItems);
        // 贸易方式
        String type = "data_trademodes";
        if (CollectionUtils.isNotEmpty(appAuditItemVOList)) {
            appAuditItemVOList.forEach(vo -> {
                if (StringUtils.isNotNull(vo.getFTrademodeid())) {
                    // 转换贸易方式
                    String dictLabel = DictUtils.getDictLabel(type, vo.getFTrademodeid().toString());
                    if (StringUtils.isNotEmpty(dictLabel)) {
                        vo.setFTrademodeName(dictLabel);
                    }
                }
                // 转换状态
                vo.setAudit(AuditStateEnum.fromType(vo.getAuditState()).getName());
                // 转换活动号
                vo.setActName(WarehouseActIdEnum.fromActId(vo.getActId().intValue()).getName());
            });
        }
        return appAuditItemVOList;
    }

}
