修改商品类别展示方式为树形结构

This commit is contained in:
cjl
2019-02-20 11:46:51 +08:00
parent 9fff3f2aac
commit 6bbc0aefb4
15 changed files with 2369 additions and 1247 deletions

View File

@@ -1,9 +1,14 @@
package com.jsh.erp.service.materialCategory;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.datasource.entities.MaterialCategory;
import com.jsh.erp.datasource.entities.MaterialCategoryExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapper;
import com.jsh.erp.datasource.mappers.MaterialCategoryMapperEx;
import com.jsh.erp.datasource.vo.TreeNode;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -12,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;
@Service
@@ -20,6 +26,10 @@ public class MaterialCategoryService {
@Resource
private MaterialCategoryMapper materialCategoryMapper;
@Resource
private MaterialCategoryMapperEx materialCategoryMapperEx;
@Resource
private UserService userService;
public MaterialCategory getMaterialCategory(long id) {
return materialCategoryMapper.selectByPrimaryKey(id);
@@ -38,11 +48,11 @@ public class MaterialCategoryService {
}
public List<MaterialCategory> select(String name, Integer parentId, int offset, int rows) {
return materialCategoryMapper.selectByConditionMaterialCategory(name, parentId, offset, rows);
return materialCategoryMapperEx.selectByConditionMaterialCategory(name, parentId, offset, rows);
}
public int countMaterialCategory(String name, Integer parentId) {
return materialCategoryMapper.countsByMaterialCategory(name, parentId);
return materialCategoryMapperEx.countsByMaterialCategory(name, parentId);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
@@ -80,4 +90,68 @@ public class MaterialCategoryService {
example.createCriteria().andIdEqualTo(id);
return materialCategoryMapper.selectByExample(example);
}
/**
* create by: cjl
* description:
*获取商品类别树数据
* create time: 2019/2/19 14:30
* @Param:
* @return java.util.List<com.jsh.erp.datasource.vo.TreeNode>
*/
public List<TreeNode> getMaterialCategoryTree() throws Exception{
return materialCategoryMapperEx.getNodeTree();
}
/**
* create by: cjl
* description:
* 新增商品类别信息
* create time: 2019/2/19 16:30
* @Param: mc
* @return void
*/
public int addMaterialCategory(MaterialCategory mc) throws Exception {
if(mc==null){
return 0;
}
if(mc.getParentid()==null){
//没有给定父级目录的id默认设置父级目录为根目录
mc.setParentid(BusinessConstants.MATERIAL_CATEGORY_ROOT_ID);
}
//数据状态新增时默认设置为启用
mc.setStatus(BusinessConstants.MATERIAL_CATEGORY_STATUS_ENABLE);
Date date=new Date();
User userInfo=userService.getCurrentUser();
//创建时间
mc.setCreateTime(date);
//创建人
mc.setCreator(userInfo==null?null:userInfo.getId());
//更新时间
mc.setUpdateTime(date);
//更新人
mc.setUpdater(userInfo==null?null:userInfo.getId());
return materialCategoryMapperEx.addMaterialCategory(mc);
}
public int batchDeleteMaterialCategoryByIds(String ids) throws Exception {
//更新时间
Date updateDate =new Date();
//更新人
User userInfo=userService.getCurrentUser();
Long updater=userInfo==null?null:userInfo.getId();
StringBuffer sb=new StringBuffer();
String strArray[]=ids.split(",");
if(strArray.length<1){
return 0;
}
return materialCategoryMapperEx.batchDeleteMaterialCategoryByIds(updateDate,updater,strArray);
}
public int editMaterialCategory(MaterialCategory mc) {
//更新时间
mc.setUpdateTime(new Date());
//更新人
User userInfo=userService.getCurrentUser();
mc.setUpdater(userInfo==null?null:userInfo.getId());
return materialCategoryMapperEx.editMaterialCategory(mc);
}
}