Commit cc364a33 authored by shiyu's avatar shiyu

标准件

parent c97d37c1
package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.controller.CategoryController;
import com.wwdz.ch.admin.entity.vo.CategoryVo;
import com.wwdz.ch.admin.service.CategoryService;
import com.wwdz.ch.core.util.ResponseUtil;
......@@ -8,11 +9,11 @@ import com.wwdz.ch.db.domain.Item;
import com.wwdz.ch.db.manager.CategoryManager;
import com.wwdz.ch.db.manager.ItemManager;
import com.xxdxxs.utils.JsonUtils;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
......@@ -22,6 +23,8 @@ import java.util.stream.Collectors;
@Service
public class CategoryServiceImpl implements CategoryService {
private static final Logger logger = LoggerFactory.getLogger(CategoryServiceImpl.class);
@Autowired
CategoryManager categoryManager;
......@@ -61,6 +64,7 @@ public class CategoryServiceImpl implements CategoryService {
//如果是叶子结点,就从商品表中查询标准件信息作为该分类的信息
if (c.getIsLeaf()) {
Item item = itemManager.findStandard(categoryVo.getId());
if (item != null) {
String extra = item.getExtra();
Map<String, Object> map = JsonUtils.toMap(extra);
categoryVo.setDiameter(map.get("diameter") == null? null: Integer.valueOf(map.get("diameter").toString()));
......@@ -68,6 +72,7 @@ public class CategoryServiceImpl implements CategoryService {
categoryVo.setWeight(map.get("weight")== null? null: Integer.valueOf(map.get("weight").toString()));
categoryVo.setIcon(item.getTopImage());
}
}
// categoryVoList.add(new CategoryVo(c));
categoryVoList.add(categoryVo);
}
......@@ -76,7 +81,7 @@ public class CategoryServiceImpl implements CategoryService {
data.put("categoryPath", categoryManager.getCategoryPath(id));
return ResponseUtil.ok(data);
} catch (Exception e) {
e.printStackTrace();
logger.error("getSubCategory id : {}, error {}", id, e);
}
return ResponseUtil.fail();
}
......
......@@ -101,6 +101,16 @@ public class ItemServiceImpl implements ItemService {
Item item = new Item();
EntityMapper.copyAttribute(coinRequestDto, item);
item.setIsStd(coinRequestDto.getIsStd() == 0 ? false : true);
//如果该商品为标准件则替换原有的标准件
if (item.getIsStd()) {
//查询出该分类下原有的标准件
Item oldStanardItem = itemManager.findStandard(item.getCid());
if (oldStanardItem != null) {
itemManager.cancelStandardItem(oldStanardItem.getId());
}
}
//查询原有的数据
Item oldItem = itemManager.findDetails(coinRequestDto.getId());
String extra = oldItem.getExtra();
......@@ -130,10 +140,7 @@ public class ItemServiceImpl implements ItemService {
}
itemManager.setCoin(item);
//设置标准件
if (item.getIsStd()) {
itemManager.setStandardItem(item.getId(), item.getCid());
}
//记录钱币设置的操作日志
OperateLog operateLog = OperateLog.of(coinRequestDto.getId(), CommonEnum.OperateTypeEnum.ITEM_SET.getDes(),
......
......@@ -20,7 +20,7 @@ public interface ItemManager {
boolean deleteById(Long id);
void setStandardItem(Long id, Integer cid);
void cancelStandardItem(Long id);
Item findStandard(Integer cid);
}
......@@ -91,16 +91,11 @@ public class ItemManagerImpl implements ItemManager {
}
@Override
public void setStandardItem(Long id, Integer cid) {
public void cancelStandardItem(Long id) {
Item item = new Item();
ItemExample example = new ItemExample();
ItemExample.Criteria criteria = example.createCriteria();
criteria.andCidEqualTo(cid);
criteria.andIdNotEqualTo(id);
item.setCid(cid);
item.setId(id);
item.setIsStd(false);
//把该分类下的除了商品为id的都设置成非标准件
itemMapper.updateByExampleSelective(item, example);
itemMapper.updateByPrimaryKeySelective(item);
}
@Override
......
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