Commit 423995a5 by weijiguang

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

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