From 32b4f6188f32e6c08e813efa98a25d94eacdc0c6 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期二, 02 四月 2024 09:32:29 +0800 Subject: [PATCH] Revert "新考核" --- ycl-server/src/main/java/com/ycl/platform/service/impl/CheckRuleServiceImpl.java | 178 ++++++++++++++++++++++++++++++++++++++++------------------- 1 files changed, 121 insertions(+), 57 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 index 518e882..8374785 100644 --- 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 @@ -1,97 +1,161 @@ 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.ICheckRuleService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import utils.DateUtils; - +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; + /** - * 鑰冩牳瑙勫垯Service涓氬姟灞傚鐞� - * - * @author ruoyi - * @date 2024-04-01 + * 鑰冩牳瑙勫垯 鏈嶅姟瀹炵幇绫� + * + * @author xp + * @since 2024-03-06 */ @Service -public class CheckRuleServiceImpl implements ICheckRuleService -{ - @Autowired - private CheckRuleMapper checkRuleMapper; +@RequiredArgsConstructor +public class CheckRuleServiceImpl extends ServiceImpl<CheckRuleMapper, CheckRule> implements CheckRuleService { + + private final CheckRuleMapper checkRuleMapper; /** - * 鏌ヨ鑰冩牳瑙勫垯 - * - * @param id 鑰冩牳瑙勫垯涓婚敭 - * @return 鑰冩牳瑙勫垯 + * 娣诲姞 + * @param form + * @return */ @Override - public CheckRule selectCheckRuleById(Long id) - { - return checkRuleMapper.selectCheckRuleById(id); + public Result add(CheckRuleForm form) { + CheckRule entity = CheckRuleForm.getEntityByForm(form, null); + if(baseMapper.insert(entity) > 0) { + return Result.ok("娣诲姞鎴愬姛"); + } + return Result.error("娣诲姞澶辫触"); } /** - * 鏌ヨ鑰冩牳瑙勫垯鍒楄〃 - * - * @param checkRule 鑰冩牳瑙勫垯 - * @return 鑰冩牳瑙勫垯 + * 淇敼 + * @param form + * @return */ @Override - public List<CheckRule> selectCheckRuleList(CheckRule checkRule) - { - return checkRuleMapper.selectCheckRuleList(checkRule); + 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 checkRule 鑰冩牳瑙勫垯 - * @return 缁撴灉 + * 鎵归噺鍒犻櫎 + * @param ids + * @return */ @Override - public int insertCheckRule(CheckRule checkRule) - { - checkRule.setCreateTime(DateUtils.getNowDate()); - return checkRuleMapper.insertCheckRule(checkRule); + public Result remove(List<String> ids) { + if(baseMapper.deleteBatchIds(ids) > 0) { + return Result.ok("鍒犻櫎鎴愬姛"); + } + return Result.error("鍒犻櫎澶辫触"); } /** - * 淇敼鑰冩牳瑙勫垯 - * - * @param checkRule 鑰冩牳瑙勫垯 - * @return 缁撴灉 + * id鍒犻櫎 + * @param id + * @return */ @Override - public int updateCheckRule(CheckRule checkRule) - { - checkRule.setUpdateTime(DateUtils.getNowDate()); - return checkRuleMapper.updateCheckRule(checkRule); + 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 deleteCheckRuleByIds(Long[] ids) - { - return checkRuleMapper.deleteCheckRuleByIds(ids); + 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())) + .eq(Objects.nonNull(query.getAuditState()),CheckRule::getAuditState, query.getAuditState()) + .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()); } /** - * 鍒犻櫎鑰冩牳瑙勫垯淇℃伅 - * - * @param id 鑰冩牳瑙勫垯涓婚敭 - * @return 缁撴灉 + * 鏍规嵁id鏌ユ壘 + * @param id + * @return */ @Override - public int deleteCheckRuleById(Long id) - { - return checkRuleMapper.deleteCheckRuleById(id); + 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