package com.yh.saas.plugin.yiliangyiyun.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alipay.sofa.runtime.api.annotation.SofaReference;
import com.alipay.sofa.runtime.api.annotation.SofaService;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.ObjectMetadata;
import com.aliyun.oss.model.PutObjectRequest;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.common.collect.Lists;
import com.winsea.svc.base.base.entity.*;
import com.winsea.svc.base.base.service.*;
import com.winsea.svc.base.base.util.DateUtils;
import com.winsea.svc.base.security.entity.User;
import com.winsea.svc.base.security.util.AuthSecurityUtils;
import com.yh.saas.common.support.util.IdGenerator;
import com.yh.saas.common.support.util.StringUtils;
import com.yh.saas.plugin.yiliangyiyun.constant.NumberConstant;
import com.yh.saas.plugin.yiliangyiyun.constant.StatusEnum;
import com.yh.saas.plugin.yiliangyiyun.entity.*;
import com.yh.saas.plugin.yiliangyiyun.entity.view.ExportVView;
import com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseView;
import com.yh.saas.plugin.yiliangyiyun.entity.view.WarehouseNumView;
import com.yh.saas.plugin.yiliangyiyun.exception.YException;
import com.yh.saas.plugin.yiliangyiyun.exception.YExceptionEnum;
import com.yh.saas.plugin.yiliangyiyun.mapper.WarehouseBaseInfoMapper;
import com.yh.saas.plugin.yiliangyiyun.service.*;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.yh.saas.plugin.yiliangyiyun.util.Const;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.util.DateUtil;
import org.apache.http.entity.ContentType;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 记录仓库信息 服务实现类
 * </p>
 *
 * @author Gongdc
 * @since 2021-05-21
 */
@SofaService
@Slf4j
public class WarehouseBaseInfoServiceImpl extends ServiceImpl<WarehouseBaseInfoMapper, WarehouseBaseInfo> implements IWarehouseBaseInfoService {

    @Autowired
    private IWarehousePositionInfoService warehousePositionInfoService;
    @Autowired
    private IWarehouseInOutInfoService warehouseInOutInfoService;
    @Autowired
    private IWarehouseInOutDetailService warehouseInOutDetailService;
    @Autowired
    private ICommonCompanyService commonCompanyService;
    @Autowired
    private IWarehousePositionStorageInfoService warehousePositionStorageInfoService;
    @Autowired
    private IWarehouseBaseInfoService warehouseBaseInfoService;
    @Autowired
    private IContractManagementInfoService contractManagementInfoService;
    @Autowired
    private IInOutWarehouseTaskService iInOutWarehouseTaskService;
    @Autowired
    private IPurchaseOrderService purchaseOrderService;
    @Autowired
    private ISaleOrderService saleOrderService;
    @Autowired
    private IContractGoodsInfoService contractGoodsInfoService;
    @Autowired
    private ITranCarInfoService tranCarInfoService;
    @Autowired
    private ICommonStaffRoleService commonStaffRoleService;
    @Autowired
    private ICommonRoleService commonRoleService;
    @Autowired
    private ITranTaskInfoService tranTaskInfoService;
    @Autowired
    private ITranProcessInfoService tranProcessInfoService;
    @SofaReference
    private ICommonRoleResourceService roleResourceService;
    @Autowired
    private ITradeWarehouseReceiptApplService tradeWarehouseReceiptApplService;
    @Value("${file-root-path}")
    private String localPath;
    @Getter
    @Value("${oss.endpoint.internal:}")
    private String baseUrl;
    @Getter
    @Value("${oss.bucket.name:}")
    private String bucket;
    @Autowired
    private OSSClient ossClient;
    @Autowired
    private CacheComponent cacheComponent;

    /**
     * 全部仓库
     *
     * @param compId
     * @return
     */
    @Override
    public List<WarehouseView> allWarehouse(String compId, String warehouseName, String goodsName) {
        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", compId);
        pageView.put("warehouseName", warehouseName);
        pageView.put("goodsName", goodsName);
        List<WarehouseView> dataList = baseMapper.getAllWarehouseListByCondition(pageView);
        return dataList;
    }

    /**
     * 今日储量明细
     *
     * @param compId
     * @return
     */
    @Override
    public List<WarehouseNumView> reservesDetails(String compId) {
        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", compId);
        List<WarehouseNumView> dataList = baseMapper.getReservesDetailsListByCondition(pageView);
        return dataList;
    }

    /**
     * 仓库管理页面列表
     *
     * @param compId
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public WarehouseBaseInfo selectWarehouseViewinfo(String compId, String warehouseName, String warehouseType) {
        WarehouseBaseInfo warehouseBaseInfos = new WarehouseBaseInfo();
        if (compId == null || compId.isEmpty()) {
            compId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getCompId();

        }
        String personCharge = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getStaffMobilePhone();

        List<WarehouseView> warehouseViews = new ArrayList<>();
        Wrapper<WarehouseBaseInfo> warehouseBaseInfoWrapper = new EntityWrapper<>();
        warehouseBaseInfoWrapper.eq(WarehouseBaseInfo.QueryFiles.COMP_ID, compId)
                .eq(WarehouseBaseInfo.QueryFiles.DELETE_FLAG, NumberConstant.CONSTANT0)
                .eq(WarehouseBaseInfo.QueryFiles.SHOW_FLAG, NumberConstant.CONSTANT1);
        if (!StringUtils.isEmpty(warehouseName)) {
//            warehouseBaseInfoWrapper.like(WarehouseBaseInfo.QueryFiles.WAREHOUSE_NAME, "%" + warehouseName + "%");
            warehouseBaseInfoWrapper.eq(WarehouseBaseInfo.QueryFiles.WAREHOUSE_NAME, warehouseName);
        }
        //PC端用
        if (!StringUtils.isEmpty(warehouseType)) {
            warehouseBaseInfoWrapper.eq(WarehouseBaseInfo.QueryFiles.WAREHOUSE_TYPE, warehouseType);
        }
        List<String> resourceIdList = this.getResourceIdList();
        if (!resourceIdList.contains("warehouseInfo-Look")) {
            if (!"13333333333".equals(personCharge)) {
                warehouseBaseInfoWrapper.andNew().eq("person_phone", personCharge).or()
                        .like("other_person_charge", personCharge);

            }
        }
        // 查出所有仓库
        List<WarehouseBaseInfo> warehouseBaseInfoList = this.selectList(warehouseBaseInfoWrapper);
        if (NumberConstant.CONSTANT1.equals(warehouseType)) {
            if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
                for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                    // 以库位为维度查询
                    List<WarehousePositionInfo> warehousePositionInfos = warehousePositionInfoService.selectList(new EntityWrapper<WarehousePositionInfo>()
                            .eq("base_id", warehouseBaseInfo.getId()).orderBy("bin_number", false));
                    if (!CollectionUtils.isEmpty(warehousePositionInfos)) {
                        for (WarehousePositionInfo warehousePositionInfo : warehousePositionInfos) {
                            WarehouseView warehouseView = new WarehouseView();
                            warehouseView.setAllowEdit(warehouseBaseInfo.getAllowEdit());
                            warehouseView.setWarehouseId(warehouseBaseInfo.getId());
                            warehouseView.setAutomaticWeightAcquisition(warehouseBaseInfo.getAutomaticWeightAcquisition());
                            warehouseView.setWarehouseName(warehouseBaseInfo.getWarehouseName());
                            warehouseView.setBinNumberId(warehousePositionInfo.getId());
                            warehouseView.setBinNumber(warehousePositionInfo.getBinNumber());
                            warehouseView.setCapacity(String.valueOf(warehousePositionInfo.getMaxStorage()));
                            warehouseView.setRemark(warehousePositionInfo.getRemark());
                            warehouseView.setWarehousePrivate(warehouseBaseInfo.getWarehousePrivate());
                            warehouseView.setWarehouseCity(warehouseBaseInfo.getWarehouseCity());
                            warehouseView.setWarehouseArea(warehouseBaseInfo.getWarehouseArea());
                            warehouseView.setDetailedAddress(warehouseBaseInfo.getDetailedAddress());
                            warehouseView.setPersonCharge(warehouseBaseInfo.getPersonCharge());
                            warehouseView.setPersonPhone(warehouseBaseInfo.getPersonPhone());
                            warehouseView.setOtherPersonCharge(warehouseBaseInfo.getOtherPersonCharge());
                            warehouseView.setWarehousePositioning(warehouseBaseInfo.getWarehousePositioning());
                            // 定义待完成数量
                            int count = 0;
                            // 定义应余量
                            String storage = "";
                            //定义入库
                            String inNetWeight = "";
                            // 子集合
                            List<WarehouseNumView> warehouseNumViewList = new ArrayList<>();
                            // 查询入库数量
                            List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                                    .eq("position_id", warehousePositionInfo.getId()).eq("delete_flag", "0")
                                    .eq("status_flag", "3").eq("in_out_flag", "2").groupBy("goods_name").orderBy("goods_name"));
                            if (!CollectionUtils.isEmpty(warehouseInOutInfoList)) {
                                for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfoList) {
                                    WarehouseNumView warehouseNumView = new WarehouseNumView();
                                    // 查询入库数量
                                    List<WarehouseInOutInfo> warehouseInOutInfoAllList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                                            .eq("position_id", warehousePositionInfo.getId()).eq("in_out_flag", "2").eq("delete_flag", "0")
                                            .eq("status_flag", "3").eq("goods_name", warehouseInOutInfo.getGoodsName()));
                                    if (!CollectionUtils.isEmpty(warehouseInOutInfoAllList)) {
                                        Double netWeight = 0d;
                                        for (WarehouseInOutInfo warehouse : warehouseInOutInfoAllList) {
                                            //潮粮累计纯重，干粮累计净重
//                                            if(warehouse.getType() == null){
//                                                netWeight = Float.valueOf(netWeight) + Float.valueOf(warehouse.getPureWeight() != null?warehouse.getPureWeight():warehouse.getNetWeight());
//                                            }
//                                            else{
//                                                netWeight = Float.valueOf(netWeight) + Float.valueOf(warehouse.getType().equals("潮粮") ?warehouse.getPureWeight():warehouse.getNetWeight());
//                                            }
                                            netWeight = (double) (Math.round(new BigDecimal(netWeight).add(new BigDecimal(warehouse.getNetWeight())).doubleValue() * 1000)) / 1000;
//                                            netWeight = (float)(Math.round(((float)(Math.round(netWeight*1000))/1000+(float)(Math.round(warehouse.getNetWeight()*1000))/1000)*1000))/1000;
                                        }
                                        warehouseNumView.setGoodsName(warehouseInOutInfoAllList.get(0).getGoodsName());
                                        DecimalFormat decimalFormat = new DecimalFormat(".000");//构造方法的字符格式这里如果小数不足2位,会以0补足.
                                        warehouseNumView.setInNetWeight(decimalFormat.format(netWeight));
                                        if (StringUtils.isEmpty(inNetWeight)) {
                                            inNetWeight = "0";
                                        }
                                        inNetWeight = String.valueOf(Float.valueOf(inNetWeight) + Float.valueOf(decimalFormat.format(netWeight)));
                                    }
                                    // 查询应余量
                                    WarehousePositionStorageInfo warehousePositionStorageInfo = warehousePositionStorageInfoService.selectOne(new EntityWrapper<WarehousePositionStorageInfo>()
                                            .eq("position_id", warehouseInOutInfo.getPositionId())
                                            .eq("goods_name", warehouseInOutInfo.getGoodsName())
                                            .eq("delete_flag", NumberConstant.CONSTANT0));
                                    if (warehousePositionStorageInfo != null) {
                                        storage = String.valueOf(warehousePositionStorageInfo.getStorage());
                                    } else {
                                        storage = "";
                                    }
                                    warehouseNumView.setStorage(storage);
                                    warehouseNumViewList.add(warehouseNumView);
                                }

                            }

                            //定义出库
                            String outNetWeight = "";
                            // 查询出库数量
                            List<WarehouseInOutInfo> warehouseInOutInfos = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                                    .eq("position_id", warehousePositionInfo.getId()).eq("delete_flag", "0")
                                    .eq("status_flag", "3").eq("in_out_flag", "1").groupBy("goods_name").orderBy("goods_name"));
                            if (!CollectionUtils.isEmpty(warehouseInOutInfos)) {
                                for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfos) {
                                    Double netWeight = 0d;
                                    outNetWeight = "0";
                                    List<WarehouseInOutInfo> warehouseInOutInfoAllList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                                            .eq("status_flag", "3").eq("delete_flag", "0")
                                            .eq("position_id", warehousePositionInfo.getId()).eq("in_out_flag", "1").eq("goods_name", warehouseInOutInfo.getGoodsName()));
                                    if (!CollectionUtils.isEmpty(warehouseInOutInfoAllList)) {
                                        for (WarehouseInOutInfo warehouse : warehouseInOutInfoAllList) {
                                            //潮粮累计纯重，干粮累计净重
//                                            netWeight = netWeight + (warehouse.getPureWeight()!=null?warehouse.getPureWeight():warehouse.getNetWeight());
                                            netWeight = Double.valueOf(netWeight) + Double.valueOf(warehouse.getNetWeight());
                                        }
                                        if (StringUtils.isEmpty(outNetWeight)) {
                                            outNetWeight = "0";
                                        }
                                        outNetWeight = String.valueOf(Float.valueOf(outNetWeight) + netWeight);
                                    }
                                    for (WarehouseNumView warehouseNumView : warehouseNumViewList) {
                                        if (warehouseNumView.getGoodsName().equals(warehouseInOutInfo.getGoodsName())) {
                                            warehouseNumView.setOutNetWeight(outNetWeight);
                                        }

                                    }
                                }

                            }
                            // 查询入库数量
                            count = warehouseInOutInfoService.selectCount(new EntityWrapper<WarehouseInOutInfo>()
                                    .eq("position_id", warehousePositionInfo.getId())
                                    .eq("status_flag", "1"));
                            warehouseView.setNumber(count);
                            warehouseView.setWarehouseNumViewList(warehouseNumViewList);
                            warehouseViews.add(warehouseView);

                        }
                    }
                }

            }

        } else {
            if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
                for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                    WarehouseView warehouseView = new WarehouseView();
                    warehouseView.setWarehouseId(warehouseBaseInfo.getId());
                    warehouseView.setCreateType(warehouseBaseInfo.getCreateType());
                    warehouseView.setClearStatus(warehouseBaseInfo.getClearStatus());
                    warehouseView.setClearStatusFlag(warehouseBaseInfo.getClearStatusFlag());
                    warehouseView.setWarehouseName(warehouseBaseInfo.getWarehouseName());
                    warehouseView.setUpdateDate(warehouseBaseInfo.getUpdateDate());
                    warehouseView.setPersonCharge(warehouseBaseInfo.getPersonCharge());
                    warehouseView.setPersonPhone(warehouseBaseInfo.getPersonPhone());
                    warehouseView.setOtherPersonCharge(warehouseBaseInfo.getOtherPersonCharge());
                    warehouseView.setWarehousePositioning(warehouseBaseInfo.getWarehousePositioning());
                    warehouseView.setAddress(warehouseBaseInfo.getWarehousePrivate() + warehouseBaseInfo.getWarehouseCity() + warehouseBaseInfo.getWarehouseArea() + warehouseBaseInfo.getDetailedAddress());
                    ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                            .eq("contract_no", warehouseBaseInfo.getWarehouseName()).eq("delete_flag", "0"));
                    warehouseView.setMaxInStorage(String.valueOf(contractManagementInfo.getWeight() + (contractManagementInfo.getWeight() * contractManagementInfo.getOverShort() / 100) + 50));
                    // 定义待完成数量
                    int count = 0;
                    //定义入库
                    String inNetWeight = "";
                    // 子集合
                    List<WarehouseNumView> warehouseNumViewList = new ArrayList<>();
                    // 查询入库数量
                    List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                            .eq("base_id", warehouseBaseInfo.getId()).eq("delete_flag", "0")
                            .eq("status_flag", "3").eq("in_out_flag", "2").groupBy("goods_name").orderBy("goods_name"));
                    if (!CollectionUtils.isEmpty(warehouseInOutInfoList)) {
                        for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfoList) {
                            WarehouseNumView warehouseNumView = new WarehouseNumView();
                            // 查询入库数量
                            List<WarehouseInOutInfo> warehouseInOutInfoAllList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                                    .eq("base_id", warehouseBaseInfo.getId()).eq("in_out_flag", "2").eq("delete_flag", "0")
                                    .eq("status_flag", "3").eq("goods_name", warehouseInOutInfo.getGoodsName()));

                            if (!CollectionUtils.isEmpty(warehouseInOutInfoAllList)) {
                                Double netWeight = 0d;
                                for (WarehouseInOutInfo warehouse : warehouseInOutInfoAllList) {
                                    //潮粮累计纯重，干粮累计净重
//                                    netWeight = netWeight + (warehouse.getPureWeight()!=null?warehouse.getPureWeight():warehouse.getNetWeight());
                                    netWeight = Double.valueOf(netWeight) + Double.valueOf(warehouse.getNetWeight());
                                }
                                warehouseNumView.setGoodsName(warehouseInOutInfoAllList.get(0).getGoodsName());
                                warehouseNumView.setInNetWeight(String.valueOf(netWeight));
                                if (StringUtils.isEmpty(inNetWeight)) {
                                    inNetWeight = "0";
                                }
                                inNetWeight = String.valueOf(Float.valueOf(inNetWeight) + netWeight);
                            }
                            warehouseNumViewList.add(warehouseNumView);
                        }

                    }

                    //定义出库
                    String outNetWeight = "";
                    // 查询出库数量
                    List<WarehouseInOutInfo> warehouseInOutInfos = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                            .eq("base_id", warehouseBaseInfo.getId()).eq("delete_flag", "0")
                            .eq("status_flag", "3").eq("in_out_flag", "1").groupBy("goods_name").orderBy("goods_name"));
                    if (!CollectionUtils.isEmpty(warehouseInOutInfos)) {
                        for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfos) {
                            Double netWeight = 0d;
                            outNetWeight = "0";
                            List<WarehouseInOutInfo> warehouseInOutInfoAllList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                                    .eq("status_flag", "3").eq("delete_flag", "0")
                                    .eq("base_id", warehouseBaseInfo.getId()).eq("in_out_flag", "1").eq("goods_name", warehouseInOutInfo.getGoodsName()));
                            if (!CollectionUtils.isEmpty(warehouseInOutInfoAllList)) {
                                for (WarehouseInOutInfo warehouse : warehouseInOutInfoAllList) {
                                    //潮粮累计纯重，干粮累计净重
//                                    netWeight = netWeight + (warehouse.getPureWeight()!=null?warehouse.getPureWeight():warehouse.getNetWeight());
                                    netWeight = Double.valueOf(netWeight) + Double.valueOf(warehouse.getNetWeight());
                                }
                                if (StringUtils.isEmpty(outNetWeight)) {
                                    outNetWeight = "0";
                                }
                                outNetWeight = String.valueOf(Float.valueOf(outNetWeight) + netWeight);
                            }
                            for (WarehouseNumView warehouseNumView : warehouseNumViewList) {
                                if (warehouseNumView.getGoodsName().equals(warehouseInOutInfo.getGoodsName())) {
                                    warehouseNumView.setOutNetWeight(outNetWeight);
                                }

                            }
                        }

                    }
                    // 查询入库数量
                    count = warehouseInOutInfoService.selectCount(new EntityWrapper<WarehouseInOutInfo>()
                            .eq("base_id", warehouseBaseInfo.getId()).eq("delete_flag", "0")
                            .eq("status_flag", "1"));
                    warehouseView.setNumber(count);
                    // 定义待完成数量
                    int outCount = 0;
                    outCount = warehouseInOutInfoService.selectCount(new EntityWrapper<WarehouseInOutInfo>()
                            .eq("base_id", warehouseBaseInfo.getId()).eq("delete_flag", "0")
                            .eq("in_out_flag", "1")
                            .eq("status_flag", "1"));
                    warehouseView.setOutNumber(outCount);
                    warehouseView.setWarehouseNumViewList(warehouseNumViewList);
                    warehouseViews.add(warehouseView);

                }
            }
        }

        //仓库储量柱形图
        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", compId);
        pageView.put("warehouseName", warehouseName);
        List<WarehouseNumView> dataList = baseMapper.getReservesWarehouseListByCondition(pageView);

        warehouseBaseInfos.setWarehouseViewList(warehouseViews);
        warehouseBaseInfos.setWarehouseNumViewList(dataList);
        return warehouseBaseInfos;
    }


    private List<String> getResourceIdList() {
        User currentUser = AuthSecurityUtils.getCurrentUserInfo();
        // 当前登录人主要角色
        return roleResourceService.getBindResourcesByUserId(currentUser.getUserId()).stream()
                .map(CommonRoleResource::getResourceId).collect(Collectors.toList());
    }

    /**
     * 添加仓库
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addWarehouse(WarehouseBaseInfo warehouseBaseInfo) {
        //新增主键id
        warehouseBaseInfo.setId(IdGenerator.generateUUID());
        Map<String, Object> pageView = new HashMap<>();
        pageView.put("compId", warehouseBaseInfo.getCompId());
        // 查询本公司仓库包括已删除的
        Integer dataCount = baseMapper.getWareHouseCountByCondition(pageView);
        //插入仓库编号
        Integer warehouseNum = dataCount + 1;
        //一位数
        if (warehouseNum < 10) {
            warehouseBaseInfo.setCommonWarehouseNo("00" + warehouseNum);
        }
        //两位数xibg
        else if (warehouseNum < 100) {
            warehouseBaseInfo.setCommonWarehouseNo("0" + warehouseNum);
        }
        //三位数
        else if (warehouseNum < 1000) {
            warehouseBaseInfo.setCommonWarehouseNo(String.valueOf(warehouseNum));
        }
        List<WarehousePositionInfo> warehousePositionInfoList = warehouseBaseInfo.getWarehousePositionInfoList();
        if (!CollectionUtils.isEmpty(warehousePositionInfoList)) {
            for (WarehousePositionInfo warehousePositionInfo : warehousePositionInfoList) {
                warehousePositionInfo.setId(IdGenerator.generateUUID());
                warehousePositionInfo.setBaseId(warehouseBaseInfo.getId());
            }
        }
        //判断仓库名称是否唯一
        List<WarehouseBaseInfo> warehouseBaseInfos =
                warehouseBaseInfoService.selectList(new EntityWrapper<WarehouseBaseInfo>()
                        .eq("warehouse_name", warehouseBaseInfo.getWarehouseName())
                        .eq("comp_id", warehouseBaseInfo.getCompId())
                        .eq("delete_flag", "0"));
        if (warehouseBaseInfos.size() > 0) {
            throw new YException(YExceptionEnum.WAREHOUSE_NAME_ERROR);
        }
        boolean one = this.insert(warehouseBaseInfo);
        boolean two = warehousePositionInfoService.insertBatch(warehousePositionInfoList);
        cacheComponent.delPrefixKey(Const.SELF_WAREHOUSE);
        // 假如 都成功返回ok
        if (one && two) {
            return "OK";
        } else {
            return "NG";
        }
    }

    /**
     * 添加临时仓库
     *
     * @param warehouseBaseInfo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String addTemporaryWarehouse(WarehouseBaseInfo warehouseBaseInfo) {
        //新增主键id
        if (StringUtils.isEmpty(warehouseBaseInfo.getId())) {
            warehouseBaseInfo.setId(IdGenerator.generateUUID());
        }
        Map<String, Object> pageView = new HashMap<>();
        pageView.put("compId", warehouseBaseInfo.getCompId());
        // 查询本公司临时仓库包括已删除的
        Integer dataCount = baseMapper.getTemWareHouseCountByCondition(pageView);
        //插入仓库编号
        Integer warehouseNum = dataCount + 1;
        //一位数
        if (warehouseNum < 10) {
            warehouseBaseInfo.setCommonWarehouseNo("000" + warehouseNum);
        }
        //两位数
        else if (warehouseNum < 100) {
            warehouseBaseInfo.setCommonWarehouseNo("00" + warehouseNum);
        }
        //三位数
        else if (warehouseNum < 1000) {
            warehouseBaseInfo.setCommonWarehouseNo("0" + warehouseNum);
        }
        //四位数
        else if (warehouseNum < 10000) {
            warehouseBaseInfo.setCommonWarehouseNo(String.valueOf(warehouseNum));
        }
        warehouseBaseInfo.setWarehouseType("2");
        warehouseBaseInfo.setClearStatusFlag(StatusEnum.NOT_CLEARED.getFlag());
        warehouseBaseInfo.setClearStatus(StatusEnum.NOT_CLEARED.getName());
        //判断仓库名称是否唯一
        List<WarehouseBaseInfo> warehouseBaseInfos =
                warehouseBaseInfoService.selectList(new EntityWrapper<WarehouseBaseInfo>()
                        .eq("warehouse_name", warehouseBaseInfo.getWarehouseName())
                        .eq("delete_flag", "0")
                        .eq("warehouse_type", "2"));
        if (warehouseBaseInfos.size() > 0) {
            throw new YException(YExceptionEnum.WAREHOUSE_NAME_ERROR);
        }
        this.insert(warehouseBaseInfo);
        cacheComponent.delPrefixKey(Const.SELF_WAREHOUSE);
        return warehouseBaseInfo.getId();
    }

    /**
     * 编辑仓库
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String editWarehouse(WarehouseBaseInfo warehouseBaseInfo) {
        WarehouseBaseInfo warehouseBaseInfo1=this.selectById(warehouseBaseInfo.getId());
        String personPhone = warehouseBaseInfo.getPersonPhone();
        String otherPhone = warehouseBaseInfo.getOtherPersonPhone();
        if(personPhone != null){
            if(!personPhone.equals(warehouseBaseInfo1.getPersonPhone())){
                cacheComponent.delPrefixKey(Const.SELF_WAREHOUSE);
            }
        }
        else{
            if(warehouseBaseInfo1.getPersonPhone()!=null){
                cacheComponent.delPrefixKey(Const.SELF_WAREHOUSE);
            }
        }
        if(otherPhone != null){
            if(!otherPhone.equals(warehouseBaseInfo1.getOtherPersonPhone())){
                cacheComponent.delPrefixKey(Const.SELF_WAREHOUSE);
            }
        }
        else{
            if(warehouseBaseInfo1.getOtherPersonPhone()!=null){
                cacheComponent.delPrefixKey(Const.SELF_WAREHOUSE);
            }
        }
        this.updateById(warehouseBaseInfo);
        if ("1".equals(warehouseBaseInfo.getWarehouseType())) {
            List<WarehousePositionInfo> warehousePositionInfoList = warehouseBaseInfo.getWarehousePositionInfoList();
            if (!CollectionUtils.isEmpty(warehousePositionInfoList)) {
                warehousePositionInfoList.forEach(warehousePositionInfo -> {
                    if (StringUtils.isEmpty(warehousePositionInfo.getId())) {
                        warehousePositionInfo.setId(IdGenerator.generateUUID());
                        warehousePositionInfo.setBaseId(warehouseBaseInfo.getId());
                        warehousePositionInfoService.insert(warehousePositionInfo);
                    } else {
                        warehousePositionInfoService.updateById(warehousePositionInfo);
                    }
                });
            }
        }
        return warehouseBaseInfo.getId();
    }

    /**
     * 查看库房下拉列表
     *
     * @return
     */
    @Override
    public List<WarehouseBaseInfo> selectWarehouse(String compId, String warehouseType) {
        Wrapper<WarehouseBaseInfo> warehouseBaseInfoWrapper = new EntityWrapper<>();
        warehouseBaseInfoWrapper.eq("comp_id", compId)
                .eq("delete_flag", "0")
                .orderBy("warehouse_type", true);
        if (warehouseType != null && !warehouseType.isEmpty()) {
            warehouseBaseInfoWrapper.eq("warehouse_type", warehouseType);
        }
        List<WarehouseBaseInfo> warehouseBaseInfoList = this.selectList(warehouseBaseInfoWrapper);
        if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
            for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                List<WarehousePositionStorageInfo> temp = new ArrayList();
                // 以库位为维度查询
                List<WarehousePositionInfo> warehousePositionInfos = warehousePositionInfoService.selectList(new EntityWrapper<WarehousePositionInfo>()
                        .eq("base_id", warehouseBaseInfo.getId()).orderBy("bin_number", false));
                if (!CollectionUtils.isEmpty(warehousePositionInfos)) {
                    for (WarehousePositionInfo warehousePositionInfo : warehousePositionInfos) {
                        //查询仓库内的货名
                        List<WarehousePositionStorageInfo> warehousePositionStorageInfos = warehousePositionStorageInfoService.selectList(new EntityWrapper<WarehousePositionStorageInfo>()
                                .eq("position_id", warehousePositionInfo.getId()));
                        if (!CollectionUtils.isEmpty(warehousePositionStorageInfos)) {
                            for (WarehousePositionStorageInfo warehousePositionStorageInfo : warehousePositionStorageInfos) {
                                temp.add(warehousePositionStorageInfo);
                            }
                        }
                    }
                    warehouseBaseInfo.setGoodsNameInfos(temp);
                }
            }

        }
        return warehouseBaseInfoList;
    }

    /**
     * 查看库房
     */
    @Override
    public WarehouseBaseInfo getWarehouse(String id) {
        WarehouseBaseInfo warehouseBaseInfo = this.selectById(id);
        List<WarehousePositionInfo> warehousePositionInfoList = warehousePositionInfoService.selectList(new EntityWrapper<WarehousePositionInfo>()
                .eq("base_id", id)
                .eq("delete_flag", "0").orderBy("bin_number", false));
        warehousePositionInfoList.forEach(warehousePositionInfo -> {
            List<WarehousePositionStorageInfo> warehousePositionStorageInfoList = warehousePositionStorageInfoService.selectList(new EntityWrapper<WarehousePositionStorageInfo>()
                    .eq("position_id", warehousePositionInfo.getId())
                    .eq("delete_flag", "0"));
            Float storage = 0f;
            String detailStorage = "";
            for (WarehousePositionStorageInfo warehousePositionStorageInfo : warehousePositionStorageInfoList) {
                storage = storage + Float.valueOf(String.valueOf(warehousePositionStorageInfo.getStorage()));
                detailStorage = detailStorage + warehousePositionStorageInfo.getGoodsName() + "(" + warehousePositionStorageInfo.getStorage() + ")  ";
            }
            warehousePositionInfo.setDetailStorage(detailStorage);
            warehousePositionInfo.setNowStorage(storage);
        });
        if (!CollectionUtils.isEmpty(warehousePositionInfoList)) {
            warehouseBaseInfo.setWarehousePositionInfoList(warehousePositionInfoList);
        }
        return warehouseBaseInfo;
    }

    /**
     * 更改显示状态
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String editShow(String id) {
        //查询仓库信息
        WarehouseBaseInfo warehouseBaseInfo = this.selectById(id);
        if (warehouseBaseInfo != null) {
            if (StatusEnum.SHOW.getFlag().equals(warehouseBaseInfo.getShowFlag())) {
                warehouseBaseInfo.setShowFlag(StatusEnum.HIDE.getFlag());
            } else {
                warehouseBaseInfo.setShowFlag(StatusEnum.SHOW.getFlag());
            }
            //更改仓库信息
            this.updateById(warehouseBaseInfo);
            return "OK";
        }
        return "NG";
    }

    /**
     * 查询所有库房
     *
     * @param compId,warehouseType
     * @return
     */
    @Override
    public List<WarehouseBaseInfo> selectAllWarehouse(String compId, String warehouseType, String warehouseName) {
        Wrapper<WarehouseBaseInfo> warehouseBaseInfoWrapper = new EntityWrapper<>();
        warehouseBaseInfoWrapper.eq("comp_id", compId).eq("delete_flag", "0").eq("show_flag", "1").eq("warehouse_type", warehouseType);
        if (!StringUtils.isEmpty(warehouseName)) {
            warehouseBaseInfoWrapper.like("warehouse_name", "%" + warehouseName + "%");
        }
        // 查出所有仓库
        List<WarehouseBaseInfo> warehouseBaseInfoList = this.selectList(warehouseBaseInfoWrapper);
        if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
            for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                // 应余量
                Float residual = 0f;
                // 以库位为维度查询
                List<WarehousePositionInfo> warehousePositionInfoList = warehousePositionInfoService.selectList(new EntityWrapper<WarehousePositionInfo>()
                        .eq("base_id", warehouseBaseInfo.getId()).orderBy("bin_number", false));
                if (!CollectionUtils.isEmpty(warehousePositionInfoList)) {
                    for (WarehousePositionInfo warehousePositionInfo : warehousePositionInfoList) {
                        // 查询应余量
                        List<WarehousePositionStorageInfo> warehousePositionStorageInfoList = warehousePositionStorageInfoService.selectList(new EntityWrapper<WarehousePositionStorageInfo>()
                                .eq("position_id", warehousePositionInfo.getId()));
                        if (!CollectionUtils.isEmpty(warehousePositionStorageInfoList)) {
                            for (WarehousePositionStorageInfo warehousePositionStorageInfo : warehousePositionStorageInfoList) {
                                residual = residual + Float.valueOf(String.valueOf(warehousePositionStorageInfo.getStorage()));
                            }
                        }
                    }
                }
                //临时仓库
                else {
                    //定义入库
                    String inNetWeight = "";
                    // 查询入库数量
                    List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                            .eq("base_id", warehouseBaseInfo.getId()).eq("status_flag", "3").eq("in_out_flag", "2"));
                    if (!CollectionUtils.isEmpty(warehouseInOutInfoList)) {
                        Float netWeight = 0f;
                        for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfoList) {
                            // 查询入库数量
                            netWeight = netWeight + Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight()));
                            ;
                            if (StringUtils.isEmpty(inNetWeight)) {
                                inNetWeight = "0";
                            }
                            inNetWeight = String.valueOf(Float.valueOf(inNetWeight) + netWeight);
                        }

                    }
                    //定义出库
                    String outNetWeight = "";
                    // 查询出库数量
                    List<WarehouseInOutInfo> warehouseInOutInfos = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                            .eq("base_id", warehouseBaseInfo.getId()).eq("status_flag", "3").eq("in_out_flag", "1"));
                    if (!CollectionUtils.isEmpty(warehouseInOutInfos)) {
                        Float netWeight = 0f;
                        for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfos) {
                            netWeight = netWeight + Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight()));
                            if (StringUtils.isEmpty(outNetWeight)) {
                                outNetWeight = "0";
                            }
                            outNetWeight = String.valueOf(Float.valueOf(outNetWeight) + netWeight);
                        }

                    }
                    residual = Float.valueOf(!StringUtils.isEmpty(inNetWeight) ? inNetWeight : "0") - Float.valueOf(!StringUtils.isEmpty(outNetWeight) ? outNetWeight : "0");
                }
                warehouseBaseInfo.setResidual(residual);
            }
        }

        return warehouseBaseInfoList;
    }

    /**
     * 删除库房
     *
     * @param id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteWarehouse(String id) {
        //查询仓库信息
        WarehouseBaseInfo warehouseBaseInfo = this.selectById(id);
        this.deleteById(warehouseBaseInfo.getId());
        if ("1".equals(warehouseBaseInfo.getWarehouseType())) {
            //查询仓位信息
            List<WarehousePositionInfo> warehousePositionInfos = warehousePositionInfoService.selectList(new EntityWrapper<WarehousePositionInfo>()
                    .eq("base_id", warehouseBaseInfo.getId()).orderBy("bin_number", false));
            if (!CollectionUtils.isEmpty(warehousePositionInfos)) {
                for (WarehousePositionInfo warehousePositionInfo : warehousePositionInfos) {
                    warehousePositionInfoService.deleteById(warehousePositionInfo.getId());
                    //查询仓位存储量
                    List<WarehousePositionStorageInfo> warehousePositionStorageInfos = warehousePositionStorageInfoService.selectList(new EntityWrapper<WarehousePositionStorageInfo>()
                            .eq("position_id", warehousePositionInfo.getId()));
                    if (!CollectionUtils.isEmpty(warehousePositionStorageInfos)) {
                        for (WarehousePositionStorageInfo warehousePositionStorageInfo : warehousePositionStorageInfos) {
                            //判断是否有剩余库存
                            if (warehousePositionStorageInfo.getStorage() > 0) {
                                throw new YException(YExceptionEnum.WAREHOSE_SYSTEM_ERROR);
                            } else {
                                warehousePositionStorageInfoService.deleteById(warehousePositionStorageInfo.getId());
                            }
                        }
                    }
                }
            }
        }

    }

    /**
     * 清仓状态
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public String editCleared(String id) {
        //查询仓库信息
        WarehouseBaseInfo warehouseBaseInfo = this.selectById(id);
        //状态改为已清仓
        warehouseBaseInfo.setClearStatusFlag(StatusEnum.CLEARED.getFlag());
        warehouseBaseInfo.setClearStatus(StatusEnum.CLEARED.getName());
        //更改仓库信息
        this.updateById(warehouseBaseInfo);
        return "OK";
    }

    /**
     * 出入库合同编号下拉列表
     *
     * @param compId
     * @param flag   0 采购合同编号 1销售合同编号 2 移库任务编号+采购、销售合同编号 null 采购、销售合同编号
     * @return
     */
    @Override
    public List<ContractManagementInfo> selectContractNoList(String compId, Integer flag) {
        if (compId == null || compId.isEmpty()) {
            compId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getCompId();
        }
        List<ContractManagementInfo> temp = new ArrayList();
        List<ContractManagementInfo> listRedis = cacheComponent.getObjList(Const.ADMIN_CONTRACTINFO+compId+flag,ContractManagementInfo.class);
        if(listRedis != null && listRedis.size() > 0 ){
            return listRedis;
        }
        //查所有合同编号
        if (flag == null) {
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("status_flag", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));

            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                temp.add(contractManagementInfo);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查采购合同编号
        if (flag == 0) {

            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("contract_type", "2")
                    .eq("status_flag", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                temp.add(contractManagementInfo);
            }
            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查销售合同编号
        else if (flag == 1) {

            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("contract_type", "1")
                    .eq("status_flag", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));

            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                temp.add(contractManagementInfo);
            }
            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查采购订单审核合同编号
        else if (flag == 3) {

            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("contract_type", "2")
                    .eq("status_flag", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));
            if (!CollectionUtils.isEmpty(contractManagementInfoList)) {
                List<PurchaseOrder> purchaseOrderList = purchaseOrderService.selectList(new EntityWrapper<PurchaseOrder>()
                        .eq("comp_id", compId)
                        .eq("delete_flag", "0"));
                for (int i = 0; i < contractManagementInfoList.size(); i++) {
                    if (!CollectionUtils.isEmpty(purchaseOrderList)) {
                        for (int j = 0; j < purchaseOrderList.size(); j++) {
                            if (contractManagementInfoList.get(i).getContractNo().equals(purchaseOrderList.get(j).getContractNo())) {
                                contractManagementInfoList.remove(contractManagementInfoList.get(i));
                                break;
                            }
                        }
                    }
                }
                temp.addAll(contractManagementInfoList);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查销售订单审核合同编号
        else if (flag == 4) {
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("contract_type", "1")
                    .eq("status_flag", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));
            if (!CollectionUtils.isEmpty(contractManagementInfoList)) {
                List<SaleOrder> saleOrderList = saleOrderService.selectList(new EntityWrapper<SaleOrder>()
                        .eq("comp_id", compId)
                        .eq("delete_flag", "0"));
                for (int i = 0; i < contractManagementInfoList.size(); i++) {
                    if (!CollectionUtils.isEmpty(saleOrderList)) {
                        for (int j = 0; j < saleOrderList.size(); j++) {
                            if (contractManagementInfoList.get(i).getContractNo().equals(saleOrderList.get(j).getContractNo())) {
                                contractManagementInfoList.remove(contractManagementInfoList.get(i));
                                break;
                            }
                        }
                    }
                }
                temp.addAll(contractManagementInfoList);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查销售合同编号,以及移库任务编号
        else if (flag == 5) {
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("delete_flag", "0")
                    .eq("status_flag", "1")
                    .eq("contract_type", "1")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                //查合同下的车牌号,出库只能查到未出库的
                List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", contractManagementInfo.getContractNo()).eq("tran_type", "1").eq("submit", "0")
                        .last("ORDER BY CONVERT ( car_no USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList)) {
                    contractManagementInfo.setTranCarInfoList(tranCarInfoList);
                }
                //查船名
                Wrapper<TranCarInfo> shipListWrapper = new EntityWrapper<>();
                shipListWrapper.eq("contract_no", contractManagementInfo.getContractNo())
                        .eq("delete_flag", "0");
                shipListWrapper.andNew().eq("tran_type", "3").or()
                        .eq("three_tran_type", "散船");
                List<TranCarInfo> shipInfoList = tranCarInfoService.selectList(shipListWrapper);
                if (!CollectionUtils.isEmpty(shipInfoList)) {
                    contractManagementInfo.setShipInfoList(shipInfoList);
                }
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
                contractManagementInfo.setInOutType("销售出库");
                //期货取点价，现货取单价
                if (contractManagementInfo.getUnitContractPrice() != null) {
                    contractManagementInfo.setContractPrice(contractManagementInfo.getPointPrice() != null ? contractManagementInfo.getPointPrice() : Float.valueOf(String.valueOf(contractManagementInfo.getUnitContractPrice())));
                }
                temp.add(contractManagementInfo);
            }
            List<InOutWarehouseTask> inOutWarehouseTaskList = iInOutWarehouseTaskService.selectList(new EntityWrapper<InOutWarehouseTask>()
                    .eq("comp_id", compId)
                    .eq("delete_flag", "0")
                    .eq("task_type_key", "3")
                    .eq("in_out_flag", "1")
                    .orderBy("update_date", false));
            for (InOutWarehouseTask inOutWarehouseTask : inOutWarehouseTaskList) {
                ContractManagementInfo contractManagementInfo = new ContractManagementInfo();
                BeanUtils.copyProperties(inOutWarehouseTask, contractManagementInfo);
                //查移库任务编号下的车牌号，移库出库只能查到未出库的
                List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", inOutWarehouseTask.getMoveTaskNo()).eq("tran_type", "1").eq("submit", "0")
                        .last("ORDER BY CONVERT ( car_no USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList)) {
                    contractManagementInfo.setTranCarInfoList(tranCarInfoList);
                }
                //查船名
                Wrapper<TranCarInfo> shipListWrapper = new EntityWrapper<>();
                shipListWrapper.eq("contract_no", inOutWarehouseTask.getMoveTaskNo())
                        .eq("delete_flag", "0");
                shipListWrapper.andNew().eq("tran_type", "3").or()
                        .eq("three_tran_type", "散船");
                List<TranCarInfo> shipInfoList = tranCarInfoService.selectList(shipListWrapper);
                if (!CollectionUtils.isEmpty(shipInfoList)) {
                    contractManagementInfo.setShipInfoList(shipInfoList);
                }
                //移库看成自运
                contractManagementInfo.setDeliverType("1");
                contractManagementInfo.setContractNo(inOutWarehouseTask.getMoveTaskNo());
                ContractManagementInfo contractManagementInfo1=contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                        .eq("contract_no",inOutWarehouseTask.getWarehouseName())
                        .eq("comp_id",inOutWarehouseTask.getCompId()));
                if (contractManagementInfo1!=null&&"定价采购".equals(contractManagementInfo1.getPriceType())) {
                    contractManagementInfo.setContractPrice(Float.valueOf(String.valueOf(contractManagementInfo1.getUnitContractPrice())));
                    contractManagementInfo.setPriceType(contractManagementInfo1.getPriceType());
                }
                else if(contractManagementInfo1!=null&&"随行就市".equals(contractManagementInfo1.getPriceType())){
                    contractManagementInfo.setPriceType(contractManagementInfo1.getPriceType());
                }
                contractManagementInfo.setGrade(inOutWarehouseTask.getGrade());
                contractManagementInfo.setSendWarehouse(inOutWarehouseTask.getSendWarehouse());
                contractManagementInfo.setReceiveWarehouse(inOutWarehouseTask.getReceiveWarehouse());
                contractManagementInfo.setInOutType("移库出库");
                temp.add(contractManagementInfo);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查采购合同编号(不包含自运）,以及移库任务编号
        else if (flag == 6) {
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("delete_flag", "0")
                    .eq("contract_type", "2")
                    .eq("status_flag", "1")
                    .eq("deliver_type", "2")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                //查合同下的车牌号,入库只能查到未提交的
                List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", contractManagementInfo.getContractNo()).eq("tran_type", "1").ne("submit", "2")
                        .last("ORDER BY CONVERT ( car_no USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList)) {
                    contractManagementInfo.setTranCarInfoList(tranCarInfoList);
                }
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                contractManagementInfo.setInOutType("采购入库");
                if (contractManagementInfo.getUnitContractPrice() != null) {
                    //期货取点价，现货取单价
                    contractManagementInfo.setContractPrice(contractManagementInfo.getPointPrice() != null ? contractManagementInfo.getPointPrice() : Float.valueOf(String.valueOf(contractManagementInfo.getUnitContractPrice())));
                }
                temp.add(contractManagementInfo);
            }
            List<InOutWarehouseTask> inOutWarehouseTaskList = iInOutWarehouseTaskService.selectList(new EntityWrapper<InOutWarehouseTask>()
                    .eq("comp_id", compId)
                    .eq("delete_flag", "0")
                    .eq("task_type_key", "3")
                    .eq("in_out_flag", "1")
                    .orderBy("update_date", false));
            for (InOutWarehouseTask inOutWarehouseTask : inOutWarehouseTaskList) {
                ContractManagementInfo contractManagementInfo = new ContractManagementInfo();
                BeanUtils.copyProperties(inOutWarehouseTask, contractManagementInfo);
                //查移库任务编号下的车牌号,移库入库只能查到已出库
                List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", inOutWarehouseTask.getMoveTaskNo()).eq("tran_type", "1").eq("submit", "1")
                        .last("ORDER BY CONVERT ( car_no USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList)) {
                    contractManagementInfo.setTranCarInfoList(tranCarInfoList);
                }
//                //移库编号成本
//                if ("移库出库".equals(inOutWarehouseTask.getInOutType())) {
//                    //自动创建的临时库移库，成本为对应的合同单价
//                    ContractManagementInfo contractManagementInfo1 = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
//                            .eq("comp_id", inOutWarehouseTask.getCompId())
//                            .eq("contract_no", inOutWarehouseTask.getWarehouseName()));
//                    if (contractManagementInfo1 != null) {
//                        contractManagementInfo.setUnitContractPrice(contractManagementInfo1.getUnitContractPrice());
//                    }
//                    //其他类型移库，一个运输阶段成本加权，多个成本为空
//                    TranTaskInfo tranTaskInfo=tranTaskInfoService.selectOne(new EntityWrapper<TranTaskInfo>()
//                            .eq("comp_id", inOutWarehouseTask.getCompId())
//                            .eq("contract_no", inOutWarehouseTask.getMoveTaskNo()));
//                    if (tranTaskInfo!=null){
//                        List<TranProcessInfo> tranProcessInfoList=tranProcessInfoService.selectList(new EntityWrapper<TranProcessInfo>()
//                        .eq("info_id",tranTaskInfo.getId()));
//                        //只有一个汽运的运输阶段
//                        if (tranProcessInfoList.size()==1&&tranProcessInfoList.get(0).getTranTypeKey()=="1"){
//                            //成本为所选车辆出库时所在库的加权成本
//                            WarehouseBaseInfo warehouseBaseInfo=warehouseBaseInfoService.selectOne(new EntityWrapper<WarehouseBaseInfo>()
//                                    .eq("comp_id", inOutWarehouseTask.getCompId())
//                                    .eq("warehouse_name", inOutWarehouseTask.getWarehouseName()));
//                            if (warehouseBaseInfo!=null){
//                                CostManagementInfo costManagementInfo=costManagementInfoService.selectOne(new EntityWrapper<CostManagementInfo>()
//                                        .eq("warehouse_id", warehouseBaseInfo.getId()));
//                                if (costManagementInfo!=null){
//                                    contractManagementInfo.setUnitContractPrice(Double.valueOf(String.valueOf(costManagementInfo.getCost())));
//                                }
//                            }
//                        }
//                        else{
//                            contractManagementInfo.setUnitContractPrice(null);
//                        }
//                    }
//                }
//                else if ("退库".equals(inOutWarehouseTask.getInOutType())) {
//                    //自动创建的临时库退库，成本为对应的合同单价
//                    ContractManagementInfo contractManagementInfo1 = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
//                            .eq("comp_id", inOutWarehouseTask.getCompId())
//                            .eq("contract_no", inOutWarehouseTask.getWarehouseName()));
//                    if (contractManagementInfo1 != null) {
//                        contractManagementInfo.setUnitContractPrice(contractManagementInfo1.getUnitContractPrice());
//                    }
//                }
//                else{
//                    contractManagementInfo.setUnitContractPrice(null);
//                }
                contractManagementInfo.setContractNo(inOutWarehouseTask.getMoveTaskNo());
                contractManagementInfo.setContractPrice(inOutWarehouseTask.getUnitPrice());
                contractManagementInfo.setInOutType("移库入库");
                temp.add(contractManagementInfo);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查采购合同编号(不包含自运）,以及移库任务编号,销售合同
        else if (flag == 7) {
//            Map<String, Object> pageView = new HashMap<>();
//            pageView.put("compId", compId);
//            pageView.put("contractType", '2');
//            pageView.put("statusFlag", '1');
//            pageView.put("deliverType", '2');
//            pageView.put("fleetFlag", '0');
//            pageView.put("tranType", '4');
//            pageView.put("threeTranType", "汽运");
//            pageView.put("submit", '2');
//            pageView.put("flag", '1');
//            //查合同下的车牌号,入库只能查到未提交的
//            List<TranCarInfo> tranCarInfoLists = baseMapper.getTranCarInfo(pageView);
//            /*****************************/
//            Map<String, Object> pageView1 = new HashMap<>();
//            pageView1.put("compId", compId);
//            pageView1.put("contractType", '2');
//            pageView1.put("statusFlag", '1');
//            pageView1.put("deliverType", '2');
//            pageView1.put("fleetFlag", '1');
//            pageView1.put("tranType", '4');
//            pageView1.put("threeTranType", "汽运");
//            pageView1.put("flag", '1');
//            //查合同下的车牌号,入库只能查到未提交的
//            List<TranCarInfo> tranCarInfoLists1 = baseMapper.getTranCarInfo(pageView1);
//            /*****************************/
//            Map<String, Object> pageView2 = new HashMap<>();
//            pageView2.put("compId", compId);
//            pageView2.put("contractType", '2');
//            pageView2.put("statusFlag", '1');
//            pageView2.put("deliverType", '2');
//            pageView2.put("tranType", '3');
//            pageView2.put("threeTranType", "散船");
//            pageView2.put("flag", '2');
//            //查合同下的车牌号,入库只能查到未提交的
//            List<TranCarInfo> tranCarInfoLists2 = baseMapper.getTranCarInfo(pageView2);
//            tranCarInfoLists.addAll(tranCarInfoLists1);
//            tranCarInfoLists.addAll(tranCarInfoLists2);
//            Set< TranCarInfo > set = new HashSet<>(tranCarInfoLists);
//            tranCarInfoLists =  set.stream()
//                    .sorted(Comparator.comparingInt(a -> Integer.parseInt(a.getContractId().substring(1, 25)))).collect(Collectors.toList());
////            List<ContractManagementInfo> contractManagementInfos = new ArrayList<>();
//            ContractManagementInfo contractManagementInfo = new ContractManagementInfo();
//            List<TranCarInfo> tranCarInfos = new ArrayList<>();
//            List<TranCarInfo> tranCarInfos1 = new ArrayList<>();
//            List<TranCarInfo> tranCarInfos2 = new ArrayList<>();
//            for (int i = 0; i < tranCarInfoLists.size(); i++) {
//                TranCarInfo tranCarInfo = tranCarInfoLists.get(i);
//
//                if (contractManagementInfo.getUnitContractPrice() != null) {
//                    //期货取点价，现货取单价
//                    contractManagementInfo.setContractPrice(contractManagementInfo.getPointPrice() != null ? contractManagementInfo.getPointPrice() : Float.valueOf(String.valueOf(contractManagementInfo.getUnitContractPrice())));
//                }
//                if("0".equals(tranCarInfo.getFleetFlag())&&"4".equals(tranCarInfo.getTranType())&&"汽运".equals(tranCarInfo.getThreeTranType())&&"2".equals(tranCarInfo.getSubmit())) {
//                    if (i == 0) {
//                        contractManagementInfo = new ContractManagementInfo();
//                        contractManagementInfo = contractManagementInfoService.selectById(tranCarInfo.getContractId());
//                        ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
//                                .eq("contract_id", tranCarInfo.getContractId()));
//                        contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
//                        contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
//                        contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
//                        contractManagementInfo.setInOutType("采购入库");
//                        tranCarInfos = new ArrayList<>();
//                        tranCarInfos1 = new ArrayList<>();
//                        tranCarInfos2 = new ArrayList<>();
//                        contractManagementInfo.setId(tranCarInfo.getId());
//                        contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
//                        contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
//                        contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
//                        contractManagementInfo.setInOutType("采购入库");
//                        tranCarInfos.add(tranCarInfo);
//                    } else if (!tranCarInfo.getContractId().equals(tranCarInfoLists.get(i - 1).getContractId())) {
//                        contractManagementInfo.setTranCarInfoList(tranCarInfos);
//                        contractManagementInfo.setTranCarInfoList1(tranCarInfos1);
//                        contractManagementInfo.setShipInfoList(tranCarInfos2);
//                        temp.add(contractManagementInfo);
//                        contractManagementInfo = new ContractManagementInfo();
//                        contractManagementInfo = contractManagementInfoService.selectById(tranCarInfo.getContractId());
//                        ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
//                                .eq("contract_id", tranCarInfo.getContractId()));
//                        contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
//                        contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
//                        contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
//                        contractManagementInfo.setInOutType("采购入库");
//                        tranCarInfos = new ArrayList<>();
//                        tranCarInfos1 = new ArrayList<>();
//                        tranCarInfos2 = new ArrayList<>();
//                        contractManagementInfo.setId(tranCarInfo.getId());
//                        tranCarInfos.add(tranCarInfo);
//                    } else if (i == tranCarInfoLists.size() - 1) {
//                        tranCarInfos.add(tranCarInfo);
//                        contractManagementInfo.setTranCarInfoList(tranCarInfos);
//                        temp.add(contractManagementInfo);
//                    } else {
//                        tranCarInfos.add(tranCarInfo);
//                    }
//                }
//                if("1".equals(tranCarInfo.getFleetFlag())&&"4".equals(tranCarInfo.getTranType())&&"汽运".equals(tranCarInfo.getThreeTranType())) {
//                    if (i == 0) {
//                        contractManagementInfo = new ContractManagementInfo();
//                        contractManagementInfo = contractManagementInfoService.selectById(tranCarInfo.getContractId());
//                        ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
//                                .eq("contract_id", tranCarInfo.getContractId()));
//                        contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
//                        contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
//                        contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
//                        contractManagementInfo.setInOutType("采购入库");
//                        tranCarInfos = new ArrayList<>();
//                        tranCarInfos1 = new ArrayList<>();
//                        tranCarInfos2 = new ArrayList<>();
//                        contractManagementInfo.setId(tranCarInfo.getId());
//                        tranCarInfos1.add(tranCarInfo);
//                    } else if (!tranCarInfo.getContractId().equals(tranCarInfoLists.get(i - 1).getContractId())) {
//                        contractManagementInfo.setTranCarInfoList(tranCarInfos);
//                        contractManagementInfo.setTranCarInfoList1(tranCarInfos1);
//                        contractManagementInfo.setShipInfoList(tranCarInfos2);
//                        temp.add(contractManagementInfo);
//                        contractManagementInfo = new ContractManagementInfo();
//                        contractManagementInfo = contractManagementInfoService.selectById(tranCarInfo.getContractId());
//                        ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
//                                .eq("contract_id", tranCarInfo.getContractId()));
//                        contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
//                        contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
//                        contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
//                        contractManagementInfo.setInOutType("采购入库");
//                        tranCarInfos = new ArrayList<>();
//                        tranCarInfos1 = new ArrayList<>();
//                        tranCarInfos2 = new ArrayList<>();
//                        contractManagementInfo.setId(tranCarInfo.getId());
//                        tranCarInfos.add(tranCarInfo);
//                    } else if (i == tranCarInfoLists.size() - 1) {
//                        tranCarInfos1.add(tranCarInfo);
//                        contractManagementInfo.setTranCarInfoList(tranCarInfos);
//                        temp.add(contractManagementInfo);
//                    } else {
//                        tranCarInfos1.add(tranCarInfo);
//                    }
//                }
//                if("3".equals(tranCarInfo.getTranType())||"散船".equals(tranCarInfo.getThreeTranType())) {
//                    if (i == 0) {
//                        contractManagementInfo = new ContractManagementInfo();
//                        contractManagementInfo = contractManagementInfoService.selectById(tranCarInfo.getContractId());
//                        ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
//                                .eq("contract_id", tranCarInfo.getContractId()));
//                        contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
//                        contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
//                        contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
//                        contractManagementInfo.setInOutType("采购入库");
//                        tranCarInfos = new ArrayList<>();
//                        tranCarInfos1 = new ArrayList<>();
//                        tranCarInfos2 = new ArrayList<>();
//                        contractManagementInfo.setId(tranCarInfo.getId());
//                        tranCarInfos2.add(tranCarInfo);
//                    } else if (!tranCarInfo.getContractId().equals(tranCarInfoLists.get(i - 1).getContractId())) {
//                        contractManagementInfo.setTranCarInfoList(tranCarInfos);
//                        contractManagementInfo.setTranCarInfoList1(tranCarInfos1);
//                        contractManagementInfo.setShipInfoList(tranCarInfos2);
//                        temp.add(contractManagementInfo);
//                        contractManagementInfo = new ContractManagementInfo();
//                        contractManagementInfo = contractManagementInfoService.selectById(tranCarInfo.getContractId());
//                        ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
//                                .eq("contract_id", tranCarInfo.getContractId()));
//                        contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
//                        contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
//                        contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
//                        contractManagementInfo.setInOutType("采购入库");
//                        tranCarInfos = new ArrayList<>();
//                        tranCarInfos1 = new ArrayList<>();
//                        tranCarInfos2 = new ArrayList<>();
//                        contractManagementInfo.setId(tranCarInfo.getId());
//                        tranCarInfos2.add(tranCarInfo);
//                    } else if (i == tranCarInfoLists.size() - 1) {
//                        tranCarInfos2.add(tranCarInfo);
//                        contractManagementInfo.setTranCarInfoList(tranCarInfos);
//                        temp.add(contractManagementInfo);
//                    } else {
//                        tranCarInfos2.add(tranCarInfo);
//                    }
//                }
//            }


/*****************************************************---------------------------******************************/
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("delete_flag", "0")
                    .eq("contract_type", "2")
                    .eq("status_flag", "1")
                    .eq("deliver_type", "2")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                //查合同下的车牌号,入库只能查到未提交的
                List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", contractManagementInfo.getContractNo())
                        .eq("fleet_flag", "0").eq("tran_type", "4").eq("three_tran_type", "汽运").ne("submit", "2")
                        .last("ORDER BY CONVERT ( car_no USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList)) {
                    contractManagementInfo.setTranCarInfoList(tranCarInfoList);
                }
                //查合同下的车队,入库只能查到未提交的
                List<TranCarInfo> tranCarInfoList1 = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", contractManagementInfo.getContractNo())
                        .eq("fleet_flag", "1").eq("tran_type", "4").eq("three_tran_type", "汽运")
                        .last("ORDER BY CONVERT ( fleet_name USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList1)) {
                    contractManagementInfo.setTranCarInfoList1(tranCarInfoList1);
                }
                //查船名
                Wrapper<TranCarInfo> shipListWrapper = new EntityWrapper<>();
                shipListWrapper.eq("contract_no", contractManagementInfo.getContractNo())
                        .eq("delete_flag", "0");
                shipListWrapper.andNew().eq("tran_type", "3").or()
                        .eq("three_tran_type", "散船");
                List<TranCarInfo> shipInfoList = tranCarInfoService.selectList(shipListWrapper);
                if (!CollectionUtils.isEmpty(shipInfoList)) {
                    contractManagementInfo.setShipInfoList(shipInfoList);
                }
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                contractManagementInfo.setGrade(contractGoodsInfo.getGrade());
                contractManagementInfo.setInOutType("采购入库");
                if (contractManagementInfo.getUnitContractPrice() != null) {
                    //期货取点价，现货取单价
                    contractManagementInfo.setContractPrice(contractManagementInfo.getPointPrice() != null ? contractManagementInfo.getPointPrice() : Float.valueOf(String.valueOf(contractManagementInfo.getUnitContractPrice())));
                }
                temp.add(contractManagementInfo);
            }
            List<ContractManagementInfo> contractManagementInfoList1 = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("status_flag", "1")
                    .eq("contract_type", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo1 : contractManagementInfoList1) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo1.getId()));
                //查合同下的车牌号,入库只能查到未提交的
                List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", contractManagementInfo1.getContractNo()).eq("fleet_flag", "0").eq("tran_type", "1").ne("submit", "2")
                        .last("ORDER BY CONVERT ( car_no USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList)) {
                    contractManagementInfo1.setTranCarInfoList(tranCarInfoList);
                }
                List<TranCarInfo> tranCarInfoList1 = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", contractManagementInfo1.getContractNo()).eq("fleet_flag", "1").eq("tran_type", "1")
                        .last("ORDER BY CONVERT ( fleet_name USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList1)) {
                    contractManagementInfo1.setTranCarInfoList1(tranCarInfoList1);
                }
                //查船名
                Wrapper<TranCarInfo> shipListWrapper = new EntityWrapper<>();
                shipListWrapper.eq("contract_no", contractManagementInfo1.getContractNo())
                        .eq("delete_flag", "0");
                shipListWrapper.andNew().eq("tran_type", "3").or()
                        .eq("three_tran_type", "散船");
                List<TranCarInfo> shipInfoList = tranCarInfoService.selectList(shipListWrapper);
                if (!CollectionUtils.isEmpty(shipInfoList)) {
                    contractManagementInfo1.setShipInfoList(shipInfoList);
                }
                contractManagementInfo1.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo1.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                contractManagementInfo1.setGrade(contractGoodsInfo.getGrade());
                contractManagementInfo1.setInOutType("退库");
                temp.add(contractManagementInfo1);
            }
            List<InOutWarehouseTask> inOutWarehouseTaskList = iInOutWarehouseTaskService.selectList(new EntityWrapper<InOutWarehouseTask>()
                    .eq("comp_id", compId)
                    .eq("delete_flag", "0")
                    .eq("task_type_key", "3")
                    .eq("in_out_flag", "1")
                    .orderBy("update_date", false));
            for (InOutWarehouseTask inOutWarehouseTask : inOutWarehouseTaskList) {
                ContractManagementInfo contractManagementInfo1 = new ContractManagementInfo();
                BeanUtils.copyProperties(inOutWarehouseTask, contractManagementInfo1);
                //查移库任务编号下的车牌号,入库只能查到已出库的
                List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", inOutWarehouseTask.getMoveTaskNo()).eq("fleet_flag", "0").eq("tran_type", "1").eq("submit", "1")
                        .last("ORDER BY CONVERT ( car_no USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList)) {
                    contractManagementInfo1.setTranCarInfoList(tranCarInfoList);
                }
                List<TranCarInfo> tranCarInfoList1 = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
                        .eq("contract_no", inOutWarehouseTask.getMoveTaskNo()).eq("fleet_flag", "1").eq("tran_type", "1")
                        .last("ORDER BY CONVERT ( fleet_name USING gbk ) ASC"));
                if (!CollectionUtils.isEmpty(tranCarInfoList1)) {
                    contractManagementInfo1.setTranCarInfoList1(tranCarInfoList1);
                }
                //查船名
                Wrapper<TranCarInfo> shipListWrapper = new EntityWrapper<>();
                shipListWrapper.eq("contract_no", inOutWarehouseTask.getMoveTaskNo())
                        .eq("delete_flag", "0");
                shipListWrapper.andNew().eq("tran_type", "3").or()
                        .eq("three_tran_type", "散船");
                List<TranCarInfo> shipInfoList = tranCarInfoService.selectList(shipListWrapper);
                if (!CollectionUtils.isEmpty(shipInfoList)) {
                    contractManagementInfo1.setShipInfoList(shipInfoList);
                }
                contractManagementInfo1.setContractNo(inOutWarehouseTask.getMoveTaskNo());
                ContractManagementInfo contractManagementInfo=contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                .eq("contract_no",inOutWarehouseTask.getWarehouseName())
                .eq("comp_id",inOutWarehouseTask.getCompId()));
                if (contractManagementInfo!=null) {
                    contractManagementInfo1.setContractPrice(Float.valueOf(String.valueOf(contractManagementInfo.getUnitContractPrice())));
                }
                //自运采购的移库
                ContractManagementInfo contractManagementInfo2 = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                        .eq("comp_id", inOutWarehouseTask.getCompId())
                        .eq("contract_no", inOutWarehouseTask.getSendWarehouse()));
                if (contractManagementInfo2 != null) {
                    contractManagementInfo1.setContractPrice(Float.valueOf(String.valueOf(contractManagementInfo2.getUnitContractPrice())));
                }
                //移库看成自运
                contractManagementInfo1.setDeliverType("1");
                contractManagementInfo1.setSendWarehouse(inOutWarehouseTask.getSendWarehouse());
                contractManagementInfo1.setGrade(inOutWarehouseTask.getGrade());
                contractManagementInfo1.setInOutType("移库入库");
                temp.add(contractManagementInfo1);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //采购合同不包含自运
        else if (flag == 8) {
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("contract_type", "2")
                    .eq("status_flag", "1")
                    .eq("deliver_type", "2")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                temp.add(contractManagementInfo);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //收购合同
        else if (flag == 9) {
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("contract_type", "3")
                    .eq("status_flag", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                //一个收购合同只能选一次
                InOutWarehouseTask inOutWarehouseTask=iInOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
                        .eq("comp_id", contractManagementInfo.getCompId())
                        .eq("contract_no", contractManagementInfo.getContractNo())
                        .eq("delete_flag", "0")
                        .orderBy("update_date", false));
                if (inOutWarehouseTask==null){
                    ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                            .eq("contract_id", contractManagementInfo.getId()));
                    contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                    contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                    temp.add(contractManagementInfo);
                }
            }
            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
        //查采购、销售合同编号,以及移库任务编号
        else {
            List<ContractManagementInfo> contractManagementInfoList = contractManagementInfoService.selectList(new EntityWrapper<ContractManagementInfo>()
                    .eq("comp_id", compId)
                    .eq("status_flag", "1")
                    .eq("delete_flag", "0")
                    .orderBy("update_date", false));
            for (ContractManagementInfo contractManagementInfo : contractManagementInfoList) {
                ContractGoodsInfo contractGoodsInfo = contractGoodsInfoService.selectOne(new EntityWrapper<ContractGoodsInfo>()
                        .eq("contract_id", contractManagementInfo.getId()));
                contractManagementInfo.setGoodsName(contractGoodsInfo.getGoodsName());
                contractManagementInfo.setGoodsNameKey(contractGoodsInfo.getGoodsNameKey());
                temp.add(contractManagementInfo);
            }
            List<InOutWarehouseTask> inOutWarehouseTaskList = iInOutWarehouseTaskService.selectList(new EntityWrapper<InOutWarehouseTask>()
                    .eq("comp_id", compId)
                    .eq("delete_flag", "0")
                    .eq("task_type_key", "3")
                    .eq("in_out_flag", "1")
                    .orderBy("update_date", false));
            for (InOutWarehouseTask inOutWarehouseTask : inOutWarehouseTaskList) {
                ContractManagementInfo contractManagementInfo = new ContractManagementInfo();
                BeanUtils.copyProperties(inOutWarehouseTask, contractManagementInfo);
                contractManagementInfo.setContractNo(inOutWarehouseTask.getMoveTaskNo());
                contractManagementInfo.setInOutType("移库入库");
                temp.add(contractManagementInfo);
            }

            cacheComponent.putRaw(Const.ADMIN_CONTRACTINFO+compId+flag,JSONObject.toJSONString(temp),60*60*24);
            return temp;
        }
    }

    /**
     * 查看自己负责的常用仓库
     *
     * @param compId
     * @param personCharge
     * @return
     */
    @Override
    public List<WarehouseBaseInfo> selectWarehouseSelfApp(String compId, String personCharge) {
        if (compId == null || compId.isEmpty()) {
            compId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getCompId();
        }
        if (personCharge == null || personCharge.isEmpty()) {
            personCharge = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getStaffMobilePhone();
        }
        List<WarehouseBaseInfo> listRedis = cacheComponent.getObjList(Const.SELF_WAREHOUSE+personCharge,WarehouseBaseInfo.class);
        if(listRedis != null && listRedis.size() > 0 ){
            return listRedis;
        }
        Wrapper<WarehouseBaseInfo> warehouseBaseInfoWrapper = new EntityWrapper<>();
        warehouseBaseInfoWrapper.eq("comp_id", compId).eq("delete_flag", "0");
        warehouseBaseInfoWrapper.andNew().eq("person_phone", personCharge).or()
                .like("other_person_charge", personCharge);
        warehouseBaseInfoWrapper.orderBy("warehouse_type,common_warehouse_no");
        List<WarehouseBaseInfo> warehouseBaseInfoList = this.selectList(warehouseBaseInfoWrapper);
        if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
            for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                //查潮粮单价已审核的数据
//                List<PurchasePrice> purchasePriceList=purchasePriceService.selectList(new EntityWrapper<PurchasePrice>()
//                        .eq("warehouse_id",warehouseBaseInfo.getId())
//                        .eq("status_flag","3"));
//                if (!CollectionUtils.isEmpty(purchasePriceList)){
//                    warehouseBaseInfo.setPurchasePriceList(purchasePriceList);
//                }
                Map<String, Object> pageView = new HashMap<>();
                pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                pageView.put("compId", warehouseBaseInfo.getCompId());
                pageView.put("serviceManagementType", "3");
                // 查询收购质检信息包括已删除的
                Integer dataCount = baseMapper.getCountByCondition(pageView);
                Map<String, Object> pageView1 = new HashMap<>();
                pageView1.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                pageView1.put("compId", warehouseBaseInfo.getCompId());
                pageView1.put("serviceManagementType", "1");
                // 查询贸易质检信息包括已删除的
                Integer dataCount1 = baseMapper.getCountByCondition(pageView1);
                warehouseBaseInfo.setCount(dataCount);
                warehouseBaseInfo.setTradeCount(dataCount1);
                Map<String, Object> pageView2 = new HashMap<>();
                pageView2.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                pageView2.put("compId", warehouseBaseInfo.getCompId());
                pageView2.put("serviceManagementType", "2");
                // 查询出库信息包括已删除的
                Integer dataCount2 = baseMapper.getCountByCondition(pageView2);
                warehouseBaseInfo.setOutCount(dataCount2);
            }
        } else {
            String staffId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getStaffId();
            List<CommonStaffRole> staffRoles = commonStaffRoleService.selectList(new EntityWrapper<CommonStaffRole>().eq("staff_id", staffId));
            List<CommonRole> list = new ArrayList<>();
            for (CommonStaffRole commonStaffRole : staffRoles) {
                list.add(commonRoleService.selectById(commonStaffRole.getRoleId()));
            }
            for (CommonRole commonRole : list) {
                if ("内勤".equals(commonRole.getRoleName()) || "决策人".equals(commonRole.getRoleName()) || "财务".equals(commonRole.getRoleName()) || "出纳".equals(commonRole.getRoleName()) || commonRole.getRoleName().equals("系统管理员") || commonRole.getRoleName().contains("总")) {
                    List<WarehouseBaseInfo> warehouseBaseInfoList1 = this.selectList(new EntityWrapper<WarehouseBaseInfo>()
                            .eq("comp_id", compId)
                            .eq("delete_flag", "0"));
                    for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList1) {
                        warehouseBaseInfo.setFlag("全部");
                        //查潮粮单价已审核的数据
//                        List<PurchasePrice> purchasePriceList=purchasePriceService.selectList(new EntityWrapper<PurchasePrice>()
//                                .eq("warehouse_id",warehouseBaseInfo.getId())
//                                .eq("status_flag","3"));
//                        if (!CollectionUtils.isEmpty(purchasePriceList)){
//                            warehouseBaseInfo.setPurchasePriceList(purchasePriceList);
//                        }
                        Map<String, Object> pageView = new HashMap<>();
                        pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                        pageView.put("compId", warehouseBaseInfo.getCompId());
                        pageView.put("serviceManagementType", "3");
                        // 查询收购质检信息包括已删除的
                        Integer dataCount = baseMapper.getCountByCondition(pageView);
                        Map<String, Object> pageView1 = new HashMap<>();
                        pageView1.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                        pageView1.put("compId", warehouseBaseInfo.getCompId());
                        pageView1.put("serviceManagementType", "1");
                        // 查询贸易质检信息包括已删除的
                        Integer dataCount1 = baseMapper.getCountByCondition(pageView1);
                        warehouseBaseInfo.setCount(dataCount);
                        warehouseBaseInfo.setTradeCount(dataCount1);
                        Map<String, Object> pageView2 = new HashMap<>();
                        pageView2.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                        pageView2.put("compId", warehouseBaseInfo.getCompId());
                        pageView2.put("serviceManagementType", "2");
                        // 查询出库信息包括已删除的
                        Integer dataCount2 = baseMapper.getCountByCondition(pageView2);
                        warehouseBaseInfo.setOutCount(dataCount2);
                        warehouseBaseInfoList.add(warehouseBaseInfo);
                    }
                    break;
//                    return warehouseBaseInfoList;
                }
            }
        }
        if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
            for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                List<WarehousePositionStorageInfo> temp = new ArrayList();
                // 以库位为维度查询
                List<WarehousePositionInfo> warehousePositionInfos = warehousePositionInfoService.selectList(new EntityWrapper<WarehousePositionInfo>()
                        .eq("base_id", warehouseBaseInfo.getId()).orderBy("bin_number", false));
                if (!CollectionUtils.isEmpty(warehousePositionInfos)) {
                    for (WarehousePositionInfo warehousePositionInfo : warehousePositionInfos) {
                        //查询仓库内的货名
                        List<WarehousePositionStorageInfo> warehousePositionStorageInfos = warehousePositionStorageInfoService.selectList(new EntityWrapper<WarehousePositionStorageInfo>()
                                .eq("position_id", warehousePositionInfo.getId()));
                        if (!CollectionUtils.isEmpty(warehousePositionStorageInfos)) {
                            for (WarehousePositionStorageInfo warehousePositionStorageInfo : warehousePositionStorageInfos) {
                                temp.add(warehousePositionStorageInfo);
                            }
                        }
                    }
                    warehouseBaseInfo.setGoodsNameInfos(temp);
                    warehouseBaseInfo.setPositionInfos(warehousePositionInfos);
                }
            }

        }
        cacheComponent.putRaw(Const.SELF_WAREHOUSE+personCharge,JSONObject.toJSONString(warehouseBaseInfoList),60*60*24);
        return warehouseBaseInfoList;
    }

    /**
     * 查看自己负责的常用仓库
     *
     * @param compId
     * @param personCharge
     * @return
     */
    @Override
    public List<WarehouseBaseInfo> selectWarehouseSelf(String compId, String personCharge) {
        if (compId == null || compId.isEmpty()) {
            compId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getCompId();
        }
        if (personCharge == null || personCharge.isEmpty()) {
            personCharge = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getStaffMobilePhone();
        }
        List<WarehouseBaseInfo> listRedis = cacheComponent.getObjList(Const.SELF_WAREHOUSE+personCharge,WarehouseBaseInfo.class);
        if(listRedis != null && listRedis.size() > 0 ){
            return listRedis;
        }
        Wrapper<WarehouseBaseInfo> warehouseBaseInfoWrapper = new EntityWrapper<>();
        warehouseBaseInfoWrapper.eq("comp_id", compId).eq("warehouse_type", "1")
                .orderBy("warehouse_type", true).eq("delete_flag", "0");
        warehouseBaseInfoWrapper.andNew().eq("person_phone", personCharge).or()
                .like("other_person_charge", personCharge);
        List<WarehouseBaseInfo> warehouseBaseInfoList = this.selectList(warehouseBaseInfoWrapper);
        if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
            for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                //查潮粮单价已审核的数据我
//                List<PurchasePrice> purchasePriceList=purchasePriceService.selectList(new EntityWrapper<PurchasePrice>()
//                        .eq("warehouse_id",warehouseBaseInfo.getId())
//                        .eq("status_flag","3"));
//                if (!CollectionUtils.isEmpty(purchasePriceList)){
//                    warehouseBaseInfo.setPurchasePriceList(purchasePriceList);
//                }
                Map<String, Object> pageView = new HashMap<>();
                pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                pageView.put("compId", warehouseBaseInfo.getCompId());
                pageView.put("serviceManagementType", "3");
                // 查询收购质检信息包括已删除的
                Integer dataCount = baseMapper.getCountByCondition(pageView);
                Map<String, Object> pageView1 = new HashMap<>();
                pageView1.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                pageView1.put("compId", warehouseBaseInfo.getCompId());
                pageView1.put("serviceManagementType", "1");
                // 查询贸易质检信息包括已删除的
                Integer dataCount1 = baseMapper.getCountByCondition(pageView1);
                warehouseBaseInfo.setCount(dataCount);
                warehouseBaseInfo.setTradeCount(dataCount1);
                Map<String, Object> pageView2 = new HashMap<>();
                pageView2.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                pageView2.put("compId", warehouseBaseInfo.getCompId());
                pageView2.put("serviceManagementType", "2");
                // 查询出库信息包括已删除的
                Integer dataCount2 = baseMapper.getCountByCondition(pageView2);
                warehouseBaseInfo.setOutCount(dataCount2);
            }
        } else {
            String staffId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getStaffId();
            List<CommonStaffRole> staffRoles = commonStaffRoleService.selectList(new EntityWrapper<CommonStaffRole>().eq("staff_id", staffId));
            List<CommonRole> list = new ArrayList<>();
            for (CommonStaffRole commonStaffRole : staffRoles) {
                list.add(commonRoleService.selectById(commonStaffRole.getRoleId()));
            }
            for (CommonRole commonRole : list) {
                if (commonRole.getRoleName().contains("内勤") || commonRole.getRoleName().contains("决策人") || commonRole.getRoleName().contains("财务") || commonRole.getRoleName().contains("出纳") || commonRole.getRoleName().equals("系统管理员") || commonRole.getRoleName().contains("总")) {
                    List<WarehouseBaseInfo> warehouseBaseInfoList1 = this.selectList(new EntityWrapper<WarehouseBaseInfo>()
                            .eq("comp_id", compId)
                            .orderBy("warehouse_type", true)
                            .eq("delete_flag", "0"));
                    for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList1) {
                        warehouseBaseInfo.setFlag("全部");
                        //查潮粮单价已审核的数据
//                        List<PurchasePrice> purchasePriceList=purchasePriceService.selectList(new EntityWrapper<PurchasePrice>()
//                                .eq("warehouse_id",warehouseBaseInfo.getId())
//                                .eq("status_flag","3"));
//                        if (!CollectionUtils.isEmpty(purchasePriceList)){
//                            warehouseBaseInfo.setPurchasePriceList(purchasePriceList);
//                        }
                        Map<String, Object> pageView = new HashMap<>();
                        pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                        pageView.put("compId", warehouseBaseInfo.getCompId());
                        pageView.put("serviceManagementType", "3");
                        // 查询收购质检信息包括已删除的
                        Integer dataCount = baseMapper.getCountByCondition(pageView);
                        Map<String, Object> pageView1 = new HashMap<>();
                        pageView1.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                        pageView1.put("compId", warehouseBaseInfo.getCompId());
                        pageView1.put("serviceManagementType", "1");
                        // 查询贸易质检信息包括已删除的
                        Integer dataCount1 = baseMapper.getCountByCondition(pageView1);
                        warehouseBaseInfo.setCount(dataCount);
                        warehouseBaseInfo.setTradeCount(dataCount1);
                        Map<String, Object> pageView2 = new HashMap<>();
                        pageView2.put("warehouseName", warehouseBaseInfo.getWarehouseName());
                        pageView2.put("compId", warehouseBaseInfo.getCompId());
                        pageView2.put("serviceManagementType", "2");
                        // 查询出库信息包括已删除的
                        Integer dataCount2 = baseMapper.getCountByCondition(pageView2);
                        warehouseBaseInfo.setOutCount(dataCount2);
                        warehouseBaseInfoList.add(warehouseBaseInfo);
                    }
                    break;
//                    return warehouseBaseInfoList;
                }
            }
        }
        if (!CollectionUtils.isEmpty(warehouseBaseInfoList)) {
            for (WarehouseBaseInfo warehouseBaseInfo : warehouseBaseInfoList) {
                List<WarehousePositionStorageInfo> temp = new ArrayList();
                // 以库位为维度查询
                List<WarehousePositionInfo> warehousePositionInfos = warehousePositionInfoService.selectList(new EntityWrapper<WarehousePositionInfo>()
                        .eq("base_id", warehouseBaseInfo.getId()).orderBy("bin_number", false));
                if (!CollectionUtils.isEmpty(warehousePositionInfos)) {
                    for (WarehousePositionInfo warehousePositionInfo : warehousePositionInfos) {
                        //查询仓库内的货名
                        List<WarehousePositionStorageInfo> warehousePositionStorageInfos = warehousePositionStorageInfoService.selectList(new EntityWrapper<WarehousePositionStorageInfo>()
                                .eq("position_id", warehousePositionInfo.getId()));
                        if (!CollectionUtils.isEmpty(warehousePositionStorageInfos)) {
                            for (WarehousePositionStorageInfo warehousePositionStorageInfo : warehousePositionStorageInfos) {
                                //查询贸易仓单可用储量
                                Double useWeight = 0d;
                                List<TradeWarehouseReceiptAppl> tradeWarehouseReceiptAppls = tradeWarehouseReceiptApplService.selectList(new EntityWrapper<TradeWarehouseReceiptAppl>()
                                        .eq("warehouse_id", warehouseBaseInfo.getId())
                                        .eq("warehouse_no_id", warehousePositionInfo.getId())
                                        .eq("goods_name", warehousePositionStorageInfo.getGoodsName())
                                        .eq("status", "待还款"));
                                if (!CollectionUtils.isEmpty(tradeWarehouseReceiptAppls)) {
                                    for (int i = 0; i < tradeWarehouseReceiptAppls.size(); i++) {
                                        //待还仓单储量和
                                        useWeight = useWeight + tradeWarehouseReceiptAppls.get(i).getWeight();
                                    }
                                }
                                warehousePositionStorageInfo.setUseStorage(warehousePositionStorageInfo.getStorage() - useWeight);
                                temp.add(warehousePositionStorageInfo);
                            }
                        }
                    }
                    warehouseBaseInfo.setGoodsNameInfos(temp);
                    warehouseBaseInfo.setPositionInfos(warehousePositionInfos);
                }
            }

        }
        cacheComponent.putRaw(Const.SELF_WAREHOUSE+personCharge,JSONObject.toJSONString(warehouseBaseInfoList),60*60*24);
        return warehouseBaseInfoList;
    }

    @Override
    public WarehouseInOutInfo getPrintInfo(String id) {
        WarehouseInOutInfo warehouseInOutInfo = warehouseInOutInfoService.selectById(id);
        ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(
                new EntityWrapper<ContractManagementInfo>()
                        .eq("contract_no", warehouseInOutInfo.getContractNo())
                        .eq("delete_flag", 0));
        String compId = "";
        if (contractManagementInfo == null) {
            InOutWarehouseTask inOutWarehouseTask = iInOutWarehouseTaskService.selectOne(
                    new EntityWrapper<InOutWarehouseTask>()
                            .eq("move_task_no", warehouseInOutInfo.getContractNo())
                            .eq("in_out_flag", "1")
                            .eq("delete_flag", 0));
            contractManagementInfo = contractManagementInfoService.selectOne(
                    new EntityWrapper<ContractManagementInfo>()
                            .eq("contract_no", inOutWarehouseTask.getWarehouseName())
                            .eq("delete_flag", 0));
            if (contractManagementInfo != null) {
                warehouseInOutInfo.setContractManagementInfo(contractManagementInfo);
                compId = contractManagementInfo.getCompId();
            } else {
                compId = inOutWarehouseTask.getCompId();
                warehouseInOutInfo.setReceiveWarehouse(inOutWarehouseTask.getReceiveWarehouse());
            }
        } else {
            compId = contractManagementInfo.getCompId();
            warehouseInOutInfo.setContractManagementInfo(contractManagementInfo);
        }
        CommonCompany commonCompany = commonCompanyService.selectOne(new EntityWrapper<CommonCompany>()
                .eq("comp_id", compId)
                .eq("delete_flag", "0"));
        warehouseInOutInfo.setCompanyName(commonCompany.getCompName());
        WarehouseInOutDetail warehouseInOutDetail = warehouseInOutDetailService.selectOne(
                new EntityWrapper<WarehouseInOutDetail>()
                        .eq("info_id", warehouseInOutInfo.getId())
                        .eq("delete_flag", 0));
        warehouseInOutInfo.setWarehouseInOutDetail(warehouseInOutDetail);
        return warehouseInOutInfo;
    }

    @Override
    public Float selectCost(String contractNo, String carNo) {
        Float cost = 0f;
        String compId = "";
        if (compId == null || compId.isEmpty()) {
            compId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getCompId();
        }
        //采购合同
        ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                .eq("comp_id", compId)
                .eq("delete_flag", "0")
                .eq("contract_no", contractNo)
                .eq("contract_type", "2")
                .eq("status_flag", "1")
                .eq("deliver_type", "2"));
        if (contractManagementInfo != null) {
            cost = Float.valueOf(String.valueOf(contractManagementInfo.getUnitContractPrice()));
        }
        //移库任务编号
        InOutWarehouseTask inOutWarehouseTask = iInOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
                .eq("comp_id", compId)
                .eq("move_task_no", contractNo)
                .eq("delete_flag", "0")
                .eq("task_type_key", "3")
                .eq("in_out_flag", "1"));
        if (inOutWarehouseTask != null) {
            if ("移库出库".equals(inOutWarehouseTask.getInOutType())) {
                //自动创建的临时库移库，成本为对应的合同单价
                ContractManagementInfo contractManagementInfo1 = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                        .eq("comp_id", inOutWarehouseTask.getCompId())
                        .eq("contract_no", inOutWarehouseTask.getWarehouseName()));
                if (contractManagementInfo1 != null) {
                    cost = Float.valueOf(String.valueOf(contractManagementInfo1.getUnitContractPrice()));
                }
                //其他类型移库，一个运输阶段成本加权，多个成本为空
                TranTaskInfo tranTaskInfo = tranTaskInfoService.selectOne(new EntityWrapper<TranTaskInfo>()
                        .eq("comp_id", inOutWarehouseTask.getCompId())
                        .eq("contract_no", inOutWarehouseTask.getMoveTaskNo()));
                if (tranTaskInfo != null) {
                    List<TranProcessInfo> tranProcessInfoList = tranProcessInfoService.selectList(new EntityWrapper<TranProcessInfo>()
                            .eq("info_id", tranTaskInfo.getId()));
                    //只有一个汽运的运输阶段
                    if (tranProcessInfoList.size() == 1 && tranProcessInfoList.get(0).getTranTypeKey() == "1") {
                        //成本为所选车辆出库时所在库的加权成本
                        WarehouseInOutInfo warehouseInOutInfo = warehouseInOutInfoService.selectOne(new EntityWrapper<WarehouseInOutInfo>()
                                .eq("car_no", carNo).eq("comp_id", compId)
                                .eq("contract_no", contractNo));
                        if (warehouseInOutInfo != null) {
                            cost = warehouseInOutInfo.getWeightedCost();
                        }
                    }
                }
            } else if ("退库".equals(inOutWarehouseTask.getInOutType())) {
                //自动创建的临时库退库，成本为对应的合同单价
                ContractManagementInfo contractManagementInfo1 = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                        .eq("comp_id", inOutWarehouseTask.getCompId())
                        .eq("contract_no", inOutWarehouseTask.getWarehouseName()));
                if (contractManagementInfo1 != null) {
                    cost = Float.valueOf(String.valueOf(contractManagementInfo1.getUnitContractPrice()));
                }
            }
        }
        return cost;
    }

    /**
     * 查自己负责的仓库
     *
     * @param compId
     * @param personCharge
     * @return
     */
    @Override
    public List<WarehouseBaseInfo> selectResponsible(String compId, String personCharge) {
        if (compId == null || compId.isEmpty()) {
            compId = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getCompId();
        }
        if (personCharge == null || personCharge.isEmpty()) {
            personCharge = AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getStaffMobilePhone();
        }
        Wrapper<WarehouseBaseInfo> warehouseBaseInfoWrapper = new EntityWrapper<>();
        warehouseBaseInfoWrapper.eq("comp_id", compId).eq("delete_flag", "0");
        warehouseBaseInfoWrapper.andNew().eq("person_phone", personCharge).or()
                .like("other_person_charge", personCharge);
        List<WarehouseBaseInfo> warehouseBaseInfoList = this.selectList(warehouseBaseInfoWrapper);
        return warehouseBaseInfoList;
    }


    /**
     * 入库导出
     *
     * @param warehouseBaseInfo
     * @param response
     * @throws Exception
     */
    @Override
    public void export(WarehouseBaseInfo warehouseBaseInfo, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        // 1.Excel的头部信息
        String headerTitle = "";

        // 2.创建一个webbook 对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();

        // 3.在webbook中添加一个sheet，对应Excel文件中的sheet
        HSSFSheet sheet;

        sheet = wb.createSheet("付款信息");
        headerTitle = "付款信息";

        // 4.设置打印参数
        sheet.setMargin(HSSFSheet.TopMargin, (short) 1);// 页边距（上）
        sheet.setMargin(HSSFSheet.BottomMargin, (short) 1);// 页边距（下）
        sheet.setMargin(HSSFSheet.LeftMargin, (short) 1);// 页边距（左）
        sheet.setMargin(HSSFSheet.RightMargin, (short) 1);// 页边距（右）

        // 不显示网格
        sheet.setDisplayGridlines(false);
        // 设置水平居中
        sheet.setHorizontallyCenter(true);

        /**************** 数据行样式 start ****************/
        HSSFFont fontTitle = wb.createFont();
        fontTitle.setFontName("宋体");
        fontTitle.setFontHeightInPoints((short) 14);
        // 设置字体加粗
        fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontComp = wb.createFont();
        fontComp.setFontName("宋体");
        fontComp.setFontHeightInPoints((short) 16);
        // 设置字体加粗
        fontComp.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontDetail = wb.createFont();
        fontDetail.setFontName("宋体");
        fontDetail.setFontHeightInPoints((short) 12);

        HSSFFont fontDetail1 = wb.createFont();
        fontDetail1.setFontName("宋体");
        fontDetail1.setFontHeightInPoints((short) 12);
        fontDetail1.setColor(HSSFColor.RED.index);

        // title
        HSSFCellStyle styleTitle = wb.createCellStyle();
        // 指定单元格居中对齐
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleTitle.setWrapText(true);
        // 设置单元格字体
        styleTitle.setFont(fontTitle);
        // 右边框
        styleTitle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleTitle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleTitle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleTitle.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        // title
        HSSFCellStyle styleComp = wb.createCellStyle();
        // 指定单元格居中对齐
        styleComp.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleComp.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleComp.setWrapText(true);
        // 设置单元格字体
        styleComp.setFont(fontComp);
        // 右边框
        styleComp.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleComp.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleComp.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleComp.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleInfo = wb.createCellStyle();
        // 指定单元格居中对齐
        styleInfo.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleInfo.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleInfo.setWrapText(true);
        // 设置单元格字体
        styleInfo.setFont(fontDetail);
        // 右边框
        styleInfo.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleInfo.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleInfo.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleInfo.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleDetail = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail.setWrapText(true);
        // 设置单元格字体
        styleDetail.setFont(fontDetail);
        // 右边框
        styleDetail.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetail1 = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail1.setWrapText(true);
        // 设置单元格字体
        styleDetail1.setFont(fontDetail1);
        // 右边框
        styleDetail1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle1 = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle1.setWrapText(true);
        // 设置单元格字体
        contextstyle1.setFont(fontDetail1);
        // 右边框
        contextstyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);


        HSSFCellStyle contextstyle2 = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle2.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle2.setWrapText(true);
        // 设置单元格字体
        contextstyle2.setFont(fontDetail1);
        // 右边框
        contextstyle2.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle2.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle2.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle2.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle.setWrapText(true);
        // 设置单元格字体
        contextstyle.setFont(fontDetail);
        // 右边框
        contextstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetailYellow = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailYellow.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetailYellow.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailYellow.setWrapText(true);
        // 设置单元格字体
        styleDetailYellow.setFont(fontDetail);
        // 右边框
        styleDetailYellow.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailYellow.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailYellow.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailYellow.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleDetailYellow.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
        styleDetailYellow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);


        HSSFCellStyle styleDetailLeft = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleDetailLeft.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailLeft.setWrapText(true);
        // 设置单元格字体
        styleDetailLeft.setFont(fontDetail);
        // 右边框
        styleDetailLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailLeft.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        /**************** 数据行样式 end ****************/

        // 设置列宽
        sheet.setColumnWidth(0, 1 * 256 + 184);
        sheet.setColumnWidth(1, "采购公司".getBytes().length * 3 * 256);
        sheet.setColumnWidth(2, "收货仓库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(3, 12 * 256 + 184);
        sheet.setColumnWidth(4, "开票日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(5, "合同编号".getBytes().length * 2 * 256);
        sheet.setColumnWidth(6, "业务编号".getBytes().length * 2 * 256);
        sheet.setColumnWidth(7, 12 * 256 + 184);
        sheet.setColumnWidth(8, 12 * 256 + 184);
        sheet.setColumnWidth(9, 12 * 256 + 184);
        sheet.setColumnWidth(10, "货名".getBytes().length * 3 * 256);
        sheet.setColumnWidth(11, 12 * 256 + 184);
        sheet.setColumnWidth(12, 12 * 256 + 184);
        sheet.setColumnWidth(13, 12 * 256 + 184);
        sheet.setColumnWidth(14, 12 * 256 + 184);
        sheet.setColumnWidth(15, 12 * 256 + 184);
        sheet.setColumnWidth(16, 12 * 256 + 184);
        sheet.setColumnWidth(17, 12 * 256 + 184);
        sheet.setColumnWidth(18, 12 * 256 + 184);
        sheet.setColumnWidth(19, 12 * 256 + 184);
        sheet.setColumnWidth(20, 12 * 256 + 184);
        sheet.setColumnWidth(21, 12 * 256 + 184);
        sheet.setColumnWidth(22, 12 * 256 + 184);
        sheet.setColumnWidth(23, 12 * 256 + 184);
        sheet.setColumnWidth(24, 12 * 256 + 184);
        sheet.setColumnWidth(25, 12 * 256 + 184);
        sheet.setColumnWidth(26, 12 * 256 + 184);
        sheet.setColumnWidth(27, 12 * 256 + 184);
        sheet.setColumnWidth(28, 12 * 256 + 184);
        sheet.setColumnWidth(29, 12 * 256 + 184);
        sheet.setColumnWidth(30, 12 * 256 + 184);
        sheet.setColumnWidth(31, 12 * 256 + 184);
        sheet.setColumnWidth(32, 12 * 256 + 184);
        sheet.setColumnWidth(33, "发货库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(34, 12 * 256 + 184);
        sheet.setColumnWidth(35, 12 * 256 + 184);
        sheet.setColumnWidth(36, 12 * 256 + 184);
        sheet.setColumnWidth(37, 12 * 256 + 184);
        sheet.setColumnWidth(38, 12 * 256 + 184);
        sheet.setColumnWidth(39, "合计应付".getBytes().length * 2 * 256);
        sheet.setColumnWidth(40, 12 * 256 + 184);
        sheet.setColumnWidth(41, 12 * 256 + 184);
        sheet.setColumnWidth(42, "卡号".getBytes().length * 4 * 256);
        sheet.setColumnWidth(43, "开户支行".getBytes().length * 4 * 256);
        sheet.setColumnWidth(44, 1 * 256 + 184);

        // 创建单元格对象
        HSSFCell cell = null;

        // 创建打印设置对象
        HSSFPrintSetup ps = sheet.getPrintSetup();
        // 打印方向，true：横向，false：纵向(默认)
        ps.setLandscape(false);
        // // 打印质量
        // ps.setVResolution((short) 700)
        // 设置缩放比例
        ps.setScale((short) 80);
        // 纸张类型
        ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);


        int rownum = 1;
        HSSFRow row0 = sheet.createRow((int) rownum);
        row0.setHeightInPoints(25);
        cell = row0.createCell(1);
        cell.setCellStyle(styleTitle);
        cell.setCellValue("入库记录");
        sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, (short) 1, (short) 22));
        cell = row0.createCell(2);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(3);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(4);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(5);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(6);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(7);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(8);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(9);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(10);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(11);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(12);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(13);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(14);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(15);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(16);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(17);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(18);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(19);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(20);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(21);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(22);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(23);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(24);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(25);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(26);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(23);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(28);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(29);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(30);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(31);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(32);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(33);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(34);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(35);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(36);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(37);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(38);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(39);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(40);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(41);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(42);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(43);
        cell.setCellStyle(styleTitle);
        rownum++;

        Double waterContentTotal = 0d;//水分合计
        Double impurityTotal = 0d;//杂质合计
        Double mildewGrainTotal = 0d;//霉变粒合计
        Double imperfectGrainTotal = 0d;//不完善粒合计
        Double bulkDensityTotal = 0d;//容重合计
        Double jiaorenliTotal = 0d;//热损伤合计
        Double carTotal = 0d;//车数合计
        Double netWeightTotal = 0d;//净重合计
        Double amountIngPayableTotal = 0d;//合计应付合计
        Double netWeightTmp = 0d;//合计应付合计
        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
        pageView.put("startDate", warehouseBaseInfo.getStartDate());
        pageView.put("endDate", warehouseBaseInfo.getEndDate());
        pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
        // 查询入库记录总数
        List<ExportVView> dataList = baseMapper.getListByCondition(pageView);
        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                HSSFRow rowx = sheet.createRow((int) rownum);
                rowx.setHeightInPoints(20);
                if(!StringUtils.isEmpty(exportVView.getWaterContent())
                        &&!StringUtils.isEmpty(exportVView.getImpurity())
                        &&!StringUtils.isEmpty(exportVView.getMildewGrain())
                        &&!StringUtils.isEmpty(exportVView.getImperfectGrain())
                        &&!StringUtils.isEmpty(exportVView.getBulkDensity())
                        &&!StringUtils.isEmpty(exportVView.getJiaorenli())){
                    //水分累计和
                    netWeightTmp = netWeightTmp + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                }
                //水分累计和
                waterContentTotal = waterContentTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getWaterContent()) ? exportVView.getWaterContent() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                impurityTotal = impurityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImpurity()) ? exportVView.getImpurity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                mildewGrainTotal = mildewGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getMildewGrain()) ? exportVView.getMildewGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                imperfectGrainTotal = imperfectGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImperfectGrain()) ? exportVView.getImperfectGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                bulkDensityTotal = bulkDensityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getBulkDensity()) ? exportVView.getBulkDensity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                jiaorenliTotal = jiaorenliTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getJiaorenli()) ? exportVView.getJiaorenli() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
//                netWeightPriceTotal = netWeightPriceTotal + (Double.valueOf(String.valueOf(exportVView.getNetWeightPrice()!=null?exportVView.getNetWeightPrice():"0")));
                netWeightTotal = netWeightTotal + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                amountIngPayableTotal = amountIngPayableTotal + (exportVView.getAmountIngPayable()!=null ? exportVView.getAmountIngPayable() : 0);
            }
        }

        HSSFRow rowp = sheet.createRow((int) (rownum));
        rowp.setHeightInPoints(20);
        HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
        contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
        HSSFDataFormat df2 = wb.createDataFormat(); // 此处设置数据格式
        contextstyle2.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,###0.000"));//保留三位小数点
        cell = rowp.createCell(1);
        cell.setCellValue("平均值/合计");
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(2);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(3);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(4);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(5);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(6);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(7);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(8);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(9);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(10);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(11);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(12);
        cell.setCellStyle(styleDetail);
        //水分平均值
        cell = rowp.createCell(13);
        cell.setCellValue(bulkDensityTotal / netWeightTmp);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(14);
        cell.setCellValue(waterContentTotal / netWeightTmp);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(15);
        cell.setCellValue(mildewGrainTotal / netWeightTmp);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(16);
        cell.setCellValue(impurityTotal / netWeightTmp);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(17);
        cell.setCellValue(jiaorenliTotal / netWeightTmp);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(18);
        cell.setCellValue(imperfectGrainTotal / netWeightTmp);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(19);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(20);
        cell.setCellValue(dataList.size());
        cell.setCellStyle(styleDetail1);
        cell = rowp.createCell(21);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(22);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(23);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(24);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(25);
        cell.setCellValue(amountIngPayableTotal / netWeightTotal);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(26);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(27);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(28);
        cell.setCellStyle(styleDetail);
        //纯重合计
        cell = rowp.createCell(29);
        cell.setCellValue(netWeightTotal);
        cell.setCellStyle(contextstyle2);
        cell = rowp.createCell(30);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(31);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(32);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(33);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(34);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(35);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(36);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(37);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(38);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(39);
        cell.setCellValue(amountIngPayableTotal);
        cell.setCellStyle(contextstyle1);
        cell = rowp.createCell(40);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(41);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(42);
        cell.setCellStyle(styleDetail);
        cell = rowp.createCell(43);
        cell.setCellStyle(styleDetail);
        rownum++;

        HSSFRow row1 = sheet.createRow((int) rownum);
        row1.setHeightInPoints(30);
        cell = row1.createCell(1);
        cell.setCellValue("采购公司");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(2);
        cell.setCellValue("收货仓库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(3);
        cell.setCellValue("仓位号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(4);
        cell.setCellValue("开票日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(5);
        cell.setCellValue("合同编号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(6);
        cell.setCellValue("业务编号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(7);
        cell.setCellValue("入库类型");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(8);
        cell.setCellValue("客户");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(9);
        cell.setCellValue("供应商");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(10);
        cell.setCellValue("货名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(11);
        cell.setCellValue("类型");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(12);
        cell.setCellValue("等级");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(13);
        cell.setCellValue("容重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(14);
        cell.setCellValue("水分");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(15);
        cell.setCellValue("霉变粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(16);
        cell.setCellValue("杂质");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(17);
        cell.setCellValue("热损伤");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(18);
        cell.setCellValue("不完善粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(19);
        cell.setCellValue("车牌号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(20);
        cell.setCellValue("车数");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(21);
        cell.setCellValue("箱号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(22);
        cell.setCellValue("箱号2");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(23);
        cell.setCellValue("封号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(24);
        cell.setCellValue("封号2");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(25);
        cell.setCellValue("净重单价");
        cell.setCellStyle(contextstyle);
        cell = row1.createCell(26);
        cell.setCellValue("毛重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(27);
        cell.setCellValue("皮重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(28);
        cell.setCellValue("扣重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(29);
        cell.setCellValue("净重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(30);
        cell.setCellValue("发货毛重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(31);
        cell.setCellValue("发货皮重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(32);
        cell.setCellValue("发货净重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(33);
        cell.setCellValue("发货库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(34);
        cell.setCellValue("运输单价");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(35);
        cell.setCellValue("运费");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(36);
        cell.setCellValue("扣单价");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(37);
        cell.setCellValue("纯重单价");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(38);
        cell.setCellValue("纯重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(39);
        cell.setCellValue("合计应付");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(40);
        cell.setCellValue("实付金额");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(41);
        cell.setCellValue("姓名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(42);
        cell.setCellValue("卡号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(43);
        cell.setCellValue("开户支行");
        cell.setCellStyle(styleDetail);


        rownum++;
        DecimalFormat decimalFormat = new DecimalFormat(".00");
//        Map<String, Object> pageView = new HashMap<>();
//        //  公司ID
//        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
//        pageView.put("startDate", warehouseBaseInfo.getStartDate());
//        pageView.put("endDate", warehouseBaseInfo.getEndDate());
//        pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
//        // 查询入库记录总数
//        List<ExportVView> dataList = baseMapper.getListByCondition(pageView);
        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                HSSFRow rowx = sheet.createRow((int) rownum);
                rowx.setHeightInPoints(20);
                cell = rowx.createCell(1);
                cell.setCellValue(exportVView.getCompName());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(2);
                cell.setCellValue(editString(exportVView.getWarehouseName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(3);
                cell.setCellValue(editString(exportVView.getBinNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(4);
                String date = addDateOneDay(exportVView.getCreateDate());
                cell.setCellValue(date);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(5);
                if ("移库入库".equals(exportVView.getInOutType())) {
                    cell.setCellValue(editString(exportVView.getSendWarehouse()));
                } else {
                    cell.setCellValue(editString(exportVView.getContractNo()));
                }
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(6);
                cell.setCellValue(editString(exportVView.getPaymentNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(7);
                cell.setCellValue(editString(exportVView.getInOutType()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(8);
                cell.setCellValue(editString(exportVView.getCustomerName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(9);
                cell.setCellValue(editString(exportVView.getSupplier()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(10);
                cell.setCellValue(editString(exportVView.getGoodsName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(11);
                cell.setCellValue(editString(exportVView.getType()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(12);
                cell.setCellValue(editString(exportVView.getGrade()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(13);
                if (!StringUtils.isEmpty(exportVView.getBulkDensity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getBulkDensity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(14);
                if (!StringUtils.isEmpty(exportVView.getWaterContent())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getWaterContent()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(15);
                if (!StringUtils.isEmpty(exportVView.getMildewGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getMildewGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(16);
                if (!StringUtils.isEmpty(exportVView.getImpurity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImpurity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(17);
                if (!StringUtils.isEmpty(exportVView.getJiaorenli())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getJiaorenli()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(18);
                if (!StringUtils.isEmpty(exportVView.getImperfectGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImperfectGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(19);
                cell.setCellValue(editString(exportVView.getCarNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(20);
                cell.setCellValue("1");
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(21);
                cell.setCellValue(editString(exportVView.getBoxNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(22);
                cell.setCellValue(editString(exportVView.getBoxNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(23);
                cell.setCellValue(editString(exportVView.getTitleNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(24);
                cell.setCellValue(editString(exportVView.getTitleNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(25);
                cell.setCellValue(Double.parseDouble(exportVView.getNetWeightPrice() != null ? exportVView.getNetWeightPrice() : "0"));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(26);
                HSSFDataFormat df = wb.createDataFormat(); // 此处设置数据格式
                contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                HSSFDataFormat df3 = wb.createDataFormat(); // 此处设置数据格式
                contextstyle2.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,###0.000"));//保留两位小数点
                if (exportVView.getGrossWeight() != null) {
                    cell.setCellValue(editDouble(exportVView.getGrossWeight()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(27);
                if (exportVView.getTare() != null) {
                    cell.setCellValue(editDouble(exportVView.getTare()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(28);
                cell.setCellValue(editFloat(exportVView.getBuckleWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(29);
                cell.setCellValue(Double.parseDouble(exportVView.getNetWeight()));
                cell.setCellStyle(contextstyle2);
                cell = rowx.createCell(30);
                cell.setCellValue(editDouble(exportVView.getDeliveryGrossWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(31);
                cell.setCellValue(editDouble(exportVView.getDeliveryTare()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(32);
                cell.setCellValue(editDouble(exportVView.getDeliveryVolume()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(33);
                cell.setCellValue(editString(exportVView.getSendWarehouse()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(34);
                cell.setCellValue(new Formatter().format("%.2f", editDouble(exportVView.getTranPrice())).toString());
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(35);
                cell.setCellValue(editFloat(exportVView.getFreight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(36);
                cell.setCellValue(editDouble(exportVView.getUnitDeduction()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(37);
                cell.setCellValue(new Formatter().format("%.3f", editDouble(exportVView.getPureWeightPrice())).toString());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(38);
                cell.setCellValue(editFloat(exportVView.getPureWeight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(39);
                cell.setCellValue(editDouble(exportVView.getAmountIngPayable()!=null ? exportVView.getAmountIngPayable() : 0));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(40);
                cell.setCellValue(new Formatter().format("%.2f", editDouble(exportVView.getAmountEdPayable())).toString());
//                cell.setCellValue(editDouble(exportVView.getAmountEdPayable()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(41);
                cell.setCellValue(editString(exportVView.getCustomerName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(42);
                cell.setCellValue(editString(exportVView.getCardNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(43);
                cell.setCellValue(editString(exportVView.getBankDeposit() + "-" + exportVView.getBankDepositBranch()));
                cell.setCellStyle(styleDetail);

                rownum++;
            }

        }


        String path = null;
        String tempPath = null;
        String excelPath = null;

        try {

            // 取得绝对路径
            tempPath = URLDecoder.decode((localPath), "utf-8");

            // EXCEL路径
            excelPath = "/web/temp/pay/" + DateUtil.formatDate(new Date(), DateUtils.DATE_FMT_YYYYMMDD_NS) + '/'
                    + UUID.randomUUID().toString().replaceAll("-", "");

            path = tempPath + excelPath + '/' + "合同信息"
                    + ".xlsx";

        } catch (Exception e) {
            log.debug(e.getMessage());
        }
        // 下载
        download(path, response, wb);

    }


    /**
     * 入库导出手机
     *
     * @param warehouseBaseInfo
     * @param response
     * @throws Exception
     */
    @Override
    public String exportphone(WarehouseBaseInfo warehouseBaseInfo, HttpServletResponse response) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        // 1.Excel的头部信息
        String headerTitle = "";

        // 2.创建一个webbook 对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();

        // 3.在webbook中添加一个sheet，对应Excel文件中的sheet
        HSSFSheet sheet;

        sheet = wb.createSheet("付款信息");
        headerTitle = "付款信息";

        // 4.设置打印参数
        sheet.setMargin(HSSFSheet.TopMargin, (short) 1);// 页边距（上）
        sheet.setMargin(HSSFSheet.BottomMargin, (short) 1);// 页边距（下）
        sheet.setMargin(HSSFSheet.LeftMargin, (short) 1);// 页边距（左）
        sheet.setMargin(HSSFSheet.RightMargin, (short) 1);// 页边距（右）

        // 不显示网格
        sheet.setDisplayGridlines(false);
        // 设置水平居中
        sheet.setHorizontallyCenter(true);

        /**************** 数据行样式 start ****************/
        HSSFFont fontTitle = wb.createFont();
        fontTitle.setFontName("宋体");
        fontTitle.setFontHeightInPoints((short) 14);
        // 设置字体加粗
        fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontComp = wb.createFont();
        fontComp.setFontName("宋体");
        fontComp.setFontHeightInPoints((short) 16);
        // 设置字体加粗
        fontComp.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontDetail = wb.createFont();
        fontDetail.setFontName("宋体");
        fontDetail.setFontHeightInPoints((short) 12);

        HSSFFont fontDetail1 = wb.createFont();
        fontDetail1.setFontName("宋体");
        fontDetail1.setFontHeightInPoints((short) 12);
        fontDetail1.setColor(HSSFColor.RED.index);

        // title
        HSSFCellStyle styleTitle = wb.createCellStyle();
        // 指定单元格居中对齐
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleTitle.setWrapText(true);
        // 设置单元格字体
        styleTitle.setFont(fontTitle);
        // 右边框
        styleTitle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleTitle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleTitle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleTitle.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        // title
        HSSFCellStyle styleComp = wb.createCellStyle();
        // 指定单元格居中对齐
        styleComp.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleComp.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleComp.setWrapText(true);
        // 设置单元格字体
        styleComp.setFont(fontComp);
        // 右边框
        styleComp.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleComp.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleComp.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleComp.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleInfo = wb.createCellStyle();
        // 指定单元格居中对齐
        styleInfo.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleInfo.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleInfo.setWrapText(true);
        // 设置单元格字体
        styleInfo.setFont(fontDetail);
        // 右边框
        styleInfo.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleInfo.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleInfo.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleInfo.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleDetail = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail.setWrapText(true);
        // 设置单元格字体
        styleDetail.setFont(fontDetail);
        // 右边框
        styleDetail.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetail1 = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail1.setWrapText(true);
        // 设置单元格字体
        styleDetail1.setFont(fontDetail1);
        // 右边框
        styleDetail1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle.setWrapText(true);
        // 设置单元格字体
        contextstyle.setFont(fontDetail);
        // 右边框
        contextstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle1 = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle1.setWrapText(true);
        // 设置单元格字体
        contextstyle1.setFont(fontDetail1);
        // 右边框
        contextstyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetailYellow = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailYellow.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetailYellow.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailYellow.setWrapText(true);
        // 设置单元格字体
        styleDetailYellow.setFont(fontDetail);
        // 右边框
        styleDetailYellow.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailYellow.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailYellow.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailYellow.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleDetailYellow.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
        styleDetailYellow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);


        HSSFCellStyle styleDetailLeft = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleDetailLeft.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailLeft.setWrapText(true);
        // 设置单元格字体
        styleDetailLeft.setFont(fontDetail);
        // 右边框
        styleDetailLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailLeft.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        /**************** 数据行样式 end ****************/

        // 设置列宽
        sheet.setColumnWidth(0, 1 * 256 + 184);
        sheet.setColumnWidth(1, "采购公司".getBytes().length * 3 * 256);
        sheet.setColumnWidth(2, "收货仓库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(3, 12 * 256 + 184);
        sheet.setColumnWidth(4, "开票日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(5, "合同编号".getBytes().length * 2 * 256);
        sheet.setColumnWidth(6, "业务编号".getBytes().length * 2 * 256);
        sheet.setColumnWidth(7, 12 * 256 + 184);
        sheet.setColumnWidth(8, 12 * 256 + 184);
        sheet.setColumnWidth(9, 12 * 256 + 184);
        sheet.setColumnWidth(10, "货名".getBytes().length * 3 * 256);
        sheet.setColumnWidth(11, 12 * 256 + 184);
        sheet.setColumnWidth(12, 12 * 256 + 184);
        sheet.setColumnWidth(13, 12 * 256 + 184);
        sheet.setColumnWidth(14, 12 * 256 + 184);
        sheet.setColumnWidth(15, 12 * 256 + 184);
        sheet.setColumnWidth(16, 12 * 256 + 184);
        sheet.setColumnWidth(17, 12 * 256 + 184);
        sheet.setColumnWidth(18, 12 * 256 + 184);
        sheet.setColumnWidth(19, 12 * 256 + 184);
        sheet.setColumnWidth(20, 12 * 256 + 184);
        sheet.setColumnWidth(21, 12 * 256 + 184);
        sheet.setColumnWidth(22, 12 * 256 + 184);
        sheet.setColumnWidth(23, 12 * 256 + 184);
        sheet.setColumnWidth(24, 12 * 256 + 184);
        sheet.setColumnWidth(25, 12 * 256 + 184);
        sheet.setColumnWidth(26, 12 * 256 + 184);
        sheet.setColumnWidth(27, 12 * 256 + 184);
        sheet.setColumnWidth(28, 12 * 256 + 184);
        sheet.setColumnWidth(29, 12 * 256 + 184);
        sheet.setColumnWidth(30, 12 * 256 + 184);
        sheet.setColumnWidth(31, 12 * 256 + 184);
        sheet.setColumnWidth(32, 12 * 256 + 184);
        sheet.setColumnWidth(33, "发货库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(34, 12 * 256 + 184);
        sheet.setColumnWidth(35, 12 * 256 + 184);
        sheet.setColumnWidth(36, 12 * 256 + 184);
        sheet.setColumnWidth(37, 12 * 256 + 184);
        sheet.setColumnWidth(38, 12 * 256 + 184);
        sheet.setColumnWidth(39, "合计应付".getBytes().length * 2 * 256);
        sheet.setColumnWidth(40, 12 * 256 + 184);
        sheet.setColumnWidth(41, 12 * 256 + 184);
        sheet.setColumnWidth(42, "卡号".getBytes().length * 4 * 256);
        sheet.setColumnWidth(43, "开户支行".getBytes().length * 4 * 256);
        sheet.setColumnWidth(44, 1 * 256 + 184);

        // 创建单元格对象
        HSSFCell cell = null;

        // 创建打印设置对象
        HSSFPrintSetup ps = sheet.getPrintSetup();
        // 打印方向，true：横向，false：纵向(默认)
        ps.setLandscape(false);
        // // 打印质量
        // ps.setVResolution((short) 700)
        // 设置缩放比例
        ps.setScale((short) 80);
        // 纸张类型
        ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);


        int rownum = 1;
        HSSFRow row0 = sheet.createRow((int) rownum);
        row0.setHeightInPoints(25);
        cell = row0.createCell(1);
        cell.setCellStyle(styleTitle);
        cell.setCellValue("入库记录");
        sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, (short) 1, (short) 22));
        cell = row0.createCell(2);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(3);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(4);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(5);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(6);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(7);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(8);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(9);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(10);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(11);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(12);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(13);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(14);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(15);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(16);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(17);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(18);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(19);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(20);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(21);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(22);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(23);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(24);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(25);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(26);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(23);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(28);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(29);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(30);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(31);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(32);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(33);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(34);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(35);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(36);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(37);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(38);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(39);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(40);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(41);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(42);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(43);
        cell.setCellStyle(styleTitle);
        rownum++;

        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
        pageView.put("startDate", warehouseBaseInfo.getStartDate());
        pageView.put("endDate", warehouseBaseInfo.getEndDate());
        pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
        // 查询入库记录总数
        List<ExportVView> dataList = baseMapper.getListByCondition(pageView);
        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            Double waterContentTotal = 0d;//水分合计
            Double impurityTotal = 0d;//杂质合计
            Double mildewGrainTotal = 0d;//霉变粒合计
            Double imperfectGrainTotal = 0d;//不完善粒合计
            Double bulkDensityTotal = 0d;//容重合计
            Double jiaorenliTotal = 0d;//热损伤合计
            Double carTotal = 0d;//车数合计
            Double netWeightTotal = 0d;//净重合计
            Double amountIngPayableTotal = 0d;//合计应付合计
            Double netWeightTmp = 0d;//合计应付合计
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                HSSFRow rowx = sheet.createRow((int) rownum);
                rowx.setHeightInPoints(20);
                if(!StringUtils.isEmpty(exportVView.getWaterContent())
                        &&!StringUtils.isEmpty(exportVView.getImpurity())
                        &&!StringUtils.isEmpty(exportVView.getMildewGrain())
                        &&!StringUtils.isEmpty(exportVView.getImperfectGrain())
                        &&!StringUtils.isEmpty(exportVView.getBulkDensity())
                        &&!StringUtils.isEmpty(exportVView.getJiaorenli())){
                    //水分累计和
                    netWeightTmp = netWeightTmp + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                }
                //水分累计和
                waterContentTotal = waterContentTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getWaterContent()) ? exportVView.getWaterContent() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                impurityTotal = impurityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImpurity()) ? exportVView.getImpurity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                mildewGrainTotal = mildewGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getMildewGrain()) ? exportVView.getMildewGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                imperfectGrainTotal = imperfectGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImperfectGrain()) ? exportVView.getImperfectGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                bulkDensityTotal = bulkDensityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getBulkDensity()) ? exportVView.getBulkDensity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                jiaorenliTotal = jiaorenliTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getJiaorenli()) ? exportVView.getJiaorenli() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
//                netWeightPriceTotal = netWeightPriceTotal + (Double.valueOf(String.valueOf(exportVView.getNetWeightPrice()!=null?exportVView.getNetWeightPrice():"0")));
                netWeightTotal = netWeightTotal + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                amountIngPayableTotal = amountIngPayableTotal + (exportVView.getAmountIngPayable()!=null ? exportVView.getAmountIngPayable() : 0);
            }
            HSSFRow rowp = sheet.createRow((int) (rownum));
            rowp.setHeightInPoints(20);
            HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
            contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
            cell = rowp.createCell(1);
            cell.setCellValue("平均值/合计");
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(2);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(3);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(4);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(5);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(6);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(7);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(8);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(9);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(10);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(11);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(12);
            cell.setCellStyle(styleDetail);
            //水分平均值
            cell = rowp.createCell(13);
            cell.setCellValue(waterContentTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(14);
            cell.setCellValue(impurityTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(15);
            cell.setCellValue(mildewGrainTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(16);
            cell.setCellValue(imperfectGrainTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(17);
            cell.setCellValue(bulkDensityTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(18);
            cell.setCellValue(jiaorenliTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(19);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(20);
            cell.setCellValue(dataList.size());
            cell.setCellStyle(styleDetail1);
            cell = rowp.createCell(21);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(22);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(23);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(24);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(25);
            cell.setCellValue(amountIngPayableTotal / netWeightTotal);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(26);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(27);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(28);
            cell.setCellStyle(styleDetail);
            //纯重合计
            cell = rowp.createCell(29);
            cell.setCellValue(netWeightTotal);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(30);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(31);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(32);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(33);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(34);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(35);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(36);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(37);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(38);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(39);
            cell.setCellValue(amountIngPayableTotal);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(40);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(41);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(42);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(43);
            cell.setCellStyle(styleDetail);
            rownum++;
        }

        HSSFRow row1 = sheet.createRow((int) rownum);
        row1.setHeightInPoints(30);
        cell = row1.createCell(1);
        cell.setCellValue("采购公司");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(2);
        cell.setCellValue("收货仓库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(3);
        cell.setCellValue("仓位号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(4);
        cell.setCellValue("开票日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(5);
        cell.setCellValue("合同编号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(6);
        cell.setCellValue("业务编号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(7);
        cell.setCellValue("入库类型");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(8);
        cell.setCellValue("客户");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(9);
        cell.setCellValue("供应商");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(10);
        cell.setCellValue("货名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(11);
        cell.setCellValue("类型");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(12);
        cell.setCellValue("等级");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(13);
        cell.setCellValue("水分");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(14);
        cell.setCellValue("杂质");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(15);
        cell.setCellValue("霉变粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(16);
        cell.setCellValue("不完善粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(17);
        cell.setCellValue("容重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(18);
        cell.setCellValue("热损伤");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(19);
        cell.setCellValue("车牌号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(20);
        cell.setCellValue("车数");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(21);
        cell.setCellValue("箱号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(22);
        cell.setCellValue("箱号2");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(23);
        cell.setCellValue("封号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(24);
        cell.setCellValue("封号2");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(25);
        cell.setCellValue("净重单价");
        cell.setCellStyle(contextstyle);
        cell = row1.createCell(26);
        cell.setCellValue("毛重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(27);
        cell.setCellValue("皮重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(28);
        cell.setCellValue("扣重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(29);
        cell.setCellValue("净重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(30);
        cell.setCellValue("发货毛重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(31);
        cell.setCellValue("发货皮重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(32);
        cell.setCellValue("发货净重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(33);
        cell.setCellValue("发货库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(34);
        cell.setCellValue("运输单价");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(35);
        cell.setCellValue("运费");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(36);
        cell.setCellValue("扣单价");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(37);
        cell.setCellValue("纯重单价");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(38);
        cell.setCellValue("纯重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(39);
        cell.setCellValue("合计应付");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(40);
        cell.setCellValue("实付金额");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(41);
        cell.setCellValue("姓名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(42);
        cell.setCellValue("卡号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(43);
        cell.setCellValue("开户支行");
        cell.setCellStyle(styleDetail);


        rownum++;
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                HSSFRow rowx = sheet.createRow((int) rownum);
                rowx.setHeightInPoints(20);
                cell = rowx.createCell(1);
                cell.setCellValue(exportVView.getCompName());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(2);
                cell.setCellValue(editString(exportVView.getWarehouseName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(3);
                cell.setCellValue(editString(exportVView.getBinNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(4);
                String date = addDateOneDay(exportVView.getCreateDate());
                cell.setCellValue(date);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(5);
                if ("移库入库".equals(exportVView.getInOutType())) {
                    cell.setCellValue(editString(exportVView.getSendWarehouse()));
                } else {
                    cell.setCellValue(editString(exportVView.getContractNo()));
                }
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(6);
                cell.setCellValue(editString(exportVView.getPaymentNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(7);
                cell.setCellValue(editString(exportVView.getInOutType()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(8);
                cell.setCellValue(editString(exportVView.getCustomerName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(9);
                cell.setCellValue(editString(exportVView.getSupplier()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(10);
                cell.setCellValue(editString(exportVView.getGoodsName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(11);
                cell.setCellValue(editString(exportVView.getType()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(12);
                cell.setCellValue(editString(exportVView.getGrade()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(13);
                if (!StringUtils.isEmpty(exportVView.getWaterContent())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getWaterContent()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(14);
                if (!StringUtils.isEmpty(exportVView.getImpurity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImpurity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(15);
                if (!StringUtils.isEmpty(exportVView.getMildewGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getMildewGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(16);
                if (!StringUtils.isEmpty(exportVView.getImperfectGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImperfectGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(17);
                if (!StringUtils.isEmpty(exportVView.getBulkDensity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getBulkDensity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(18);
                if (!StringUtils.isEmpty(exportVView.getJiaorenli())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getJiaorenli()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(19);
                cell.setCellValue(editString(exportVView.getCarNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(20);
                cell.setCellValue("1");
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(21);
                cell.setCellValue(editString(exportVView.getBoxNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(22);
                cell.setCellValue(editString(exportVView.getBoxNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(23);
                cell.setCellValue(editString(exportVView.getTitleNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(24);
                cell.setCellValue(editString(exportVView.getTitleNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(25);
                cell.setCellValue(Double.parseDouble(exportVView.getNetWeightPrice() != null ? exportVView.getNetWeightPrice() : "0"));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(26);
                HSSFDataFormat df = wb.createDataFormat(); // 此处设置数据格式
                contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
                contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                cell.setCellValue(editDouble(exportVView.getGrossWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(27);
                cell.setCellValue(editDouble(exportVView.getTare()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(28);
                cell.setCellValue(editFloat(exportVView.getBuckleWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(29);
                cell.setCellValue(Double.parseDouble(exportVView.getNetWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(30);
                cell.setCellValue(editDouble(exportVView.getDeliveryGrossWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(31);
                cell.setCellValue(editDouble(exportVView.getDeliveryTare()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(32);
                cell.setCellValue(editDouble(exportVView.getDeliveryVolume()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(33);
                cell.setCellValue(editString(exportVView.getSendWarehouse()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(34);
                cell.setCellValue(new Formatter().format("%.2f", editDouble(exportVView.getTranPrice())).toString());
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(35);
                cell.setCellValue(editFloat(exportVView.getFreight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(36);
                cell.setCellValue(editDouble(exportVView.getUnitDeduction()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(37);
                cell.setCellValue(new Formatter().format("%.3f", editDouble(exportVView.getPureWeightPrice())).toString());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(38);
                cell.setCellValue(editFloat(exportVView.getPureWeight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(39);
                cell.setCellValue(editDouble(exportVView.getAmountIngPayable()!=null ? exportVView.getAmountIngPayable() : 0));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(40);
                cell.setCellValue(new Formatter().format("%.2f", editDouble(exportVView.getAmountEdPayable())).toString());
//                cell.setCellValue(editDouble(exportVView.getAmountEdPayable()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(41);
                cell.setCellValue(editString(exportVView.getCustomerName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(42);
                cell.setCellValue(editString(exportVView.getCardNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(43);
                cell.setCellValue(editString(exportVView.getBankDeposit() + "-" + exportVView.getBankDepositBranch()));
                cell.setCellStyle(styleDetail);

                rownum++;
            }
        }


        String path = null;
        String tempPath = null;
        String excelPath = null;

        try {

            // 取得绝对路径
            tempPath = URLDecoder.decode((localPath), "utf-8");

            // EXCEL路径
            excelPath = "/web/temp/pay/" + DateUtil.formatDate(new Date(), DateUtils.DATE_FMT_YYYYMMDD_NS) + '/'
                    + UUID.randomUUID().toString().replaceAll("-", "");

            path = tempPath + excelPath + '/' + "合同信息"
                    + ".xlsx";

        } catch (Exception e) {
            log.debug(e.getMessage());
        }
        // 下载
        return downloadPhone(path, response, wb);

    }


    /**
     * 导出出库
     *
     * @param warehouseBaseInfo
     * @param response
     * @throws Exception
     */
    @Override
    public void exportOut(WarehouseBaseInfo warehouseBaseInfo, HttpServletResponse response) throws Exception {

        // 1.Excel的头部信息
        String headerTitle = "";

        // 2.创建一个webbook 对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();

        // 3.在webbook中添加一个sheet，对应Excel文件中的sheet
        HSSFSheet sheet;

        sheet = wb.createSheet("出库记录");
        headerTitle = "出库记录";

        // 4.设置打印参数
        sheet.setMargin(HSSFSheet.TopMargin, (short) 1);// 页边距（上）
        sheet.setMargin(HSSFSheet.BottomMargin, (short) 1);// 页边距（下）
        sheet.setMargin(HSSFSheet.LeftMargin, (short) 1);// 页边距（左）
        sheet.setMargin(HSSFSheet.RightMargin, (short) 1);// 页边距（右）

        // 不显示网格
        sheet.setDisplayGridlines(false);
        // 设置水平居中
        sheet.setHorizontallyCenter(true);

        /**************** 数据行样式 start ****************/
        HSSFFont fontTitle = wb.createFont();
        fontTitle.setFontName("宋体");
        fontTitle.setFontHeightInPoints((short) 14);
        // 设置字体加粗
        fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontComp = wb.createFont();
        fontComp.setFontName("宋体");
        fontComp.setFontHeightInPoints((short) 16);
        // 设置字体加粗
        fontComp.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontDetail = wb.createFont();
        fontDetail.setFontName("宋体");
        fontDetail.setFontHeightInPoints((short) 12);

        HSSFFont fontDetail1 = wb.createFont();
        fontDetail1.setFontName("宋体");
        fontDetail1.setFontHeightInPoints((short) 12);
        fontDetail1.setColor(HSSFColor.RED.index);

        // title
        HSSFCellStyle styleTitle = wb.createCellStyle();
        // 指定单元格居中对齐
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleTitle.setWrapText(true);
        // 设置单元格字体
        styleTitle.setFont(fontTitle);
        // 右边框
        styleTitle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleTitle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleTitle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleTitle.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        // title
        HSSFCellStyle styleComp = wb.createCellStyle();
        // 指定单元格居中对齐
        styleComp.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleComp.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleComp.setWrapText(true);
        // 设置单元格字体
        styleComp.setFont(fontComp);
        // 右边框
        styleComp.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleComp.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleComp.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleComp.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleInfo = wb.createCellStyle();
        // 指定单元格居中对齐
        styleInfo.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleInfo.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleInfo.setWrapText(true);
        // 设置单元格字体
        styleInfo.setFont(fontDetail);
        // 右边框
        styleInfo.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleInfo.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleInfo.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleInfo.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleDetail = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail.setWrapText(true);
        // 设置单元格字体
        styleDetail.setFont(fontDetail);
        // 右边框
        styleDetail.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetail1 = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail1.setWrapText(true);
        // 设置单元格字体
        styleDetail1.setFont(fontDetail1);
        // 右边框
        styleDetail1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle.setWrapText(true);
        // 设置单元格字体
        contextstyle.setFont(fontDetail);
        // 右边框
        contextstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle1 = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle1.setWrapText(true);
        // 设置单元格字体
        contextstyle1.setFont(fontDetail1);
        // 右边框
        contextstyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetailYellow = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailYellow.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetailYellow.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailYellow.setWrapText(true);
        // 设置单元格字体
        styleDetailYellow.setFont(fontDetail);
        // 右边框
        styleDetailYellow.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailYellow.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailYellow.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailYellow.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleDetailYellow.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
        styleDetailYellow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);


        HSSFCellStyle styleDetailLeft = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleDetailLeft.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailLeft.setWrapText(true);
        // 设置单元格字体
        styleDetailLeft.setFont(fontDetail);
        // 右边框
        styleDetailLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailLeft.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        /**************** 数据行样式 end ****************/

        // 设置列宽
        sheet.setColumnWidth(0, 1 * 256 + 184);
        sheet.setColumnWidth(1, "销售公司".getBytes().length * 3 * 256);
        sheet.setColumnWidth(2, "发货仓库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(3, "收货仓库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(4, 12 * 256 + 184);
        sheet.setColumnWidth(5, 12 * 256 + 184);
        sheet.setColumnWidth(6, "发货日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(7, "合同编号".getBytes().length * 2 * 256);
        sheet.setColumnWidth(8, 12 * 256 + 184);
        sheet.setColumnWidth(9, 12 * 256 + 184);
        sheet.setColumnWidth(10, 12 * 256 + 184);
        sheet.setColumnWidth(11, 12 * 256 + 184);
        sheet.setColumnWidth(12, "客户".getBytes().length * 6 * 256);
        sheet.setColumnWidth(13, 12 * 256 + 184);
        sheet.setColumnWidth(14, "货名".getBytes().length * 3 * 256);
        sheet.setColumnWidth(15, 12 * 256 + 184);
        sheet.setColumnWidth(16, 12 * 256 + 184);
        sheet.setColumnWidth(17, 12 * 256 + 184);
        sheet.setColumnWidth(18, 12 * 256 + 184);
        sheet.setColumnWidth(19, 12 * 256 + 184);
        sheet.setColumnWidth(20, 12 * 256 + 184);
        sheet.setColumnWidth(21, 12 * 256 + 184);
        sheet.setColumnWidth(22, 12 * 256 + 184);
        sheet.setColumnWidth(23, 12 * 256 + 184);
        sheet.setColumnWidth(24, 12 * 256 + 184);
        sheet.setColumnWidth(25, 12 * 256 + 184);
        sheet.setColumnWidth(26, 12 * 256 + 184);
        sheet.setColumnWidth(27, 12 * 256 + 184);
        sheet.setColumnWidth(28, 12 * 256 + 184);
        sheet.setColumnWidth(29, 12 * 256 + 184);
        sheet.setColumnWidth(30, 12 * 256 + 184);
        sheet.setColumnWidth(31, 12 * 256 + 184);
        sheet.setColumnWidth(32, 12 * 256 + 184);
        sheet.setColumnWidth(33, 12 * 256 + 184);
        sheet.setColumnWidth(34, 12 * 256 + 184);
        sheet.setColumnWidth(35, 12 * 256 + 184);
        sheet.setColumnWidth(36, "反馈日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(37, 12 * 256 + 184);
        sheet.setColumnWidth(38, 12 * 256 + 184);
        sheet.setColumnWidth(39, 12 * 256 + 184);
        sheet.setColumnWidth(40, 12 * 256 + 184);
        sheet.setColumnWidth(41, 12 * 256 + 184);
        sheet.setColumnWidth(42, 12 * 256 + 184);
        sheet.setColumnWidth(43, 12 * 256 + 184);
        sheet.setColumnWidth(44, 12 * 256 + 184);
        sheet.setColumnWidth(45, 12 * 256 + 184);
        sheet.setColumnWidth(46, "收款日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(47, 12 * 256 + 184);
        sheet.setColumnWidth(48, 12 * 256 + 184);
        sheet.setColumnWidth(49, 1 * 256 + 184);

        // 创建单元格对象
        HSSFCell cell = null;

        // 创建打印设置对象
        HSSFPrintSetup ps = sheet.getPrintSetup();
        // 打印方向，true：横向，false：纵向(默认)
        ps.setLandscape(false);
        // // 打印质量
        // ps.setVResolution((short) 700)
        // 设置缩放比例
        ps.setScale((short) 80);
        // 纸张类型
        ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);


        int rownum = 1;
        HSSFRow row0 = sheet.createRow((int) rownum);
        row0.setHeightInPoints(25);
        cell = row0.createCell(1);
        cell.setCellStyle(styleTitle);
        cell.setCellValue("出库记录");
        sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, (short) 1, (short) 22));
        cell = row0.createCell(2);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(3);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(4);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(5);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(6);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(7);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(8);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(9);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(10);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(11);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(12);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(13);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(14);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(15);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(16);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(17);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(18);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(19);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(20);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(21);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(22);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(23);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(24);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(25);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(26);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(27);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(28);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(29);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(30);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(31);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(32);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(33);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(34);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(35);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(36);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(37);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(38);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(39);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(40);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(41);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(42);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(43);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(44);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(45);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(46);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(47);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(48);
        cell.setCellStyle(styleTitle);
        rownum++;

        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
        pageView.put("startDate", warehouseBaseInfo.getStartDate());
        pageView.put("endDate", warehouseBaseInfo.getEndDate());
        pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
        // 查询服务商总数
        List<ExportVView> dataList = baseMapper.getListByConditionOut(pageView);
        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            Double waterContentTotal = 0d;//水分合计
            Double impurityTotal = 0d;//杂质合计
            Double mildewGrainTotal = 0d;//霉变粒合计
            Double imperfectGrainTotal = 0d;//不完善粒合计
            Double bulkDensityTotal = 0d;//容重合计
            Double jiaorenliTotal = 0d;//热损伤合计
            Double netWeightPriceTotal = 0d;//单价合计
            Double netWeightTotal = 0d;//净重合计
            Double amountIngPayableTotal = 0d;//应收合计
            Double netWeightTmp = 0d;//应收合计
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                if(!StringUtils.isEmpty(exportVView.getWaterContent())
                        &&!StringUtils.isEmpty(exportVView.getImpurity())
                        &&!StringUtils.isEmpty(exportVView.getMildewGrain())
                        &&!StringUtils.isEmpty(exportVView.getImperfectGrain())
                        &&!StringUtils.isEmpty(exportVView.getBulkDensity())
                        &&!StringUtils.isEmpty(exportVView.getJiaorenli())){
                    //水分累计和
                    netWeightTmp = netWeightTmp + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                }
                //水分累计和
                waterContentTotal = waterContentTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getWaterContent()) ? exportVView.getWaterContent() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                impurityTotal = impurityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImpurity()) ? exportVView.getImpurity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                mildewGrainTotal = mildewGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getMildewGrain()) ? exportVView.getMildewGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                imperfectGrainTotal = imperfectGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImperfectGrain()) ? exportVView.getImperfectGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                bulkDensityTotal = bulkDensityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getBulkDensity()) ? exportVView.getBulkDensity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                jiaorenliTotal = jiaorenliTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getJiaorenli()) ? exportVView.getJiaorenli() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                netWeightPriceTotal = netWeightPriceTotal + (Double.valueOf(String.valueOf(exportVView.getUnitContractPrice() != null ? exportVView.getUnitContractPrice() : "0")));
                netWeightTotal = netWeightTotal + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                amountIngPayableTotal = amountIngPayableTotal + exportVView.getAmountIngReceivable();

            }
            HSSFRow rowp = sheet.createRow((int) (rownum));
            rowp.setHeightInPoints(20);
            HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
            contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
            cell = rowp.createCell(1);
            cell.setCellValue("平均值/合计");
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(2);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(3);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(4);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(5);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(6);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(7);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(8);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(9);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(10);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(11);
            cell.setCellValue(netWeightPriceTotal / dataList.size());
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(12);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(13);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(14);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(15);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(16);
            cell.setCellStyle(styleDetail);
            //水分平均值
            cell = rowp.createCell(17);
            cell.setCellStyle(contextstyle1);
            cell.setCellValue(waterContentTotal / netWeightTmp);
            cell = rowp.createCell(18);
            cell.setCellValue(impurityTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(19);
            cell.setCellValue(mildewGrainTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(20);
            cell.setCellValue(imperfectGrainTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(21);
            cell.setCellValue(bulkDensityTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(22);
            cell.setCellValue(jiaorenliTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(23);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(24);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(25);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(26);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(27);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(28);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(29);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(30);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(31);
            cell.setCellValue(dataList.size());
            cell.setCellStyle(styleDetail1);
            cell = rowp.createCell(32);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(33);
            cell.setCellStyle(styleDetail);
            //纯重合计
            cell = rowp.createCell(34);
            cell.setCellValue(netWeightTotal);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(35);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(36);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(37);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(38);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(39);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(40);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(41);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(42);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(43);
            cell.setCellValue(amountIngPayableTotal);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(44);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(45);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(46);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(47);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(48);
            cell.setCellStyle(styleDetail);
            rownum++;
        }


        HSSFRow row1 = sheet.createRow((int) rownum);
        row1.setHeightInPoints(30);
        cell = row1.createCell(1);
        cell.setCellValue("销售公司");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(2);
        cell.setCellValue("发货仓库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(3);
        cell.setCellValue("收货仓库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(4);
        cell.setCellValue("成本单价(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(5);
        cell.setCellValue("仓位号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(6);
        cell.setCellValue("发货日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(7);
        cell.setCellValue("合同编号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(8);
        cell.setCellValue("出库任务编号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(9);
        cell.setCellValue("合同结算状态");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(10);
        cell.setCellValue("合同重量(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(11);
        cell.setCellValue("合同单价(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(12);
        cell.setCellValue("客户");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(13);
        cell.setCellValue("备注");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(14);
        cell.setCellValue("货名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(15);
        cell.setCellValue("类型");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(16);
        cell.setCellValue("等级");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(17);
        cell.setCellValue("水分");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(18);
        cell.setCellValue("杂质");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(19);
        cell.setCellValue("霉变粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(20);
        cell.setCellValue("不完善粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(21);
        cell.setCellValue("容重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(22);
        cell.setCellValue("热损伤");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(23);
        cell.setCellValue("车厢号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(24);
        cell.setCellValue("箱号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(25);
        cell.setCellValue("箱号2");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(26);
        cell.setCellValue("封号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(27);
        cell.setCellValue("封号2");
        cell.setCellStyle(contextstyle);
        cell = row1.createCell(28);
        cell.setCellValue("船名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(29);
        cell.setCellValue("航次");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(30);
        cell.setCellValue("车牌号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(31);
        cell.setCellValue("车数");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(32);
        cell.setCellValue("毛重(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(33);
        cell.setCellValue("皮重(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(34);
        cell.setCellValue("出库净重(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(35);
        cell.setCellValue("反馈重量(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(36);
        cell.setCellValue("反馈日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(37);
        cell.setCellValue("结算重量(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(38);
        cell.setCellValue("结算单价(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(39);
        cell.setCellValue("汽运运费(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(40);
        cell.setCellValue("火运运费(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(41);
        cell.setCellValue("船运运费(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(42);
        cell.setCellValue("运费");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(43);
        cell.setCellValue("应收金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(44);
        cell.setCellValue("已收金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(45);
        cell.setCellValue("未收金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(46);
        cell.setCellValue("收款日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(47);
        cell.setCellValue("已开票金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(48);
        cell.setCellValue("状态");
        cell.setCellStyle(styleDetail);
        rownum++;

        DecimalFormat decimalFormat = new DecimalFormat(".00");

        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                HSSFRow rowx = sheet.createRow((int) rownum);
                rowx.setHeightInPoints(20);
                cell = rowx.createCell(1);
                cell.setCellValue(exportVView.getCompName());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(2);
                cell.setCellValue(editString(exportVView.getWarehouseName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(3);
                cell.setCellValue(editString(exportVView.getReceiveWarehouse()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(4);
                cell.setCellValue(new Formatter().format("%.2f", editFloat(exportVView.getCostPrice())).toString());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(5);
                cell.setCellValue(editString(exportVView.getBinNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(6);
                String date = addDateOneDay(exportVView.getCreateDate());
                cell.setCellValue(date);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(7);
                if(!StringUtils.isEmpty(exportVView.getContractNo())){
                    cell.setCellValue(editString(exportVView.getContractNo()));
                }
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(8);
                cell.setCellValue(editString(exportVView.getInOutTaskNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(9);
                cell.setCellValue(editString(exportVView.getContractStatus()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(10);
                cell.setCellValue(editFloat(exportVView.getWeight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(11);
                cell.setCellValue(editFloat(exportVView.getUnitContractPrice()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(12);
                cell.setCellValue(editString(exportVView.getCustomerName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(13);
                cell.setCellValue(editString(exportVView.getRemark()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(14);
                cell.setCellValue(editString(exportVView.getGoodsName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(15);
                cell.setCellValue(editString(exportVView.getType()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(16);
                cell.setCellValue(editString(exportVView.getGrade()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(17);
                if (!StringUtils.isEmpty(exportVView.getWaterContent())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getWaterContent()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(18);
                if (!StringUtils.isEmpty(exportVView.getImpurity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImpurity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(19);
                if (!StringUtils.isEmpty(exportVView.getMildewGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getMildewGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(20);
                if (!StringUtils.isEmpty(exportVView.getImperfectGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImperfectGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(21);
                if (!StringUtils.isEmpty(exportVView.getBulkDensity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getBulkDensity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(22);
                if (!StringUtils.isEmpty(exportVView.getJiaorenli())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getJiaorenli()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(23);
                cell.setCellValue(editString(exportVView.getWingNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(24);
                cell.setCellValue(editString(exportVView.getBoxNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(25);
                cell.setCellValue(editString(exportVView.getBoxNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(26);
                cell.setCellValue(editString(exportVView.getTitleNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(27);
                cell.setCellValue(editString(exportVView.getTitleNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(28);
                cell.setCellValue(editString(exportVView.getShipNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(29);
                cell.setCellValue(editString(exportVView.getShipName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(30);
                cell.setCellValue(editString(exportVView.getCarNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(31);
                cell.setCellValue("1");
                cell.setCellStyle(styleDetail);
                HSSFDataFormat df = wb.createDataFormat(); // 此处设置数据格式
                contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
                contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                cell = rowx.createCell(32);
                cell.setCellValue(editDouble(exportVView.getGrossWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(33);
                cell.setCellValue(editDouble(exportVView.getTare()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(34);
                cell.setCellValue(Double.parseDouble(exportVView.getNetWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(35);
                cell.setCellValue(editFloat(exportVView.getFeedbackWeight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(36);
                String date1 = addDateOneDay(exportVView.getFeedbackDate() != null ? exportVView.getFeedbackDate() : new Date());
                cell.setCellValue(date1);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(37);
                cell.setCellValue(editFloat(exportVView.getSettlementWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(38);
                cell.setCellValue(editFloat(exportVView.getSettlementPrice()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(39);
                cell.setCellValue(editFloat(exportVView.getCarFreight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(40);
                cell.setCellValue(editFloat(exportVView.getTrainFreight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(41);
                cell.setCellValue(editFloat(exportVView.getShipFreight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(42);
                cell.setCellValue(editFloat(exportVView.getShipFreight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(43);
                cell.setCellValue(editDouble(exportVView.getAmountIngReceivable()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(44);
                cell.setCellValue(editDouble(exportVView.getAmountEdReceivable()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(45);
                cell.setCellValue(editDouble(exportVView.getAmountNotReceivable()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(46);
                String date2 = addDateOneDay(exportVView.getCollectionDate() != null ? exportVView.getCollectionDate() : new Date());
                cell.setCellValue(date2);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(47);
                cell.setCellValue(editFloat(exportVView.getMoney()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(48);
                cell.setCellValue(editString(exportVView.getStatus()));
                cell.setCellStyle(styleDetail);

                rownum++;
            }
        }


        String path = null;
        String tempPath = null;
        String excelPath = null;

        try {

            // 取得绝对路径
            tempPath = URLDecoder.decode((localPath), "utf-8");

            // EXCEL路径
            excelPath = "/web/temp/pay/" + DateUtil.formatDate(new Date(), DateUtils.DATE_FMT_YYYYMMDD_NS) + '/'
                    + UUID.randomUUID().toString().replaceAll("-", "");

            path = tempPath + excelPath + '/' + "合同信息"
                    + ".xlsx";

        } catch (Exception e) {
            log.debug(e.getMessage());
        }
        // 下载
        download(path, response, wb);

    }


    /**
     * 导出出库手机
     *
     * @param warehouseBaseInfo
     * @param response
     * @throws Exception
     */
    @Override
    public String exportPhoneOut(WarehouseBaseInfo warehouseBaseInfo, HttpServletResponse response) throws Exception {

        // 1.Excel的头部信息
        String headerTitle = "";

        // 2.创建一个webbook 对应一个Excel文件
        HSSFWorkbook wb = new HSSFWorkbook();

        // 3.在webbook中添加一个sheet，对应Excel文件中的sheet
        HSSFSheet sheet;

        sheet = wb.createSheet("出库记录");
        headerTitle = "出库记录";

        // 4.设置打印参数
        sheet.setMargin(HSSFSheet.TopMargin, (short) 1);// 页边距（上）
        sheet.setMargin(HSSFSheet.BottomMargin, (short) 1);// 页边距（下）
        sheet.setMargin(HSSFSheet.LeftMargin, (short) 1);// 页边距（左）
        sheet.setMargin(HSSFSheet.RightMargin, (short) 1);// 页边距（右）

        // 不显示网格
        sheet.setDisplayGridlines(false);
        // 设置水平居中
        sheet.setHorizontallyCenter(true);

        /**************** 数据行样式 start ****************/
        HSSFFont fontTitle = wb.createFont();
        fontTitle.setFontName("宋体");
        fontTitle.setFontHeightInPoints((short) 14);
        // 设置字体加粗
        fontTitle.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontComp = wb.createFont();
        fontComp.setFontName("宋体");
        fontComp.setFontHeightInPoints((short) 16);
        // 设置字体加粗
        fontComp.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);

        HSSFFont fontDetail = wb.createFont();
        fontDetail.setFontName("宋体");
        fontDetail.setFontHeightInPoints((short) 12);

        HSSFFont fontDetail1 = wb.createFont();
        fontDetail1.setFontName("宋体");
        fontDetail1.setFontHeightInPoints((short) 12);
        fontDetail1.setColor(HSSFColor.RED.index);

        // title
        HSSFCellStyle styleTitle = wb.createCellStyle();
        // 指定单元格居中对齐
        styleTitle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleTitle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleTitle.setWrapText(true);
        // 设置单元格字体
        styleTitle.setFont(fontTitle);
        // 右边框
        styleTitle.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleTitle.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleTitle.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleTitle.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        // title
        HSSFCellStyle styleComp = wb.createCellStyle();
        // 指定单元格居中对齐
        styleComp.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleComp.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleComp.setWrapText(true);
        // 设置单元格字体
        styleComp.setFont(fontComp);
        // 右边框
        styleComp.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleComp.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleComp.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleComp.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleInfo = wb.createCellStyle();
        // 指定单元格居中对齐
        styleInfo.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleInfo.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleInfo.setWrapText(true);
        // 设置单元格字体
        styleInfo.setFont(fontDetail);
        // 右边框
        styleInfo.setBorderRight(HSSFCellStyle.BORDER_NONE);
        // 左边框
        styleInfo.setBorderLeft(HSSFCellStyle.BORDER_NONE);
        // 上边框
        styleInfo.setBorderTop(HSSFCellStyle.BORDER_NONE);
        // 下边框
        styleInfo.setBorderBottom(HSSFCellStyle.BORDER_NONE);

        HSSFCellStyle styleDetail = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail.setWrapText(true);
        // 设置单元格字体
        styleDetail.setFont(fontDetail);
        // 右边框
        styleDetail.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetail1 = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetail1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetail1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetail1.setWrapText(true);
        // 设置单元格字体
        styleDetail1.setFont(fontDetail1);
        // 右边框
        styleDetail1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetail1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetail1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetail1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle.setWrapText(true);
        // 设置单元格字体
        contextstyle.setFont(fontDetail);
        // 右边框
        contextstyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle contextstyle1 = wb.createCellStyle();
        // 指定单元格居中对齐
        contextstyle1.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        contextstyle1.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        contextstyle1.setWrapText(true);
        // 设置单元格字体
        contextstyle1.setFont(fontDetail1);
        // 右边框
        contextstyle1.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        contextstyle1.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        contextstyle1.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        contextstyle1.setBorderBottom(HSSFCellStyle.BORDER_THIN);

        HSSFCellStyle styleDetailYellow = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailYellow.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        // 指定单元格垂直居中对齐
        styleDetailYellow.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailYellow.setWrapText(true);
        // 设置单元格字体
        styleDetailYellow.setFont(fontDetail);
        // 右边框
        styleDetailYellow.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailYellow.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailYellow.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailYellow.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        styleDetailYellow.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
        styleDetailYellow.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);


        HSSFCellStyle styleDetailLeft = wb.createCellStyle();
        // 指定单元格居中对齐
        styleDetailLeft.setAlignment(HSSFCellStyle.ALIGN_LEFT);
        // 指定单元格垂直居中对齐
        styleDetailLeft.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        // 指定单元格自动换行
        styleDetailLeft.setWrapText(true);
        // 设置单元格字体
        styleDetailLeft.setFont(fontDetail);
        // 右边框
        styleDetailLeft.setBorderRight(HSSFCellStyle.BORDER_THIN);
        // 左边框
        styleDetailLeft.setBorderLeft(HSSFCellStyle.BORDER_THIN);
        // 上边框
        styleDetailLeft.setBorderTop(HSSFCellStyle.BORDER_THIN);
        // 下styleDetailTitle
        styleDetailLeft.setBorderBottom(HSSFCellStyle.BORDER_THIN);
        /**************** 数据行样式 end ****************/

        // 设置列宽
        sheet.setColumnWidth(0, 1 * 256 + 184);
        sheet.setColumnWidth(1, "销售公司".getBytes().length * 3 * 256);
        sheet.setColumnWidth(2, "发货仓库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(3, "收货仓库".getBytes().length * 25 / 10 * 256);
        sheet.setColumnWidth(4, 12 * 256 + 184);
        sheet.setColumnWidth(5, 12 * 256 + 184);
        sheet.setColumnWidth(6, "发货日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(7, "合同编号".getBytes().length * 2 * 256);
        sheet.setColumnWidth(8, 12 * 256 + 184);
        sheet.setColumnWidth(9, 12 * 256 + 184);
        sheet.setColumnWidth(10, 12 * 256 + 184);
        sheet.setColumnWidth(11, "客户".getBytes().length * 6 * 256);
        sheet.setColumnWidth(12, "货名".getBytes().length * 3 * 256);
        sheet.setColumnWidth(13, 12 * 256 + 184);
        sheet.setColumnWidth(14, 12 * 256 + 184);
        sheet.setColumnWidth(15, 12 * 256 + 184);
        sheet.setColumnWidth(16, 12 * 256 + 184);
        sheet.setColumnWidth(17, 12 * 256 + 184);
        sheet.setColumnWidth(18, 12 * 256 + 184);
        sheet.setColumnWidth(19, 12 * 256 + 184);
        sheet.setColumnWidth(20, 12 * 256 + 184);
        sheet.setColumnWidth(21, 12 * 256 + 184);
        sheet.setColumnWidth(22, 12 * 256 + 184);
        sheet.setColumnWidth(23, 12 * 256 + 184);
        sheet.setColumnWidth(24, 12 * 256 + 184);
        sheet.setColumnWidth(25, 12 * 256 + 184);
        sheet.setColumnWidth(26, 12 * 256 + 184);
        sheet.setColumnWidth(27, 12 * 256 + 184);
        sheet.setColumnWidth(28, 12 * 256 + 184);
        sheet.setColumnWidth(29, 12 * 256 + 184);
        sheet.setColumnWidth(30, 12 * 256 + 184);
        sheet.setColumnWidth(31, 12 * 256 + 184);
        sheet.setColumnWidth(32, 12 * 256 + 184);
        sheet.setColumnWidth(33, 12 * 256 + 184);
        sheet.setColumnWidth(34, "反馈日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(35, 12 * 256 + 184);
        sheet.setColumnWidth(36, 12 * 256 + 184);
        sheet.setColumnWidth(37, 12 * 256 + 184);
        sheet.setColumnWidth(38, 12 * 256 + 184);
        sheet.setColumnWidth(39, 12 * 256 + 184);
        sheet.setColumnWidth(40, 12 * 256 + 184);
        sheet.setColumnWidth(41, 12 * 256 + 184);
        sheet.setColumnWidth(42, 12 * 256 + 184);
        sheet.setColumnWidth(43, 12 * 256 + 184);
        sheet.setColumnWidth(44, "收款日期".getBytes().length * 2 * 256);
        sheet.setColumnWidth(45, 12 * 256 + 184);
        sheet.setColumnWidth(46, 12 * 256 + 184);
        sheet.setColumnWidth(47, 1 * 256 + 184);

        // 创建单元格对象
        HSSFCell cell = null;

        // 创建打印设置对象
        HSSFPrintSetup ps = sheet.getPrintSetup();
        // 打印方向，true：横向，false：纵向(默认)
        ps.setLandscape(false);
        // // 打印质量
        // ps.setVResolution((short) 700)
        // 设置缩放比例
        ps.setScale((short) 80);
        // 纸张类型
        ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);


        int rownum = 1;
        HSSFRow row0 = sheet.createRow((int) rownum);
        row0.setHeightInPoints(25);
        cell = row0.createCell(1);
        cell.setCellStyle(styleTitle);
        cell.setCellValue("出库记录");
        sheet.addMergedRegion(new CellRangeAddress(rownum, rownum, (short) 1, (short) 22));
        cell = row0.createCell(2);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(3);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(4);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(5);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(6);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(7);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(8);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(9);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(10);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(11);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(12);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(13);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(14);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(15);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(16);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(17);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(18);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(19);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(20);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(21);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(22);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(23);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(24);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(25);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(26);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(27);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(28);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(29);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(30);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(31);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(32);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(33);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(34);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(35);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(36);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(37);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(38);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(39);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(40);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(41);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(42);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(43);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(44);
        cell.setCellStyle(styleTitle);
        cell = row0.createCell(46);
        cell.setCellStyle(styleTitle);
        rownum++;

        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
        pageView.put("startDate", warehouseBaseInfo.getStartDate());
        pageView.put("endDate", warehouseBaseInfo.getEndDate());
        pageView.put("warehouseName", warehouseBaseInfo.getWarehouseName());
        // 查询服务商总数
        List<ExportVView> dataList = baseMapper.getListByConditionOut(pageView);
        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            Double waterContentTotal = 0d;//水分合计
            Double impurityTotal = 0d;//杂质合计
            Double mildewGrainTotal = 0d;//霉变粒合计
            Double imperfectGrainTotal = 0d;//不完善粒合计
            Double bulkDensityTotal = 0d;//容重合计
            Double jiaorenliTotal = 0d;//热损伤合计
            Double netWeightPriceTotal = 0d;//单价合计
            Double netWeightTotal = 0d;//净重合计
            Double amountIngPayableTotal = 0d;//应收合计
            Double netWeightTmp = 0d;//应收合计
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                HSSFRow rowx = sheet.createRow((int) rownum);
                rowx.setHeightInPoints(20);
                if(!StringUtils.isEmpty(exportVView.getWaterContent())
                        &&!StringUtils.isEmpty(exportVView.getImpurity())
                        &&!StringUtils.isEmpty(exportVView.getMildewGrain())
                        &&!StringUtils.isEmpty(exportVView.getImperfectGrain())
                        &&!StringUtils.isEmpty(exportVView.getBulkDensity())
                        &&!StringUtils.isEmpty(exportVView.getJiaorenli())){
                    //水分累计和
                    netWeightTmp = netWeightTmp + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                }
                //水分累计和
                waterContentTotal = waterContentTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getWaterContent()) ? exportVView.getWaterContent() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                impurityTotal = impurityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImpurity()) ? exportVView.getImpurity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                mildewGrainTotal = mildewGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getMildewGrain()) ? exportVView.getMildewGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                imperfectGrainTotal = imperfectGrainTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getImperfectGrain()) ? exportVView.getImperfectGrain() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                bulkDensityTotal = bulkDensityTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getBulkDensity()) ? exportVView.getBulkDensity() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                jiaorenliTotal = jiaorenliTotal + ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getJiaorenli()) ? exportVView.getJiaorenli() : "0")) * ((Double.parseDouble(!StringUtils.isEmpty(exportVView.getNetWeight()) ? exportVView.getNetWeight() : "0"))));
                netWeightPriceTotal = netWeightPriceTotal + (Double.valueOf(exportVView.getUnitContractPrice()));
                netWeightTotal = netWeightTotal + (Double.valueOf(String.valueOf(exportVView.getNetWeight() != null ? exportVView.getNetWeight() : "0")));
                amountIngPayableTotal = amountIngPayableTotal + exportVView.getAmountIngReceivable();
            }
            HSSFRow rowp = sheet.createRow((int) (rownum));
            rowp.setHeightInPoints(20);
            HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
            contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
            cell = rowp.createCell(1);
            cell.setCellValue("平均值/合计");
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(2);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(3);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(4);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(5);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(6);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(7);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(8);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(9);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(10);
            cell.setCellValue(netWeightPriceTotal / dataList.size());
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(11);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(12);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(13);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(14);
            cell.setCellStyle(styleDetail);
            //水分平均值
            cell = rowp.createCell(15);
            cell.setCellStyle(contextstyle1);
            cell.setCellValue(waterContentTotal / netWeightTmp);
            cell = rowp.createCell(16);
            cell.setCellValue(impurityTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(17);
            cell.setCellValue(mildewGrainTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(18);
            cell.setCellValue(imperfectGrainTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(19);
            cell.setCellValue(bulkDensityTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(20);
            cell.setCellValue(jiaorenliTotal / netWeightTmp);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(21);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(22);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(23);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(24);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(25);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(26);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(27);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(28);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(29);
            cell.setCellValue(dataList.size());
            cell.setCellStyle(styleDetail1);
            cell = rowp.createCell(30);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(31);
            cell.setCellStyle(styleDetail);
            //纯重合计
            cell = rowp.createCell(32);
            cell.setCellValue(netWeightTotal);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(33);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(34);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(35);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(36);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(37);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(38);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(39);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(40);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(41);
            cell.setCellValue(amountIngPayableTotal);
            cell.setCellStyle(contextstyle1);
            cell = rowp.createCell(42);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(43);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(44);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(45);
            cell.setCellStyle(styleDetail);
            cell = rowp.createCell(46);
            cell.setCellStyle(styleDetail);
            rownum++;
        }


        HSSFRow row1 = sheet.createRow((int) rownum);
        row1.setHeightInPoints(30);
        cell = row1.createCell(1);
        cell.setCellValue("销售公司");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(2);
        cell.setCellValue("发货仓库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(3);
        cell.setCellValue("收货仓库");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(4);
        cell.setCellValue("成本单价(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(5);
        cell.setCellValue("仓位号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(6);
        cell.setCellValue("发货日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(7);
        cell.setCellValue("合同编号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(8);
        cell.setCellValue("合同结算状态");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(9);
        cell.setCellValue("合同重量(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(10);
        cell.setCellValue("合同单价(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(11);
        cell.setCellValue("客户");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(12);
        cell.setCellValue("货名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(13);
        cell.setCellValue("类型");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(14);
        cell.setCellValue("等级");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(15);
        cell.setCellValue("水分");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(16);
        cell.setCellValue("杂质");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(17);
        cell.setCellValue("霉变粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(18);
        cell.setCellValue("不完善粒");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(19);
        cell.setCellValue("容重");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(20);
        cell.setCellValue("热损伤");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(21);
        cell.setCellValue("车厢号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(22);
        cell.setCellValue("箱号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(23);
        cell.setCellValue("箱号2");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(24);
        cell.setCellValue("封号1");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(25);
        cell.setCellValue("封号2");
        cell.setCellStyle(contextstyle);
        cell = row1.createCell(26);
        cell.setCellValue("船名");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(27);
        cell.setCellValue("航次");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(28);
        cell.setCellValue("车牌号");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(29);
        cell.setCellValue("车数");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(30);
        cell.setCellValue("毛重(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(31);
        cell.setCellValue("皮重(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(32);
        cell.setCellValue("出库净重(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(33);
        cell.setCellValue("反馈重量(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(34);
        cell.setCellValue("反馈日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(35);
        cell.setCellValue("结算重量(吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(36);
        cell.setCellValue("结算单价(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(37);
        cell.setCellValue("汽运运费(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(38);
        cell.setCellValue("火运运费(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(39);
        cell.setCellValue("船运运费(元/吨)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(40);
        cell.setCellValue("运费");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(41);
        cell.setCellValue("应收金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(42);
        cell.setCellValue("已收金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(43);
        cell.setCellValue("未收金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(44);
        cell.setCellValue("收款日期");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(45);
        cell.setCellValue("已开票金额(元)");
        cell.setCellStyle(styleDetail);
        cell = row1.createCell(46);
        cell.setCellValue("状态");
        cell.setCellStyle(styleDetail);
        rownum++;

        DecimalFormat decimalFormat = new DecimalFormat(".00");
        // 详情信息
        if (!CollectionUtils.isEmpty(dataList)) {
            for (int i = 0; i < dataList.size(); i++) {
                ExportVView exportVView = dataList.get(i);
                HSSFRow rowx = sheet.createRow((int) rownum);
                rowx.setHeightInPoints(20);
                cell = rowx.createCell(1);
                cell.setCellValue(exportVView.getCompName());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(2);
                cell.setCellValue(editString(exportVView.getWarehouseName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(3);
                cell.setCellValue(editString(exportVView.getReceiveWarehouse()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(4);
                cell.setCellValue(new Formatter().format("%.2f", editFloat(exportVView.getCostPrice())).toString());
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(5);
                cell.setCellValue(editString(exportVView.getBinNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(6);
                String date = addDateOneDay(exportVView.getCreateDate());
                cell.setCellValue(date);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(7);
                cell.setCellValue(editString(exportVView.getContractNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(8);
                cell.setCellValue(editString(exportVView.getContractStatus()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(9);
                cell.setCellValue(editFloat(exportVView.getWeight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(10);
                cell.setCellValue(editFloat(exportVView.getUnitContractPrice()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(11);
                cell.setCellValue(editString(exportVView.getCustomerName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(12);
                cell.setCellValue(editString(exportVView.getGoodsName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(13);
                cell.setCellValue(editString(exportVView.getType()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(14);
                cell.setCellValue(editString(exportVView.getGrade()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(15);
                if (!StringUtils.isEmpty(exportVView.getWaterContent())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getWaterContent()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(16);
                if (!StringUtils.isEmpty(exportVView.getImpurity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImpurity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(17);
                if (!StringUtils.isEmpty(exportVView.getMildewGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getMildewGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(18);
                if (!StringUtils.isEmpty(exportVView.getImperfectGrain())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getImperfectGrain()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(19);
                if (!StringUtils.isEmpty(exportVView.getBulkDensity())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getBulkDensity()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(20);
                if (!StringUtils.isEmpty(exportVView.getJiaorenli())) {
                    cell.setCellValue(Double.parseDouble(exportVView.getJiaorenli()));
                }
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(21);
                cell.setCellValue(editString(exportVView.getWingNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(22);
                cell.setCellValue(editString(exportVView.getBoxNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(23);
                cell.setCellValue(editString(exportVView.getBoxNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(24);
                cell.setCellValue(editString(exportVView.getTitleNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(25);
                cell.setCellValue(editString(exportVView.getTitleNoOther()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(26);
                cell.setCellValue(editString(exportVView.getShipNumber()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(27);
                cell.setCellValue(editString(exportVView.getShipName()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(28);
                cell.setCellValue(editString(exportVView.getCarNo()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(29);
                cell.setCellValue("1");
                cell.setCellStyle(styleDetail);
                HSSFDataFormat df = wb.createDataFormat(); // 此处设置数据格式
                contextstyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                HSSFDataFormat df1 = wb.createDataFormat(); // 此处设置数据格式
                contextstyle1.setDataFormat(HSSFDataFormat.getBuiltinFormat("#,##0.00"));//保留两位小数点
                cell = rowx.createCell(30);
                cell.setCellValue(editDouble(exportVView.getGrossWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(31);
                cell.setCellValue(editDouble(exportVView.getTare()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(32);
                cell.setCellValue(Double.parseDouble(exportVView.getNetWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(33);
                cell.setCellValue(editFloat(exportVView.getFeedbackWeight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(34);
                String date1 = addDateOneDay(exportVView.getFeedbackDate() != null ? exportVView.getFeedbackDate() : new Date());
                cell.setCellValue(date1);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(35);
                cell.setCellValue(editFloat(exportVView.getSettlementWeight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(36);
                cell.setCellValue(editFloat(exportVView.getSettlementPrice()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(37);
                cell.setCellValue(editFloat(exportVView.getCarFreight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(38);
                cell.setCellValue(editFloat(exportVView.getTrainFreight()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(39);
                cell.setCellValue(editFloat(exportVView.getShipFreight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(40);
                cell.setCellValue(editFloat(exportVView.getShipFreight()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(41);
                cell.setCellValue(editDouble(exportVView.getAmountIngReceivable()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(42);
                cell.setCellValue(editDouble(exportVView.getAmountEdReceivable()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(43);
                cell.setCellValue(editDouble(exportVView.getAmountNotReceivable()));
                cell.setCellStyle(contextstyle);
                cell = rowx.createCell(44);
                String date2 = addDateOneDay(exportVView.getCollectionDate() != null ? exportVView.getCollectionDate() : new Date());
                cell.setCellValue(date2);
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(45);
                cell.setCellValue(editFloat(exportVView.getMoney()));
                cell.setCellStyle(styleDetail);
                cell = rowx.createCell(46);
                cell.setCellValue(editString(exportVView.getStatus()));
                cell.setCellStyle(styleDetail);

                rownum++;
            }
        }


        String path = null;
        String tempPath = null;
        String excelPath = null;

        try {

            // 取得绝对路径
            tempPath = URLDecoder.decode((localPath), "utf-8");

            // EXCEL路径
            excelPath = "/web/temp/pay/" + DateUtil.formatDate(new Date(), DateUtils.DATE_FMT_YYYYMMDD_NS) + '/'
                    + UUID.randomUUID().toString().replaceAll("-", "");

            path = tempPath + excelPath + '/' + "仓库信息"
                    + ".xlsx";

        } catch (Exception e) {
            log.debug(e.getMessage());
        }
        // 下载
        return downloadPhone(path, response, wb);

    }

    @Override
    public Integer getTemWareHouseCountByCondition(Map<String, Object> pageView) {
        return baseMapper.getTemWareHouseCountByCondition(pageView);
    }
    private String addDateOneDay(Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        return sdf.format(date);
    }

    /**
     * 下载
     *
     * @param path
     * @param response
     */
    private String downloadPhone(String path, HttpServletResponse response, Workbook wb) {

        try {

            // path是指欲下载的文件的路径。
//            File file = new File(path);
//            File file = new File( new String(("templates" + File.separator + "仓库信息"+".xlsx").getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
            // 取得文件名。
            String fileName = "excel";
            // 给文件名编码
            fileName = new String(fileName.getBytes("GBK"), "ISO-8859-1");

            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment;filename=" + fileName);

            // 定义byte输出流
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            // 写导出文件
            wb.write(out);

            // 取得模板文件中的数据
            byte[] result = out.toByteArray();

            // 设置输出数据类型
            response.setContentType("application/vnd.ms-excel");
            // 设置输出数据长度
            response.setContentLength(result.length);

            // 设置文件名称
            response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
            // 将文件流输出到画面
//            response.getOutputStream().write(result);

            out.flush();
            out.close();
            //生成的新文件路径
            String outputFile = "templates" + File.separator + fileName + ".xlsx";
            File file1 = new File(new String(outputFile.getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));
            try (FileOutputStream fos = new FileOutputStream(file1)) {
                wb.write(fos);
            }

            FileInputStream fileInputStream = new FileInputStream(file1.getAbsoluteFile());

            MultipartFile multipartFile = new MockMultipartFile(ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
            String result1 = upload(multipartFile, fileName);
            file1.delete();
            return result1;
        } catch (IOException ex) {
            log.debug(ex.getMessage());
        }
        return "ng";
    }


    /**
     * 后台通过服务器间接传文件
     *
     * @param file
     * @return
     * @throws IOException
     */
    public String upload(MultipartFile file, String name) throws IOException {
        ObjectMetadata objectMetadata = new ObjectMetadata();
        objectMetadata.setContentLength(file.getSize());
        objectMetadata.setContentType(file.getContentType());
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, "pcfiles/" + name + ".xlsx", file.getInputStream(), objectMetadata);
        ossClient.putObject(putObjectRequest);
        return baseUrl + "pcfiles/" + name + ".xlsx";
    }

    /**
     * 判断浮点数
     *
     * @param example
     * @return
     */
    private Float editFloat(Float example) {
        Float exampleOne = example != null ? example : 0f;
        return exampleOne;
    }

    /**
     * 判断浮点数
     *
     * @param example
     * @return
     */
    private Double editDouble(Double example) {
        Double exampleOne = example != null ? example : 0.00;
        return exampleOne;
    }

    /**
     * 判断字符串
     *
     * @param example
     * @return
     */
    private String editString(String example) {
        String exampleOne = example != null ? example : "";
        return exampleOne;
    }

    /**
     * 下载
     *
     * @param path
     * @param response
     */
    private void download(String path, HttpServletResponse response, Workbook wb) {

        try {

            // path是指欲下载的文件的路径。
            File file = new File(path);
            // 取得文件名。
            String fileName = file.getName();
            // 给文件名编码
            fileName = new String(fileName.getBytes("GBK"), "ISO-8859-1");

            response.setContentType("application/vnd.ms-excel");
            response.addHeader("Content-Disposition", "attachment;filename=" + fileName);

            // 定义byte输出流
            ByteArrayOutputStream out = new ByteArrayOutputStream();

            // 写导出文件
            wb.write(out);

            // 取得模板文件中的数据
            byte[] result = out.toByteArray();

            // 设置输出数据类型
            response.setContentType("application/vnd.ms-excel");
            // 设置输出数据长度
            response.setContentLength(result.length);

            // 设置文件名称
            response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
            // 将文件流输出到画面
            response.getOutputStream().write(result);

            out.flush();
            out.close();

        } catch (IOException ex) {
            log.debug(ex.getMessage());
        }

    }

    /**
     *
     * 库点利润详情列表
     * @param warehouseBaseInfo
     * @return
     */
    @Override
    public Page<WarehouseBaseInfo> selectBaseInfo(WarehouseBaseInfo warehouseBaseInfo) {

        Map<String, Object> pageView = new HashMap<>();
        pageView.put("startRecord", (warehouseBaseInfo.getCurrentPage() - 1)
                * warehouseBaseInfo.getPageSize());
        //  公司ID
        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
        pageView.put("searchKeyWord", warehouseBaseInfo.getSearchKeyWord());
        pageView.put("startDate", warehouseBaseInfo.getStartDate());
        pageView.put("endDate", warehouseBaseInfo.getEndDate());
        pageView.put("pageSize", warehouseBaseInfo.getPageSize());
        pageView.put("currentPage", warehouseBaseInfo.getCurrentPage());
        // 查询服务商总数
        Integer dataCount = baseMapper.getBaseCountByCondition(pageView);
        List<WarehouseBaseInfo> dataList = baseMapper.getBaseListByCondition(pageView);


        Page<WarehouseBaseInfo> page = new Page<>();
        page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
        page.setTotal(dataCount == null ? 0 : dataCount);
        page.setCurrent(warehouseBaseInfo.getCurrentPage());
        page.setSize(warehouseBaseInfo.getPageSize());
        return page;
    }

    @Override
    public WarehouseBaseInfo selectWarehouseChart(WarehouseBaseInfo warehouseBaseInfo) {
        WarehouseBaseInfo warehouseBaseInfo1=new WarehouseBaseInfo();
        Map<String, Object> pageView = new HashMap<>();
        //  公司ID
        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
        pageView.put("startDate", warehouseBaseInfo.getStartDate());
        pageView.put("endDate", warehouseBaseInfo.getEndDate());
        List<WarehouseBaseInfo> dataList = baseMapper.getWarehouseChartByCondition(pageView);
        List<WarehouseBaseInfo> dataList1 = baseMapper.getWarehouseFormByCondition(pageView);
        warehouseBaseInfo1.setChartList(dataList);
        warehouseBaseInfo1.setFormList(dataList1);

        return warehouseBaseInfo1;
    }

}