| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ycl.exception.ServiceException; |
| | | import com.ycl.platform.domain.entity.CheckResult; |
| | | import com.ycl.platform.domain.form.ManualScoreForm; |
| | | import com.ycl.platform.mapper.CheckResultMapper; |
| | | import com.ycl.platform.service.CheckResultService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.form.CheckResultForm; |
| | | import com.ycl.platform.domain.vo.CheckResultVO; |
| | | import com.ycl.platform.domain.query.CheckResultQuery; |
| | | import com.ycl.platform.service.ICheckResultService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import utils.DateUtils; |
| | | |
| | | import java.util.List; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.ycl.system.page.PageUtil; |
| | | 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-07 |
| | | * 考核结果Service业务层处理 |
| | | * |
| | | * @author ruoyi |
| | | * @date 2024-04-01 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class CheckResultServiceImpl extends ServiceImpl<CheckResultMapper, CheckResult> implements CheckResultService { |
| | | |
| | | private final CheckResultMapper checkResultMapper; |
| | | public class CheckResultServiceImpl implements ICheckResultService |
| | | { |
| | | @Autowired |
| | | private CheckResultMapper checkResultMapper; |
| | | |
| | | /** |
| | | * 添加 |
| | | * @param form |
| | | * @return |
| | | * 查询考核结果 |
| | | * |
| | | * @param id 考核结果主键 |
| | | * @return 考核结果 |
| | | */ |
| | | @Override |
| | | public Result add(CheckResultForm form) { |
| | | CheckResult entity = CheckResultForm.getEntityByForm(form, null); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | public CheckResult selectCheckResultById(Long id) |
| | | { |
| | | return checkResultMapper.selectCheckResultById(id); |
| | | } |
| | | |
| | | /** |
| | | * 修改 |
| | | * @param form |
| | | * @return |
| | | * 查询考核结果列表 |
| | | * |
| | | * @param checkResult 考核结果 |
| | | * @return 考核结果 |
| | | */ |
| | | @Override |
| | | public Result update(CheckResultForm form) { |
| | | |
| | | CheckResult entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | } |
| | | return Result.error("修改失败"); |
| | | public List<CheckResult> selectCheckResultList(CheckResult checkResult) |
| | | { |
| | | return checkResultMapper.selectCheckResultList(checkResult); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * @param ids |
| | | * @return |
| | | * 新增考核结果 |
| | | * |
| | | * @param checkResult 考核结果 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result remove(List<String> ids) { |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | public int insertCheckResult(CheckResult checkResult) |
| | | { |
| | | return checkResultMapper.insertCheckResult(checkResult); |
| | | } |
| | | |
| | | /** |
| | | * id删除 |
| | | * @param id |
| | | * @return |
| | | * 修改考核结果 |
| | | * |
| | | * @param checkResult 考核结果 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | public int updateCheckResult(CheckResult checkResult) |
| | | { |
| | | checkResult.setUpdateTime(DateUtils.getNowDate()); |
| | | return checkResultMapper.updateCheckResult(checkResult); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @param query |
| | | * @return |
| | | * 批量删除考核结果 |
| | | * |
| | | * @param ids 需要删除的考核结果主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result page(CheckResultQuery query) { |
| | | query.setTime(); |
| | | IPage page = PageUtil.getPage(query, CheckResult.class); |
| | | baseMapper.page(page, query); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | public int deleteCheckResultByIds(Long[] ids) |
| | | { |
| | | return checkResultMapper.deleteCheckResultByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * 根据id查找 |
| | | * @param id |
| | | * @return |
| | | * 删除考核结果信息 |
| | | * |
| | | * @param id 考核结果主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result detail(String id) { |
| | | |
| | | CheckResult entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | CheckResultVO vo = CheckResultVO.getVoByEntity(entity, null); |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result all() { |
| | | List<CheckResult> entities = baseMapper.selectList(null); |
| | | List<CheckResultVO> vos = entities.stream() |
| | | .map( |
| | | entity -> CheckResultVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | } |
| | | |
| | | @Override |
| | | public Result manualScore(ManualScoreForm form) { |
| | | CheckResult checkResult = baseMapper.selectById(form.getId()); |
| | | if (Objects.isNull(checkResult)) { |
| | | throw new ServiceException("考核结果不存在"); |
| | | } |
| | | checkResult.setManualScore(form.getManualScore()); |
| | | checkResult.setCheckScore(form.getManualScore().add(checkResult.getSystemScore())); |
| | | baseMapper.updateById(checkResult); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | @Override |
| | | public Result publishById(String id) { |
| | | CheckResult checkResult = new CheckResult(); |
| | | checkResult.setId(Integer.valueOf(id)); |
| | | checkResult.setPublish(1); |
| | | if(baseMapper.updateById(checkResult) > 0) { |
| | | return Result.ok("发布成功"); |
| | | } |
| | | return Result.error("发布失败"); |
| | | public int deleteCheckResultById(Long id) |
| | | { |
| | | return checkResultMapper.deleteCheckResultById(id); |
| | | } |
| | | } |