|  |  | @ -18,18 +18,25 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
			
		
	
		
			
				
					|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.FieldConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.dto.result.OptionResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.EpmetErrorCode; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.page.PageData; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.ConvertUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.Result; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.IcResiDemandDictDao; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.IcResiDemandDictDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.demand.UserDemandNameQueryFormDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.demand.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.demand.DemandPageResDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.demand.OptionDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.IcResiDemandDictEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.IcResiDemandDictService; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageHelper; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageInfo; | 
			
		
	
		
			
				
					|  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
	
		
			
				
					|  |  | @ -44,18 +51,90 @@ import java.util.Map; | 
			
		
	
		
			
				
					|  |  |  |  * @author generator generator@elink-cn.com | 
			
		
	
		
			
				
					|  |  |  |  * @since v1.0.0 2021-10-27 | 
			
		
	
		
			
				
					|  |  |  |  */ | 
			
		
	
		
			
				
					|  |  |  | @Slf4j | 
			
		
	
		
			
				
					|  |  |  | @Service | 
			
		
	
		
			
				
					|  |  |  | public class IcResiDemandDictServiceImpl extends BaseServiceImpl<IcResiDemandDictDao, IcResiDemandDictEntity> implements IcResiDemandDictService { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 分页查询 | 
			
		
	
		
			
				
					|  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |      * @param formDTO | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public PageData<IcResiDemandDictDTO> page(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |         IPage<IcResiDemandDictEntity> page = baseDao.selectPage( | 
			
		
	
		
			
				
					|  |  |  |                 getPage(params, FieldConstant.CREATED_TIME, false), | 
			
		
	
		
			
				
					|  |  |  |                 getWrapper(params) | 
			
		
	
		
			
				
					|  |  |  |         ); | 
			
		
	
		
			
				
					|  |  |  |         return getPageData(page, IcResiDemandDictDTO.class); | 
			
		
	
		
			
				
					|  |  |  |     public PageData<DemandPageResDTO> page(DemandDictPageFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         PageInfo<DemandPageResDTO> pageInfo= PageHelper.startPage(formDTO.getPageNo(), | 
			
		
	
		
			
				
					|  |  |  |                 formDTO.getPageSize()).doSelectPageInfo(() -> baseDao.pageSelect(formDTO.getCustomerId(),formDTO.getFirstCategoryCode())); | 
			
		
	
		
			
				
					|  |  |  |         return new PageData<>(pageInfo.getList(), pageInfo.getTotal()); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 新增一级分类 | 
			
		
	
		
			
				
					|  |  |  |      * @param formDTO | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void addFirstCategory(AddFirstCategoryFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         if (checkCategoryName(formDTO.getCustomerId(), formDTO.getCategoryName(), NumConstant.ONE, NumConstant.ZERO_STR,null) > NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |             // 名称唯一
 | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(EpmetErrorCode.DEMAND_NAME_EXITED.getCode(), EpmetErrorCode.DEMAND_NAME_EXITED.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         IcResiDemandDictEntity entity = new IcResiDemandDictEntity(); | 
			
		
	
		
			
				
					|  |  |  |         entity.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setCategoryName(formDTO.getCategoryName()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setLevel(NumConstant.ONE); | 
			
		
	
		
			
				
					|  |  |  |         entity.setParentCode(NumConstant.ZERO_STR); | 
			
		
	
		
			
				
					|  |  |  |         entity.setAwardPoint(NumConstant.ZERO); | 
			
		
	
		
			
				
					|  |  |  |         entity.setUsableFlag(true); | 
			
		
	
		
			
				
					|  |  |  |         // 获取当前最大的排序号
 | 
			
		
	
		
			
				
					|  |  |  |         Integer maxSort = baseDao.selectMaxSort(formDTO.getCustomerId(), NumConstant.ONE,NumConstant.ZERO_STR); | 
			
		
	
		
			
				
					|  |  |  |         entity.setSort(null == maxSort ? NumConstant.ZERO : maxSort + 1); | 
			
		
	
		
			
				
					|  |  |  |         // 一级分类,直接获取最大的,然后+1
 | 
			
		
	
		
			
				
					|  |  |  |         Integer maxFirstCategoryCode = baseDao.selectMaxCategoryCode(formDTO.getCustomerId(),NumConstant.ONE,NumConstant.ZERO_STR); | 
			
		
	
		
			
				
					|  |  |  |         entity.setCategoryCode(null == maxFirstCategoryCode ? "1001" : String.valueOf(maxFirstCategoryCode + 1)); | 
			
		
	
		
			
				
					|  |  |  |         baseDao.insert(entity); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void addChild(AddCategoryFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         if (checkCategoryName(formDTO.getCustomerId(), formDTO.getCategoryName(), NumConstant.TWO, formDTO.getParentCategoryCode(),null) > NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |             // 名称唯一
 | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(EpmetErrorCode.DEMAND_NAME_EXITED.getCode(), EpmetErrorCode.DEMAND_NAME_EXITED.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         IcResiDemandDictEntity entity = new IcResiDemandDictEntity(); | 
			
		
	
		
			
				
					|  |  |  |         entity.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setCategoryName(formDTO.getCategoryName()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setLevel(NumConstant.TWO); | 
			
		
	
		
			
				
					|  |  |  |         entity.setParentCode(formDTO.getParentCategoryCode()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setAwardPoint(formDTO.getAwardPoint()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setUsableFlag(true); | 
			
		
	
		
			
				
					|  |  |  |         // 获取当前最大的排序号
 | 
			
		
	
		
			
				
					|  |  |  |         Integer maxSort = baseDao.selectMaxSort(formDTO.getCustomerId(), NumConstant.TWO,formDTO.getParentCategoryCode()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setSort(null == maxSort ? NumConstant.ZERO : maxSort + 1); | 
			
		
	
		
			
				
					|  |  |  |         // 二级分类,直接获取最大的,然后+1
 | 
			
		
	
		
			
				
					|  |  |  |         Integer maxCategoryCode = baseDao.selectMaxCategoryCode(formDTO.getCustomerId(),NumConstant.TWO,formDTO.getParentCategoryCode()); | 
			
		
	
		
			
				
					|  |  |  |         entity.setCategoryCode(null == maxCategoryCode ? formDTO.getParentCategoryCode().concat("0001") : String.valueOf(maxCategoryCode + 1)); | 
			
		
	
		
			
				
					|  |  |  |         baseDao.insert(entity); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 校验名字是否存在 | 
			
		
	
		
			
				
					|  |  |  |      * @param customerId | 
			
		
	
		
			
				
					|  |  |  |      * @param categoryName | 
			
		
	
		
			
				
					|  |  |  |      * @param level | 
			
		
	
		
			
				
					|  |  |  |      * @param id | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public int checkCategoryName(String customerId,String categoryName,int level,String parentCategoryCode,String id){ | 
			
		
	
		
			
				
					|  |  |  |         return  baseDao.selectCountName(customerId,categoryName,level,parentCategoryCode,id); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public List<IcResiDemandDictDTO> list(Map<String, Object> params) { | 
			
		
	
		
			
				
					|  |  |  |         List<IcResiDemandDictEntity> entityList = baseDao.selectList(getWrapper(params)); | 
			
		
	
	
		
			
				
					|  |  | @ -72,24 +151,26 @@ public class IcResiDemandDictServiceImpl extends BaseServiceImpl<IcResiDemandDic | 
			
		
	
		
			
				
					|  |  |  |         return wrapper; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public IcResiDemandDictDTO get(String id) { | 
			
		
	
		
			
				
					|  |  |  |         IcResiDemandDictEntity entity = baseDao.selectById(id); | 
			
		
	
		
			
				
					|  |  |  |         return ConvertUtils.sourceToTarget(entity, IcResiDemandDictDTO.class); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void save(IcResiDemandDictDTO dto) { | 
			
		
	
		
			
				
					|  |  |  |         IcResiDemandDictEntity entity = ConvertUtils.sourceToTarget(dto, IcResiDemandDictEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         insert(entity); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * 修改分类 | 
			
		
	
		
			
				
					|  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |      * | 
			
		
	
		
			
				
					|  |  |  |      * @param formDTO | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public void update(IcResiDemandDictDTO dto) { | 
			
		
	
		
			
				
					|  |  |  |         IcResiDemandDictEntity entity = ConvertUtils.sourceToTarget(dto, IcResiDemandDictEntity.class); | 
			
		
	
		
			
				
					|  |  |  |         updateById(entity); | 
			
		
	
		
			
				
					|  |  |  |     public void update(UpdateFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         IcResiDemandDictEntity origin = baseDao.selectById(formDTO.getCategoryId()); | 
			
		
	
		
			
				
					|  |  |  |         if (checkCategoryName(formDTO.getCustomerId(), formDTO.getCategoryName(), NumConstant.TWO, origin.getParentCode(), formDTO.getCategoryId()) > NumConstant.ZERO) { | 
			
		
	
		
			
				
					|  |  |  |             // 名称唯一
 | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException(EpmetErrorCode.DEMAND_NAME_EXITED.getCode(), EpmetErrorCode.DEMAND_NAME_EXITED.getMsg()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         origin.setCategoryName(formDTO.getCategoryName()); | 
			
		
	
		
			
				
					|  |  |  |         if (NumConstant.TWO == origin.getLevel()) { | 
			
		
	
		
			
				
					|  |  |  |             origin.setAwardPoint(formDTO.getAwardPoint()); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         updateById(origin); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
	
		
			
				
					|  |  | @ -117,4 +198,31 @@ public class IcResiDemandDictServiceImpl extends BaseServiceImpl<IcResiDemandDic | 
			
		
	
		
			
				
					|  |  |  |         return new Result<String>().ok(baseDao.selectCategoryNames(formDTO.getCustomerId(),formDTO.getCodeSet())); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public List<OptionDTO> querySubCodeList(SubCodeFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         return baseDao.selectByPCode(formDTO.getParentCategoryCode(),formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void updateStatus(StatusFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  |         IcResiDemandDictEntity origin = baseDao.selectById(formDTO.getCategoryId()); | 
			
		
	
		
			
				
					|  |  |  |         if (null == origin) { | 
			
		
	
		
			
				
					|  |  |  |             log.error("category_id=" + formDTO.getCategoryId() + " 没有找到记录"); | 
			
		
	
		
			
				
					|  |  |  |             return; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         origin.setUsableFlag(formDTO.getUsableFlag()); | 
			
		
	
		
			
				
					|  |  |  |         updateById(origin); | 
			
		
	
		
			
				
					|  |  |  |         // 如果修改的是一级分类, 同步到二级
 | 
			
		
	
		
			
				
					|  |  |  |         if (NumConstant.ONE == origin.getLevel()) { | 
			
		
	
		
			
				
					|  |  |  |             QueryWrapper<IcResiDemandDictEntity> wrapper = new QueryWrapper<>(); | 
			
		
	
		
			
				
					|  |  |  |             wrapper.eq(StringUtils.isNotBlank(origin.getCategoryCode()), "PARENT_CODE", origin.getCategoryCode()); | 
			
		
	
		
			
				
					|  |  |  |             List<IcResiDemandDictEntity> entityList = baseDao.selectList(wrapper); | 
			
		
	
		
			
				
					|  |  |  |             for (IcResiDemandDictEntity sub : entityList) { | 
			
		
	
		
			
				
					|  |  |  |                 sub.setUsableFlag(formDTO.getUsableFlag()); | 
			
		
	
		
			
				
					|  |  |  |                 updateById(sub); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } |