From 800be390ac246656b4f8d5803cfbb7602c476c4b Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期四, 07 三月 2024 10:44:50 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- ycl-server/src/main/java/com/ycl/platform/service/impl/CheckRuleServiceImpl.java | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 160 insertions(+), 0 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckRuleServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckRuleServiceImpl.java new file mode 100644 index 0000000..c357e57 --- /dev/null +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/CheckRuleServiceImpl.java @@ -0,0 +1,160 @@ +package com.ycl.platform.service.impl; + +import com.ycl.platform.base.BaseSelect; +import com.ycl.platform.domain.entity.CheckRule; +import com.ycl.platform.domain.entity.YwUnit; +import com.ycl.platform.mapper.CheckRuleMapper; +import com.ycl.platform.service.CheckRuleService; +import com.ycl.system.Result; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ycl.platform.domain.form.CheckRuleForm; +import com.ycl.platform.domain.vo.CheckRuleVO; +import com.ycl.platform.domain.query.CheckRuleQuery; +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.StringUtils; + +/** + * 鑰冩牳瑙勫垯 鏈嶅姟瀹炵幇绫� + * + * @author xp + * @since 2024-03-06 + */ +@Service +@RequiredArgsConstructor +public class CheckRuleServiceImpl extends ServiceImpl<CheckRuleMapper, CheckRule> implements CheckRuleService { + + private final CheckRuleMapper checkRuleMapper; + + /** + * 娣诲姞 + * @param form + * @return + */ + @Override + public Result add(CheckRuleForm form) { + CheckRule entity = CheckRuleForm.getEntityByForm(form, null); + if(baseMapper.insert(entity) > 0) { + return Result.ok("娣诲姞鎴愬姛"); + } + return Result.error("娣诲姞澶辫触"); + } + + /** + * 淇敼 + * @param form + * @return + */ + @Override + public Result update(CheckRuleForm form) { + + CheckRule entity = baseMapper.selectById(form.getId()); + + // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + BeanUtils.copyProperties(form, entity); + if (baseMapper.updateById(entity) > 0) { + return Result.ok("淇敼鎴愬姛"); + } + return Result.error("淇敼澶辫触"); + } + + /** + * 鎵归噺鍒犻櫎 + * @param ids + * @return + */ + @Override + public Result remove(List<String> ids) { + if(baseMapper.deleteBatchIds(ids) > 0) { + return Result.ok("鍒犻櫎鎴愬姛"); + } + return Result.error("鍒犻櫎澶辫触"); + } + + /** + * id鍒犻櫎 + * @param id + * @return + */ + @Override + public Result removeById(String id) { + if(baseMapper.deleteById(id) > 0) { + return Result.ok("鍒犻櫎鎴愬姛"); + } + return Result.error("鍒犻櫎澶辫触"); + } + + /** + * 鍒嗛〉鏌ヨ + * @param query + * @return + */ + @Override + public Result page(CheckRuleQuery query) { + + IPage<CheckRule> page = new LambdaQueryChainWrapper<>(baseMapper) + .like(StringUtils.hasText(query.getRuleName()), CheckRule::getRuleName, query.getRuleName()) + .between(Objects.nonNull(query.getStart()) && Objects.nonNull(query.getEnd()), + CheckRule::getCreateTime, + DateUtils.getDayStart(query.getStart()), + DateUtils.getDayEnd(query.getEnd())) + .orderByDesc(CheckRule::getCreateTime) + .page(PageUtil.getPage(query, CheckRule.class)); + + List<CheckRuleVO> vos = page.getRecords().stream() + .map( + entity -> CheckRuleVO.getVoByEntity(entity, null) + ) + .collect(Collectors.toList()); + return Result.ok().data(vos).total(page.getTotal()); + } + + /** + * 鏍规嵁id鏌ユ壘 + * @param id + * @return + */ + @Override + public Result detail(String id) { + + CheckRule entity = baseMapper.selectById(id); + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + CheckRuleVO vo = CheckRuleVO.getVoByEntity(entity, null); + return Result.ok().data(vo); + } + + /** + * 鍒楄〃 + * @return + */ + @Override + public Result all() { + List<CheckRule> entities = baseMapper.selectList(null); + List<BaseSelect> vos = entities.stream() + .map( + entity -> { + BaseSelect vo = new BaseSelect(); + vo.setId(entity.getId()); + vo.setValue(entity.getRuleName()); + return vo; + } + ) + .collect(Collectors.toList()); + return Result.ok().data(vos); + } +} -- Gitblit v1.8.0