| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.ycl.exception.ServiceException; |
| | | import com.ycl.platform.domain.entity.DefaultRule; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | import com.ycl.platform.domain.form.DefaultRuleSetForm; |
| | | import com.ycl.platform.mapper.DefaultRuleMapper; |
| | | import com.ycl.platform.service.IDefaultRuleService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import utils.DateUtils; |
| | | |
| | | import com.ycl.platform.service.DefaultRuleService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.form.DefaultRuleForm; |
| | | import com.ycl.platform.domain.vo.DefaultRuleVO; |
| | | import com.ycl.platform.domain.query.DefaultRuleQuery; |
| | | import java.util.List; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.utils.DateUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.security.core.context.SecurityContextHolder; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import java.util.ArrayList; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | /** |
| | | * 违约规则Service业务层处理 |
| | | * 违约规则 服务实现类 |
| | | * |
| | | * @author ruoyi |
| | | * @date 2024-04-01 |
| | | * @author xp |
| | | * @since 2024-03-05 |
| | | */ |
| | | @Service |
| | | public class DefaultRuleServiceImpl implements IDefaultRuleService |
| | | { |
| | | @Autowired |
| | | private DefaultRuleMapper defaultRuleMapper; |
| | | @RequiredArgsConstructor |
| | | public class DefaultRuleServiceImpl extends ServiceImpl<DefaultRuleMapper, DefaultRule> implements DefaultRuleService { |
| | | |
| | | private final DefaultRuleMapper defaultRuleMapper; |
| | | |
| | | /** |
| | | * 查询违约规则 |
| | | * |
| | | * @param id 违约规则主键 |
| | | * @return 违约规则 |
| | | * 添加 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public DefaultRule selectDefaultRuleById(Long id) |
| | | { |
| | | return defaultRuleMapper.selectDefaultRuleById(id); |
| | | public Result add(DefaultRuleForm form) { |
| | | DefaultRule entity = DefaultRuleForm.getEntityByForm(form, null); |
| | | entity.setRuleStatus("未启用"); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | } |
| | | |
| | | /** |
| | | * 查询违约规则列表 |
| | | * |
| | | * @param defaultRule 违约规则 |
| | | * @return 违约规则 |
| | | * 修改 |
| | | * @param form |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<DefaultRule> selectDefaultRuleList(DefaultRule defaultRule) |
| | | { |
| | | return defaultRuleMapper.selectDefaultRuleList(defaultRule); |
| | | public Result update(DefaultRuleForm form) { |
| | | |
| | | DefaultRule entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | } |
| | | return Result.error("修改失败"); |
| | | } |
| | | |
| | | /** |
| | | * 新增违约规则 |
| | | * |
| | | * @param defaultRule 违约规则 |
| | | * @return 结果 |
| | | * 批量删除 |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int insertDefaultRule(DefaultRule defaultRule) |
| | | { |
| | | defaultRule.setCreateTime(DateUtils.getNowDate()); |
| | | return defaultRuleMapper.insertDefaultRule(defaultRule); |
| | | public Result remove(List<String> ids) { |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | } |
| | | |
| | | /** |
| | | * 修改违约规则 |
| | | * |
| | | * @param defaultRule 违约规则 |
| | | * @return 结果 |
| | | * id删除 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int updateDefaultRule(DefaultRule defaultRule) |
| | | { |
| | | defaultRule.setUpdateTime(DateUtils.getNowDate()); |
| | | return defaultRuleMapper.updateDefaultRule(defaultRule); |
| | | public Result removeById(String id) { |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除违约规则 |
| | | * |
| | | * @param ids 需要删除的违约规则主键 |
| | | * @return 结果 |
| | | * 分页查询 |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int deleteDefaultRuleByIds(Long[] ids) |
| | | { |
| | | return defaultRuleMapper.deleteDefaultRuleByIds(ids); |
| | | public Result page(DefaultRuleQuery query) { |
| | | |
| | | IPage<DefaultRule> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .like(StringUtils.hasText(query.getRuleName()), DefaultRule::getRuleName, query.getRuleName()) |
| | | .between(Objects.nonNull(query.getStart()) && Objects.nonNull(query.getEnd()), |
| | | DefaultRule::getCreateTime, |
| | | DateUtils.getDayStart(query.getStart()), |
| | | DateUtils.getDayEnd(query.getEnd())) |
| | | .orderByDesc(DefaultRule::getCreateTime) |
| | | .page(PageUtil.getPage(query, DefaultRule.class)); |
| | | |
| | | List<DefaultRuleVO> vos = page.getRecords().stream() |
| | | .map( |
| | | entity -> DefaultRuleVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | | * 删除违约规则信息 |
| | | * |
| | | * @param id 违约规则主键 |
| | | * @return 结果 |
| | | * 根据id查找 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public int deleteDefaultRuleById(Long id) |
| | | { |
| | | return defaultRuleMapper.deleteDefaultRuleById(id); |
| | | public Result detail(String id) { |
| | | |
| | | DefaultRule entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | DefaultRuleVO vo = DefaultRuleVO.getVoByEntity(entity, null); |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result all() { |
| | | List<DefaultRule> entities = baseMapper.selectList(null); |
| | | List<DefaultRuleVO> vos = entities.stream() |
| | | .map( |
| | | entity -> DefaultRuleVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | | @Override |
| | | public Result set(DefaultRuleSetForm form) { |
| | | DefaultRule defaultRule = baseMapper.selectById(form.getId()); |
| | | if (Objects.isNull(defaultRule)) { |
| | | throw new ServiceException("违约规则不存在"); |
| | | } |
| | | if (form.getFlag()) { |
| | | // 启用之前检查是否已经有启用的规则了,保持一个开启 |
| | | List<DefaultRule> useList = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .eq(DefaultRule::getRuleStatus, "启用") |
| | | .list(); |
| | | if (! CollectionUtils.isEmpty(useList)) { |
| | | throw new ServiceException("已经有规则被启用了,只能同时启用一个规则"); |
| | | } |
| | | defaultRule.setRuleStatus("启用"); |
| | | } else { |
| | | defaultRule.setRuleStatus("未启用"); |
| | | } |
| | | baseMapper.updateById(defaultRule); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | } |