Browse Source

添加删除逻辑;修改名称重复问题

master
Jackwang 3 years ago
parent
commit
9d22cd7ac2
  1. 44
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointAdditiveRuleServiceImpl.java
  2. 2
      epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/PointAdditiveRuleDao.xml

44
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointAdditiveRuleServiceImpl.java

@ -12,11 +12,13 @@ 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.PointAdditiveRuleDao;
import com.epmet.dao.PointApplyDao;
import com.epmet.dto.CategorydetailResultDTO;
import com.epmet.dto.PointAdditiveRuleDTO;
import com.epmet.dto.form.*;
import com.epmet.dto.result.List4ApplyResultDTO;
import com.epmet.entity.PointAdditiveRuleEntity;
import com.epmet.entity.PointApplyEntity;
import com.epmet.redis.PointAdditiveRuleRedis;
import com.epmet.service.PointAdditiveRuleService;
import org.apache.commons.collections4.CollectionUtils;
@ -39,6 +41,9 @@ public class PointAdditiveRuleServiceImpl extends BaseServiceImpl<PointAdditiveR
@Autowired
private PointAdditiveRuleRedis pointAdditiveRuleRedis;
@Autowired
private PointApplyDao pointApplyDao;
@Override
public PageData<PointAdditiveRuleDTO> page(Map<String, Object> params) {
IPage<PointAdditiveRuleEntity> page = baseDao.selectPage(
@ -88,6 +93,31 @@ public class PointAdditiveRuleServiceImpl extends BaseServiceImpl<PointAdditiveR
@Transactional(rollbackFor = Exception.class)
public void delete(String[] ids) {
// 逻辑删除(@TableLogic 注解)
for(String id : ids){
PointAdditiveRuleEntity entity = baseDao.selectById(id);
if(null == entity){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "未查到相关信息。","未查到相关信息。");
}
if(PointAddRuleEnum.CATEGORY_TYPE.getCode().equals(entity.getType())){
//分类判断是否有下级
PointAdditiveRuleEntity queryData = new PointAdditiveRuleEntity();
queryData.setPid(entity.getId());
QueryWrapper<PointAdditiveRuleEntity> wrapper = new QueryWrapper<>(queryData);
List<PointAdditiveRuleEntity> applyList = baseDao.selectList(wrapper);
if(CollectionUtils.isNotEmpty(applyList)){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "请先删除下级的积分规则。","请先删除下级的积分规则。");
}
}else{
//判断其规则下面是否有待审核的积分申请,如果有则不允许修改/删除
PointApplyEntity queryData = new PointApplyEntity();
queryData.setRuleId(entity.getId());
QueryWrapper<PointApplyEntity> wrapper = new QueryWrapper<>(queryData);
List<PointApplyEntity> applyList = pointApplyDao.selectList(wrapper);
if(CollectionUtils.isNotEmpty(applyList)){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该规则下有积分申请尚未完成,请处理完成后再执行该操作。","该规则下有积分申请尚未完成,请处理完成后再执行该操作。");
}
}
}
baseDao.deleteBatchIds(Arrays.asList(ids));
}
@ -214,7 +244,7 @@ public class PointAdditiveRuleServiceImpl extends BaseServiceImpl<PointAdditiveR
}
if(PointAddRuleEnum.CATEGORY_TYPE.getCode().equals(dto.getType())){
//类别
PointAdditiveRuleEntity isExist = baseDao.selectEntityByName(null,dto.getCustomerId(),dto.getCategoryName(),null);
PointAdditiveRuleEntity isExist = baseDao.selectEntityByName(dto.getId(),dto.getCustomerId(),dto.getCategoryName(),null);
if(isExist != null){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该名称已存在","该名称已存在");
}
@ -224,10 +254,20 @@ public class PointAdditiveRuleServiceImpl extends BaseServiceImpl<PointAdditiveR
}
}else if(PointAddRuleEnum.RULE_TYPE.getCode().equals(dto.getType())){
//规则
PointAdditiveRuleEntity isExist = baseDao.selectEntityByName(null,dto.getCustomerId(),null,dto.getRuleName());
//判断名称重复
PointAdditiveRuleEntity isExist = baseDao.selectEntityByName(dto.getId(),dto.getCustomerId(),null,dto.getRuleName());
if(isExist != null){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该名称已存在","该名称已存在");
}
//判断其规则下面是否有待审核的积分申请,如果有则不允许修改/删除
PointApplyEntity queryData = new PointApplyEntity();
queryData.setRuleId(entity.getId());
QueryWrapper<PointApplyEntity> wrapper = new QueryWrapper<>(queryData);
List<PointApplyEntity> applyList = pointApplyDao.selectList(wrapper);
if(CollectionUtils.isNotEmpty(applyList)){
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "该规则下有积分申请尚未完成,请处理完成后再执行该操作。","该规则下有积分申请尚未完成,请处理完成后再执行该操作。");
}
entity.setRuleName(dto.getRuleName());
entity.setPointValue(dto.getPointValue());
entity.setApplyFlag(dto.getApplyFlag());

2
epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/PointAdditiveRuleDao.xml

@ -100,7 +100,7 @@
where DEL_FLAG='0'
and CUSTOMER_ID=#{customerId}
<if test="id != null and id != ''">
and id= #{id}
and id != #{id}
</if>
<if test="categoryName != null and categoryName != ''">
and CATEGORY_NAME= #{categoryName}

Loading…
Cancel
Save