Commit 423995a5 by weijiguang

修复,修改商品时规格未变化不能修改标签的问题

parent 3020ccff
...@@ -31,8 +31,7 @@ import java.util.stream.Collectors; ...@@ -31,8 +31,7 @@ import java.util.stream.Collectors;
*/ */
@Service @Service
@Slf4j @Slf4j
public class GoodsServiceImpl implements IGoodsService public class GoodsServiceImpl implements IGoodsService {
{
@Autowired @Autowired
private GoodsMapper goodsMapper; private GoodsMapper goodsMapper;
@Autowired @Autowired
...@@ -170,6 +169,7 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -170,6 +169,7 @@ public class GoodsServiceImpl implements IGoodsService
goods.setState("1"); goods.setState("1");
goodsMapper.insertGoods(goods); goodsMapper.insertGoods(goods);
insertgoodsExt(goods); insertgoodsExt(goods);
insertGoodsTags(goods);
return 1; return 1;
} }
...@@ -178,6 +178,21 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -178,6 +178,21 @@ public class GoodsServiceImpl implements IGoodsService
return StringPool.COMMA + categoryIdStr + StringPool.COMMA; return StringPool.COMMA + categoryIdStr + StringPool.COMMA;
} }
private void insertGoodsTags(Goods goods) {
List<String> goodsTagList = goods.getGoodsTagList();
if (CollectionUtils.isEmpty(goodsTagList)) {
return;
}
for (String tagName : goodsTagList) {
GoodsTag goodsTag = new GoodsTag();
goodsTag.setGoodsId(goods.getId());
goodsTag.setState("1");
goodsTag.setCreatedAt(new Date());
goodsTag.setTag(tagName);
goodsTagMapper.insertGoodsTag(goodsTag);
}
}
private void insertgoodsExt(Goods goods) { private void insertgoodsExt(Goods goods) {
String specString = goods.getSpec(); String specString = goods.getSpec();
long goodsId = goods.getId(); long goodsId = goods.getId();
...@@ -204,30 +219,19 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -204,30 +219,19 @@ public class GoodsServiceImpl implements IGoodsService
} }
} }
} }
createSku(ruleNodeList,goodsId,goods.getDiscount(),goods.getPrice()); createSku(ruleNodeList, goodsId, goods.getDiscount(), goods.getPrice());
}
List<String> goodsTagList = goods.getGoodsTagList();
if(goodsTagList!=null &&!goodsTagList.isEmpty()){
for (String tagName : goodsTagList) {
GoodsTag goodsTag = new GoodsTag();
goodsTag.setGoodsId(goodsId);
goodsTag.setState("1");
goodsTag.setCreatedAt(new Date());
goodsTag.setTag(tagName);
goodsTagMapper.insertGoodsTag(goodsTag);
}
} }
} }
private void createSku(List<RuleNode> ruleNodeList, long goodsId, BigDecimal discount,BigDecimal price) { private void createSku(List<RuleNode> ruleNodeList, long goodsId, BigDecimal discount, BigDecimal price) {
for (RuleNode<SpecRule> ruleNode : ruleNodeList) { for (RuleNode<SpecRule> ruleNode : ruleNodeList) {
List<SpecRule> specRuleList = new ArrayList<>(); List<SpecRule> specRuleList = new ArrayList<>();
RuleNode<SpecRule> parentRuleNode = ruleNode.getParentRuleNode(); RuleNode<SpecRule> parentRuleNode = ruleNode.getParentRuleNode();
specRuleList.add(ruleNode.getRuleNode()); specRuleList.add(ruleNode.getRuleNode());
if(parentRuleNode!=null){ if (parentRuleNode != null) {
findPartentRuleNode(parentRuleNode,specRuleList); findPartentRuleNode(parentRuleNode, specRuleList);
} }
Collections.reverse(specRuleList); Collections.reverse(specRuleList);
GoodsSku goodsSku = new GoodsSku(); GoodsSku goodsSku = new GoodsSku();
...@@ -237,12 +241,12 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -237,12 +241,12 @@ public class GoodsServiceImpl implements IGoodsService
goodsSku.setUpdatedAt(new Date()); goodsSku.setUpdatedAt(new Date());
BigDecimal price1 = new BigDecimal(price.toPlainString()); BigDecimal price1 = new BigDecimal(price.toPlainString());
BigDecimal discount1 = new BigDecimal(discount.toPlainString()); BigDecimal discount1 = new BigDecimal(discount.toPlainString());
log.info("商品价格为:{},{}",price.toPlainString(),discount.toPlainString()); log.info("商品价格为:{},{}", price.toPlainString(), discount.toPlainString());
for (SpecRule specRule : specRuleList) { for (SpecRule specRule : specRuleList) {
price1 = price1.add(specRule.getAmount()); price1 = price1.add(specRule.getAmount());
discount1 = discount1.add(specRule.getAmount()); discount1 = discount1.add(specRule.getAmount());
} }
log.info("产品价格为:{},{}",price.toPlainString(),discount.toPlainString()); log.info("产品价格为:{},{}", price.toPlainString(), discount.toPlainString());
goodsSku.setPrice(price1); goodsSku.setPrice(price1);
goodsSku.setDiscount(discount1); goodsSku.setDiscount(discount1);
goodsSku.setRuleList(JSONArray.toJSONString(specRuleList)); goodsSku.setRuleList(JSONArray.toJSONString(specRuleList));
...@@ -253,15 +257,15 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -253,15 +257,15 @@ public class GoodsServiceImpl implements IGoodsService
private void findPartentRuleNode(RuleNode<SpecRule> ruleRuleNode, List<SpecRule> specRuleList) { private void findPartentRuleNode(RuleNode<SpecRule> ruleRuleNode, List<SpecRule> specRuleList) {
specRuleList.add(ruleRuleNode.getRuleNode()); specRuleList.add(ruleRuleNode.getRuleNode());
RuleNode<SpecRule> parentRuleNode = ruleRuleNode.getParentRuleNode(); RuleNode<SpecRule> parentRuleNode = ruleRuleNode.getParentRuleNode();
if(parentRuleNode!=null){ if (parentRuleNode != null) {
findPartentRuleNode(parentRuleNode,specRuleList); findPartentRuleNode(parentRuleNode, specRuleList);
} }
} }
private void putRuleNodeChild(RuleNode ruleNode,List<SpecRule> specRules,List<RuleNode> ruleNodeList) { private void putRuleNodeChild(RuleNode ruleNode, List<SpecRule> specRules, List<RuleNode> ruleNodeList) {
List<RuleNode> childNode = ruleNode.getChildNode(); List<RuleNode> childNode = ruleNode.getChildNode();
if(childNode == null ||childNode.isEmpty()){ if (childNode == null || childNode.isEmpty()) {
List<RuleNode> ruleNodes = new ArrayList<>(); List<RuleNode> ruleNodes = new ArrayList<>();
ruleNode.setChildNode(ruleNodes); ruleNode.setChildNode(ruleNodes);
for (SpecRule specRule : specRules) { for (SpecRule specRule : specRules) {
...@@ -271,9 +275,9 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -271,9 +275,9 @@ public class GoodsServiceImpl implements IGoodsService
ruleNodes.add(ruleNode1); ruleNodes.add(ruleNode1);
ruleNodeList.add(ruleNode1); ruleNodeList.add(ruleNode1);
} }
}else{ } else {
for (RuleNode node : childNode) { for (RuleNode node : childNode) {
putRuleNodeChild(node,specRules,ruleNodeList); putRuleNodeChild(node, specRules, ruleNodeList);
} }
} }
...@@ -292,6 +296,9 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -292,6 +296,9 @@ public class GoodsServiceImpl implements IGoodsService
} }
Goods goodsOri = goodsMapper.selectGoodsById(goods.getId()); Goods goodsOri = goodsMapper.selectGoodsById(goods.getId());
int i = goodsMapper.updateGoods(goods); int i = goodsMapper.updateGoods(goods);
goodsTagMapper.deleteGoodsTagByGoodsId(String.valueOf(goods.getId()));
insertGoodsTags(goods);
if (StringUtils.isEmpty(goods.getSpec()) || Objects.equals(goodsOri.getSpec(), goods.getSpec())) { if (StringUtils.isEmpty(goods.getSpec()) || Objects.equals(goodsOri.getSpec(), goods.getSpec())) {
return i; return i;
} }
...@@ -299,9 +306,6 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -299,9 +306,6 @@ public class GoodsServiceImpl implements IGoodsService
goodsSkuMapper.deleteGoodsSkuByGoodsId(String.valueOf(goods.getId())); goodsSkuMapper.deleteGoodsSkuByGoodsId(String.valueOf(goods.getId()));
}*/ }*/
goodsSkuMapper.deleteGoodsSkuByGoodsId(String.valueOf(goods.getId())); goodsSkuMapper.deleteGoodsSkuByGoodsId(String.valueOf(goods.getId()));
if (goods.getGoodsTagList() != null && !goods.getGoodsTagList().isEmpty()) {
goodsTagMapper.deleteGoodsTagByGoodsId(String.valueOf(goods.getId()));
}
insertgoodsExt(goods); insertgoodsExt(goods);
return i; return i;
} }
...@@ -313,8 +317,7 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -313,8 +317,7 @@ public class GoodsServiceImpl implements IGoodsService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteGoodsByIds(String[] ids) public int deleteGoodsByIds(String[] ids) {
{
return goodsMapper.deleteGoodsByIds(ids); return goodsMapper.deleteGoodsByIds(ids);
} }
...@@ -325,8 +328,7 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -325,8 +328,7 @@ public class GoodsServiceImpl implements IGoodsService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteGoodsById(String id) public int deleteGoodsById(String id) {
{
return 1; return 1;
...@@ -334,10 +336,10 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -334,10 +336,10 @@ public class GoodsServiceImpl implements IGoodsService
@Override @Override
public String putShop(Long goodsId, boolean boo) { public String putShop(Long goodsId, boolean boo) {
GoodsSku goodsSku =new GoodsSku(); GoodsSku goodsSku = new GoodsSku();
goodsSku.setGoodsId(goodsId); goodsSku.setGoodsId(goodsId);
List<GoodsSku> goodsSkus = goodsSkuMapper.selectGoodsSkuList(goodsSku); List<GoodsSku> goodsSkus = goodsSkuMapper.selectGoodsSkuList(goodsSku);
if(goodsSkus.isEmpty()){ if (goodsSkus.isEmpty()) {
throw new ServiceException("商品信息不全,请修改商品"); throw new ServiceException("商品信息不全,请修改商品");
} }
Goods goods = new Goods(); Goods goods = new Goods();
...@@ -346,7 +348,7 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -346,7 +348,7 @@ public class GoodsServiceImpl implements IGoodsService
goods.setUpdatedAt(new Date()); goods.setUpdatedAt(new Date());
goods.setShelfAt(new Date()); goods.setShelfAt(new Date());
int i = goodsMapper.updateGoods(goods); int i = goodsMapper.updateGoods(goods);
if(boo&&i>0){ if (boo && i > 0) {
Shop shop = new Shop(); Shop shop = new Shop();
List<Shop> shops = shopService.selectShopList(shop); List<Shop> shops = shopService.selectShopList(shop);
for (Shop shop1 : shops) { for (Shop shop1 : shops) {
...@@ -366,9 +368,9 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -366,9 +368,9 @@ public class GoodsServiceImpl implements IGoodsService
ShopGoods shopGoods = new ShopGoods(); ShopGoods shopGoods = new ShopGoods();
shopGoods.setGoodsId(goodsId); shopGoods.setGoodsId(goodsId);
List<ShopGoods> shopGoodsList = shopGoodsMapper.selectShopGoodsList(shopGoods); List<ShopGoods> shopGoodsList = shopGoodsMapper.selectShopGoodsList(shopGoods);
if(!boo){ if (!boo) {
Boolean isExist = shopGoodsList.size()>0; Boolean isExist = shopGoodsList.size() > 0;
if(isExist){ if (isExist) {
return "99"; return "99";
} }
} }
...@@ -381,21 +383,22 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -381,21 +383,22 @@ public class GoodsServiceImpl implements IGoodsService
shopGoodsMapper.deleteShopGoodsById(shopGoods1.getId()); shopGoodsMapper.deleteShopGoodsById(shopGoods1.getId());
shopGoodsSkuMapper.deleteShopGoodsSkuByGoodsId(shopGoods1.getGoodsId()); shopGoodsSkuMapper.deleteShopGoodsSkuByGoodsId(shopGoods1.getGoodsId());
List<String> goodsIds = Arrays.asList(String.valueOf(shopGoods1.getGoodsId())); List<String> goodsIds = Arrays.asList(String.valueOf(shopGoods1.getGoodsId()));
shopRecommendMapper.deleteByShopIdGoods(shopGoods1.getShopId(),goodsIds); shopRecommendMapper.deleteByShopIdGoods(shopGoods1.getShopId(), goodsIds);
updateApplication(shopGoods1.getShopId()); updateApplication(shopGoods1.getShopId());
} }
return i+""; return i + "";
} }
public void updateApplication(long shopId){
public void updateApplication(long shopId) {
Machine machine = new Machine(); Machine machine = new Machine();
machine.setShopId(shopId); machine.setShopId(shopId);
List<Machine> machines = machineMapper.selectMachineList(machine); List<Machine> machines = machineMapper.selectMachineList(machine);
if(!machines.isEmpty()){ if (!machines.isEmpty()) {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("action","GOODS_CHANGED"); jsonObject.put("action", "GOODS_CHANGED");
jsonObject.put("timestamp",System.currentTimeMillis()); jsonObject.put("timestamp", System.currentTimeMillis());
jiGuangPushService.push(machines.get(0).getCode(),jsonObject); jiGuangPushService.push(machines.get(0).getCode(), jsonObject);
} }
...@@ -406,9 +409,9 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -406,9 +409,9 @@ public class GoodsServiceImpl implements IGoodsService
ShopGoods shopGoods = new ShopGoods(); ShopGoods shopGoods = new ShopGoods();
shopGoods.setGoodsId(id); shopGoods.setGoodsId(id);
List<ShopGoods> shopGoodsList = shopGoodsMapper.selectShopGoodsList(shopGoods); List<ShopGoods> shopGoodsList = shopGoodsMapper.selectShopGoodsList(shopGoods);
if(!boo){ if (!boo) {
Boolean isExist = shopGoodsList.size()>0; Boolean isExist = shopGoodsList.size() > 0;
if(isExist){ if (isExist) {
return "99"; return "99";
} }
} }
...@@ -423,7 +426,7 @@ public class GoodsServiceImpl implements IGoodsService ...@@ -423,7 +426,7 @@ public class GoodsServiceImpl implements IGoodsService
} }
@Override @Override
public List<GoodsSku> getGoodsSkus(long goodsId){ public List<GoodsSku> getGoodsSkus(long goodsId) {
GoodsSku goodsSku = new GoodsSku(); GoodsSku goodsSku = new GoodsSku();
goodsSku.setGoodsId(goodsId); goodsSku.setGoodsId(goodsId);
return goodsSkuMapper.selectGoodsSkuList(goodsSku); return goodsSkuMapper.selectGoodsSkuList(goodsSku);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment