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.iplatform.model.po.S_user_core; 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) { 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); } } //创建人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 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 queryBaseCategoryList(BaseCategoryParam param) { StringBuilder sql = new StringBuilder("SELECT * FROM base_category WHERE 1 = 1 "); HashMap 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, S_user_core currentUser) { baseCategory.setStates(Constants.STATES_DELETED); //删除时间 baseCategory.setDTime(DateUtils.getDateTimeNumber(System.currentTimeMillis())); //删除人id和删除人姓名 baseCategory.setDUserId(currentUser.getId()); baseCategory.setDUserName(currentUser.getUser_name()); return this.update(baseCategory); } /** * 根据节点id查询节点详情 * @author 卢庆阳 * @Date 2023/10/23 */ public BaseCategory getById(Long id) { return this.get(new BaseCategory(id)); } }