|  |  | 
 |  |  | package com.doumee.service.business.impl; | 
 |  |  |  | 
 |  |  | import com.doumee.biz.system.SystemDictDataBiz; | 
 |  |  | import com.doumee.core.annotation.excel.ExcelImporter; | 
 |  |  | import com.doumee.core.constants.ResponseStatus; | 
 |  |  | import com.doumee.core.exception.BusinessException; | 
 |  |  | import com.doumee.core.model.LoginUserInfo; | 
 |  |  | import com.doumee.core.model.PageData; | 
 |  |  | import com.doumee.core.model.PageWrap; | 
 |  |  | import com.doumee.core.utils.Constants; | 
 |  |  | import com.doumee.core.utils.PinYinUtil; | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.business.BaseGoodsMapper; | 
 |  |  | import com.doumee.dao.business.model.BaseGoods; | 
 |  |  | import com.doumee.dao.business.*; | 
 |  |  | import com.doumee.dao.business.join.BaseGoodsJoinMapper; | 
 |  |  | import com.doumee.dao.business.model.*; | 
 |  |  | import com.doumee.dao.business.model.dto.BaseGoodsCreateOrUpdateRequest; | 
 |  |  | import com.doumee.dao.business.model.dto.BaseGoodsDTO; | 
 |  |  | import com.doumee.dao.business.model.dto.BaseGoodsImportDTO; | 
 |  |  | import com.doumee.dao.business.model.dto.BaseGoodsParamCreatRequest; | 
 |  |  | import com.doumee.service.business.BaseGoodsService; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
 |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
 |  |  | import com.github.yulichang.wrapper.MPJLambdaWrapper; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.apache.shiro.SecurityUtils; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.context.annotation.Lazy; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.util.CollectionUtils; | 
 |  |  | import org.springframework.web.multipart.MultipartFile; | 
 |  |  |  | 
 |  |  | import java.util.Arrays; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Objects; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * 素材库-商品信息表Service实现 | 
 |  |  |  * @author 江蹄蹄 | 
 |  |  |  * @date 2023/09/07 11:41 | 
 |  |  |  */ | 
 |  |  | @Slf4j | 
 |  |  | @Service | 
 |  |  | public class BaseGoodsServiceImpl implements BaseGoodsService { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BaseGoodsMapper baseGoodsMapper; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BaseGoodsJoinMapper baseGoodsJoinMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BaseGoodsParamMapper baseGoodsParamMapper; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private MultifileMapper multifileMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     @Lazy | 
 |  |  |     private SystemDictDataBiz systemDictDataBiz; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BrandMapper brandMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private GoodsMapper goodsMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private BaseCategoryMapper baseCategoryMapper; | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer create(BaseGoods baseGoods) { | 
 |  |  |         baseGoodsMapper.insert(baseGoods); | 
 |  |  |         return baseGoods.getId(); | 
 |  |  |     public Integer create(BaseGoodsCreateOrUpdateRequest baseGoods) { | 
 |  |  |         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",baseGoods.getName()))>0){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+baseGoods.getName()+"】已存在"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         Integer integer = baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO)); | 
 |  |  |         BaseGoods insert = new BaseGoods(); | 
 |  |  |         insert.setCreator(user.getId()); | 
 |  |  |         insert.setCreateDate(new Date()); | 
 |  |  |         insert.setEditor(user.getId()); | 
 |  |  |         insert.setEditDate(new Date()); | 
 |  |  |         insert.setIsdeleted(Constants.ZERO); | 
 |  |  |         insert.setRemark(baseGoods.getRemark()); | 
 |  |  |         insert.setName(baseGoods.getName()); | 
 |  |  |         insert.setStatus(Constants.ZERO); | 
 |  |  |         insert.setSortnum(integer+Constants.ONE); | 
 |  |  |         insert.setImgurl(baseGoods.getImgurl()); | 
 |  |  |         insert.setCategoryId(baseGoods.getCategoryId()); | 
 |  |  |         insert.setBrandId(baseGoods.getBrandId()); | 
 |  |  |         insert.setZdPrice(baseGoods.getZdPrice()); | 
 |  |  |         insert.setPrice(baseGoods.getPrice()); | 
 |  |  |         insert.setContent(baseGoods.getContent()); | 
 |  |  |         insert.setPinyin(PinYinUtil.getFullSpell(insert.getName())); | 
 |  |  |         insert.setShortPinyin(PinYinUtil.getFirstSpell(insert.getName())); | 
 |  |  |         baseGoodsMapper.insert(insert); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         List<Multifile> multifileList = baseGoods.getMultifileList(); | 
 |  |  |         if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ | 
 |  |  |             for (int i = 0; i < multifileList.size(); i++) { | 
 |  |  |                 Multifile multifile = multifileList.get(i); | 
 |  |  |                 multifile.setCreator(user.getId()); | 
 |  |  |                 multifile.setCreateDate(new Date()); | 
 |  |  |                 multifile.setIsdeleted(Constants.ZERO); | 
 |  |  |                 multifile.setSortnum(i+Constants.ONE); | 
 |  |  |                 multifile.setObjId(insert.getId()); | 
 |  |  |                 multifile.setType(Constants.ZERO); | 
 |  |  |                 multifile.setObjType(Constants.ONE); | 
 |  |  |                 multifileMapper.insert(multifile); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |         List<BaseGoodsParamCreatRequest> goodsParamList = baseGoods.getBaseGoodsParamList(); | 
 |  |  |         if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ | 
 |  |  |             for (int i = 0; i < goodsParamList.size(); i++) { | 
 |  |  |                 BaseGoodsParamCreatRequest param = goodsParamList.get(i); | 
 |  |  |                 BaseGoodsParam baseGoodsParam = new BaseGoodsParam(); | 
 |  |  |                 baseGoodsParam.setCreator(user.getId()); | 
 |  |  |                 baseGoodsParam.setCreateDate(new Date()); | 
 |  |  |                 baseGoodsParam.setEditor(user.getId()); | 
 |  |  |                 baseGoodsParam.setEditDate(new Date()); | 
 |  |  |                 baseGoodsParam.setIsdeleted(Constants.ZERO); | 
 |  |  |                 baseGoodsParam.setName(param.getName()); | 
 |  |  |                 baseGoodsParam.setRemark(param.getRemark()); | 
 |  |  |                 baseGoodsParam.setStatus(Constants.ZERO); | 
 |  |  |                 baseGoodsParam.setSortnum(i+Constants.ONE); | 
 |  |  |                 baseGoodsParam.setPramaId(param.getPramaId()); | 
 |  |  |                 baseGoodsParam.setVal(param.getVal()); | 
 |  |  |                 baseGoodsParam.setGoodsId(insert.getId()); | 
 |  |  |                 baseGoodsParamMapper.insert(baseGoodsParam); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         return insert.getId(); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |             return; | 
 |  |  |         } | 
 |  |  |         baseGoodsMapper.deleteBatchIds(ids); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     @Override | 
 |  |  |     public void update(BaseGoodsCreateOrUpdateRequest baseGoods) { | 
 |  |  |  | 
 |  |  |         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>() | 
 |  |  |                 .eq("ISDELETED",Constants.ZERO).ne("id",baseGoods.getId()) | 
 |  |  |                 .eq("name",baseGoods.getName()))>0){ | 
 |  |  |             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+baseGoods.getName()+"】已存在"); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         UpdateWrapper<BaseGoods> wrapper = new UpdateWrapper<>(); | 
 |  |  |         wrapper.lambda() | 
 |  |  |                 .eq(BaseGoods::getId,baseGoods.getId()) | 
 |  |  |                 .set(BaseGoods::getName,baseGoods.getName()) | 
 |  |  |                 .set(BaseGoods::getBrandId,baseGoods.getBrandId()) | 
 |  |  |                 .set(BaseGoods::getCategoryId,baseGoods.getCategoryId()) | 
 |  |  |                 .set(BaseGoods::getImgurl,baseGoods.getImgurl()) | 
 |  |  |                 .set(BaseGoods::getPrice,baseGoods.getPrice()) | 
 |  |  |                 .set(BaseGoods::getZdPrice,baseGoods.getZdPrice()); | 
 |  |  |         baseGoodsMapper.update(null,wrapper); | 
 |  |  |  | 
 |  |  |         multifileMapper.delete(new QueryWrapper<Multifile>().eq("OBJ_ID",baseGoods.getId()) | 
 |  |  |                                                             .eq("OBJ_TYPE",Constants.ONE)); | 
 |  |  |         List<Multifile> multifileList = baseGoods.getMultifileList(); | 
 |  |  |         if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){ | 
 |  |  |             for (int i = 0; i < multifileList.size(); i++) { | 
 |  |  |                 Multifile multifile = multifileList.get(i); | 
 |  |  |                 multifile.setCreator(user.getId()); | 
 |  |  |                 multifile.setCreateDate(new Date()); | 
 |  |  |                 multifile.setIsdeleted(Constants.ZERO); | 
 |  |  |                 multifile.setSortnum(i+Constants.ONE); | 
 |  |  |                 multifile.setObjId(baseGoods.getId()); | 
 |  |  |                 multifile.setType(Constants.ZERO); | 
 |  |  |                 multifile.setObjType(Constants.ONE); | 
 |  |  |                 multifileMapper.insert(multifile); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         baseGoodsParamMapper.delete(new QueryWrapper<BaseGoodsParam>().eq("GOODS_ID",baseGoods.getId())); | 
 |  |  |         List<BaseGoodsParamCreatRequest> goodsParamList = baseGoods.getBaseGoodsParamList(); | 
 |  |  |         if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){ | 
 |  |  |             for (int i = 0; i < goodsParamList.size(); i++) { | 
 |  |  |                 BaseGoodsParamCreatRequest param = goodsParamList.get(i); | 
 |  |  |                 BaseGoodsParam baseGoodsParam = new BaseGoodsParam(); | 
 |  |  |                 baseGoodsParam.setCreator(user.getId()); | 
 |  |  |                 baseGoodsParam.setCreateDate(new Date()); | 
 |  |  |                 baseGoodsParam.setEditor(user.getId()); | 
 |  |  |                 baseGoodsParam.setEditDate(new Date()); | 
 |  |  |                 baseGoodsParam.setIsdeleted(Constants.ZERO); | 
 |  |  |                 baseGoodsParam.setName(param.getName()); | 
 |  |  |                 baseGoodsParam.setRemark(param.getRemark()); | 
 |  |  |                 baseGoodsParam.setStatus(Constants.ZERO); | 
 |  |  |                 baseGoodsParam.setSortnum(i+Constants.ONE); | 
 |  |  |                 baseGoodsParam.setPramaId(param.getPramaId()); | 
 |  |  |                 baseGoodsParam.setVal(param.getVal()); | 
 |  |  |                 baseGoodsParam.setGoodsId(baseGoods.getId()); | 
 |  |  |                 baseGoodsParamMapper.insert(baseGoodsParam); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     @Override | 
 |  |  |     public void updateStatusByIds(BaseGoods param) { | 
 |  |  |         if (CollectionUtils.isEmpty(param.getIdList()) | 
 |  |  |                 || param.getStatus() == null | 
 |  |  |                || !(Constants.equalsInteger(param.getStatus(), Constants.ONE)||Constants.equalsInteger(param.getStatus()  ,Constants.ZERO))){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  |         } | 
 |  |  |         param.getIdList().forEach(s->updateStatusById(s,param.getStatus())); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Transactional(rollbackFor = {Exception.class,BusinessException.class}) | 
 |  |  |     @Override | 
 |  |  |     public void updateStatusById(Integer id, Integer status) { | 
 |  |  |         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         if (Objects.isNull(status)){ | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品状态不能为空"); | 
 |  |  |         } | 
 |  |  |         if (Constants.equalsInteger(status,Constants.ZERO)){ | 
 |  |  |             //如果启用 | 
 |  |  |             BaseGoods baseGoods = new BaseGoods(); | 
 |  |  |             baseGoods.setId(id); | 
 |  |  |             baseGoods.setEditDate(new Date()); | 
 |  |  |             baseGoods.setEditor(user.getId()); | 
 |  |  |             baseGoods.setStatus(status); | 
 |  |  |             baseGoodsMapper.updateById(baseGoods); | 
 |  |  |         }else if (Constants.equalsInteger(status,Constants.ONE)){ | 
 |  |  |             //如果禁用 | 
 |  |  |             BaseGoods baseGoods = new BaseGoods(); | 
 |  |  |             baseGoods.setId(id); | 
 |  |  |             baseGoods.setEditDate(new Date()); | 
 |  |  |             baseGoods.setEditor(user.getId()); | 
 |  |  |             baseGoods.setStatus(status); | 
 |  |  |             baseGoodsMapper.updateById(baseGoods); | 
 |  |  |  | 
 |  |  |             UpdateWrapper<Goods> goodsUpdate = new UpdateWrapper<>(); | 
 |  |  |             goodsUpdate.lambda() | 
 |  |  |                         .eq(Goods::getType,Constants.ONE) | 
 |  |  |                         .eq(Goods::getGoodsId,id) | 
 |  |  |                         .set(Goods::getStatus,Constants.ONE) | 
 |  |  |                         .set(Goods::getEditor,user.getId()) | 
 |  |  |                         .set(Goods::getEditDate,new Date()); | 
 |  |  |             goodsMapper.update(null,goodsUpdate); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public BaseGoodsDTO findByIdBaseGoods(Integer id) { | 
 |  |  |  | 
 |  |  |         MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>(); | 
 |  |  |  | 
 |  |  |         queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId) | 
 |  |  |                 .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getBaseDataId) | 
 |  |  |                 .selectAll(BaseGoods.class) | 
 |  |  |                 .selectAs(Brand::getName,BaseGoodsDTO::getBrandName) | 
 |  |  |                 .selectAs(BaseCategory::getSortnum,BaseGoodsDTO::getCategoryName) | 
 |  |  |                 .eq(BaseGoods::getId,id); | 
 |  |  |  | 
 |  |  |         BaseGoodsDTO baseGoodsDTO = baseGoodsJoinMapper.selectJoinOne(BaseGoodsDTO.class, queryWrapper); | 
 |  |  |         String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode() | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode(); | 
 |  |  |         baseGoodsDTO.setImgfullurl(prefixUrl+baseGoodsDTO.getImgurl()); | 
 |  |  |  | 
 |  |  |         List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>() | 
 |  |  |                 .eq("OBJ_ID", id) | 
 |  |  |                 .eq("OBJ_TYPE", Constants.ONE)); | 
 |  |  |         if (!CollectionUtils.isEmpty(multifiles)){ | 
 |  |  |             multifiles.forEach(s->s.setFilefullurl(prefixUrl+s.getFileurl())); | 
 |  |  |         } | 
 |  |  |         baseGoodsDTO.setMultifileList(multifiles); | 
 |  |  |  | 
 |  |  |         QueryWrapper<BaseGoodsParam> baseGoodsParamQuery = new QueryWrapper<>(); | 
 |  |  |         baseGoodsParamQuery.select("base_goods_param.*,(select name from base_cate_param bcp where (bcp.id = base_goods_param.PRAMA_ID)) as paramName") | 
 |  |  |                             .lambda() | 
 |  |  |                             .eq(BaseGoodsParam::getGoodsId,id) | 
 |  |  |                             .orderByAsc(BaseGoodsParam::getSortnum); | 
 |  |  |         List<BaseGoodsParam> baseGoodsParams = baseGoodsParamMapper.selectList(baseGoodsParamQuery); | 
 |  |  |         baseGoodsDTO.setBaseGoodsParamList(baseGoodsParams); | 
 |  |  |         return baseGoodsDTO; | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public BaseGoods findOne(BaseGoods baseGoods) { | 
 |  |  |         QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods); | 
 |  |  |         return baseGoodsMapper.selectOne(wrapper); | 
 |  |  | 
 |  |  |         QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods); | 
 |  |  |         return baseGoodsMapper.selectList(wrapper); | 
 |  |  |     } | 
 |  |  |    | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public PageData<BaseGoods> findPage(PageWrap<BaseGoods> pageWrap) { | 
 |  |  |         pageWrap.getModel().setIsdeleted(Constants.ZERO); | 
 |  |  |         IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
 |  |  |         QueryWrapper<BaseGoods> queryWrapper = new QueryWrapper<>(); | 
 |  |  |         MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>(); | 
 |  |  |         Utils.MP.blankToNull(pageWrap.getModel()); | 
 |  |  |         if (pageWrap.getModel().getId() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getId, pageWrap.getModel().getId()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getCreator() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getCreator, pageWrap.getModel().getCreator()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getCreateDate() != null) { | 
 |  |  |             queryWrapper.lambda().ge(BaseGoods::getCreateDate, Utils.Date.getStart(pageWrap.getModel().getCreateDate())); | 
 |  |  |             queryWrapper.lambda().le(BaseGoods::getCreateDate, Utils.Date.getEnd(pageWrap.getModel().getCreateDate())); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getEditor() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getEditor, pageWrap.getModel().getEditor()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getEditDate() != null) { | 
 |  |  |             queryWrapper.lambda().ge(BaseGoods::getEditDate, Utils.Date.getStart(pageWrap.getModel().getEditDate())); | 
 |  |  |             queryWrapper.lambda().le(BaseGoods::getEditDate, Utils.Date.getEnd(pageWrap.getModel().getEditDate())); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getIsdeleted() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getIsdeleted, pageWrap.getModel().getIsdeleted()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getRemark() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getRemark, pageWrap.getModel().getRemark()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getName() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getName, pageWrap.getModel().getName()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getStatus() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getStatus, pageWrap.getModel().getStatus()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getSortnum() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getSortnum, pageWrap.getModel().getSortnum()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getImgurl() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getImgurl, pageWrap.getModel().getImgurl()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getCategoryId() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getBrandId() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getBrandId, pageWrap.getModel().getBrandId()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getZdPrice() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getZdPrice, pageWrap.getModel().getZdPrice()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getPrice() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getPrice, pageWrap.getModel().getPrice()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getContent() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getContent, pageWrap.getModel().getContent()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getPinyin() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getPinyin, pageWrap.getModel().getPinyin()); | 
 |  |  |         } | 
 |  |  |         if (pageWrap.getModel().getShortPinyin() != null) { | 
 |  |  |             queryWrapper.lambda().eq(BaseGoods::getShortPinyin, pageWrap.getModel().getShortPinyin()); | 
 |  |  |         } | 
 |  |  |         for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
 |  |  |             if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
 |  |  |                 queryWrapper.orderByDesc(sortData.getProperty()); | 
 |  |  |             } else { | 
 |  |  |                 queryWrapper.orderByAsc(sortData.getProperty()); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |         return PageData.from(baseGoodsMapper.selectPage(page, queryWrapper)); | 
 |  |  |         queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId) | 
 |  |  |                     .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getCategoryId) | 
 |  |  |                     .selectAll(BaseGoods.class) | 
 |  |  |                     .selectAs(Brand::getName,BaseGoods::getBrandName) | 
 |  |  |                     .selectAs(BaseCategory::getName,BaseGoods::getCategoryName) | 
 |  |  |                     .eq(BaseGoods::getIsdeleted, Constants.ZERO) | 
 |  |  |                     .like(StringUtils.isNotBlank(pageWrap.getModel().getName()), BaseGoods::getName,pageWrap.getModel().getName()) | 
 |  |  |                     .like(pageWrap.getModel().getId()!=null,BaseGoods::getId, pageWrap.getModel().getId()) | 
 |  |  |                     .eq(pageWrap.getModel().getCategoryId()!=null,BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId()) | 
 |  |  |                     .eq(pageWrap.getModel().getBrandId()!=null,BaseGoods::getBrandId, pageWrap.getModel().getBrandId()) | 
 |  |  |                     .eq(pageWrap.getModel().getStatus()!=null,BaseGoods::getStatus, pageWrap.getModel().getStatus()); | 
 |  |  |  | 
 |  |  |         queryWrapper.orderByDesc(Goods::getId); | 
 |  |  |         PageData<BaseGoods> pageData =PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper)); | 
 |  |  |         String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() | 
 |  |  |                 + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); | 
 |  |  |         pageData.getRecords().forEach(i->{ | 
 |  |  |             i.setFullImgUrl(prefixUrl + i.getImgurl()); | 
 |  |  |         }); | 
 |  |  |         return pageData; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  | 
 |  |  |         QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods); | 
 |  |  |         return baseGoodsMapper.selectCount(wrapper); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public Integer importBaseGoodsBatch(MultipartFile file) { | 
 |  |  |  | 
 |  |  |         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
 |  |  |         try { | 
 |  |  |  | 
 |  |  |             ExcelImporter ie = new ExcelImporter(file,0,0); | 
 |  |  |             List<BaseGoodsImportDTO> dataList = ie.getDataList(BaseGoodsImportDTO.class,null); | 
 |  |  |             if(dataList == null || dataList.size() ==0){ | 
 |  |  |                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"对不起,录入数据为空!"); | 
 |  |  |             } | 
 |  |  |             List<String> comNameList = dataList.stream().map(s -> s.getName().trim()).distinct().collect(Collectors.toList()); | 
 |  |  |  | 
 |  |  |             if (!(dataList.size() == comNameList.size())){ | 
 |  |  |                 throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品名称有已存在"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  | //            List<String> collect1 = dataList.stream().filter(s->{ | 
 |  |  | //                if (StringUtils.isBlank(s.getBrandName())){ | 
 |  |  | //                    throw new BusinessException(ResponseStatus.BAD_REQUEST); | 
 |  |  | //                }else { | 
 |  |  | //                    return true; | 
 |  |  | //                } | 
 |  |  | //            }).map(s -> s.getCategoryName()).collect(Collectors.toList()); | 
 |  |  | //            QueryWrapper<BaseCategory> wrapper = new QueryWrapper<>(); | 
 |  |  | //            wrapper.lambda() | 
 |  |  | //                    .in(BaseCategory::getName,collect1); | 
 |  |  | //            List<BaseCategory> baseCategories = baseCategoryMapper.selectList(wrapper); | 
 |  |  |  | 
 |  |  |             dataList.forEach(s->{ | 
 |  |  |  | 
 |  |  |                 BaseGoods baseGoods = new BaseGoods(); | 
 |  |  |                 baseGoods.setCreator(user.getId()); | 
 |  |  |                 baseGoods.setCreateDate(new Date()); | 
 |  |  |                 baseGoods.setEditor(user.getId()); | 
 |  |  |                 baseGoods.setEditDate(new Date()); | 
 |  |  |                 baseGoods.setIsdeleted(Constants.ZERO); | 
 |  |  |                 baseGoods.setName(s.getName()); | 
 |  |  |                 baseGoods.setStatus(Constants.ZERO); | 
 |  |  |  | 
 |  |  |                 if (StringUtils.isBlank(s.getCategoryName())){ | 
 |  |  |                     throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品类别不可为空"); | 
 |  |  |                 } | 
 |  |  |                 QueryWrapper<BaseCategory> categoryQuery = new QueryWrapper<>(); | 
 |  |  |                 categoryQuery.lambda() | 
 |  |  |                     .eq(BaseCategory::getName,s.getCategoryName()); | 
 |  |  |                 BaseCategory baseCategory = baseCategoryMapper.selectOne(categoryQuery); | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 QueryWrapper<Brand> brandQuery = new QueryWrapper<>(); | 
 |  |  |                 brandQuery.lambda() | 
 |  |  |                         .eq(Brand::getName,s.getBrandName()); | 
 |  |  |                 Brand brand = brandMapper.selectOne(brandQuery); | 
 |  |  |  | 
 |  |  | //                baseGoods.setImgurl(); | 
 |  |  |                 baseGoods.setCategoryId(baseCategory.getId()); | 
 |  |  |                 baseGoods.setBrandId(brand.getId()); | 
 |  |  |                 baseGoodsMapper.insert(baseGoods); | 
 |  |  |  | 
 |  |  |                 String baseGoodsParamString = s.getBaseGoodsParamString(); | 
 |  |  |                 List<List<String>> collect = Arrays.asList(baseGoodsParamString.split("\n")) | 
 |  |  |                         .stream().map(s1 -> Arrays.asList(s1.split("[:,:]")) ).collect(Collectors.toList()); | 
 |  |  |                 if (!CollectionUtils.isEmpty(collect)){ | 
 |  |  |                     Integer i = 0; | 
 |  |  |                     collect.forEach(s2->{ | 
 |  |  |                         if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){ | 
 |  |  |  | 
 |  |  |                             BaseCateParam baseCateParam = baseCategory.getBaseCateParamList() | 
 |  |  |                                     .stream().filter(s3 -> s3.getName().equals(s2.get(0))).findFirst() | 
 |  |  |                                     .orElseThrow(()->new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"配置参数不存在")); | 
 |  |  |                             BaseGoodsParam baseGoodsParam = new BaseGoodsParam(); | 
 |  |  |                             baseGoodsParam.setCreator(user.getId()); | 
 |  |  |                             baseGoodsParam.setCreateDate(new Date()); | 
 |  |  |                             baseGoodsParam.setEditor(user.getId()); | 
 |  |  |                             baseGoodsParam.setEditDate(new Date()); | 
 |  |  |                             baseGoodsParam.setIsdeleted(Constants.ZERO); | 
 |  |  |                             baseGoodsParam.setName(baseCateParam.getName()); | 
 |  |  |                             baseGoodsParam.setRemark(baseCateParam.getRemark()); | 
 |  |  |                             baseGoodsParam.setStatus(Constants.ZERO); | 
 |  |  |                             baseGoodsParam.setSortnum(i+Constants.ONE); | 
 |  |  |                             baseGoodsParam.setPramaId(baseCateParam.getId()); | 
 |  |  |                             baseGoodsParam.setVal(s2.size() > 1 ? s2.get(1) : null ); | 
 |  |  |                             baseGoodsParam.setGoodsId(baseGoods.getId()); | 
 |  |  |                             baseGoodsParamMapper.insert(baseGoodsParam); | 
 |  |  |  | 
 |  |  |                         } | 
 |  |  |                     }); | 
 |  |  |  | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |             }); | 
 |  |  |         }catch (Exception e) { | 
 |  |  |             log.error(String.format("批量插入异常%s ",e.getMessage())); | 
 |  |  |             throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),e.getMessage()); | 
 |  |  |         }finally { | 
 |  |  |  | 
 |  |  |         } | 
 |  |  |         return null; | 
 |  |  |     } | 
 |  |  | } |