|
|
@ -21,6 +21,8 @@ import com.alibaba.fastjson.JSON; |
|
|
|
import com.epmet.common.enu.PointUnitEnum; |
|
|
|
import com.epmet.common.enu.SysResponseEnum; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.Constant; |
|
|
|
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.exception.RenException; |
|
|
@ -44,8 +46,10 @@ import com.epmet.feign.EpmetUserOpenFeignClient; |
|
|
|
import com.epmet.feign.OperCustomizeOpenFeignClient; |
|
|
|
import com.epmet.service.PointRuleService; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
@ -111,7 +115,7 @@ public class PointRuleServiceImpl extends BaseServiceImpl<PointRuleDao, PointRul |
|
|
|
log.error("list ruleId:{} have not pointUnit or pointNum,pointRule:{}", JSON.toJSONString(pointRuleEntity)); |
|
|
|
return null; |
|
|
|
} |
|
|
|
resultDTO.setPointValue(pointRuleEntity.getPoint().toString().concat(StrConstant.SEPARATOR).concat(pointUnitEnum.getCode())); |
|
|
|
resultDTO.setPointValue(pointRuleEntity.getPoint().toString().concat("分").concat(StrConstant.SEPARATOR).concat(pointUnitEnum.getDesc())); |
|
|
|
return resultDTO; |
|
|
|
}).filter(fun -> fun != null).collect(Collectors.toList()); |
|
|
|
return result; |
|
|
@ -123,43 +127,60 @@ public class PointRuleServiceImpl extends BaseServiceImpl<PointRuleDao, PointRul |
|
|
|
if (pointRuleEntity == null) { |
|
|
|
throw new RenException(SysResponseEnum.POINT_RULE_IS_NOT_EXIST.getCode(), SysResponseEnum.POINT_RULE_IS_NOT_EXIST.getMsg()); |
|
|
|
} |
|
|
|
return ConvertUtils.sourceToTarget(pointRuleEntity, PointDetailResultDTO.class); |
|
|
|
PointDetailResultDTO resultDTO = ConvertUtils.sourceToTarget(pointRuleEntity, PointDetailResultDTO.class); |
|
|
|
resultDTO.setRuleId(pointRuleEntity.getId()); |
|
|
|
resultDTO.setEnabledFlag(NumConstant.ONE_STR.equals(pointRuleEntity.getEnabledFlag()) ? "true" : "false"); |
|
|
|
return resultDTO; |
|
|
|
} |
|
|
|
|
|
|
|
@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()); |
|
|
|
} |
|
|
|
PointRuleEntity entityNew = ConvertUtils.sourceToTarget(formDTO, PointRuleEntity.class); |
|
|
|
entityNew.setId(formDTO.getRuleId()); |
|
|
|
entityNew.setEnabledFlag(StrConstant.TRUE.equals(formDTO.getEnabledFlag()) ? "1" : "0"); |
|
|
|
if (entityDB.equals(entityNew)) { |
|
|
|
log.warn("update ignore tow entity is same"); |
|
|
|
return; |
|
|
|
} |
|
|
|
insertOperateRecord(tokenDTO, formDTO, entityDB, CommonOperateTypeEnum.EDIT.getCode()); |
|
|
|
baseDao.updateByCustomerId(entityNew); |
|
|
|
insertOperateRecord(tokenDTO, entityNew, entityDB, CommonOperateTypeEnum.EDIT.getCode()); |
|
|
|
} |
|
|
|
|
|
|
|
private void validateEnableFlag(PointRuleFormDTO formDTO) { |
|
|
|
if (StringUtils.isNotBlank(formDTO.getEnabledFlag()) && !StrConstant.TRUE.equals(formDTO.getEnabledFlag()) && !StrConstant.FALSE.equals(formDTO.getEnabledFlag())) { |
|
|
|
throw new RenException(SysResponseEnum.POINT_ENABLE_FLAG_PARAM_ERROR.getCode(), SysResponseEnum.POINT_ENABLE_FLAG_PARAM_ERROR.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void add(TokenDto tokenDTO, PointRuleFormDTO formDTO) { |
|
|
|
validateEnableFlag(formDTO); |
|
|
|
PointRuleEntity entity = ConvertUtils.sourceToTarget(formDTO, PointRuleEntity.class); |
|
|
|
if (tokenDTO == null){ |
|
|
|
insertOperateRecord(tokenDTO, formDTO, null, CommonOperateTypeEnum.ADD.getCode()); |
|
|
|
} |
|
|
|
baseDao.insert(entity); |
|
|
|
insertOperateRecord(tokenDTO, entity, null, CommonOperateTypeEnum.ADD.getCode()); |
|
|
|
} |
|
|
|
|
|
|
|
private void insertOperateRecord(TokenDto tokenDTO, PointRuleFormDTO formDTO, PointRuleEntity entityDB, String opType) { |
|
|
|
CustomerStaffDTO userInfo = getCustomerStaff(tokenDTO.getUserId()); |
|
|
|
private void insertOperateRecord(TokenDto tokenDTO, PointRuleEntity entityNew, PointRuleEntity entityDB, String opType) { |
|
|
|
RuleOperateLogEntity record = new RuleOperateLogEntity(); |
|
|
|
record.setCustomerId(formDTO.getCustomerId()); |
|
|
|
record.setRuleId(entityDB.getId()); |
|
|
|
record.setOpType(opType); |
|
|
|
if (tokenDTO != null) { |
|
|
|
CustomerStaffDTO userInfo = getCustomerStaff(tokenDTO.getUserId()); |
|
|
|
record.setOpUser(userInfo.getRealName()); |
|
|
|
record.setBefordData(JSON.toJSONString(entityDB)); |
|
|
|
record.setAfterData(JSON.toJSONString(formDTO)); |
|
|
|
} else { |
|
|
|
record.setOpUser(Constant.APP_USER_FLAG); |
|
|
|
} |
|
|
|
record.setCustomerId(entityNew.getCustomerId()); |
|
|
|
record.setRuleId(entityNew.getId()); |
|
|
|
record.setOpType(opType); |
|
|
|
record.setBeforeData(entityDB == null ? null : JSON.toJSONString(entityDB)); |
|
|
|
record.setAfterData(JSON.toJSONString(entityNew)); |
|
|
|
ruleOperateLogDao.insert(record); |
|
|
|
} |
|
|
|
|
|
|
|