consum-base/src/main/java/com/consum/base/Constants.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
consum-base/src/main/java/com/consum/base/controller/BaseCategoryController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
consum-base/src/main/java/com/consum/base/pojo/BaseCategoryParam.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
consum-base/src/main/java/com/consum/base/service/BaseCategoryServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
consum-base/src/main/java/com/consum/base/service/BaseGoodsTemplateServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
consum-model-pojo/src/main/java/com/consum/model/po/BaseCategory.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
consum-model-pojo/src/main/java/com/consum/model/po/BaseCategory_mapper.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
consum-base/src/main/java/com/consum/base/Constants.java
@@ -42,4 +42,15 @@ // 是否完成 public static final Integer PROJECT_YES = 1;// 已完成 public static final Integer PROJECT_NO = 0;// 未完成 //物品分类层级(1,2,3) public static final Integer LEVELS_ONE = 1; public static final Integer LEVELS_TWO = 2; public static final Integer LEVELS_THREE = 3; //物品分类STATES 1=正常;2=禁用;3=已删除 public static final Integer CATEGORY_ENABLE = 1; public static final Integer CATEGORY_DISABLE = 2; public static final Integer CATEGORY_DELETED = 3; } consum-base/src/main/java/com/consum/base/controller/BaseCategoryController.java
New file @@ -0,0 +1,155 @@ package com.consum.base.controller; import com.consum.base.BaseController; import com.consum.base.pojo.BaseCategoryParam; import com.consum.base.service.BaseCategoryServiceImpl; import com.consum.base.service.BaseGoodsTemplateServiceImpl; import com.consum.model.po.BaseCategory; import com.iplatform.model.po.S_user_core; import com.walker.db.page.GenericPager; import com.walker.infrastructure.utils.StringUtils; import com.walker.web.ResponseValue; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import java.util.List; /** * @Description 物品分类 * @Author 卢庆阳 * @Date 2023/10/23 */ @RestController @RequestMapping("/pc/base/category") public class BaseCategoryController extends BaseController { @Autowired private BaseCategoryServiceImpl baseCategoryService; @Autowired private BaseGoodsTemplateServiceImpl baseGoodsTemplateService; /** * @Description 新增分类 * @Author 卢庆阳 * @Date 2023/10/23 */ @PostMapping("/add") public ResponseValue add(@RequestBody BaseCategoryParam param) { if (StringUtils.isEmpty(param.getCategoryName())) { return ResponseValue.error("分类名称为空"); } if (param.getOrderNumber() == null) { return ResponseValue.error("顺序号为空"); } //判断同一父类id下分类名称是否重复 BaseCategory category = this.baseCategoryService.getByCategoryNameAndFatherCategoryId(param.getCategoryName(),param.getFatherCategoryId()); if (category != null) { return ResponseValue.error("分类名称已存在"); } // int result = this.baseCategoryService.add(param,this.getCurrentUser()); int result = this.baseCategoryService.add(param); if(result>0) return ResponseValue.success(1); return ResponseValue.error("新增失败!"); } /** * @Description 物品分类列表查询 * @Author 卢庆阳 * @Date 2023/10/23 */ @GetMapping("/list") public ResponseValue queryBaseCategoryList(BaseCategoryParam param) { // S_user_core currentUser = this.getCurrentUser(); // if (currentUser == null) { // return ResponseValue.error("登录用户信息不存在"); // } GenericPager<BaseCategory> pager = this.baseCategoryService.queryBaseCategoryList(param); return ResponseValue.success(pager); } /** * @Description 编辑 * @Author 卢庆阳 * @Date 2023/10/23 */ @PostMapping("/edit") public ResponseValue edit(@RequestBody BaseCategory baseCategory) { Long id = baseCategory.getId(); if (id == null || id.longValue() <= 0) { return ResponseValue.error("编辑的物品分类不存在"); } if (StringUtils.isEmpty(baseCategory.getCategoryName())) { return ResponseValue.error("分类名称为空"); } if (baseCategory.getOrderNumber() == null) { return ResponseValue.error("顺序号为空"); } //判断同一父类id下分类名称是否重复 BaseCategory category = this.baseCategoryService.getByCategoryNameAndFatherCategoryId(baseCategory.getCategoryName(),baseCategory.getFatherCategoryId()); if (category != null) { return ResponseValue.error("分类名称已存在"); } // S_user_core currentUser = this.getCurrentUser(); // if (currentUser == null) { // return ResponseValue.error("登录用户信息不存在"); // } int num = this.baseCategoryService.updateBaseCategory(baseCategory); return num>0 ? ResponseValue.success(1):ResponseValue.error("编辑失败!"); } /** * 修改状态 * @author 卢庆阳 * @date 2023/9/27 */ //分类下有正常状态的物品时,不允许禁用 @PostMapping("/updStatus") public ResponseValue updateStatus(@RequestBody BaseCategory baseCategory){ if (baseCategory==null || baseCategory.getId() ==null || baseCategory.getStates() == null) { return ResponseValue.error("参数错误"); } //根据分类id和状态查询物品模版 List<BaseCategory> list = this.baseGoodsTemplateService.getByCategoryId(baseCategory.getId()); if (baseCategory.getStates() == 2 && !CollectionUtils.isEmpty(list)) { return ResponseValue.error("分类下有正常状态的物品,不允许禁用"); } int num = this.baseCategoryService.updateStatus(baseCategory); return num>0 ? ResponseValue.success(1):ResponseValue.error("修改失败!"); } /** * @Description 根据节点id删除节点(逻辑删除) * @Author 卢庆阳 * @Date 2023/10/23 */ @DeleteMapping("/del") public ResponseValue updateById(@RequestBody BaseCategory baseCategory){ if (baseCategory.getId() == null) { return ResponseValue.error("分类id为空"); } //S_user_core currentUser = this.getCurrentUser(); int num = this.baseCategoryService.updateById(baseCategory); return num>0 ? ResponseValue.success(1):ResponseValue.error("删除失败!"); } /** * 根据节点id查询节点详情 * @author 卢庆阳 * @date 2023/9/26 */ @GetMapping("/detail") public ResponseValue getById(Long id){ if (id == null) { return ResponseValue.error("分类id为空"); } BaseCategory baseCategory = this.baseCategoryService.getById(id); if (baseCategory == null) return ResponseValue.error("查询失败!"); return ResponseValue.success("查询成功!",baseCategory); } } consum-base/src/main/java/com/consum/base/pojo/BaseCategoryParam.java
New file @@ -0,0 +1,54 @@ package com.consum.base.pojo; import com.walker.web.param.ParamRequest; public class BaseCategoryParam extends ParamRequest { private Long fatherCategoryId; private String categoryName; /** * 分裂类别:A,B,C */ private String classification; private Integer orderNumber; private Integer states; public Long getFatherCategoryId() { return fatherCategoryId; } public void setFatherCategoryId(Long fatherCategoryId) { this.fatherCategoryId = fatherCategoryId; } public String getCategoryName() { return categoryName; } public void setCategoryName(String categoryName) { this.categoryName = categoryName; } public String getClassification() { return classification; } public void setClassification(String classification) { this.classification = classification; } public Integer getOrderNumber() { return orderNumber; } public void setOrderNumber(Integer orderNumber) { this.orderNumber = orderNumber; } public Integer getStates() { return states; } public void setStates(Integer states) { this.states = states; } } consum-base/src/main/java/com/consum/base/service/BaseCategoryServiceImpl.java
New file @@ -0,0 +1,143 @@ package com.consum.base.service; import com.consum.base.Constants; import com.consum.base.pojo.BaseCategoryParam; import com.consum.base.util.IdUtil; import com.consum.model.po.BaseCategory; import com.walker.db.page.GenericPager; import com.walker.infrastructure.utils.DateUtils; import com.walker.infrastructure.utils.StringUtils; import com.walker.jdbc.service.BaseServiceImpl; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.HashMap; /** * @Description 物品分类 * @Author 卢庆阳 * @Date 2023/10/23 */ @Service public class BaseCategoryServiceImpl extends BaseServiceImpl { /** * @Description 新增分类 * @Author 卢庆阳 * @Date 2023/10/23 */ // public int add(BaseCategoryParam param, S_user_core currentUser) { public int add(BaseCategoryParam param) { BaseCategory baseCategory = new BaseCategory(); BeanUtils.copyProperties(param, baseCategory); baseCategory.setId(IdUtil.generateId()); //层级 if (baseCategory.getFatherCategoryId() == 0L) { //一级分类 baseCategory.setLevels(Constants.LEVELS_ONE); } else { //根据父类id查询上级分类信息 BaseCategory category = this.get(new BaseCategory(baseCategory.getFatherCategoryId())); if (category.getFatherCategoryId() == 0L) { //二级分类 baseCategory.setLevels(Constants.LEVELS_TWO); } else { //三级分类 baseCategory.setLevels(Constants.LEVELS_THREE); } } //TODO 创建人id和创建人姓名 // baseCategory.setCreateUserId(currentUser.getId()); // baseCategory.setCreateUserName(currentUser.getUser_name()); //创建时间 baseCategory.setCreateTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); return this.insert(baseCategory); } /** * @Description 根据分类名称和父类id查询分类 * @Author 卢庆阳 * @Date 2023/10/23 * @param categoryName * @param fatherCategoryId */ public BaseCategory getByCategoryNameAndFatherCategoryId(String categoryName, Long fatherCategoryId) { StringBuilder sql = new StringBuilder("SELECT * FROM base_category WHERE 1 = 1 "); HashMap<String, Object> paramts = new HashMap<>(); //分类名称 sql.append(" and category_name =:category_name "); paramts.put("category_name", categoryName); //父类id sql.append(" and father_category_id =:father_category_id "); paramts.put("father_category_id", fatherCategoryId); return this.get(sql.toString(), paramts, new BaseCategory()); } /** * @Description 物品分类列表查询 * @Author 卢庆阳 * @Date 2023/10/23 */ public GenericPager<BaseCategory> queryBaseCategoryList(BaseCategoryParam param) { StringBuilder sql = new StringBuilder("SELECT * FROM base_category WHERE 1 = 1 "); HashMap<String, Object> paramts = new HashMap<>(); //分类名称 if (!StringUtils.isEmpty(param.getCategoryName())) { sql.append(" and category_name like:category_name "); paramts.put("category_name", StringUtils.CHAR_PERCENT + param.getCategoryName() + StringUtils.CHAR_PERCENT); } //类别 if (!StringUtils.isEmpty(param.getClassification())) { sql.append(" and classification =:classification "); paramts.put("classification", param.getClassification()); } //状态 if (param.getStates() != null) { sql.append(" and status =:status "); paramts.put("status", param.getStates()); } sql.append(" ORDER BY ORDER_NUMBER,CREATE_TIME DESC "); return selectSplit(sql.toString(), paramts, new BaseCategory()); } /** * @Description 编辑 * @Author 卢庆阳 * @Date 2023/10/23 */ public int updateBaseCategory(BaseCategory baseCategory) { return this.update(baseCategory); } /** * 修改状态 * @author 卢庆阳 * @date 2023/9/27 */ public int updateStatus(BaseCategory baseCategory) { return this.update(baseCategory); } /** * @Description 根据节点id删除节点(逻辑删除) * @Author 卢庆阳 * @Date 2023/10/23 */ public int updateById(BaseCategory baseCategory) { baseCategory.setStates(Constants.CATEGORY_DELETED); //删除时间 baseCategory.setDTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); //TODO 删除人id和删除人姓名 return this.update(baseCategory); } /** * 根据节点id查询节点详情 * @author 卢庆阳 * @date 2023/9/26 */ public BaseCategory getById(Long id) { return this.get(new BaseCategory(id)); } } consum-base/src/main/java/com/consum/base/service/BaseGoodsTemplateServiceImpl.java
New file @@ -0,0 +1,37 @@ package com.consum.base.service; import com.consum.model.po.BaseCategory; import com.walker.jdbc.service.BaseServiceImpl; import org.springframework.stereotype.Service; import java.util.HashMap; import java.util.List; /** * @Description 物品模板 * @Author 卢庆阳 * @Date 2023/10/23 */ @Service public class BaseGoodsTemplateServiceImpl extends BaseServiceImpl { /** * @Description 根据分类id和状态查询物品模版 * @Author 卢庆阳 * @Date 2023/10/23 * @return */ public List<BaseCategory> getByCategoryId(Long categoryId) { StringBuilder sql = new StringBuilder("SELECT * FROM base_goods_template WHERE 1 = 1 "); HashMap<String, Object> paramts = new HashMap<>(); //分类id if (categoryId != null) { sql.append(" and category_id =:category_id "); paramts.put("category_id", categoryId); } sql.append(" and states =1 "); return this.select(sql.toString(), paramts, new BaseCategory()); } } consum-model-pojo/src/main/java/com/consum/model/po/BaseCategory.java
@@ -44,6 +44,30 @@ @JsonIgnore protected boolean isset_fatherCategoryId = false; private Long createUserId = null; @JsonIgnore protected boolean isset_createUserId = false; private Long createTime = null; @JsonIgnore protected boolean isset_createTime = false; private String createUserName = null; @JsonIgnore protected boolean isset_createUserName = false; private Long dTime = null; @JsonIgnore protected boolean isset_dTime = false; private Long dUserId = null; @JsonIgnore protected boolean isset_dUserId = false; private String dUserName = null; @JsonIgnore protected boolean isset_dUserName = false; /** * 默认构造函数 */ @@ -163,6 +187,90 @@ return this.fatherCategoryId == null; } public Long getCreateUserId() { return this.createUserId; } public void setCreateUserId(Long createUserId) { this.createUserId = createUserId; this.isset_createUserId = true; } @JsonIgnore public boolean isEmptyCreateUserId() { return this.createUserId == null; } public Long getCreateTime() { return this.createTime; } public void setCreateTime(Long createTime) { this.createTime = createTime; this.isset_createTime = true; } @JsonIgnore public boolean isEmptyCreateTime() { return this.createTime == null; } public String getCreateUserName() { return this.createUserName; } public void setCreateUserName(String createUserName) { this.createUserName = createUserName; this.isset_createUserName = true; } @JsonIgnore public boolean isEmptyCreateUserName() { return this.createUserName == null || this.createUserName.length() == 0; } public Long getDTime() { return this.dTime; } public void setDTime(Long dTime) { this.dTime = dTime; this.isset_dTime = true; } @JsonIgnore public boolean isEmptyDTime() { return this.dTime == null; } public Long getDUserId() { return this.dUserId; } public void setDUserId(Long dUserId) { this.dUserId = dUserId; this.isset_dUserId = true; } @JsonIgnore public boolean isEmptyDUserId() { return this.dUserId == null; } public String getDUserName() { return this.dUserName; } public void setDUserName(String dUserName) { this.dUserName = dUserName; this.isset_dUserName = true; } @JsonIgnore public boolean isEmptyDUserName() { return this.dUserName == null || this.dUserName.length() == 0; } /** * 重写 toString() 方法 */ @@ -176,6 +284,12 @@ .append("states=").append(this.states) .append("levels=").append(this.levels) .append("fatherCategoryId=").append(this.fatherCategoryId) .append("createUserId=").append(this.createUserId) .append("createTime=").append(this.createTime) .append("createUserName=").append(this.createUserName) .append("dTime=").append(this.dTime) .append("dUserId=").append(this.dUserId) .append("dUserName=").append(this.dUserName) .toString(); } @@ -211,6 +325,24 @@ if (this.isset_fatherCategoryId) { base_category.setFatherCategoryId(this.getFatherCategoryId()); } if (this.isset_createUserId) { base_category.setCreateUserId(this.getCreateUserId()); } if (this.isset_createTime) { base_category.setCreateTime(this.getCreateTime()); } if (this.isset_createUserName) { base_category.setCreateUserName(this.getCreateUserName()); } if (this.isset_dTime) { base_category.setDTime(this.getDTime()); } if (this.isset_dUserId) { base_category.setDUserId(this.getDUserId()); } if (this.isset_dUserName) { base_category.setDUserName(this.getDUserName()); } return base_category; } } consum-model-pojo/src/main/java/com/consum/model/po/BaseCategory_mapper.java
@@ -34,6 +34,12 @@ public static final String States = "states"; public static final String Levels = "levels"; public static final String FatherCategoryId = "father_category_id"; public static final String CreateUserId = "create_user_id"; public static final String CreateTime = "create_time"; public static final String CreateUserName = "create_user_name"; public static final String DTime = "d_time"; public static final String DUserId = "d_user_id"; public static final String DUserName = "d_user_name"; /** * 默认构造函数 @@ -64,6 +70,24 @@ } if (baseCategory.isset_fatherCategoryId) { this.setFatherCategoryId(baseCategory.getFatherCategoryId()); } if (baseCategory.isset_createUserId) { this.setCreateUserId(baseCategory.getCreateUserId()); } if (baseCategory.isset_createTime) { this.setCreateTime(baseCategory.getCreateTime()); } if (baseCategory.isset_createUserName) { this.setCreateUserName(baseCategory.getCreateUserName()); } if (baseCategory.isset_dTime) { this.setDTime(baseCategory.getDTime()); } if (baseCategory.isset_dUserId) { this.setDUserId(baseCategory.getDUserId()); } if (baseCategory.isset_dUserName) { this.setDUserName(baseCategory.getDUserName()); } // 去掉,2022-09-07 // this.setDatabaseName_(base_category.getDatabaseName_()); @@ -114,6 +138,12 @@ ib.set(States, this.getStates(), this.isset_states); ib.set(Levels, this.getLevels(), this.isset_levels); ib.set(FatherCategoryId, this.getFatherCategoryId(), this.isset_fatherCategoryId); ib.set(CreateUserId, this.getCreateUserId(), this.isset_createUserId); ib.set(CreateTime, this.getCreateTime(), this.isset_createTime); ib.set(CreateUserName, this.getCreateUserName(), this.isset_createUserName); ib.set(DTime, this.getDTime(), this.isset_dTime); ib.set(DUserId, this.getDUserId(), this.isset_dUserId); ib.set(DUserName, this.getDUserName(), this.isset_dUserName); return ib.genMapSql(); } @@ -129,6 +159,12 @@ ub.set(States, this.getStates(), this.isset_states); ub.set(Levels, this.getLevels(), this.isset_levels); ub.set(FatherCategoryId, this.getFatherCategoryId(), this.isset_fatherCategoryId); ub.set(CreateUserId, this.getCreateUserId(), this.isset_createUserId); ub.set(CreateTime, this.getCreateTime(), this.isset_createTime); ub.set(CreateUserName, this.getCreateUserName(), this.isset_createUserName); ub.set(DTime, this.getDTime(), this.isset_dTime); ub.set(DUserId, this.getDUserId(), this.isset_dUserId); ub.set(DUserName, this.getDUserName(), this.isset_dUserName); ub.where(this.getPkName_(), this.getPkValue_()); return ub.genMapSql(); } @@ -145,6 +181,12 @@ ub.set(States, this.getStates(), this.isset_states); ub.set(Levels, this.getLevels(), this.isset_levels); ub.set(FatherCategoryId, this.getFatherCategoryId(), this.isset_fatherCategoryId); ub.set(CreateUserId, this.getCreateUserId(), this.isset_createUserId); ub.set(CreateTime, this.getCreateTime(), this.isset_createTime); ub.set(CreateUserName, this.getCreateUserName(), this.isset_createUserName); ub.set(DTime, this.getDTime(), this.isset_dTime); ub.set(DUserId, this.getDUserId(), this.isset_dUserId); ub.set(DUserName, this.getDUserName(), this.isset_dUserName); return ub.genMapSql(where, parameters); } @@ -160,6 +202,12 @@ ub.set(States, this.getStates(), this.isset_states); ub.set(Levels, this.getLevels(), this.isset_levels); ub.set(FatherCategoryId, this.getFatherCategoryId(), this.isset_fatherCategoryId); ub.set(CreateUserId, this.getCreateUserId(), this.isset_createUserId); ub.set(CreateTime, this.getCreateTime(), this.isset_createTime); ub.set(CreateUserName, this.getCreateUserName(), this.isset_createUserName); ub.set(DTime, this.getDTime(), this.isset_dTime); ub.set(DUserId, this.getDUserId(), this.isset_dUserId); ub.set(DUserName, this.getDUserName(), this.isset_dUserName); return ub.genArraySql(where, parameters); } @@ -207,7 +255,7 @@ */ @Override public SqlAndParameters<Map<String, Object>> getSelectSql_(String where, Map<String, Object> parameters) { return new SqlAndParameters<>("select id, category_name, classification, order_number, states, levels, father_category_id from " + this.getTableName_() + " " + where, parameters); return new SqlAndParameters<>("select id, category_name, classification, order_number, states, levels, father_category_id, create_user_id, create_time, create_user_name, d_time, d_user_id, d_user_name from " + this.getTableName_() + " " + where, parameters); } /** @@ -215,7 +263,7 @@ */ @Override public SqlAndParameters<Object[]> getSelectSql_(String where, Object[] parameters) { return new SqlAndParameters<>("select id, category_name, classification, order_number, states, levels, father_category_id from " + this.getTableName_() + " " + where, parameters); return new SqlAndParameters<>("select id, category_name, classification, order_number, states, levels, father_category_id, create_user_id, create_time, create_user_name, d_time, d_user_id, d_user_name from " + this.getTableName_() + " " + where, parameters); } /** @@ -292,6 +340,46 @@ base_category.setFatherCategoryId(rs.getLong(columnIndex)); } } columnIndex = resultSetUtils.findColumn(rs, BaseCategory_mapper.CreateUserId); if (columnIndex > 0) { if (rs.getBigDecimal(columnIndex) == null) { base_category.setCreateUserId(null); } else { base_category.setCreateUserId(rs.getLong(columnIndex)); } } columnIndex = resultSetUtils.findColumn(rs, BaseCategory_mapper.CreateTime); if (columnIndex > 0) { if (rs.getBigDecimal(columnIndex) == null) { base_category.setCreateTime(null); } else { base_category.setCreateTime(rs.getLong(columnIndex)); } } columnIndex = resultSetUtils.findColumn(rs, BaseCategory_mapper.CreateUserName); if (columnIndex > 0) { base_category.setCreateUserName(rs.getString(columnIndex)); } columnIndex = resultSetUtils.findColumn(rs, BaseCategory_mapper.DTime); if (columnIndex > 0) { if (rs.getBigDecimal(columnIndex) == null) { base_category.setDTime(null); } else { base_category.setDTime(rs.getLong(columnIndex)); } } columnIndex = resultSetUtils.findColumn(rs, BaseCategory_mapper.DUserId); if (columnIndex > 0) { if (rs.getBigDecimal(columnIndex) == null) { base_category.setDUserId(null); } else { base_category.setDUserId(rs.getLong(columnIndex)); } } columnIndex = resultSetUtils.findColumn(rs, BaseCategory_mapper.DUserName); if (columnIndex > 0) { base_category.setDUserName(rs.getString(columnIndex)); } return base_category; } }