| | |
| | | package com.ycl.platform.service.impl; |
| | | |
| | | import com.ycl.platform.domain.entity.CheckTemplate; |
| | | import com.ycl.platform.domain.entity.YwUnit; |
| | | import com.ycl.platform.mapper.CheckTemplateMapper; |
| | | import com.ycl.platform.service.CheckTemplateService; |
| | | import com.ycl.system.Result; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.form.CheckTemplateForm; |
| | | import com.ycl.platform.domain.vo.CheckTemplateVO; |
| | | import com.ycl.platform.domain.query.CheckTemplateQuery; |
| | | import com.ycl.platform.service.ICheckTemplateService; |
| | | 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 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业务层处理 |
| | | * |
| | | * @author ruoyi |
| | | * @date 2024-04-01 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class CheckTemplateServiceImpl extends ServiceImpl<CheckTemplateMapper, CheckTemplate> implements CheckTemplateService { |
| | | |
| | | private final CheckTemplateMapper checkTemplateMapper; |
| | | public class CheckTemplateServiceImpl implements ICheckTemplateService |
| | | { |
| | | @Autowired |
| | | private CheckTemplateMapper checkTemplateMapper; |
| | | |
| | | /** |
| | | * 添加 |
| | | * @param form |
| | | * @return |
| | | * 查询考核模板 |
| | | * |
| | | * @param id 考核模板主键 |
| | | * @return 考核模板 |
| | | */ |
| | | @Override |
| | | public Result add(CheckTemplateForm form) { |
| | | CheckTemplate entity = CheckTemplateForm.getEntityByForm(form, null); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | public CheckTemplate selectCheckTemplateById(Long id) |
| | | { |
| | | return checkTemplateMapper.selectCheckTemplateById(id); |
| | | } |
| | | |
| | | /** |
| | | * 修改 |
| | | * @param form |
| | | * @return |
| | | * 查询考核模板列表 |
| | | * |
| | | * @param checkTemplate 考核模板 |
| | | * @return 考核模板 |
| | | */ |
| | | @Override |
| | | public Result update(CheckTemplateForm form) { |
| | | |
| | | CheckTemplate 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<CheckTemplate> selectCheckTemplateList(CheckTemplate checkTemplate) |
| | | { |
| | | return checkTemplateMapper.selectCheckTemplateList(checkTemplate); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除 |
| | | * @param ids |
| | | * @return |
| | | * 新增考核模板 |
| | | * |
| | | * @param checkTemplate 考核模板 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result remove(List<String> ids) { |
| | | if(baseMapper.deleteBatchIds(ids) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | public int insertCheckTemplate(CheckTemplate checkTemplate) |
| | | { |
| | | checkTemplate.setCreateTime(DateUtils.getNowDate()); |
| | | return checkTemplateMapper.insertCheckTemplate(checkTemplate); |
| | | } |
| | | |
| | | /** |
| | | * id删除 |
| | | * @param id |
| | | * @return |
| | | * 修改考核模板 |
| | | * |
| | | * @param checkTemplate 考核模板 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result removeById(String id) { |
| | | if(baseMapper.deleteById(id) > 0) { |
| | | return Result.ok("删除成功"); |
| | | } |
| | | return Result.error("删除失败"); |
| | | public int updateCheckTemplate(CheckTemplate checkTemplate) |
| | | { |
| | | checkTemplate.setUpdateTime(DateUtils.getNowDate()); |
| | | return checkTemplateMapper.updateCheckTemplate(checkTemplate); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @param query |
| | | * @return |
| | | * 批量删除考核模板 |
| | | * |
| | | * @param ids 需要删除的考核模板主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result page(CheckTemplateQuery query) { |
| | | IPage<CheckTemplate> page = new LambdaQueryChainWrapper<>(baseMapper) |
| | | .like(StringUtils.hasText(query.getTemplateName()), CheckTemplate::getTemplateName, query.getTemplateName()) |
| | | .eq(StringUtils.hasText(query.getStatus()), CheckTemplate::getStatus, query.getStatus()) |
| | | .between(Objects.nonNull(query.getStart()) && Objects.nonNull(query.getEnd()), |
| | | CheckTemplate::getCreateTime, |
| | | DateUtils.getDayStart(query.getStart()), |
| | | DateUtils.getDayEnd(query.getEnd())) |
| | | .orderByDesc(CheckTemplate::getCreateTime) |
| | | .page(PageUtil.getPage(query, CheckTemplate.class)); |
| | | |
| | | List<CheckTemplateVO> vos = page.getRecords().stream() |
| | | .map( |
| | | entity -> CheckTemplateVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos).total(page.getTotal()); |
| | | public int deleteCheckTemplateByIds(Long[] ids) |
| | | { |
| | | return checkTemplateMapper.deleteCheckTemplateByIds(ids); |
| | | } |
| | | |
| | | /** |
| | | * 根据id查找 |
| | | * @param id |
| | | * @return |
| | | * 删除考核模板信息 |
| | | * |
| | | * @param id 考核模板主键 |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public Result detail(String id) { |
| | | |
| | | CheckTemplate entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | CheckTemplateVO vo = CheckTemplateVO.getVoByEntity(entity, null); |
| | | return Result.ok().data(vo); |
| | | } |
| | | |
| | | /** |
| | | * 列表 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public Result all() { |
| | | List<CheckTemplate> entities = baseMapper.selectList(null); |
| | | List<CheckTemplateVO> vos = entities.stream() |
| | | .map( |
| | | entity -> CheckTemplateVO.getVoByEntity(entity, null) |
| | | ) |
| | | .collect(Collectors.toList()); |
| | | return Result.ok().data(vos); |
| | | public int deleteCheckTemplateById(Long id) |
| | | { |
| | | return checkTemplateMapper.deleteCheckTemplateById(id); |
| | | } |
| | | } |