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 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
|
@RequiredArgsConstructor
|
public class CheckResultServiceImpl extends ServiceImpl<CheckResultMapper, CheckResult> implements CheckResultService {
|
|
private final CheckResultMapper checkResultMapper;
|
|
/**
|
* 添加
|
* @param form
|
* @return
|
*/
|
@Override
|
public Result add(CheckResultForm form) {
|
CheckResult entity = CheckResultForm.getEntityByForm(form, null);
|
if(baseMapper.insert(entity) > 0) {
|
return Result.ok("添加成功");
|
}
|
return Result.error("添加失败");
|
}
|
|
/**
|
* 修改
|
* @param form
|
* @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("修改失败");
|
}
|
|
/**
|
* 批量删除
|
* @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(CheckResultQuery query) {
|
query.setTime();
|
IPage page = PageUtil.getPage(query, CheckResult.class);
|
baseMapper.page(page, query);
|
return Result.ok().data(page.getRecords()).total(page.getTotal());
|
}
|
|
/**
|
* 根据id查找
|
* @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 = baseMapper.selectById(id);
|
if(Objects.equals(1, checkResult.getPublish())) {
|
checkResult.setPublish(0);
|
} else {
|
checkResult.setPublish(1);
|
}
|
if(baseMapper.updateById(checkResult) > 0) {
|
return Result.ok("发布成功");
|
}
|
return Result.error("发布失败");
|
}
|
}
|