From 8d322f025a9483030a47d4671c5fa7502bbcb930 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 18 九月 2023 15:56:32 +0800
Subject: [PATCH] 休bug
---
server/service/src/main/java/com/doumee/service/business/impl/BaseGoodsServiceImpl.java | 164 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 139 insertions(+), 25 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 f5c34f2..562835a 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;
@@ -14,6 +15,7 @@
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;
@@ -21,22 +23,28 @@
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;
/**
* 绱犳潗搴�-鍟嗗搧淇℃伅琛⊿ervice瀹炵幇
* @author 姹熻箘韫�
* @date 2023/09/07 11:41
*/
+@Slf4j
@Service
public class BaseGoodsServiceImpl implements BaseGoodsService {
@@ -63,6 +71,10 @@
@Autowired
private GoodsMapper goodsMapper;
+
+ @Autowired
+ private BaseCategoryMapper baseCategoryMapper;
+
@Override
public Integer create(BaseGoodsCreateOrUpdateRequest baseGoods) {
@@ -216,29 +228,36 @@
@Transactional(rollbackFor = {Exception.class,BusinessException.class})
@Override
- public void updateStatusByIds(List<Integer> idList, Integer status) {
- if (CollectionUtils.isEmpty(idList)){
- throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"鍟嗗搧鐘舵�佷笉鑳戒负绌�");
+ 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);
}
- idList.forEach(s->updateStatusById(s,status));
-
+ 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);
@@ -246,7 +265,9 @@
goodsUpdate.lambda()
.eq(Goods::getType,Constants.ONE)
.eq(Goods::getGoodsId,id)
- .set(Goods::getStatus,Constants.ONE);
+ .set(Goods::getStatus,Constants.ONE)
+ .set(Goods::getEditor,user.getId())
+ .set(Goods::getEditDate,new Date());
goodsMapper.update(null,goodsUpdate);
}
}
@@ -321,30 +342,22 @@
@Override
public PageData<BaseGoods> findPage(PageWrap<BaseGoods> pageWrap) {
+ pageWrap.getModel().setIsdeleted(Constants.ZERO);
IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>();
Utils.MP.blankToNull(pageWrap.getModel());
-
- if (pageWrap.getModel().getId() != null) {
- queryWrapper.like(BaseGoods::getId, pageWrap.getModel().getId());
- }
- if (pageWrap.getModel().getName() != null) {
- queryWrapper.eq(BaseGoods::getName, pageWrap.getModel().getName());
- }
- if (pageWrap.getModel().getStatus() != null) {
- queryWrapper.eq(BaseGoods::getStatus, pageWrap.getModel().getStatus());
- }
- if (pageWrap.getModel().getCategoryId() != null) {
- queryWrapper.eq(BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId());
- }
- if (pageWrap.getModel().getBrandId() != null) {
- queryWrapper.eq(BaseGoods::getBrandId, pageWrap.getModel().getBrandId());
- }
queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId)
- .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getBaseDataId)
+ .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getCategoryId)
.selectAll(BaseGoods.class)
.selectAs(Brand::getName,BaseGoods::getBrandName)
- .selectAs(BaseCategory::getSortnum,BaseGoods::getCategoryName);
+ .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()
@@ -360,4 +373,105 @@
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;
+ }
}
--
Gitblit v1.9.3