|
|
@ -20,9 +20,13 @@ package com.elink.esua.epdc.service.impl; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.elink.esua.epdc.commons.tools.exception.ErrorCode; |
|
|
|
import com.elink.esua.epdc.commons.tools.page.PageData; |
|
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisKeys; |
|
|
|
import com.elink.esua.epdc.commons.tools.redis.RedisUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.ConvertUtils; |
|
|
|
import com.elink.esua.epdc.commons.tools.constant.FieldConstant; |
|
|
|
import com.elink.esua.epdc.commons.tools.utils.Result; |
|
|
|
import com.elink.esua.epdc.dao.PointsRuleDao; |
|
|
|
import com.elink.esua.epdc.dto.PointsRuleDTO; |
|
|
|
import com.elink.esua.epdc.entity.PointsRuleEntity; |
|
|
@ -49,13 +53,14 @@ public class PointsRuleServiceImpl extends BaseServiceImpl<PointsRuleDao, Points |
|
|
|
@Autowired |
|
|
|
private PointsRuleRedis pointsRuleRedis; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<PointsRuleDTO> page(Map<String, Object> params) { |
|
|
|
IPage<PointsRuleEntity> page = baseDao.selectPage( |
|
|
|
getPage(params, FieldConstant.CREATED_TIME, false), |
|
|
|
getWrapper(params) |
|
|
|
); |
|
|
|
return getPageData(page, PointsRuleDTO.class); |
|
|
|
IPage<PointsRuleDTO> page = getPage(params); |
|
|
|
List<PointsRuleDTO> list = baseDao.selectListPointsRule(params); |
|
|
|
return new PageData<>(list, page.getTotal()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -82,23 +87,62 @@ public class PointsRuleServiceImpl extends BaseServiceImpl<PointsRuleDao, Points |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void save(PointsRuleDTO dto) { |
|
|
|
public Result save(PointsRuleDTO dto) { |
|
|
|
Result checkRuleCode = this.checkRuleCodeIsExist(dto.getRuleCode()); |
|
|
|
if (checkRuleCode.getCode() == ErrorCode.INTERNAL_SERVER_ERROR) { |
|
|
|
return checkRuleCode; |
|
|
|
} |
|
|
|
PointsRuleEntity entity = ConvertUtils.sourceToTarget(dto, PointsRuleEntity.class); |
|
|
|
insert(entity); |
|
|
|
// 存入redis
|
|
|
|
redisUtils.set(RedisKeys.getAllPointsRuleCodeKey(entity.getRuleCode()) , entity, RedisUtils.NOT_EXPIRE); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @Description: 查询积分规则编码是否存在 |
|
|
|
* @Param: [behaviorCode] |
|
|
|
* @return: com.elink.esua.epdc.commons.tools.utils.Result |
|
|
|
* @Author: zy |
|
|
|
* @Date: 2020-04-28 |
|
|
|
*/ |
|
|
|
private Result checkRuleCodeIsExist(String ruleCode) { |
|
|
|
Object bhc = redisUtils.get(RedisKeys.getAllPointsRuleCodeKey(ruleCode)); |
|
|
|
if (bhc != null) { |
|
|
|
return new Result().error("积分规则编码已存在,请重新设置"); |
|
|
|
} |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(PointsRuleDTO dto) { |
|
|
|
public Result update(PointsRuleDTO dto) { |
|
|
|
// 查询之前的动作编码
|
|
|
|
PointsRuleEntity queryEntity = baseDao.selectById(dto.getId()); |
|
|
|
// 判断本次修改操作是否修改了积分规则编码, 如果改动了,查询新的积分规则编码是否已存在
|
|
|
|
if (!(queryEntity.getRuleCode().equals(dto.getRuleCode()))) { |
|
|
|
Result checkRuleCode = this.checkRuleCodeIsExist(dto.getRuleCode()); |
|
|
|
if (checkRuleCode.getCode() == ErrorCode.INTERNAL_SERVER_ERROR) { |
|
|
|
return checkRuleCode; |
|
|
|
} |
|
|
|
} |
|
|
|
PointsRuleEntity entity = ConvertUtils.sourceToTarget(dto, PointsRuleEntity.class); |
|
|
|
updateById(entity); |
|
|
|
// 删除redis中的存储信息
|
|
|
|
redisUtils.delete(RedisKeys.getAllPointsRuleCodeKey(queryEntity.getRuleCode())); |
|
|
|
// 新增redis信息
|
|
|
|
redisUtils.set(RedisKeys.getAllPointsRuleCodeKey(entity.getRuleCode()) , entity, RedisUtils.NOT_EXPIRE); |
|
|
|
return new Result(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void delete(String[] ids) { |
|
|
|
PointsRuleEntity entity = baseDao.selectById(ids[0]); |
|
|
|
// 逻辑删除(@TableLogic 注解)
|
|
|
|
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|
|
|
// 删除redis中的存储信息
|
|
|
|
redisUtils.delete(RedisKeys.getAllPointsRuleCodeKey(entity.getRuleCode())); |
|
|
|
} |
|
|
|
|
|
|
|
} |