aaa
doum
2026-06-04 08e9a67dd679f311e79a27b04cd0c53a30b4bccf
server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -1,5 +1,6 @@
package com.doumee.service.business.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -17,18 +18,22 @@
import com.doumee.dao.business.*;
import com.doumee.dao.business.join.GoodsJoinMapper;
import com.doumee.dao.business.model.*;
import com.doumee.dao.business.model.dto.BatchDisableDTO;
import com.doumee.dao.business.model.dto.GoodCreatePlatRequest;
import com.doumee.dao.business.model.dto.GoodsRequest;
import com.doumee.dao.business.model.dto.PlatGoodsParam;
import com.doumee.dao.business.model.dto.*;
import com.doumee.dao.system.model.SystemDepartment;
import com.doumee.service.CateParamSelectService;
import com.doumee.service.business.BaseDataService;
import com.doumee.service.business.GoodsService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import io.swagger.v3.oas.annotations.callbacks.Callback;
import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
@@ -43,6 +48,8 @@
import java.net.URLEncoder;
import java.nio.charset.Charset;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
 * 商品信息表Service实现
@@ -55,11 +62,16 @@
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    @Lazy
    private BaseDataService baseDataService;
    @Autowired
    private BaseGoodsMapper baseGoodsMapper;
    @Autowired
    private BaseGoodsParamMapper baseGoodsParamMapper;
    @Autowired
    private CategoryMapper categoryMapper;
    @Autowired
    private BaseCategoryMapper baseCategoryMapper;
    @Autowired
    private CateAttrMapper cateAttrMapper;
    @Autowired
@@ -76,10 +88,13 @@
    @Autowired
    private GoodsJoinMapper goodsJoinMapper;
    @Lazy
    @Autowired
    private CateParamSelectMapper cateParamSelectMapper;
    private CateParamSelectService cateParamSelectService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Override
@@ -127,10 +142,13 @@
        return goods.getId();
    }
    @Async
    @Override
    @Transactional( rollbackFor = {Exception.class, BusinessException.class})
    public  Integer createPlat(GoodCreatePlatRequest param){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(Constants.equalsInteger(user.getType(), Constants.UserType.COMPANY.getKey())){
        if(!Constants.equalsInteger(user.getType(), Constants.UserType.COMPANY.getKey())){
            //非企业用户不能操作
            throw new BusinessException(ResponseStatus.NOT_ALLOWED);
        }
@@ -143,12 +161,17 @@
            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
        }
        Category category = categoryMapper.selectById(param.getCategoryId());
        if(category ==null ||Constants.equalsInteger(category.getIsdeleted(), Constants.ONE) ||Constants.equalsInteger(category.getCompanyId(), user.getCompanyId())){
        if(category ==null ||Constants.equalsInteger(category.getIsdeleted(), Constants.ONE) ||!Constants.equalsInteger(category.getCompanyId(), user.getCompanyId())){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,类别信息不正确,请刷新重试!");
        }
        if(category.getPlatCateId() == null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请前往【类别管理】先关联平台类别!");
        }
        BaseCategory baseCategory = baseCategoryMapper.selectById(category.getPlatCateId());
        if(baseCategory == null){
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请前往【类别管理】先关联平台类别!");
        }
        BaseGoods bp = new BaseGoods();
        bp.setCategoryId(category.getPlatCateId());
        bp.setIsdeleted(Constants.ZERO);
@@ -160,32 +183,51 @@
                if(p.getGoodsId() == null || p.getPrice() == null){
                    throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请正确选择平台商品并配置入手价!");
                }
                if(ids == null){
                    ids = new ArrayList<>();
                }
                ids.add(p.getGoodsId());
            }
        }
        goodsList = baseGoodsMapper.selectList(new QueryWrapper<>(bp).lambda().in((ids!=null && ids.size()>0),BaseGoods::getId,ids));
        if(Constants.equalsInteger(Constants.ONE, param.getType()) || goodsList==null || ids.size()!=goodsList.size()){
        if(Constants.equalsInteger(Constants.ONE, param.getType()) &&( goodsList==null || ids.size()!=goodsList.size())){
            //  如果选择平台商品和查询结果对不上,提示错误
            throw  new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,请正确选择平台商品!");
        }
        for(BaseGoods model : goodsList){
            //遍历平台商品信息,进行商品信息同步
            Goods goods = initGoodsPlatParam(user,model,param);
            if(goods == null){
                continue;
        List<Multifile> multifileList = new ArrayList<>();
        List<GoodsParam> goodsParamList = new ArrayList<>();
        try{
            for(BaseGoods model : goodsList){
                //遍历平台商品信息,进行商品信息同步
                //分类加价系数
                model.setCateRatePrice(baseCategory.getPriceRate());
                Goods goods = initGoodsPlatParam(user,model,param);
                if(goods == null){
                    continue;
                }
                goodsMapper.insert(goods);
                //开始处理附件
                dealPlatMultifule(goods.getId(),user,model,multifileList);
                //开始处理参数配置
                dealPlatGoodsParam(model,goods,user,goodsParamList);
            }
            goodsMapper.insert(goods);
           //开始处理附件
            dealPlatMultifule(goods.getId(),user,model);
            //开始处理参数配置
            dealPlatGoodsParam(model,goods,user);
            if(multifileList.size()>0){
                multifileMapper.insertBatch(multifileList);
            }
            if(goodsParamList.size()>0){
                goodsParamMapper.insertBatch(goodsParamList);
            }
            cateParamSelectService.dealCateParamSelect();
        }catch (Exception e){
           e.printStackTrace();
        }finally {
            redisTemplate.opsForValue().set(user.getCompanyId()+Constants.OPEN_SYNC_SWITCH,false);
        }
        return 1;
    }
    private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user) {
    private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user,List<GoodsParam> paramList) {
        BaseGoodsParam baseGoodsParam = new BaseGoodsParam();
        baseGoodsParam.setGoodsId(model.getId());
        baseGoodsParam.setIsdeleted(Constants.ZERO);
@@ -193,6 +235,16 @@
        if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
            for (int i = 0; i < goodsParamList.size(); i++) {
                BaseGoodsParam bgParam = goodsParamList.get(i);
                //根据平台商品配置的平台参数信息查询企业绑定的参数信息 进行存储到 企业商品参数内
                CateParam cateParam = cateParamMapper.selectOne(new QueryWrapper<CateParam>()
                        .eq("CATEGORY_ID",goods.getCategoryId())
                        .eq("BASE_CATE_PARAM_ID",bgParam.getPramaId())
                        .eq("ISDELETED",Constants.ZERO)
                        .eq("STATUS",Constants.ZERO)
                        .last(" limit 1 "));
//                if(Objects.isNull(cateParam)){
//                    throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"企业分类数据同步异常请联系管理员");
//                }
                GoodsParam goodsParam = new GoodsParam();
                goodsParam.setCreator(user.getId());
                goodsParam.setCreateDate(new Date());
@@ -202,7 +254,9 @@
                goodsParam.setGoodsId(goods.getId());
                goodsParam.setVal(bgParam.getVal());
                goodsParam.setName(bgParam.getName());
                goodsParamMapper.insert(goodsParam);
                goodsParam.setPramaId(Objects.isNull(cateParam)?null:cateParam.getId());
                paramList.add(goodsParam);
//                goodsParamMapper.insert(goodsParam);
            }
        }
    }
@@ -211,6 +265,7 @@
        Goods goods = new Goods();
        goods.setIsdeleted(Constants.ZERO);
        goods.setGoodsId(model.getId());
        goods.setCompanyId(user.getCompanyId());
        if(goodsMapper.selectCount(new QueryWrapper<>(goods))>0){
            //如果已经同步过,跳过此次同步
            return  null;
@@ -219,6 +274,7 @@
        goods.setStatus(Constants.ZERO);
        goods.setCreateDate(new Date());
        goods.setCreator(user.getId());
        goods.setCompanyId(user.getCompanyId());
        goods.setIsdeleted(Constants.ZERO);
        //处理拼音问题
        goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
@@ -237,10 +293,12 @@
    /**
     *  开始处理平台商品关联附件,复制一套到企业商品上
     */
    private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model) {
    private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model,List<Multifile> fileList ) {
        Multifile f = new Multifile();
        f.setObjId(model.getId());
        f.setObjType(Constants.ONE);
        f.setIsdeleted(Constants.ZERO);
        f.setObjType(Constants.ONE);
        List<Multifile> multifileList =multifileMapper.selectList(new QueryWrapper<>(f));
        if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
            for (int i = 0; i < multifileList.size(); i++) {
@@ -256,7 +314,8 @@
                multifile.setName(multifile.getName());
                multifile.setSortnum(multifile.getSortnum());
                multifile.setCompanyId(user.getCompanyId());
                multifileMapper.insert(multifile);
                fileList.add(multifile);
//                multifileMapper.insert(multifile);
            }
        }
    }
@@ -265,16 +324,17 @@
        if(Constants.equalsInteger(Constants.ONE, param.getType())){
            for(PlatGoodsParam p: param.getGoodsParamList()){
                if(Constants.equalsInteger(model.getId(),p.getGoodsId())){
                    return p.getPrice();
                    return p.getPrice().setScale(0,BigDecimal.ROUND_CEILING);
                }
            }
            throw new BusinessException(ResponseStatus.DATA_ERRO.getCode(),"数据异常请刷新重试");
        }
        //如果没有配置入手价,安装加价系数来计算
        if(model.getCateRatePrice()==null){
            model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate());
        }
        //返回
        return Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate());
        //返回 .multiply(model.getCateRatePrice())
        return (Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate())).setScale(0,BigDecimal.ROUND_CEILING);
    }
@@ -294,15 +354,18 @@
        goods.setCreateDate(new Date());
        goods.setCreator(user.getId());
        goods.setIsdeleted(Constants.ZERO);
        //处理拼音问题
        goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
        goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
        this.validateSubCategory(goods);
        goodsMapper.insert(goods);
        List<Multifile> multifileList = goods.getMultifileList();
        if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
            for (int i = 0; i < multifileList.size(); i++) {
                Multifile multifile = multifileList.get(i);
                if(StringUtils.isBlank(multifile.getFileurl())){
                    continue;
                }
                multifile.setCreator(user.getId());
                multifile.setCreateDate(new Date());
                multifile.setIsdeleted(Constants.ZERO);
@@ -310,6 +373,7 @@
                multifile.setObjId(goods.getId());
                multifile.setType(Constants.ZERO);
                multifile.setObjType(Constants.ZERO);
                multifile.setCompanyId(goods.getCompanyId());
                multifileMapper.insert(multifile);
            }
        }
@@ -317,6 +381,7 @@
        if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
            for (int i = 0; i < goodsParamList.size(); i++) {
                GoodsParam goodsParam = goodsParamList.get(i);
                goodsParam.setId(null);
                goodsParam.setCreator(user.getId());
                goodsParam.setCreateDate(new Date());
                goodsParam.setIsdeleted(Constants.ZERO);
@@ -324,20 +389,6 @@
                goodsParam.setSortnum(i+Constants.ONE);
                goodsParam.setGoodsId(goods.getId());
                goodsParamMapper.insert(goodsParam);
                //存储 cate_param_select 查询是否已存在
                if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
                        .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){
                    CateParamSelect cateParamSelect = new CateParamSelect();
                    cateParamSelect.setCreator(user.getId());
                    cateParamSelect.setCreateDate(new Date());
                    cateParamSelect.setName(goodsParam.getVal());
                    cateParamSelect.setIsdeleted(Constants.ZERO);
                    cateParamSelect.setStatus(Constants.ZERO);
                    cateParamSelect.setParamId(goodsParam.getPramaId());
                    cateParamSelect.setCategoryId(goods.getCategoryId());
                    cateParamSelect.setStatus(Constants.ZERO);
                    cateParamSelectMapper.insert(cateParamSelect);
                };
            }
        }
        return goods.getId();
@@ -364,7 +415,10 @@
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        goodsMapper.deleteBatchIds(ids);
        for(Integer id : ids){
            deleteById(id);
        }
//        goodsMapper.deleteBatchIds(ids);
    }
    @Override
@@ -422,19 +476,21 @@
        }else{
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前登录用户类别错误,无法进行该操作");
        }
        if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId()).eq("ISDELETED",Constants.ZERO).ne("id",goods.getId()).eq("name",goods.getName()))>0){
        if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("COMPANY_ID",user.getCompanyId())
                .eq("ISDELETED",Constants.ZERO).ne("id",goods.getId()).eq("name",goods.getName()))>0){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+goods.getName()+"】已存在");
        };
        goods.setStatus(Constants.ZERO);
        goods.setEditDate(new Date());
        goods.setEditor(user.getId());
        goods.setIsdeleted(Constants.ZERO);
        //处理拼音问题
        goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
        goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
        this.validateSubCategory(goods);
        goodsMapper.updateById(goods);
        multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId()));
        multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",goods.getId())
                .eq("OBJ_TYPE",0).eq("COMPANY_ID",user.getCompanyId()));
        List<Multifile> multifileList = goods.getMultifileList();
        if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
            for (int i = 0; i < multifileList.size(); i++) {
@@ -445,6 +501,7 @@
                multifile.setSortnum(i+Constants.ONE);
                multifile.setObjId(goods.getId());
                multifile.setType(Constants.ZERO);
                multifile.setCompanyId(goods.getCompanyId());
                multifile.setObjType(Constants.ZERO);
                multifileMapper.insert(multifile);
            }
@@ -454,6 +511,7 @@
        if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
            for (int i = 0; i < goodsParamList.size(); i++) {
                GoodsParam goodsParam = goodsParamList.get(i);
                goodsParam.setId(null);
                goodsParam.setCreator(user.getId());
                goodsParam.setCreateDate(new Date());
                goodsParam.setIsdeleted(Constants.ZERO);
@@ -462,19 +520,19 @@
                goodsParam.setGoodsId(goods.getId());
                goodsParamMapper.insert(goodsParam);
                //存储 cate_param_select 查询是否已存在
                if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
                        .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){
                    CateParamSelect cateParamSelect = new CateParamSelect();
                    cateParamSelect.setCreator(user.getId());
                    cateParamSelect.setCreateDate(new Date());
                    cateParamSelect.setName(goodsParam.getVal());
                    cateParamSelect.setIsdeleted(Constants.ZERO);
                    cateParamSelect.setStatus(Constants.ZERO);
                    cateParamSelect.setParamId(goodsParam.getPramaId());
                    cateParamSelect.setCategoryId(goods.getCategoryId());
                    cateParamSelect.setStatus(Constants.ZERO);
                    cateParamSelectMapper.insert(cateParamSelect);
                };
//                if(cateParamSelectMapper.selectCount(new QueryWrapper<CateParamSelect>()
//                        .eq("PARAM_ID",goodsParam.getPramaId()).eq("NAME",goodsParam.getName()))<=Constants.ZERO){
//                    CateParamSelect cateParamSelect = new CateParamSelect();
//                    cateParamSelect.setCreator(user.getId());
//                    cateParamSelect.setCreateDate(new Date());
//                    cateParamSelect.setName(goodsParam.getVal());
//                    cateParamSelect.setIsdeleted(Constants.ZERO);
//                    cateParamSelect.setStatus(Constants.ZERO);
//                    cateParamSelect.setParamId(goodsParam.getPramaId());
//                    cateParamSelect.setCategoryId(goods.getCategoryId());
//                    cateParamSelect.setStatus(Constants.ZERO);
//                    cateParamSelectMapper.insert(cateParamSelect);
//                };
            }
        }
    }
@@ -499,7 +557,7 @@
            throw new BusinessException(ResponseStatus.DATA_EMPTY);
        }
        //拉式商品 且 上架时,需要限制 平台商品是否已下架
        if(dbGoods.getType().equals(Constants.goodsType.PULL)&&goods.getStatus().equals(Constants.ZERO)){
        if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&goods.getStatus().equals(Constants.ZERO)){
            BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId());
            if(Objects.isNull(baseGoods)){
                throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到平台商品信息");
@@ -537,7 +595,7 @@
                continue;
            }
            //拉式商品 且 上架时,需要限制 平台商品是否已下架
            if(dbGoods.getType().equals(Constants.goodsType.PULL)&&batchDisableDTO.getStatus().equals(Constants.ZERO)){
            if(dbGoods.getType().equals(Constants.goodsType.PULL.getValue())&&batchDisableDTO.getStatus().equals(Constants.ZERO)){
                BaseGoods baseGoods = baseGoodsMapper.selectById(dbGoods.getGoodsId());
                if(Objects.isNull(baseGoods)||!baseGoods.getStatus().equals(Constants.ZERO)){
                    errNum++;
@@ -559,8 +617,8 @@
    @Override
    public Goods findById(Integer id) {
        Goods goods = goodsMapper.selectById(id);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        goods.setPrefixUrl(prefixUrl);
        Brand brand = brandMapper.selectById(goods.getBrandId());
        if(!Objects.isNull(brand)){
@@ -570,7 +628,7 @@
        if(!Objects.isNull(category)){
            goods.setCategoryName(category.getName());
        }
        goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",id)));
        goods.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_TYPE",Constants.ZERO).eq("OBJ_ID",id)));
        return goods;
    }
@@ -592,6 +650,7 @@
        queryWrapper.leftJoin(Category.class, Category::getId, Goods::getCategoryId);
        queryWrapper.leftJoin(Brand.class, Brand::getId, Goods::getBrandId);
        queryWrapper.eq(Goods::getStatus,Constants.ZERO);
        queryWrapper.eq(Goods::getCompanyId, goods.getCompanyId());
        queryWrapper.eq(Goods::getIsdeleted,Constants.ZERO);
        queryWrapper.like(StringUtils.isNotBlank(goods.getAttrFirstIds()),Goods::getAttrFirstIds,goods.getAttrFirstIds());
        queryWrapper.like(StringUtils.isNotBlank(goods.getAttrFirstNames()),Goods::getAttrFirstNames,goods.getAttrFirstNames());
@@ -602,14 +661,11 @@
        queryWrapper.between(!Objects.isNull(goods.getSPrice())&&!Objects.isNull(goods.getEPrice()),
                Goods::getPrice,goods.getSPrice(),goods.getEPrice());
        queryWrapper.orderByDesc(Goods::getId);
        List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        goodsList.forEach(i->{
            i.setPrefixUrl(prefixUrl);
            i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM ")));
            i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()).orderByAsc(" SORTNUM ")));
        });
        List<Goods> goodsList =  this.goodsMapper.selectListByCollection(goods);
      //  List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper);
        if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){
            this.dealGoodsMsg(goodsList);
        }
        return goodsList;
    }
@@ -621,11 +677,16 @@
        queryWrapper.selectAll(Goods.class);
        queryWrapper.selectAs(Category::getName, Goods::getCategoryName);
        queryWrapper.selectAs(BaseGoods::getZdPrice, Goods::getBaseZdPrice);
        queryWrapper.selectAs(BaseGoods::getPrice, Goods::getBasePrice);
        queryWrapper.selectAs(Brand::getName, Goods::getBrandName);
        queryWrapper.selectAs(Category::getAttrFirst, Goods::getAttrFirst);
        queryWrapper.selectAs(Category::getAttrSecond, Goods::getAttrSecond);
        queryWrapper.selectAs(BaseCategory::getPriceRate,Goods::getBasePriceRate);
        queryWrapper.leftJoin(Category.class, Category::getId, Goods::getCategoryId);
        queryWrapper.leftJoin(Brand.class, Brand::getId, Goods::getBrandId);
        queryWrapper.leftJoin(BaseGoods.class,BaseGoods::getId,Goods::getGoodsId);
        queryWrapper.leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getCategoryId);
        queryWrapper.eq(Goods::getIsdeleted, Constants.ZERO);
        if (pageWrap.getModel().getId() != null) {
@@ -637,21 +698,27 @@
        if (pageWrap.getModel().getStatus() != null) {
            queryWrapper.eq(Goods::getStatus, pageWrap.getModel().getStatus());
        }
        if (pageWrap.getModel().getType() != null) {
            queryWrapper.eq(Goods::getType, pageWrap.getModel().getType());
        }
        if (pageWrap.getModel().getCategoryId() != null) {
            queryWrapper.eq(Goods::getCategoryId, pageWrap.getModel().getCategoryId());
        }
        if (pageWrap.getModel().getBrandId() != null) {
            queryWrapper.eq(Goods::getBrandId, pageWrap.getModel().getBrandId());
        }
        if (pageWrap.getModel().getCompanyId() != null) {
            queryWrapper.eq(Goods::getCompanyId, pageWrap.getModel().getCompanyId());
        }
        queryWrapper.orderByDesc(Goods::getId);
        IPage<Goods> goodsIPage =  goodsJoinMapper.selectJoinPage(page, Goods.class, queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        goodsIPage.getRecords().forEach(i->{
            i.setPrefixUrl(prefixUrl);
            if(i.getType().equals(Constants.ONE)){
                i.setBasePrice(Constants.formatBigdecimal(i.getBasePrice()).multiply(Constants.formatBigdecimal(i.getBasePriceRate())).setScale(0,BigDecimal.ROUND_CEILING));
            }
        });
        return PageData.from(goodsIPage);
    }
@@ -674,6 +741,265 @@
    @Override
    public Integer importBatch(MultipartFile file){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Boolean  isGrouping = (Boolean)redisTemplate.opsForValue().get(user.getCompanyId()+Constants.COMPANY_IMPORT_GOODS);
        if(isGrouping!=null && isGrouping ){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"当前已存在产品导入操作,此次操作无效,请稍后重试!");
        }
        redisTemplate.opsForValue().set(user.getCompanyId()+Constants.COMPANY_IMPORT_GOODS,true,30, TimeUnit.MINUTES);
        int num =1,index =1;
        try {
            ExcelImporter ie =  new ExcelImporter(file,0,0);;
            List<GoodsImport> dataList =ie.getDataList(GoodsImport.class,null);
            if(dataList == null || dataList.size() ==0){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!");
            }
            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
            String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode() + proDir + File.separator + user.getCompanyId();
            //品类数据
            List<Brand> brandList = brandMapper.selectList(new LambdaQueryWrapper<Brand>() .eq(Brand::getIsdeleted,Constants.ZERO)
                    .and(wapper-> wapper.eq(Brand::getCompanyId ,user.getCompanyId()).or().eq(Brand::getType,Constants.ONE)));
            //企业产品数据
            List<Goods> goodsList = goodsMapper.selectList(new LambdaQueryWrapper<Goods>() .eq(Goods::getIsdeleted,Constants.ZERO)
                    .eq(Goods::getCompanyId,user.getCompanyId()));
            //品类数据
            List<Category> categoryList = categoryMapper.selectList(new LambdaQueryWrapper<Category>() .eq(Category::getIsdeleted,Constants.ZERO)
                            .eq(Category::getCompanyId,user.getCompanyId()));
            //查询全部产品参数配置
            List<CateParam> allParamsList = cateParamMapper.selectList(new LambdaQueryWrapper<CateParam>().eq(CateParam::getIsdeleted,Constants.ZERO));
            for(GoodsImport m: dataList){
                if(StringUtils.isBlank(m.getName())
                        &&StringUtils.isBlank(m.getCategory())
                        &&StringUtils.isBlank(m.getZdPrice())
                        &&StringUtils.isBlank(m.getPrice())
                        &&StringUtils.isBlank(m.getId())
                        &&StringUtils.isBlank(m.getBrand())){
                   // 全部空行,跳过处理;
                    num++;
                    continue;
                }
                if(StringUtils.isBlank(m.getName())
                        ||StringUtils.isBlank(m.getCategory())
                        ||StringUtils.isBlank(m.getZdPrice())
                        ||StringUtils.isBlank(m.getPrice())
                        ||StringUtils.isBlank(m.getId())
                        ||StringUtils.isBlank(m.getBrand())){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行数据无效,请检查输入!");
                }
                Goods g = new Goods();
                g.setIsdeleted(Constants.ZERO);
                g.setRemark(m.getId());
                g.setCompanyId(user.getCompanyId());
                //品类数据
                g = goodsMapper.selectOne(new QueryWrapper<>(g).last(" limit 1"));
                if(g != null){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品图片文件夹重复,请检查输入!");
                }
                Category cate = getCategroyByNameFromList(m.getCategory(),categoryList);
                if(cate == null){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品类别无效,请检查输入!");
                }
                Brand brand = getImportBrandByNameFromList(m.getBrand(),brandList);
                if(brand == null){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品品牌无效,请检查输入!");
                }
                if(findGoodsByNameFromList(m.getName(),goodsList) !=null){
                        throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"第【"+(num)+"】行产品名称【"+m.getName()+"】已存在");
                }
                Goods newModel = new Goods();
                newModel.setRemark(m.getId());
                newModel.setCategoryId(cate.getId());
                newModel.setBrandId(brand.getId());
                newModel.setIsdeleted(Constants.ZERO);
                newModel.setCreator(user.getId());
                newModel.setCompanyId(user.getCompanyId());
                newModel.setCreateDate(new Date());
                newModel.setName(m.getName());
                newModel.setStatus(Constants.ZERO);
                try {
                    newModel.setZdPrice(BigDecimal.valueOf(Double.parseDouble(m.getZdPrice())));
                    newModel.setPrice(BigDecimal.valueOf(Double.parseDouble(m.getPrice())));
                }catch (Exception e){
                }
                if(newModel.getZdPrice() == null){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行指导价无效,请检查输入!");
                }
                if(newModel.getPrice() == null){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行入手价无效,请检查输入!");
                }
                newModel.setPinyin(PinYinUtil.getFullSpell(m.getName()));
                newModel.setShortPinyin(PinYinUtil.getFirstSpell(m.getName()));
                List<String> mulFiles =getGoodsImageFileList(newModel,path);
                //查询商品信息
                goodsMapper.insert(newModel);
                //加入到已经存在的产品集合中,用于下一个信息去重处理
                goodsList.add(newModel);
                //处理产品属性业务
                dealGoodsParamBiz(cate,newModel,m,allParamsList,num);
                //处理产品图片资源业务
                dealGoodsImagesBiz(mulFiles,newModel);
                index++;//记录导入产品成功+1
            }
        }catch (BusinessException e){
            throw e;
        }catch (Exception e){
            throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"导入产品数据发生异常,请稍后重试!");
        }finally {
            redisTemplate.opsForValue().set(user.getCompanyId()+Constants.COMPANY_IMPORT_GOODS,false);
        }
        return  index;
    }
    private void dealGoodsImagesBiz(List<String> mulFiles, Goods newModel) {
        if(mulFiles !=null && mulFiles.size()>0){
            List<Multifile> multifileList = new ArrayList<>();
            for(int i=0;i<mulFiles.size();i++){
                String s = mulFiles.get(i);
                Multifile f = new Multifile();
                f.setObjType(Constants.ZERO);
                f.setName(s);
                f.setType(Constants.ZERO);
                f.setObjId(newModel.getId());
                f.setCreateDate(newModel.getCreateDate());
                f.setCreator(newModel.getCreator());
                f.setIsdeleted(Constants.ZERO);
                f.setSortnum(i);
                f.setCompanyId(newModel.getCompanyId());
                f.setFileurl(s);
                multifileList.add(f);
            }
            multifileMapper.insert(multifileList);
        }
    }
    private List<String> getGoodsImageFileList(Goods newModel, String path) {
        List<String> mulFiles = null;
        if(StringUtils.isNotBlank(path)){
            OssModel ossModel = baseDataService.initOssModel();
            File dir =new File(path+File.separator+newModel.getRemark()+File.separator);
            if(dir!=null && dir.isDirectory()){
                File[]  files = dir.listFiles();
                if(files!=null && files.length>0){
                    for(File f:files){
                        if(StringUtils.isBlank(newModel.getImgurl()) && isImgFile(f)){
                            //取第一张图片作为列表图
                            newModel.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
                        }
                        if((mulFiles ==null || mulFiles.size() == 0) && f.isDirectory()){
                            //如果是文件夹
                            File[] fs = f.listFiles();
                            if(fs!=null && fs.length>0){
                                for(File mf : fs){
                                    if(isImgFile(mf)){
                                        if(mulFiles==null){
                                            mulFiles = new ArrayList<>();
                                        }
                                        mulFiles.add(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),mf));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return mulFiles;
    }
    private void dealGoodsParamBiz(Category cate, Goods newModel, GoodsImport m, List<CateParam> allParamsList,int num) {
        List<GoodsParam> paramList = new ArrayList<>();
        String[] params =  StringUtils.defaultString(m.getParamStr(),"").split("\n");
        //查询全部产品参数配置
        List<CateParam> allParams =getCateParamByCateid(cate.getId(),allParamsList);
        if(params.length > 0){
            for(String s : params){
                if(StringUtils.isBlank(s)){
                    continue;
                }
                s = s.replace(":",":");
                String[] ts = s.split(":");
                if(ts.length == 0){
                    continue;
                }
                //查询属性规格对象
                CateParam ta = getCateParamByName(ts[0], allParams);
                if(ta == null){
                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行产品参数中【"+s+"】无效,请检查输入!");
                }
                GoodsParam gp = new GoodsParam();
                gp.setIsdeleted(Constants.ZERO);
                gp.setCreator(newModel.getCreator());
                gp.setCreateDate(newModel.getCreateDate());
                gp.setGoodsId(newModel.getId());
                gp.setName(ta.getName());
                gp.setPramaId(ta.getId());
                gp.setStatus(Constants.ZERO);
                gp.setVal(ts.length>1?ts[1]:null);
                gp.setSortnum(ta.getSortnum());
                //插入产品参数关联表
                paramList.add(gp);
//                        goodsParamMapper.insert(gp);
            }
        }
        if(paramList.size() >0){
            goodsParamMapper.insert(paramList);
        }
    }
    private Goods findGoodsByNameFromList(String name, List<Goods> goodsList) {
        if(goodsList!=null){
            for(Goods brand :goodsList){
                if(StringUtils.equals(name.trim(),brand.getName())){
                    return brand;
                }
            }
        }
        return null;
    }
    private List<CateParam> getCateParamByCateid(Integer cateid, List<CateParam> allParamsList) {
        List<CateParam> list = null;
        if(allParamsList!=null){
            for(CateParam brand :allParamsList){
                if(Constants.equalsInteger(cateid,brand.getCategoryId())){
                   if(list == null){
                       list = new ArrayList<>();
                   }
                   list.add(brand);
                }
            }
        }
        return list;
    }
    private Category getCategroyByNameFromList(String name, List<Category> categoryList) {
        if(categoryList!=null){
            for(Category brand :categoryList){
                if(StringUtils.equals(name.trim(),brand.getName())){
                    return brand;
                }
            }
        }
        return null;
    }
    private Brand getImportBrandByNameFromList(String name, List<Brand> brandList) {
        if(brandList!=null){
            for(Brand brand :brandList){
                if(StringUtils.equals(name.trim(),brand.getName())){
                    return brand;
                }
            }
        }
        return null;
    }
    @Transactional(rollbackFor = {Exception.class, BusinessException.class})
    @Override
    public Integer importBatchImg(MultipartFile file){
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        ExcelImporter ie = null;
        List<GoodsImport> dataList =null;
        try {
@@ -688,134 +1014,32 @@
        int num =1;
        for(GoodsImport m: dataList){
            if(StringUtils.isBlank(m.getName())
                    &&StringUtils.isBlank(m.getCategory())
                    &&StringUtils.isBlank(m.getZdPrice())
                    &&StringUtils.isBlank(m.getPrice())
                    &&StringUtils.isBlank(m.getId())
                    &&StringUtils.isBlank(m.getBrand())){
            if(  StringUtils.isBlank(m.getId()) ){
                continue;
            }
            if(StringUtils.isBlank(m.getName())
                    ||StringUtils.isBlank(m.getCategory())
                    ||StringUtils.isBlank(m.getZdPrice())
                    ||StringUtils.isBlank(m.getPrice())
                    ||StringUtils.isBlank(m.getId())
                    ||StringUtils.isBlank(m.getBrand())){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行数据无效,请检查输入!");
            }
            Goods g = new Goods();
            g.setIsdeleted(Constants.ZERO);
            g.setRemark(m.getId());
            g.setCompanyId(user.getCompanyId());
            //品类数据
            g = goodsMapper.selectOne(new QueryWrapper<>(g).last(" limit 1"));
            if(g != null){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品图片文件夹重复,请检查输入!");
            if(g == null){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品不存在,请检查输入!");
            }
            Category cate = new Category();
            cate.setIsdeleted(Constants.ZERO);
            cate.setName(m.getCategory());
            //品类数据
            cate = categoryMapper.selectOne(new QueryWrapper<>(cate).last(" limit 1"));
            if(cate == null){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品类别无效,请检查输入!");
            }
            Brand brand = new Brand();
            brand.setIsdeleted(Constants.ZERO);
            brand.setName(m.getBrand());
            //品类数据
            brand = brandMapper.selectOne(new QueryWrapper<>(brand).last(" limit 1"));
            if(brand == null){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行商品品牌无效,请检查输入!");
            }
            if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",m.getName()))>0){
                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+m.getName()+"】已存在");
            };
            Goods newModel = new Goods();
            newModel.setRemark(m.getId());
            newModel.setCategoryId(cate.getId());
            newModel.setBrandId(brand.getId());
            newModel.setIsdeleted(Constants.ZERO);
            newModel.setCreator(user.getId());
            newModel.setCreateDate(new Date());
            newModel.setName(m.getName());
            newModel.setStatus(Constants.ZERO);
            try {
                newModel.setZdPrice(BigDecimal.valueOf(Double.parseDouble(m.getZdPrice())));
                newModel.setPrice(BigDecimal.valueOf(Double.parseDouble(m.getPrice())));
            }catch (Exception e){
            newModel.setId(g.getId());
            newModel.setEditor(user.getId());
            newModel.setEditDate(new Date());
            }
            if(newModel.getZdPrice() == null){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行指导价无效,请检查输入!");
            }
            if(newModel.getPrice() == null){
                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行入手价无效,请检查输入!");
            }
            newModel.setPinyin(PinYinUtil.getFullSpell(m.getName()));
            newModel.setShortPinyin(PinYinUtil.getFirstSpell(m.getName()));
            CateAttr ca = new CateAttr();
            ca.setCategoryId(cate.getId());
            ca.setIsdeleted(Constants.ZERO);
            //查询全部属性1和属性2规格值
            List<CateAttr> allAttr = cateAttrMapper.selectList(new QueryWrapper<>(ca));
            //属性1集合
            String[] attrs = StringUtils.defaultString(m.getAttrFirstNames(),"").split("\n");
            //属性2集合
            String[] attrs2 = StringUtils.defaultString(m.getAttrSecodNames(),"").split("\n");
            //产品参数集合
            String[] params =  StringUtils.defaultString(m.getParamStr(),"").split("\n");
            if(attrs.length > 0){
                String attrids="" ,attrNames="";
                for(String s : attrs){
                    if(StringUtils.isBlank(s)){
                        continue;
                    }
                    //查询属性规格对象
                    CateAttr ta = getCateAttrByName(s,Constants.ZERO,allAttr);
                    if(ta == null){
                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行属性1中【"+s+"】无效,请检查输入!");
                    }
                    if(StringUtils.isNotBlank(attrids)){
                        attrids += ",";
                        attrNames += ",";
                    }
                    attrids+= ta.getId();
                    attrNames+= ta.getName();
                }
                newModel.setAttrFirstIds(attrids);
                newModel.setAttrFirstNames(attrNames);
            }
            if(attrs2.length > 0){
                String attrids="" ,attrNames="";
                for(String s : attrs2){
                    if(StringUtils.isBlank(s)){
                        continue;
                    }
                    //查询属性规格对象
                    CateAttr ta = getCateAttrByName(s,Constants.ONE,allAttr);
                    if(ta == null){
                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行属性1中【"+s+"】无效,请检查输入!");
                    }
                    if(StringUtils.isNotBlank(attrids)){
                        attrids += ",";
                        attrNames += ",";
                    }
                    attrids+= ta.getId();
                    attrNames+= ta.getName();
                }
                newModel.setAttrSecodIds(attrids);
                newModel.setAttrSecodNames(attrNames);
            }
            List<String> mulFiles = null;
            String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PROJECTS).getCode();
            String tf = proDir.substring(0,proDir.length()-1);
            String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode()
                    + proDir;
                    + proDir + File.separator + user.getCompanyId();
            if(StringUtils.isNotBlank(path)){
                OssModel ossModel = baseDataService.initOssModel();
                File dir =new File(path+File.separator+newModel.getRemark()+File.separator);
                if(dir!=null && dir.isDirectory()){
                    File[]  files = dir.listFiles();
@@ -823,16 +1047,8 @@
                        for(File f:files){
                            if(StringUtils.isBlank(newModel.getImgurl()) && isImgFile(f)){
                                //取第一张图片作为列表图
                                String imgdir =f.getPath().substring(f.getPath().indexOf(tf)+tf.length()+1);
                                newModel.setImgurl(imgdir.replace(File.separator,"/"));
//                                 newModel.setImgurl(f.getPath().replace(path.replace(File.separator,"/"),""));
                                newModel.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f));
                            }
//                             else{
//                                 if(mulFiles==null){
//                                     mulFiles = new ArrayList<>();
//                                 }
//                                 mulFiles.add(f.getPath().replace(path.replace("/",File.separator),""));
//                             }
                            if((mulFiles ==null || mulFiles.size() == 0) && f.isDirectory()){
                                //如果是文件夹
                                File[] fs = f.listFiles();
@@ -842,12 +1058,7 @@
                                            if(mulFiles==null){
                                                mulFiles = new ArrayList<>();
                                            }
                                            String imgdir =mf.getPath().substring(mf.getPath().indexOf(tf)+tf.length()+1);
                                            mulFiles.add(imgdir.replace(File.separator,"/"));
//                                             newModel.setImgurl(imgdir);
////                                             mulFiles.add(mf.getName());
//                                             mulFiles.add(mf.getPath().replace(path.replace(File.separator,"/"),""));
                                            mulFiles.add(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),mf));
                                        }
                                    }
                                }
@@ -857,42 +1068,13 @@
                }
            }
            //查询商品信息
            goodsMapper.insert(newModel);
            CateParam cp = new CateParam();
            cp.setIsdeleted(Constants.ZERO);
            cp.setCategoryId(cate.getId());
            //查询全部产品参数配置
            List<CateParam> allParams = cateParamMapper.selectList(new QueryWrapper<>(cp));
            if(params.length > 0){
                for(String s : params){
                    if(StringUtils.isBlank(s)){
                        continue;
                    }
                    s = s.replace(":",":");
                    String[] ts = s.split(":");
                    if(ts.length == 0){
                        continue;
                    }
                    //查询属性规格对象
                    CateParam ta = getCateParamByName(ts[0], allParams);
                    if(ta == null){
                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,第【"+(num)+"】行产品参数中【"+s+"】无效,请检查输入!");
                    }
                    GoodsParam gp = new GoodsParam();
                    gp.setIsdeleted(Constants.ZERO);
                    gp.setCreator(user.getId());
                    gp.setCreateDate(newModel.getCreateDate());
                    gp.setGoodsId(newModel.getId());
                    gp.setName(ta.getName());
                    gp.setPramaId(ta.getId());
                    gp.setStatus(Constants.ZERO);
                    gp.setVal(ts.length>1?ts[1]:null);
                    gp.setSortnum(ta.getSortnum());
                    //插入产品参数关联表
                    goodsParamMapper.insert(gp);
                }
            }
            goodsMapper.updateById(newModel);
            if(mulFiles !=null && mulFiles.size()>0){
                multifileMapper.update(null,new UpdateWrapper<Multifile>().lambda()
                        .set(Multifile::getIsdeleted,Constants.ONE)
                        .eq(Multifile::getIsdeleted,Constants.ZERO)
                        .eq(Multifile::getObjId,g.getId())
                        .eq(Multifile::getType,Constants.ZERO));
                for(int i=0;i<mulFiles.size();i++){
                    String s = mulFiles.get(i);
                    Multifile f = new Multifile();
@@ -904,6 +1086,7 @@
                    f.setCreator(newModel.getCreator());
                    f.setIsdeleted(Constants.ZERO);
                    f.setSortnum(i);
                    f.setCompanyId(user.getCompanyId());
                    f.setFileurl(s);
                    multifileMapper.insert(f);
                }
@@ -913,6 +1096,9 @@
        return  num;
    }
    private boolean isImgFile(File f) {
        if(f!=null && f.isFile() ){
@@ -999,6 +1185,7 @@
    @Override
    public void export(HttpServletRequest request, HttpServletResponse response) throws Exception {
        try {
            LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
            String fileName = "产品导入表"+System.currentTimeMillis()+".xlsx";
            // 获取文件输入流
            InputStream inputStream =  this.getClass().getClassLoader().getResourceAsStream("static/file/goodsExcelTemp.xlsx");
@@ -1012,7 +1199,10 @@
            // sheet.getPhysicalNumberOfRows()获取总的行数
            // 循环读取每一行
            Row row = sheet.createRow(1);
            List<Category> categoryList = categoryMapper.selectList(new QueryWrapper<Category>().eq("ISDELETED",0));
            List<Category> categoryList = categoryMapper.selectList(
                    new QueryWrapper<Category>().eq("ISDELETED",0)
                            .eq("COMPANY_ID",loginUserInfo.getCompanyId())
            );
            categoryList.forEach(i->{
                i.setParamList(cateParamMapper.selectList(new QueryWrapper<CateParam>().eq("ISDELETED",0).eq("CATEGORY_ID",i.getId())));
            });
@@ -1065,31 +1255,70 @@
        queryWrapper.eq(Goods::getIsdeleted,Constants.ZERO);
        queryWrapper.eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getCategoryId()), Goods::getCategoryId, pageWrap.getModel().getCategoryId())
                .eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getSubCategoryId()), Goods::getSubCategoryId, pageWrap.getModel().getSubCategoryId())
                .eq(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getBrandId()), Goods::getBrandId, pageWrap.getModel().getBrandId())
                .and(!Objects.isNull(pageWrap.getModel()) && StringUtils.isNotBlank(pageWrap.getModel().getKeyword()),
                        i->i.like(Goods::getPinyin,pageWrap.getModel().getKeyword())
                                .or().like(Goods::getShortPinyin,pageWrap.getModel().getKeyword())
                                .or().like(Goods::getName,pageWrap.getModel().getKeyword())
                )
                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrFirst()), " find_in_set('"+pageWrap.getModel().getAttrFirst()+"',t.ATTR_FIRST_IDS) ")
                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrSecond()), " find_in_set('"+pageWrap.getModel().getAttrSecond()+"',t.ATTR_SECOD_IDS) ")
//                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrFirst()), " find_in_set('"+pageWrap.getModel().getAttrFirst()+"',t.ATTR_FIRST_IDS) ")
//                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrSecond()), " find_in_set('"+pageWrap.getModel().getAttrSecond()+"',t.ATTR_SECOD_IDS) ")
                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrFirst()), " t.id in ( SELECT  gp.GOODS_ID   FROM  cate_param_select cps  ,  goods_param gp where     gp.PRAMA_ID = cps.PARAM_ID     and gp.VAL = cps.`NAME`  " +
                        " and cps.ID = '"+pageWrap.getModel().getAttrFirst()+"' ) ")
                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getAttrSecond()), " t.id in ( SELECT  gp.GOODS_ID   FROM  cate_param_select cps  ,  goods_param gp where     gp.PRAMA_ID = cps.PARAM_ID     and gp.VAL = cps.`NAME`  " +
                        " and cps.ID = '"+pageWrap.getModel().getAttrSecond()+"' ) ")
                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getSPrice()), "  t.PRICE >=  "+pageWrap.getModel().getSPrice()+" ")
                .apply(!Objects.isNull(pageWrap.getModel()) && !Objects.isNull(pageWrap.getModel().getEPrice()), "  t.PRICE <=  "+pageWrap.getModel().getEPrice()+" ");
        queryWrapper.orderByDesc(Goods::getId);
        IPage<Goods> goodsIPage =  goodsJoinMapper.selectJoinPage(page, Goods.class, queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        goodsIPage.getRecords().forEach(i->{
            i.setPrefixUrl(prefixUrl);
            i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM ")));
            i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()).orderByAsc(" SORTNUM ")));
        });
        if(!Objects.isNull(goodsIPage.getRecords())&&goodsIPage.getRecords().size()>Constants.ZERO){
            this.dealGoodsMsg(goodsIPage.getRecords());
        }
        return PageData.from(goodsIPage);
    }
    private void validateSubCategory(Goods goods) {
        if (goods.getSubCategoryId() == null) {
            return;
        }
        Category sub = categoryMapper.selectById(goods.getSubCategoryId());
        if (sub == null || sub.getParentId() == null || !sub.getParentId().equals(goods.getCategoryId())) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "二级类别必须属于所选一级品类");
        }
    }
    public void dealGoodsMsg(List<Goods> goodsList){
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode();
        String prefixUrlCategory = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode()
                + systemDictDataBiz.queryByCode(Constants.OSS, Constants.CATEGORY_IMG).getCode();
        List<Integer> integerList = goodsList.stream().map(Goods::getId).collect(Collectors.toList());
        List<Multifile> mFileList = multifileMapper.selectList(new QueryWrapper<Multifile>()
                .lambda().in(Multifile::getObjId,integerList)
                .eq(Multifile::getType,Constants.ZERO)
                .eq(Multifile::getIsdeleted,Constants.ZERO)
                .eq(Multifile::getObjType,Constants.ZERO));
        List<GoodsParam> goodsParamList = goodsParamMapper.selectList(new QueryWrapper<GoodsParam>()
                    .in("GOODS_ID",integerList)
                    .orderByAsc(" SORTNUM "));
        goodsList.forEach(i->{
            i.setCategoryImgurl(prefixUrlCategory + i.getCategoryImgurl());
            i.setPrefixUrl(prefixUrl);
            i.setMultifileList(mFileList.stream().filter(s -> s.getObjId().equals(i.getId())).collect(Collectors.toList()));
            i.setGoodsParamList(goodsParamList.stream().filter(s -> s.getGoodsId().equals(i.getId())).collect(Collectors.toList()));
        });
    }
    @Override
    public List<Goods> findListForH5(GoodsRequest goodsRequest) {
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!loginUserInfo.getType().equals(Constants.UserType.ZHUBO.getKey())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"非主播用户无法使用");
        }
        MPJLambdaWrapper<Goods> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(Goods.class);
        queryWrapper.selectAs(Category::getName, Goods::getCategoryName);
@@ -1101,7 +1330,9 @@
        queryWrapper.leftJoin(Brand.class, Brand::getId, Goods::getBrandId);
        queryWrapper.eq(Goods::getStatus,Constants.ZERO);
        queryWrapper.eq(Goods::getIsdeleted,Constants.ZERO);
        queryWrapper.eq(Goods::getCompanyId,loginUserInfo.getCompanyId());
        queryWrapper.eq(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getCategoryId()), Goods::getCategoryId, goodsRequest.getCategoryId())
                .eq(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getSubCategoryId()), Goods::getSubCategoryId, goodsRequest.getSubCategoryId())
                .eq(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getBrandId()), Goods::getBrandId, goodsRequest.getBrandId())
                .and(!Objects.isNull(goodsRequest) && StringUtils.isNotBlank(goodsRequest.getKeyword()),
                        i->i.like(Goods::getPinyin,goodsRequest.getKeyword())
@@ -1114,15 +1345,23 @@
                .apply(!Objects.isNull(goodsRequest) && !Objects.isNull(goodsRequest.getEPrice()), "  t.PRICE <=  "+goodsRequest.getEPrice()+" ");
        queryWrapper.orderByDesc(Goods::getId);
        List<Goods> goodsList = goodsJoinMapper.selectJoinList(Goods.class,queryWrapper);
        String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
                + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
        goodsList.forEach(i->{
            i.setPrefixUrl(prefixUrl);
            i.setMultifileList(multifileMapper.selectList(new QueryWrapper<Multifile>().eq("OBJ_ID",i.getId()).orderByAsc(" SORTNUM ")));
            i.setGoodsParamList(goodsParamMapper.selectList(new QueryWrapper<GoodsParam>().eq("GOODS_ID",i.getId()).orderByAsc(" SORTNUM ")));
        });
        if(!Objects.isNull(goodsList)&&goodsList.size()>Constants.ZERO){
            this.dealGoodsMsg(goodsList);
        }
        return goodsList;
    }
    @Override
    @Transactional
    public  void openSyncSwitch() {
        LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        Boolean  openSyncSwitch = (Boolean)redisTemplate.opsForValue().get(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH);
        if(openSyncSwitch!=null && openSyncSwitch ){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"数据同步中,请稍后刷新重试");
        }
        redisTemplate.opsForValue().set(loginUserInfo.getCompanyId()+Constants.OPEN_SYNC_SWITCH,true);
    }
}