Browse Source

积分规则修改

master
zxc 4 years ago
parent
commit
18e9346e58
  1. 5
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/StrConstant.java
  2. 9
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/dao/PointRuleDao.java
  3. 52
      epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointRuleServiceImpl.java
  4. 15
      epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/PointRuleDao.xml

5
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/StrConstant.java

@ -86,4 +86,9 @@ public interface StrConstant {
String SPECIAL_CUSTOMER = "150282ed25c14ff0785e7e06283b6283";
//平音客户
String PY_CUSTOMER = "6f203e30de1a65aab7e69c058826cd80";
/**
* 单位积分,积分上限积分说明积分事件
*/
String POINT_CHANGE = "修改了%s规则,将%s调整为%s";
}

9
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/dao/PointRuleDao.java

@ -56,4 +56,13 @@ public interface PointRuleDao extends BaseDao<PointRuleEntity> {
List<String> selectCustomerIds();
/**
* @Description 校验重名的规则
* @Param ruleName
* @Param customerId
* @author zxc
* @date 2021/6/18 1:39 下午
*/
Integer checkSameName(@Param("ruleName")String ruleName,@Param("customerId") String customerId,@Param("ruleId")String ruleId);
}

52
epmet-module/epmet-point/epmet-point-server/src/main/java/com/epmet/service/impl/PointRuleServiceImpl.java

@ -27,6 +27,7 @@ import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
import com.epmet.commons.tools.enums.CommonOperateTypeEnum;
import com.epmet.commons.tools.enums.EventEnum;
import com.epmet.commons.tools.exception.EpmetErrorCode;
import com.epmet.commons.tools.exception.ExceptionUtils;
import com.epmet.commons.tools.exception.RenException;
import com.epmet.commons.tools.security.dto.TokenDto;
@ -146,15 +147,31 @@ public class PointRuleServiceImpl extends BaseServiceImpl<PointRuleDao, PointRul
return resultDTO;
}
/**
* @Description 积分规则修改
* @Param tokenDTO
* @Param formDTO
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TokenDto tokenDTO, PointRuleFormDTO formDTO) {
// 积分规则开启状态参数校验
validateEnableFlag(formDTO);
PointRuleEntity entityDB = baseDao.selectById(formDTO.getRuleId());
//数据库不存在或者客户Id不相等 则抛出异常
if (entityDB == null || !entityDB.getCustomerId().equals(formDTO.getCustomerId())) {
throw new RenException(SysResponseEnum.POINT_RULE_IS_NOT_EXIST.getCode(), SysResponseEnum.POINT_RULE_IS_NOT_EXIST.getMsg());
}
// 校验规则是否有重复名字
Integer sameCount = baseDao.checkSameName(formDTO.getRuleName(), formDTO.getCustomerId(), formDTO.getRuleId());
if (sameCount > NumConstant.ZERO){
throw new RenException(EpmetErrorCode.SAME_RULE_NAME.getCode());
}
// 检验积分上限是不是单位积分的整数倍
Integer remainder = formDTO.getUpLimit() % formDTO.getPoint();
if (remainder > NumConstant.ZERO){
throw new RenException(EpmetErrorCode.UP_LIMIT_POINT.getCode());
}
PointRuleEntity entityNew = ConvertUtils.sourceToTarget(formDTO, PointRuleEntity.class);
entityNew.setId(formDTO.getRuleId());
entityNew.setEnabledFlag(StrConstant.TRUE.equals(formDTO.getEnabledFlag()) ? "1" : "0");
@ -164,6 +181,41 @@ public class PointRuleServiceImpl extends BaseServiceImpl<PointRuleDao, PointRul
}
baseDao.updateByCustomerId(entityNew);
insertOperateRecord(tokenDTO, entityNew, entityDB, CommonOperateTypeEnum.EDIT.getCode());
// 系统日志记录
List<String> messages = disposeLog(formDTO, entityDB);
// TODO add
}
/**
* @Description 变更处理
* @Param f
* @Param e
* @author zxc
* @date 2021/6/18 3:14 下午
*/
private List<String> disposeLog(PointRuleFormDTO f,PointRuleEntity e){
List<String> result = new ArrayList<>();
// 单位积分
if (!e.getPoint().equals(f.getPoint())){
String s = String.format(StrConstant.POINT_CHANGE, e.getRuleName(), e.getPoint(), f.getPoint());
result.add(s);
}
// 积分上限
if (!e.getUpLimit().equals(f.getUpLimit())){
String s = String.format(StrConstant.POINT_CHANGE, e.getRuleName(), e.getUpLimit(), f.getUpLimit());
result.add(s);
}
// 积分事件
if (!e.getRuleName().equals(f.getRuleName())){
String s = String.format(StrConstant.POINT_CHANGE, e.getRuleName(), e.getRuleName(), f.getRuleName());
result.add(s);
}
// 积分说明
if (!e.getRuleDesc().equals(f.getRuleDesc())){
String s = String.format(StrConstant.POINT_CHANGE, e.getRuleName(), e.getRuleDesc(), f.getRuleDesc());
result.add(s);
}
return result;
}
private void validateEnableFlag(PointRuleFormDTO formDTO) {

15
epmet-module/epmet-point/epmet-point-server/src/main/resources/mapper/PointRuleDao.xml

@ -39,7 +39,9 @@
SET
POINT = #{point,jdbcType=INTEGER},
ENABLED_FLAG = #{enabledFlag,jdbcType=VARCHAR},
UP_LIMIT = #{upLimit,jdbcType=INTEGER}
UP_LIMIT = #{upLimit,jdbcType=INTEGER},
RULE_NAME = #{ruleName},
RULE_DESC = #{ruleDesc}
WHERE id = #{id,jdbcType=VARCHAR} and CUSTOMER_ID = #{customerId,jdbcType=VARCHAR}
</update>
@ -54,4 +56,15 @@
<select id="selectCustomerIds" resultType="java.lang.String">
SELECT DISTINCT CUSTOMER_ID FROM point_rule WHERE DEL_FLAG = '0'
</select>
<!-- 校验重名的规则 -->
<select id="checkSameName" resultType="java.lang.Integer">
SELECT
COUNT( ID )
FROM point_rule
WHERE DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
AND RULE_NAME = #{ruleName}
AND ID != #{ruleId}
</select>
</mapper>

Loading…
Cancel
Save