From b5aa2c49f7a801de9af91eec71e339ff6d2781bb Mon Sep 17 00:00:00 2001 From: jiaosong <jiaosong6760@dingtalk.com> Date: 星期二, 19 九月 2023 14:55:24 +0800 Subject: [PATCH] #联调修改 --- server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java | 248 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 238 insertions(+), 10 deletions(-) diff --git a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java index b6e046d..70c6bb7 100644 --- a/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java +++ b/server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java @@ -1,6 +1,7 @@ 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; @@ -12,15 +13,15 @@ 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.BaseGoodsParamCreatRequest; +import com.doumee.dao.business.model.dto.*; +import com.doumee.service.business.BaseDataService; 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; @@ -28,16 +29,19 @@ 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.Date; -import java.util.List; -import java.util.Objects; +import java.io.File; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.Collectors; /** * 绱犳潗搴�-鍟嗗搧淇℃伅琛⊿ervice瀹炵幇 * @author 姹熻箘韫� * @date 2023/09/07 11:41 */ +@Slf4j @Service public class BaseGoodsServiceImpl implements BaseGoodsService { @@ -65,6 +69,15 @@ @Autowired private GoodsMapper goodsMapper; + @Autowired + private BaseCategoryMapper baseCategoryMapper; + + + @Autowired + @Lazy + private BaseDataService baseDataService; + + @Override public Integer create(BaseGoodsCreateOrUpdateRequest baseGoods) { LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); @@ -81,7 +94,8 @@ insert.setIsdeleted(Constants.ZERO); insert.setRemark(baseGoods.getRemark()); insert.setName(baseGoods.getName()); - insert.setStatus(Constants.ZERO); + //榛樿涓嬫灦 + insert.setStatus(Constants.ONE); insert.setSortnum(integer+Constants.ONE); insert.setImgurl(baseGoods.getImgurl()); insert.setCategoryId(baseGoods.getCategoryId()); @@ -294,8 +308,8 @@ .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(); + String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); baseGoodsDTO.setImgfullurl(prefixUrl+baseGoodsDTO.getImgurl()); List<Multifile> multifiles = multifileMapper.selectList(new QueryWrapper<Multifile>() @@ -342,7 +356,7 @@ .selectAs(BaseCategory::getName,BaseGoods::getCategoryName) .eq(BaseGoods::getIsdeleted, Constants.ZERO) .like(StringUtils.isNotBlank(pageWrap.getModel().getName()), BaseGoods::getName,pageWrap.getModel().getName()) - .eq(pageWrap.getModel().getId()!=null,BaseGoods::getId, pageWrap.getModel().getId()) + .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()); @@ -357,9 +371,223 @@ return pageData; } + + @Override + public PageData<BaseGoods> findCompanyPage(PageWrap<BaseGoods> pageWrap) { + LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); + pageWrap.getModel().setIsdeleted(Constants.ZERO); + IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); + MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>(); + Utils.MP.blankToNull(pageWrap.getModel()); + 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::getStatus, Constants.ZERO) + .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()) + .notExists(user.getType().equals(Constants.UserType.COMPANY.getKey())," select 1 from goods g where g.GOODS_ID = t.id and g.TYPE = 1 and g.company_id = "+user.getCompanyId()+" "); + 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 public long count(BaseGoods baseGoods) { QueryWrapper<BaseGoods> wrapper = new QueryWrapper<>(baseGoods); return baseGoodsMapper.selectCount(wrapper); } + + @Transactional(rollbackFor = {Exception.class,BusinessException.class}) + @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->{ + + if(baseGoodsMapper.selectCount(new QueryWrapper<BaseGoods>().eq("ISDELETED", Constants.ZERO).eq("name",s.getName()))>0){ + throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+s.getName()+"銆戝凡瀛樺湪"); + } + + 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); + baseGoods.setZdPrice(new BigDecimal(s.getZdPrice())); + baseGoods.setPrice(new BigDecimal(s.getPrice())); + 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); + if (Objects.isNull(baseCategory)){ + throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧绫诲埆涓嶅瓨鍦�"); + } + + QueryWrapper<Brand> brandQuery = new QueryWrapper<>(); + brandQuery.lambda() + .eq(Brand::getType,Constants.ONE) + .eq(Brand::getName,s.getBrandName()); + Brand brand = brandMapper.selectOne(brandQuery); + + if (Objects.isNull(brand)){ + throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧鍝佺墝涓嶅瓨鍦�"); + } + //澶勭悊鎵归噺涓婁紶 + String proDir =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.PLATFORM).getCode(); + + String path = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.GOODS_IMG_DIR).getCode() + + proDir + File.separator + s.getId(); + + List<String> mulFiles = new ArrayList<>(); + if(StringUtils.isNotBlank(path)){ + OssModel ossModel = baseDataService.initOssModel(); + File dir =new File(path+File.separator); + if(dir!=null && dir.isDirectory()){ + File[] files = dir.listFiles(); + if(files!=null && files.length>0){ + for(File f:files){ + if(isImgFile(f)){ + //鍙栫涓�寮犲浘鐗囦綔涓哄垪琛ㄥ浘 + baseGoods.setImgurl(baseDataService.getOssImgurl(ossModel,ossModel.getGoodsFolder(),f)); + } + if(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)); + } + } + } + } + } + } + } + } + + +// baseGoods.setImgurl(); + baseGoods.setCategoryId(baseCategory.getId()); + baseGoods.setBrandId(brand.getId()); + baseGoodsMapper.insert(baseGoods); + + if(mulFiles !=null && mulFiles.size()>0){ + for(int i=0;i<mulFiles.size();i++){ + String str = mulFiles.get(i); + Multifile f = new Multifile(); + f.setObjType(Constants.ZERO); + f.setName(str); + f.setType(Constants.ZERO); + f.setObjId(baseGoods.getId()); + f.setCreateDate(new Date()); + f.setCreator(user.getId()); + f.setIsdeleted(Constants.ZERO); + f.setSortnum(i); + f.setCompanyId(user.getCompanyId()); + f.setFileurl(str); + multifileMapper.insert(f); + } + } + + 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; + for (int i = 0; i < collect.size(); i++){ + if (!CollectionUtils.isEmpty(baseCategory.getBaseCateParamList())){ + List<String> s2 = collect.get(i); + 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; + } + + private boolean isImgFile(File f) { + if(f!=null && f.isFile() ){ + String name = f.getName(); + if(name.endsWith(".jpg") + ||name.endsWith(".JPG") + ||name.endsWith(".JPEG") + ||name.endsWith(".jpeg") + ||name.endsWith(".PNG") + ||name.endsWith(".png")){ + return true; + } + } + return false; + } } -- Gitblit v1.9.3