/*
 * Copyright [2022] [https://www.xiaonuo.vip]
 *
 * Snowy采用APACHE LICENSE 2.0开源协议，您在使用过程中，需要注意以下几点：
 *
 * 1.请不要删除和修改根目录下的LICENSE文件。
 * 2.请不要删除和修改Snowy源码头部的版权声明。
 * 3.本项目代码可免费商业使用，商业使用请保留源码和相关描述文件的项目出处，作者声明等。
 * 4.分发源码时候，请注明软件出处 https://www.xiaonuo.vip
 * 5.不可二次分发开源参与同类竞品，如有想法可联系团队xiaonuobase@qq.com商议合作。
 * 6.若您的项目无法满足以上几点，需要更多功能代码，获取Snowy商业授权许可，请在官网购买授权，地址为 https://www.xiaonuo.vip
 */
package com.unis.emergencySupport.modular.es.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollStreamUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unis.biz.modular.dict.entity.BizDict;
import com.unis.emergencySupport.modular.es.entity.EsNetworkEntryGrain;
import com.unis.emergencySupport.modular.es.entity.vo.EsNetworkEntryCountVO;
import com.unis.emergencySupport.modular.es.entity.vo.EsNetworkEntryVO;
import com.unis.emergencySupport.modular.es.param.*;
import com.unis.emergencySupport.modular.es.service.EsNetworkEntryGrainService;
import com.unis.emergencySupport.modular.esstorageenterprise.util.FileImport;
import com.unis.policy.info.modular.auditRecord.entity.AuditRecord;
import com.unis.policy.info.modular.auditRecord.service.AuditRecordService;
import com.unis.policy.info.modular.auditRequest.entity.AuditRequest;
import com.unis.policy.info.modular.auditRequest.service.AuditRequestService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.unis.common.exception.CommonException;
import com.unis.emergencySupport.modular.es.entity.EsNetworkEntry;
import com.unis.emergencySupport.modular.es.mapper.EsNetworkEntryMapper;
import com.unis.emergencySupport.modular.es.service.EsNetworkEntryService;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 应急保障-应急供应网点管理-应急网点录入表Service接口实现类
 *
 * @author ZeroLiYi
 * @date  2024/05/28 09:21
 **/
@Service
public class EsNetworkEntryServiceImpl extends ServiceImpl<EsNetworkEntryMapper, EsNetworkEntry> implements EsNetworkEntryService {

    @Resource
    private com.unis.biz.modular.dict.service.impl.BizDictServiceImpl BizDictServiceImpl;
    
    @Resource
    private AuditRecordService auditRecordService;

    @Resource
    private EsNetworkEntryMapper esNetworkEntryMapper;

    @Resource
    private EsNetworkEntryGrainService esNetworkEntryGrainService;

    @Resource
    private AuditRequestService auditRequestService;

    @Override
    public Page<EsNetworkEntry> page(EsNetworkEntryPageParam esNetworkEntryPageParam) {
        //条形查询器
        QueryWrapper<EsNetworkEntry> queryWrapper = new QueryWrapper<>();
        //分页相关
        if(StringUtils.isNotBlank(esNetworkEntryPageParam.getEnterpriseName())){
            queryWrapper.like("enterprise_name",esNetworkEntryPageParam.getEnterpriseName());
        }
        Page<EsNetworkEntry> p =new Page<>(esNetworkEntryPageParam.getCurrent(),esNetworkEntryPageParam.getSize());

        return   this.page(p,queryWrapper);
    }



    @Transactional(rollbackFor = Exception.class)
    @Override
    public void add(EsNetworkEntryAddParam esNetworkEntryAddParam) {
        EsNetworkEntry esNetworkEntry = BeanUtil.toBean(esNetworkEntryAddParam, EsNetworkEntry.class);
        List<EsNetworkEntryGrainAddParam> esNetworkEntryGrainAddParam= esNetworkEntryAddParam.getCategoryAddParamList();
        if(esNetworkEntryAddParam.getId()==null){//添加

            this.save(esNetworkEntry);

            if(esNetworkEntryGrainAddParam!=null){ //有数据

                for (EsNetworkEntryGrainAddParam addparam:esNetworkEntryGrainAddParam) {
                    addparam.setEsNetworkEntryId(esNetworkEntry.getId());
                    esNetworkEntryGrainService.add(addparam);
                }

            }
        }else{//修改
            //修改主表数据
                this.updateById(esNetworkEntry);
            if(esNetworkEntryGrainAddParam!=null){ //有数据

                for (EsNetworkEntryGrainAddParam addparam:esNetworkEntryGrainAddParam) {
                    if(addparam.getId()!=null){
                        esNetworkEntryGrainService.removeById(addparam.getId());
                    }
                    addparam.setEsNetworkEntryId(esNetworkEntry.getId());
                    esNetworkEntryGrainService.add(addparam);
                }

            }

        }


    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void edit(EsNetworkEntryEditParam esNetworkEntryEditParam) {
        EsNetworkEntry esNetworkEntry = this.queryEntity(esNetworkEntryEditParam.getId());
        BeanUtil.copyProperties(esNetworkEntryEditParam, esNetworkEntry);
        this.updateById(esNetworkEntry);
        AuditRequest auditRequest=new AuditRequest();
        auditRequest.setType(5);
        auditRequest.setStep(1);
        auditRequest.setRequestId(esNetworkEntryEditParam.getId());
        auditRequest.setAuditStatus(0);
        auditRequestService.save(auditRequest);
        AuditRecord auditRecord =new AuditRecord();
        auditRecord.setType(5);
        auditRecord.setStep(1);
        auditRecord.setRequestId(esNetworkEntryEditParam.getId());
        auditRecord.setAuditStatus(0);
        auditRecordService.updateById(auditRecord);

    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void delete(List<EsNetworkEntryIdParam> esNetworkEntryIdParamList) {
        // 执行删除
        for (EsNetworkEntryIdParam enid:esNetworkEntryIdParamList
             ) {
            QueryWrapper<EsNetworkEntryGrain> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("es_network_entry_id",enid.getId());
            esNetworkEntryGrainService.remove(queryWrapper);
        }
        this.removeByIds(CollStreamUtil.toList(esNetworkEntryIdParamList, EsNetworkEntryIdParam::getId));
    }

    @Override
    public EsNetworkEntry detail(EsNetworkEntryIdParam esNetworkEntryIdParam) {
        EsNetworkEntry esNetworkEntry =this.queryEntity(esNetworkEntryIdParam.getId());


        QueryWrapper<EsNetworkEntryGrain> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("es_network_entry_id",esNetworkEntryIdParam.getId());
        List<EsNetworkEntryGrain> esNetworkEntryGrains = esNetworkEntryGrainService.list(queryWrapper);
        if(esNetworkEntryGrains!=null){
            esNetworkEntry.setEsNetworkEntryGrainList(esNetworkEntryGrains);
        }
        return esNetworkEntry;
    }

    @Override
    public EsNetworkEntry queryEntity(String id) {
        EsNetworkEntry esNetworkEntry = this.getById(id);
        if(ObjectUtil.isEmpty(esNetworkEntry)) {
            throw new CommonException("应急保障-应急供应网点管理-应急网点录入表不存在，id值为：{}", id);
        }
        return esNetworkEntry;
    }

    @Override
    public List<EsNetworkEntryCountVO> selectCount(EsNetworkEntryCountParam esNetworkEntryCountParam) {
        List<EsNetworkEntryCountVO> esNetworkEntryCountVOList=new ArrayList<>();
        if(esNetworkEntryCountParam.getManagementAreaCity()!=null &&!esNetworkEntryCountParam.getManagementAreaCity().isEmpty()){//市
            esNetworkEntryCountVOList.addAll(esNetworkEntryMapper.selectCityCount(esNetworkEntryCountParam));
            esNetworkEntryCountVOList.addAll(esNetworkEntryMapper.selectCountyCount(esNetworkEntryCountParam));
        }
        if(esNetworkEntryCountParam.getManagementAreaCounty()!=null&&!esNetworkEntryCountParam.getManagementAreaCounty().isEmpty()){//县（区）
            esNetworkEntryCountVOList.addAll(esNetworkEntryMapper.selectCountyCount(esNetworkEntryCountParam));
            esNetworkEntryCountVOList.addAll(esNetworkEntryMapper.selectEnterpriseCount(esNetworkEntryCountParam));

        }else{

            esNetworkEntryCountVOList.addAll(esNetworkEntryMapper.selectProvinceCount(esNetworkEntryCountParam));
            esNetworkEntryCountVOList.addAll(esNetworkEntryMapper.selectCityCount(esNetworkEntryCountParam));
        }

    return esNetworkEntryCountVOList;
    }
    @Transactional
    @Override
    public Map<String, Object> importByEntityResult(MultipartFile file, Map<String, Object> map) throws IOException {
        // TODO Auto-generated method stub
        Integer index = 6;
        List<String[]> list = FileImport.importByFile(file, index);
        if (list.size() > 0) {
            int res = 0;
            int insertNum = 0;
            int updateNum = 0;
            int skipNum = 0;
            int failNum = 0;
            int size = list.size();
            for (String[] strings : list) {

                /*
                 * 判断是否为整数
                 * 判断第一列是否是 数字 不是跳过
                 */
                String str = strings[0].toString();
                if (!str.matches("^[-\\+]?[\\d]*$")){
                    continue;
                }

                if (strings[13] != null && strings[13] != "" && strings[12] != null && strings[12] != "") {

                    /**
                     * 查询是否存在此条数据
                     * 根据企业名称和社会信用代码
                     */
                    QueryWrapper<EsNetworkEntry> queryWrapper = new QueryWrapper<>();
                    queryWrapper.eq("enterprise_name", strings[12]);
                    queryWrapper.eq("credit_code", strings[13]);
                    List<EsNetworkEntry> mainList = this.list(queryWrapper);

                    if (mainList.size() > 0) {
                        //修改
                        this.importUpdate(strings,mainList,updateNum,res,failNum);
                    } else if(mainList.size() ==0){
                        EsNetworkEntry EsNetworkEntry = new EsNetworkEntry();
                        //新增

                        QueryWrapper<BizDict> queryWrapper1 = new QueryWrapper<>();
                        queryWrapper1.eq("DICT_LABEL",strings[1]);
                        List<BizDict> list1 = BizDictServiceImpl.list(queryWrapper1);
                        EsNetworkEntry.setManagementAreaProvince(list1.get(0).getId());//归口管理地区-省

                        QueryWrapper<BizDict> queryWrapper2 = new QueryWrapper<>();
                        queryWrapper2.eq("DICT_LABEL",strings[2]);
                        List<BizDict> list2 = BizDictServiceImpl.list(queryWrapper2);
                        EsNetworkEntry.setManagementAreaCity(list2.get(0).getId());//归口管理地区-市

                        QueryWrapper<BizDict> queryWrapper3 = new QueryWrapper<>();
                        queryWrapper3.eq("DICT_LABEL",strings[3]);
                        List<BizDict> list3 = BizDictServiceImpl.list(queryWrapper3);
                        EsNetworkEntry.setManagementAreaCounty(list3.get(0).getId());//归口管理地区-县


                        QueryWrapper<BizDict> queryWrapper4 = new QueryWrapper<>();
                        queryWrapper4.eq("DICT_LABEL",strings[4]);
                        List<BizDict> list4 = BizDictServiceImpl.list(queryWrapper4);
                        EsNetworkEntry.setActualAddressProvince(list4.get(0).getId());//实际经营地址-省

                        QueryWrapper<BizDict> queryWrapper5 = new QueryWrapper<>();
                        queryWrapper5.eq("DICT_LABEL",strings[5]);
                        List<BizDict> list5 = BizDictServiceImpl.list(queryWrapper5);
                        EsNetworkEntry.setActualAddressCity(list5.get(0).getId());//实际经营地址-市

                        QueryWrapper<BizDict> queryWrapper6 = new QueryWrapper<>();
                        queryWrapper6.eq("DICT_LABEL",strings[6]);
                        List<BizDict> list6 = BizDictServiceImpl.list(queryWrapper6);
                        EsNetworkEntry.setActualAddressCounty(list6.get(0).getId());//实际经营地址-县


                        if(strings[7] != null && strings[7] != ""){
                            EsNetworkEntry.setIsNational(1);//供应应急级别-是否国家级，0：否；1：是
                        }else{
                            EsNetworkEntry.setIsNational(0);//供应应急级别-是否国家级，0：否；1：是
                        }
                        if(strings[8] != null && strings[8] != ""){
                            EsNetworkEntry.setIsProvincial(1);//供应应急级别-是否省级，0：否；1：是
                        }else{
                            EsNetworkEntry.setIsProvincial(0);//供应应急级别-是否省级，0：否；1：是
                        }

                        if(strings[9] != null && strings[9] != ""){
                            EsNetworkEntry.setIsCity(1);//供应应急级别-是否市级，0：否；1：是
                        }else{
                            EsNetworkEntry.setIsCity(0);//供应应急级别-是否市级，0：否；1：是
                        }

                        if(strings[10] != null && strings[10] != ""){
                            EsNetworkEntry.setIsCounty(1);//供应应急级别-是否县级，0：否；1：是
                        }else{
                            EsNetworkEntry.setIsCounty(0);//供应应急级别-是否县级，0：否；1：是
                        }


                        EsNetworkEntry.setHeadquarterCreditCode(strings[11]);//所属总公司企业信用代码
                        EsNetworkEntry.setEnterpriseName(strings[12]);//企业名称
                        EsNetworkEntry.setCreditCode(strings[13]);//统一社会信用代码
                        EsNetworkEntry.setActualBusinessAddress(strings[14]);//实际经营地址（省、市、县、乡镇街道门牌号）

                        QueryWrapper<BizDict> queryWrapper7 = new QueryWrapper<>();
                        queryWrapper7.eq("DICT_LABEL",strings[15].trim());
                        List<BizDict> list7 = BizDictServiceImpl.list(queryWrapper7);
                        EsNetworkEntry.setEnterpriseNature(strings[15]);//企业性质
                        QueryWrapper<BizDict> queryWrapper8 = new QueryWrapper<>();
                        queryWrapper8.eq("DICT_LABEL",strings[16]);
                        List<BizDict> list8 = BizDictServiceImpl.list(queryWrapper8);
                        EsNetworkEntry.setEnterpriseType(strings[16]);//企业类型

                        EsNetworkEntry.setLongitude(new BigDecimal(strings[17]));//经度

                        EsNetworkEntry.setLatitude(new BigDecimal(strings[18]));//纬度


                        EsNetworkEntry.setLegalRepresentative(strings[19]);//法人姓名
                        EsNetworkEntry.setLegalContact(strings[20]);//法人联系方式
                        EsNetworkEntry.setContactPerson(strings[21]);//联系人姓名
                        EsNetworkEntry.setContactNumber(strings[22]);//联系电话


                        if(strings[39] != null && strings[39] != ""){
                            if(strings[39].equals("生产")){
                                EsNetworkEntry.setProductionStatus(1);//生产状态，0：停产；1：生产
                            }else{
                                EsNetworkEntry.setProductionStatus(0);//生产状态，0：停产；1：生产
                            }
                        }
                        EsNetworkEntry.setStatus(0);
                        EsNetworkEntry.setCityState(strings[5].trim());
                        this.save(EsNetworkEntry);
                        /**
                         * 数量
                         */
                        BigDecimal quantity=new BigDecimal(0.00);
                        if((strings[23] != null && strings[23] != "") || (strings[32] != null && strings[32] != "") || (strings[41] != null && strings[41] != "") || (strings[51] != null && strings[51] != "")){
                            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
                            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
                            EsNetworkEntryGrain.setGrainVariety(1);//粮食品种 1：小麦粉成品粮
                            if(strings[23] != null && strings[23] != ""){
                                EsNetworkEntryGrain.setType(1);//类型 1：日库存；
                                if(strings[23]!=null&&!strings[23].isEmpty()){
                                    quantity=new BigDecimal(strings[23]);
                                }
                                EsNetworkEntryGrain.setQuantity(quantity);//数量
                            }else if(strings[27] != null && strings[27] != ""){
                                EsNetworkEntryGrain.setType(2);//类型 2：日销量；
                                if(strings[32]!=null&&!strings[32].isEmpty()){
                                    quantity=new BigDecimal(strings[32]);
                                }
                                EsNetworkEntryGrain.setQuantity(quantity);//数量
                            }else if(strings[31] != null && strings[31] != ""){
                                EsNetworkEntryGrain.setType(3);//类型 3：日供应能力；
                                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[41]));//数量
                            }else if(strings[35] != null && strings[35] != ""){
                                EsNetworkEntryGrain.setType(4);//类型 4：安全库存
                                if(StringUtils.isNotBlank(strings[51])){
                                    quantity=new BigDecimal(strings[51]);
                                }
                                EsNetworkEntryGrain.setQuantity(quantity);//数量
                            }
                            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
                        }
                        if((strings[24] != null && strings[24] != "") || (strings[28] != null && strings[28] != "") || (strings[32] != null && strings[32] != "") || (strings[36] != null && strings[36] != "")){
                            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
                            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
                            EsNetworkEntryGrain.setGrainVariety(2);//粮食品种 2：大米成品粮；
                            if(strings[24] != null && strings[24] != ""){
                                EsNetworkEntryGrain.setType(1);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力

                                if(StringUtils.isNotBlank(strings[24])){
                                    quantity=new BigDecimal(strings[24]);
                                }
                                EsNetworkEntryGrain.setQuantity(quantity);//数量

                            }else if(strings[28] != null && strings[28] != ""){
                                EsNetworkEntryGrain.setType(2);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(StringUtils.isNotBlank(strings[33])){
                                    quantity=new BigDecimal(strings[33]);
                                }
                                EsNetworkEntryGrain.setQuantity(quantity);//数量

                            }else if(strings[32] != null && strings[32] != ""){
                                EsNetworkEntryGrain.setType(3);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[42]));//数量

                            }else if(strings[36] != null && strings[36] != ""){
                                EsNetworkEntryGrain.setType(4);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(strings[52]!=null&&!strings[52].isEmpty()){
                                    quantity =new BigDecimal(strings[25]);
                                }


                                EsNetworkEntryGrain.setQuantity(quantity);//数量

                            }
                            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
                        }
                        if((strings[25] != null && strings[25] != "") || (strings[29] != null && strings[29] != "") || (strings[33] != null && strings[33] != "") || (strings[37] != null && strings[37] != "")){
                            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
                            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
                            EsNetworkEntryGrain.setGrainVariety(3);//粮食品种 1：小麦原粮:2：稻谷原粮:3：大豆原粮；4：玉米原粮；5：其他原粮；6：小麦粉成品粮；7：大米成品粮；8：食用油成品粮；9：其他成品粮
                            if(strings[25] != null && strings[25] != ""){
                                EsNetworkEntryGrain.setType(1);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力

                                if(StringUtils.isNotBlank(strings[25])){
                                    quantity=new BigDecimal(strings[25]);
                                }

                                EsNetworkEntryGrain.setQuantity(quantity);//数量

                            }else if(strings[29] != null && strings[29] != ""){
                                EsNetworkEntryGrain.setType(2);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(strings[34]!=null&&!strings[34].isEmpty()){
                                    quantity =new BigDecimal(strings[34]);
                                }


                                EsNetworkEntryGrain.setQuantity(quantity);//数量

                            }else if(strings[33] != null && strings[33] != ""){
                                EsNetworkEntryGrain.setType(3);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(strings[43]!=null&&!strings[43].isEmpty()){
                                    quantity =new BigDecimal(strings[43]);
                                }


                                EsNetworkEntryGrain.setQuantity(quantity);//数量

                            }else if(strings[37] != null && strings[53] != ""){
                                EsNetworkEntryGrain.setType(4);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(strings[53]!=null&&!strings[53].isEmpty()){
                                    quantity =new BigDecimal(strings[53]);
                                }

                                EsNetworkEntryGrain.setQuantity(quantity);//数量

                            }
                            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
                        }
                        if((strings[26] != null && strings[26] != "") || (strings[30] != null && strings[30] != "") || (strings[34] != null && strings[34] != "") || (strings[38] != null && strings[38] != "")){
                            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
                            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
                            EsNetworkEntryGrain.setGrainVariety(4);//粮食品种 1：小麦原粮:2：稻谷原粮:3：大豆原粮；4：玉米原粮；5：其他原粮；6：小麦粉成品粮；7：大米成品粮；8：食用油成品粮；9：其他成品粮
                            if(strings[26] != null && strings[26] != ""){
                                EsNetworkEntryGrain.setType(1);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(strings[26]!=null&&!strings[26].isEmpty()){
                                    quantity =new BigDecimal(strings[26]);
                                }
                                EsNetworkEntryGrain.setQuantity(quantity);//数量
                            }else if(strings[30] != null && strings[30] != ""){
                                EsNetworkEntryGrain.setType(2);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(StringUtils.isNotBlank(strings[35])){
                                    quantity=new BigDecimal(strings[35]);
                                }

                                EsNetworkEntryGrain.setQuantity(quantity);//数量
                            }else if(strings[34] != null && strings[34] != ""){
                                EsNetworkEntryGrain.setType(3);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                                if(StringUtils.isNotBlank(strings[44])){
                                    quantity=new BigDecimal(strings[44]);
                                }

                                EsNetworkEntryGrain.setQuantity(quantity);//数量
                            }else if(strings[38] != null && strings[38] != ""){
                                EsNetworkEntryGrain.setType(4);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力

                                if(StringUtils.isNotBlank(strings[54])){
                                    quantity=new BigDecimal(strings[54]);
                                }

                                EsNetworkEntryGrain.setQuantity(quantity);//数量
                            }
                            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
                        }



                        res = 1;
                        if(res>0){
                            insertNum+= 1;
                        } else{
                            failNum+= 1;
                        }
                    }else{
                        skipNum+= 1;
                    }

                }

            }
            map.put("status", 200);
            map.put("massage", "共" + size + ",跳过" + skipNum + ",失败" + failNum + ",成功新增" + insertNum + ",成功更新" + updateNum);
            return map;

        } else {
            map.put("status", 500);
            map.put("massage", "未读取到有效数据或存在无法解析的属性");
            return map;
        }

    }
    @Transactional
    public void importUpdate (String[] strings, List<EsNetworkEntry> list, Integer updateNum, Integer res, Integer failNum){

        EsNetworkEntry EsNetworkEntry = list.get(0);
        EsNetworkEntry.setId(EsNetworkEntry.getId());
        //修改

        QueryWrapper<BizDict> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.eq("DICT_LABEL",strings[1]);
        List<BizDict> list1 = BizDictServiceImpl.list(queryWrapper1);
        EsNetworkEntry.setManagementAreaProvince(list1.get(0).getId());//归口管理地区-省

        QueryWrapper<BizDict> queryWrapper2 = new QueryWrapper<>();
        queryWrapper2.eq("DICT_LABEL",strings[2]);
        List<BizDict> list2 = BizDictServiceImpl.list(queryWrapper2);
        EsNetworkEntry.setManagementAreaCity(list2.get(0).getId());//归口管理地区-市

        QueryWrapper<BizDict> queryWrapper3 = new QueryWrapper<>();
        queryWrapper3.eq("DICT_LABEL",strings[3]);
        List<BizDict> list3 = BizDictServiceImpl.list(queryWrapper3);
        EsNetworkEntry.setManagementAreaCounty(list3.get(0).getId());//归口管理地区-县


        QueryWrapper<BizDict> queryWrapper4 = new QueryWrapper<>();
        queryWrapper4.eq("DICT_LABEL",strings[4]);
        List<BizDict> list4 = BizDictServiceImpl.list(queryWrapper4);
        EsNetworkEntry.setActualAddressProvince(list4.get(0).getId());//实际经营地址-省

        QueryWrapper<BizDict> queryWrapper5 = new QueryWrapper<>();
        queryWrapper5.eq("DICT_LABEL",strings[5]);
        List<BizDict> list5 = BizDictServiceImpl.list(queryWrapper5);
        EsNetworkEntry.setActualAddressCity(list5.get(0).getId());//实际经营地址-市

        QueryWrapper<BizDict> queryWrapper6 = new QueryWrapper<>();
        queryWrapper6.eq("DICT_LABEL",strings[6]);
        List<BizDict> list6 = BizDictServiceImpl.list(queryWrapper6);
        EsNetworkEntry.setActualAddressCounty(list6.get(0).getId());//实际经营地址-县


        if(strings[7] != null && strings[7] != ""){
            EsNetworkEntry.setIsNational(1);//供应应急级别-是否国家级，0：否；1：是
        }else{
            EsNetworkEntry.setIsNational(0);//供应应急级别-是否国家级，0：否；1：是
        }
        if(strings[8] != null && strings[8] != ""){
            EsNetworkEntry.setIsProvincial(1);//供应应急级别-是否省级，0：否；1：是
        }else{
            EsNetworkEntry.setIsProvincial(0);//供应应急级别-是否省级，0：否；1：是
        }

        if(strings[9] != null && strings[9] != ""){
            EsNetworkEntry.setIsCity(1);//供应应急级别-是否市级，0：否；1：是
        }else{
            EsNetworkEntry.setIsCity(0);//供应应急级别-是否市级，0：否；1：是
        }

        if(strings[10] != null && strings[10] != ""){
            EsNetworkEntry.setIsCounty(1);//供应应急级别-是否县级，0：否；1：是
        }else{
            EsNetworkEntry.setIsCounty(0);//供应应急级别-是否县级，0：否；1：是
        }


        EsNetworkEntry.setHeadquarterCreditCode(strings[11]);//所属总公司企业信用代码
        EsNetworkEntry.setEnterpriseName(strings[12]);//企业名称
        EsNetworkEntry.setCreditCode(strings[13]);//统一社会信用代码
        EsNetworkEntry.setActualBusinessAddress(strings[14]);//实际经营地址（省、市、县、乡镇街道门牌号）

        QueryWrapper<BizDict> queryWrapper7 = new QueryWrapper<>();
        queryWrapper7.eq("DICT_LABEL",strings[15]);
        List<BizDict> list7 = BizDictServiceImpl.list(queryWrapper7);
        EsNetworkEntry.setEnterpriseNature(strings[15]);//企业性质
        QueryWrapper<BizDict> queryWrapper8 = new QueryWrapper<>();
        queryWrapper8.eq("DICT_LABEL",strings[16]);
        List<BizDict> list8 = BizDictServiceImpl.list(queryWrapper8);
        EsNetworkEntry.setEnterpriseType(strings[16]);//企业类型

        EsNetworkEntry.setLongitude(new BigDecimal(strings[17]));//经度

        EsNetworkEntry.setLatitude(new BigDecimal(strings[18]));//纬度


        EsNetworkEntry.setLegalRepresentative(strings[19]);//法人姓名
        EsNetworkEntry.setLegalContact(strings[20]);//法人联系方式
        EsNetworkEntry.setContactPerson(strings[21]);//联系人姓名
        EsNetworkEntry.setContactNumber(strings[22]);//联系电话


        if(strings[39] != null && strings[39] != ""){
            if(strings[39].equals("生产")){
                EsNetworkEntry.setProductionStatus(1);//生产状态，0：停产；1：生产
            }else{
                EsNetworkEntry.setProductionStatus(0);//生产状态，0：停产；1：生产
            }
        }
        EsNetworkEntry.setCityState(strings[5].trim());

        this.updateById(EsNetworkEntry);

        QueryWrapper<EsNetworkEntryGrain> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("es_network_entry_id", EsNetworkEntry.getId());
        List<EsNetworkEntryGrain> zList = esNetworkEntryGrainService.list(queryWrapper);
        esNetworkEntryGrainService.removeByIds(zList);

        /**
         * 数量
         */
        BigDecimal quantity=new BigDecimal(0.00);
        if((strings[23] != null && strings[23] != "") || (strings[32] != null && strings[32] != "") || (strings[41] != null && strings[41] != "") || (strings[51] != null && strings[51] != "")){
            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
            EsNetworkEntryGrain.setGrainVariety(1);//粮食品种 1：小麦粉成品粮
            if(strings[23] != null && strings[23] != ""){
                EsNetworkEntryGrain.setType(1);//类型 1：日库存；
                if(strings[23]!=null&&!strings[23].isEmpty()){
                    quantity=new BigDecimal(strings[23]);
                }
                EsNetworkEntryGrain.setQuantity(quantity);//数量
            }else if(strings[27] != null && strings[27] != ""){
                EsNetworkEntryGrain.setType(2);//类型 2：日销量；
                if(strings[32]!=null&&!strings[32].isEmpty()){
                    quantity=new BigDecimal(strings[32]);
                }
                EsNetworkEntryGrain.setQuantity(quantity);//数量
            }else if(strings[31] != null && strings[31] != ""){
                EsNetworkEntryGrain.setType(3);//类型 3：日供应能力；
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[41]));//数量
            }else if(strings[35] != null && strings[35] != ""){
                EsNetworkEntryGrain.setType(4);//类型 4：安全库存
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[51]));//数量
            }
            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
        }
        if((strings[24] != null && strings[24] != "") || (strings[28] != null && strings[28] != "") || (strings[32] != null && strings[32] != "") || (strings[36] != null && strings[36] != "")){
            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
            EsNetworkEntryGrain.setGrainVariety(2);//粮食品种 2：大米成品粮；
            if(strings[24] != null && strings[24] != ""){
                EsNetworkEntryGrain.setType(1);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力

                if(StringUtils.isNotBlank(strings[24])){
                    quantity=new BigDecimal(strings[24]);
                }
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[24]));//数量

            }else if(strings[28] != null && strings[28] != ""){
                EsNetworkEntryGrain.setType(2);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[33]));//数量

            }else if(strings[32] != null && strings[32] != ""){
                EsNetworkEntryGrain.setType(3);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[42]));//数量

            }else if(strings[36] != null && strings[36] != ""){
                EsNetworkEntryGrain.setType(4);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[52]));//数量

            }
            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
        }
        if((strings[25] != null && strings[25] != "") || (strings[29] != null && strings[29] != "") || (strings[33] != null && strings[33] != "") || (strings[37] != null && strings[37] != "")){
            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
            EsNetworkEntryGrain.setGrainVariety(3);//粮食品种 1：小麦原粮:2：稻谷原粮:3：大豆原粮；4：玉米原粮；5：其他原粮；6：小麦粉成品粮；7：大米成品粮；8：食用油成品粮；9：其他成品粮
            if(strings[25] != null && strings[25] != ""){
                EsNetworkEntryGrain.setType(1);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[25]));//数量

            }else if(strings[29] != null && strings[29] != ""){
                EsNetworkEntryGrain.setType(2);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[34]));//数量

            }else if(strings[33] != null && strings[33] != ""){
                EsNetworkEntryGrain.setType(3);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[43]));//数量

            }else if(strings[37] != null && strings[53] != ""){
                EsNetworkEntryGrain.setType(4);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[53]));//数量

            }
            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
        }
        if((strings[26] != null && strings[26] != "") || (strings[30] != null && strings[30] != "") || (strings[34] != null && strings[34] != "") || (strings[38] != null && strings[38] != "")){
            EsNetworkEntryGrain EsNetworkEntryGrain = new EsNetworkEntryGrain();
            EsNetworkEntryGrain.setEsNetworkEntryId(EsNetworkEntry.getId());//biz_es_storage_enterprise的id
            EsNetworkEntryGrain.setGrainVariety(4);//粮食品种 1：小麦原粮:2：稻谷原粮:3：大豆原粮；4：玉米原粮；5：其他原粮；6：小麦粉成品粮；7：大米成品粮；8：食用油成品粮；9：其他成品粮
            if(strings[26] != null && strings[26] != ""){
                EsNetworkEntryGrain.setType(1);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                if(strings[26]!=null&&!strings[26].isEmpty()){
                    quantity =new BigDecimal(strings[26]);
                }
                EsNetworkEntryGrain.setQuantity(quantity);//数量
            }else if(strings[30] != null && strings[30] != ""){
                EsNetworkEntryGrain.setType(2);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[35]));//数量
            }else if(strings[34] != null && strings[34] != ""){
                EsNetworkEntryGrain.setType(3);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[44]));//数量
            }else if(strings[38] != null && strings[38] != ""){
                EsNetworkEntryGrain.setType(4);//类型 1：日库存；2：日出库量；3：日入库量；4：出库能力
                EsNetworkEntryGrain.setQuantity(new BigDecimal(strings[54]));//数量
            }
            esNetworkEntryGrainService.save(EsNetworkEntryGrain);
        }

        res = 1;
        if(res>0){
            updateNum+= 1;
        } else{
            failNum+= 1;
        }

    }

}
