From d077a683730cc0e9af4490908e4ced51ca303276 Mon Sep 17 00:00:00 2001
From: jiaosong <jiaosong6760@dingtalk.com>
Date: 星期四, 14 九月 2023 16:47:08 +0800
Subject: [PATCH] #自测修改
---
server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java | 138 ++++++++++++++++++++++++++++++++++++++-------
1 files changed, 116 insertions(+), 22 deletions(-)
diff --git a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
index fd52229..1b54d9a 100644
--- a/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
+++ b/server/service/src/main/java/com/doumee/service/business/impl/GoodsServiceImpl.java
@@ -20,6 +20,7 @@
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.service.business.GoodsService;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.commons.lang3.StringUtils;
@@ -38,7 +39,6 @@
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.nio.charset.Charset;
@@ -54,6 +54,10 @@
@Autowired
private GoodsMapper goodsMapper;
+ @Autowired
+ private BaseGoodsMapper baseGoodsMapper;
+ @Autowired
+ private BaseGoodsParamMapper baseGoodsParamMapper;
@Autowired
private CategoryMapper categoryMapper;
@Autowired
@@ -75,8 +79,6 @@
@Autowired
private CateParamSelectMapper cateParamSelectMapper;
- @Autowired
- private BaseGoodsMapper baseGoodsMapper;
@@ -140,11 +142,80 @@
|| param.getGoodsParamList().size()==0))){
throw new BusinessException(ResponseStatus.BAD_REQUEST);
}
- Goods goods = new Goods();
-
- if(goodsMapper.selectCount(new QueryWrapper<Goods>().eq("ISDELETED",Constants.ZERO).eq("name",goods.getName()))>0){
- throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"銆�"+goods.getName()+"銆戝凡瀛樺湪");
+ Category category = categoryMapper.selectById(param.getCategoryId());
+ 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(),"瀵逛笉璧凤紝璇峰墠寰�銆愮被鍒鐞嗐�戝厛鍏宠仈骞冲彴绫诲埆锛�");
+ }
+ BaseGoods bp = new BaseGoods();
+ bp.setCategoryId(category.getPlatCateId());
+ bp.setIsdeleted(Constants.ZERO);
+ List<BaseGoods> goodsList = new ArrayList<>();
+ List<Integer> ids = null;
+ if(Constants.equalsInteger(Constants.ONE, param.getType())){
+ //濡傛灉閫夋嫨閮ㄥ垎鍟嗗搧
+ for(PlatGoodsParam p : param.getGoodsParamList()){
+ if(p.getGoodsId() == null || p.getPrice() == null){
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇锋纭�夋嫨骞冲彴鍟嗗搧骞堕厤缃叆鎵嬩环锛�");
+ }
+ 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()){
+ // 濡傛灉閫夋嫨骞冲彴鍟嗗搧鍜屾煡璇㈢粨鏋滃涓嶄笂锛屾彁绀洪敊璇�
+ throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇锋纭�夋嫨骞冲彴鍟嗗搧锛�");
+ }
+ for(BaseGoods model : goodsList){
+ //閬嶅巻骞冲彴鍟嗗搧淇℃伅锛岃繘琛屽晢鍝佷俊鎭悓姝�
+ Goods goods = initGoodsPlatParam(user,model,param);
+ if(goods == null){
+ continue;
+ }
+ goodsMapper.insert(goods);
+ //寮�濮嬪鐞嗛檮浠�
+ dealPlatMultifule(goods.getId(),user,model);
+ //寮�濮嬪鐞嗗弬鏁伴厤缃�
+ dealPlatGoodsParam(model,goods,user);
+ }
+
+
+ return 1;
+ }
+
+ private void dealPlatGoodsParam(BaseGoods model, Goods goods, LoginUserInfo user) {
+ BaseGoodsParam baseGoodsParam = new BaseGoodsParam();
+ baseGoodsParam.setGoodsId(model.getId());
+ baseGoodsParam.setIsdeleted(Constants.ZERO);
+ List<BaseGoodsParam> goodsParamList = baseGoodsParamMapper.selectList(new QueryWrapper<>(baseGoodsParam));
+ if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
+ for (int i = 0; i < goodsParamList.size(); i++) {
+ BaseGoodsParam bgParam = goodsParamList.get(i);
+ GoodsParam goodsParam = new GoodsParam();
+ goodsParam.setCreator(user.getId());
+ goodsParam.setCreateDate(new Date());
+ goodsParam.setIsdeleted(Constants.ZERO);
+ goodsParam.setSortnum(i+Constants.ONE);
+ goodsParam.setStatus(Constants.ZERO);
+ goodsParam.setGoodsId(goods.getId());
+ goodsParam.setVal(bgParam.getVal());
+ goodsParam.setName(bgParam.getName());
+ goodsParamMapper.insert(goodsParam);
+ }
+ }
+ }
+
+ private Goods initGoodsPlatParam(LoginUserInfo user, BaseGoods model, GoodCreatePlatRequest param) {
+ Goods goods = new Goods();
+ goods.setIsdeleted(Constants.ZERO);
+ goods.setGoodsId(model.getId());
+ if(goodsMapper.selectCount(new QueryWrapper<>(goods))>0){
+ //濡傛灉宸茬粡鍚屾杩囷紝璺宠繃姝ゆ鍚屾
+ return null;
+ }
+ goods.setType(Constants.ONE);
goods.setStatus(Constants.ZERO);
goods.setCreateDate(new Date());
goods.setCreator(user.getId());
@@ -152,9 +223,25 @@
//澶勭悊鎷奸煶闂
goods.setPinyin(PinYinUtil.getFullSpell(goods.getName()));
goods.setShortPinyin(PinYinUtil.getFirstSpell(goods.getName()));
- goodsMapper.insert(goods);
+ goods.setName(model.getName());
+ goods.setCategoryId(param.getCategoryId());
+ //鑾峰彇鍏ユ墜浠锋牸
+ goods.setPrice(getPriceFromParam(model,param));
+ goods.setZdPrice(model.getZdPrice());
+ goods.setRemark(model.getRemark());
+ goods.setImgurl(model.getImgurl());
+ goods.setBrandId(model.getBrandId());
+ return goods;
+ }
- List<Multifile> multifileList = goods.getMultifileList();
+ /**
+ * 寮�濮嬪鐞嗗钩鍙板晢鍝佸叧鑱旈檮浠讹紝澶嶅埗涓�濂楀埌浼佷笟鍟嗗搧涓�
+ */
+ private void dealPlatMultifule(Integer id, LoginUserInfo user, BaseGoods model) {
+ Multifile f = new Multifile();
+ f.setObjId(model.getId());
+ f.setIsdeleted(Constants.ZERO);
+ List<Multifile> multifileList =multifileMapper.selectList(new QueryWrapper<>(f));
if(!Objects.isNull(multifileList)&&multifileList.size()>Constants.ZERO){
for (int i = 0; i < multifileList.size(); i++) {
Multifile multifile = multifileList.get(i);
@@ -162,26 +249,33 @@
multifile.setCreateDate(new Date());
multifile.setIsdeleted(Constants.ZERO);
multifile.setSortnum(i+Constants.ONE);
- multifile.setObjId(goods.getId());
+ multifile.setObjId(id);
multifile.setType(Constants.ZERO);
multifile.setObjType(Constants.ZERO);
+ multifile.setFileurl(multifile.getFileurl());
+ multifile.setName(multifile.getName());
+ multifile.setSortnum(multifile.getSortnum());
+ multifile.setCompanyId(user.getCompanyId());
multifileMapper.insert(multifile);
}
}
- List<GoodsParam> goodsParamList = goods.getGoodsParamList();
- if(!Objects.isNull(goodsParamList)&&goodsParamList.size()>0){
- for (int i = 0; i < goodsParamList.size(); i++) {
- GoodsParam goodsParam = goodsParamList.get(i);
- goodsParam.setCreator(user.getId());
- goodsParam.setCreateDate(new Date());
- goodsParam.setIsdeleted(Constants.ZERO);
- goodsParam.setStatus(Constants.ZERO);
- goodsParam.setSortnum(i+Constants.ONE);
- goodsParam.setGoodsId(goods.getId());
- goodsParamMapper.insert(goodsParam);
+ }
+
+ private BigDecimal getPriceFromParam(BaseGoods model, GoodCreatePlatRequest param) {
+ if(Constants.equalsInteger(Constants.ONE, param.getType())){
+ for(PlatGoodsParam p: param.getGoodsParamList()){
+ if(Constants.equalsInteger(model.getId(),p.getGoodsId())){
+ return p.getPrice();
+ }
}
}
- return goods.getId();
+ //濡傛灉娌℃湁閰嶇疆鍏ユ墜浠凤紝瀹夎鍔犱环绯绘暟鏉ヨ绠�
+ if(model.getCateRatePrice()==null){
+ model.setCateRatePrice(systemDictDataBiz.getGoodsPriceRate());
+ }
+ //杩斿洖
+ return Constants.formatBigdecimal(model.getPrice()).multiply(model.getCateRatePrice()).multiply(param.getRate());
+
}
--
Gitblit v1.9.3