Commit c97d37c1 authored by shiyu's avatar shiyu

标准件

parent 4ce6e6af
......@@ -98,6 +98,7 @@ public class AdminAuthController {
}
logger.info("【请求结束】系统管理->用户登录,响应结果:{}", JSONObject.toJSONString(currentUser.getSession().getId()));
currentUser.getSession().setTimeout(1000*60*60*12);
return ResponseUtil.ok(currentUser.getSession().getId());
}
......
......@@ -10,9 +10,11 @@ import javax.validation.constraints.NotNull;
import com.wwdz.ch.admin.annotation.RequiresPermissionsDesc;
import com.wwdz.ch.admin.entity.vo.CategoryVo;
import com.wwdz.ch.admin.service.CategoryService;
import com.wwdz.ch.admin.util.AuthSupport;
import com.wwdz.ch.core.type.ListResult;
import com.wwdz.ch.db.domain.Category;
import com.wwdz.ch.db.manager.CategoryManager;
import com.wwdz.ch.db.manager.impl.CategoryManagerImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
......@@ -40,7 +42,10 @@ public class CategoryController {
private static final Logger logger = LoggerFactory.getLogger(CategoryController.class);
@Autowired
private CategoryManagerImpl categoryManager;
private CategoryManager categoryManager;
@Autowired
private CategoryService categoryService;
@RequiresPermissions("admin:category:list")
@RequiresPermissionsDesc(menu = { "商场管理", "类目管理" }, button = "查询")
......@@ -50,9 +55,7 @@ public class CategoryController {
@Sort @RequestParam(defaultValue = "add_time") String sort,
@Order @RequestParam(defaultValue = "desc") String order) {
logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 商场管理->类目管理->查询,请求参数:name:{},page:{}", name, page);
List<Category> collectList = categoryManager.querySelective(id, name, page, limit, sort, order);
List<CategoryVo> data = collectList.parallelStream().map(a -> new CategoryVo(a)).collect(Collectors.toList());
List<CategoryVo> data = categoryService.querySelective(id, name, page, limit, sort, order);
logger.info("【请求结束】商场管理->类目管理->查询:total:{}", JSONObject.toJSONString(data));
return new ListResult<>(data, data.size());
}
......@@ -96,18 +99,9 @@ public class CategoryController {
@GetMapping("/getSubCategory")
public Object getSubCategory(@NotNull Integer id) {
logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 查询根据类目ID查询子类目");
List<CategoryVo> categoryVoList = new ArrayList<>();
List<Category> categoryList = categoryManager.queryByPid(id);
for (Category c : categoryList) {
CategoryVo categoryVo = new CategoryVo(c);
categoryVo.setCategoryPath(StringUtils.join(categoryManager.getCategoryPath(c.getId()), ">"));
categoryVoList.add(new CategoryVo(c));
}
Map<String, Object> data = new HashMap<>();
data.put("categoryList", categoryVoList);
data.put("categoryPath", categoryManager.getCategoryPath(id));
Object data = categoryService.getSubCategory(id);
logger.info("【请求结束】查询根据类目ID查询子类目 : {}", JSONObject.toJSONString(data));
return ResponseUtil.ok(data);
return data;
}
......@@ -117,18 +111,8 @@ public class CategoryController {
@PostMapping("/create")
public Object create(@RequestBody CategoryVo categoryVo) {
logger.info("【请求开始】操作人:[" + AuthSupport.userName()+ "] 商场管理->类目管理->添加,请求参数:{}", JSONObject.toJSONString(categoryVo));
Integer pid = categoryVo.getPid();
Category category = categoryVo.toDo();
if (null != pid) {
Category pCat = new Category();
pCat.setId(pid);
pCat.setIsLeaf(false);
categoryManager.updateById(pCat);
} else {
category.setIsLeaf(true);
}
categoryManager.add(category);
categoryService.create(categoryVo);
logger.info("【请求结束】商场管理->类目管理->添加:响应结果:{}", JSONObject.toJSONString(category));
return ResponseUtil.ok(category);
}
......
......@@ -4,6 +4,7 @@ import com.alibaba.druid.support.json.JSONUtils;
import com.wwdz.ch.db.domain.Category;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.StringUtils;
import java.io.Serializable;
......@@ -12,6 +13,7 @@ import java.util.List;
import java.util.Map;
@ApiModel
@Data
public class CategoryVo implements Serializable {
private static final long serialVersionUID = 96458407347975312L;
......
package com.wwdz.ch.admin.impl;
import com.wwdz.ch.admin.entity.vo.CategoryVo;
import com.wwdz.ch.admin.service.CategoryService;
import com.wwdz.ch.core.util.ResponseUtil;
import com.wwdz.ch.db.domain.Category;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service
public class CategoryServiceImpl implements CategoryService {
@Autowired
CategoryManager categoryManager;
@Autowired
ItemManager itemManager;
@Override
public List<Category> queryByLevel(Integer level, Integer offset, Integer limit) {
return null;
}
@Override
public List<Category> queryByPid(Integer pid) {
return null;
}
@Override
public Category findById(Integer id) {
return null;
}
@Override
public List<CategoryVo> querySelective(String id, String name, Integer page, Integer size, String sort, String order) {
List<Category> collectList = categoryManager.querySelective(id, name, page, size, sort, order);
List<CategoryVo> data = collectList.parallelStream().map(a -> new CategoryVo(a)).collect(Collectors.toList());
return data;
}
public Object getSubCategory(Integer id){
try {
List<CategoryVo> categoryVoList = new ArrayList<>();
List<Category> categoryList = categoryManager.queryByPid(id);
for (Category c : categoryList) {
CategoryVo categoryVo = new CategoryVo(c);
categoryVo.setCategoryPath(StringUtils.join(categoryManager.getCategoryPath(c.getId()), ">"));
//如果是叶子结点,就从商品表中查询标准件信息作为该分类的信息
if (c.getIsLeaf()) {
Item item = itemManager.findStandard(categoryVo.getId());
String extra = item.getExtra();
Map<String, Object> map = JsonUtils.toMap(extra);
categoryVo.setDiameter(map.get("diameter") == null? null: Integer.valueOf(map.get("diameter").toString()));
categoryVo.setThickness(map.get("thickness")== null? null: Integer.valueOf(map.get("thickness").toString()));
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);
}
Map<String, Object> data = new HashMap<>();
data.put("categoryList", categoryVoList);
data.put("categoryPath", categoryManager.getCategoryPath(id));
return ResponseUtil.ok(data);
} catch (Exception e) {
e.printStackTrace();
}
return ResponseUtil.fail();
}
@Override
public void create(CategoryVo categoryVo) {
Integer pid = categoryVo.getPid();
Category category = categoryVo.toDo();
if (null != pid) {
Category pCat = new Category();
pCat.setId(pid);
pCat.setIsLeaf(false);
categoryManager.updateById(pCat);
} else {
category.setIsLeaf(true);
}
categoryManager.add(category);
}
@Override
public int updateById(Category category) {
return 0;
}
@Override
public void deleteById(Integer id) {
}
@Override
public void add(Category category) {
}
@Override
public Integer getMaxCagtegoryLevel() {
return null;
}
@Override
public List<String> getCategoryPath(Integer id) {
return null;
}
}
......@@ -100,6 +100,7 @@ public class ItemServiceImpl implements ItemService {
try {
Item item = new Item();
EntityMapper.copyAttribute(coinRequestDto, item);
item.setIsStd(coinRequestDto.getIsStd() == 0 ? false : true);
//查询原有的数据
Item oldItem = itemManager.findDetails(coinRequestDto.getId());
String extra = oldItem.getExtra();
......@@ -127,9 +128,13 @@ public class ItemServiceImpl implements ItemService {
paramMap.put("topImage", url);
item.setTopImage(url);
}
item.setIsStd(coinRequestDto.getIsStd()==0?false:true);
itemManager.setCoin(item);
//设置标准件
if (item.getIsStd()) {
itemManager.setStandardItem(item.getId(), item.getCid());
}
//记录钱币设置的操作日志
OperateLog operateLog = OperateLog.of(coinRequestDto.getId(), CommonEnum.OperateTypeEnum.ITEM_SET.getDes(),
CommonEnum.OperateTypeEnum.ITEM_SET.getCode(), AuthSupport.adminId(), AuthSupport.userName(), JsonUtils.fromMap(paramMap));
......
package com.wwdz.ch.admin.service;
import com.wwdz.ch.admin.entity.vo.CategoryVo;
import com.wwdz.ch.db.domain.Category;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
public interface CategoryService {
List<CategoryVo> querySelective(String id, String name, Integer page, Integer size, String sort, String order);
Object getSubCategory(Integer id);
void create(CategoryVo categoryVo);
List<Category> queryByLevel(Integer level, Integer offset, Integer limit);
List<Category> queryByPid(Integer pid);
Category findById(Integer id);
int updateById(Category category);
void deleteById(Integer id);
void add(Category category);
Integer getMaxCagtegoryLevel();
List<String> getCategoryPath(Integer id);
}
......@@ -19,4 +19,8 @@ public interface ItemManager {
int deleteUserItems(CoinRequestDto coinRequestDto);
boolean deleteById(Long id);
void setStandardItem(Long id, Integer cid);
Item findStandard(Integer cid);
}
......@@ -89,4 +89,26 @@ public class ItemManagerImpl implements ItemManager {
int num = itemMapper.updateByExampleSelective(item, example);
return num > 0;
}
@Override
public void setStandardItem(Long id, Integer cid) {
Item item = new Item();
ItemExample example = new ItemExample();
ItemExample.Criteria criteria = example.createCriteria();
criteria.andCidEqualTo(cid);
criteria.andIdNotEqualTo(id);
item.setCid(cid);
item.setIsStd(false);
//把该分类下的除了商品为id的都设置成非标准件
itemMapper.updateByExampleSelective(item, example);
}
@Override
public Item findStandard(Integer cid) {
ItemExample example = new ItemExample();
ItemExample.Criteria criteria = example.createCriteria();
criteria.andCidEqualTo(cid);
criteria.andIsStdEqualTo(true);
return itemMapper.selectOneByExampleWithBLOBs(example);
}
}
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