package com.gunshi.project.xyt.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gunshi.project.xyt.entity.dto.InspectItemDto; import com.gunshi.project.xyt.entity.so.AttCctvBasePage; import com.gunshi.project.xyt.mapper.AssessTemplateMapper; import com.gunshi.project.xyt.model.AssessIndicator; import com.gunshi.project.xyt.model.AssessTemplate; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.Date; import java.util.List; import java.util.Objects; /** * 描述: 考核模板 * author: xusan * date: 2024-09-04 13:42:40 */ @Service @Slf4j @Transactional(rollbackFor = Exception.class) public class AssessTemplateService extends ServiceImpl { @Autowired private AssessTemplateIndicatorRelService relService; public AssessTemplate saveData(AssessTemplate dto) { dto.setId(IdWorker.getId()); dto.setStatus(0); dto.setCreateTime(new Date()); this.save(dto); relService.saveRel(dto.getIndicatorIds(),dto.getId()); return dto; } public AssessTemplate updateData(AssessTemplate dto) { if (Objects.isNull(this.getById(dto.getId()))) { throw new IllegalArgumentException("当前数据不存在"); } this.updateById(dto); relService.updateRel(dto.getIndicatorIds(),dto.getId()); return dto; } public Boolean delData(Long id) { if (Objects.isNull(this.getById(id))) { throw new IllegalArgumentException("当前数据不存在"); } relService.delRel(id); return this.removeById(id); } public Page pageQuery(AttCctvBasePage page) { LambdaQueryWrapper query = Wrappers.lambdaQuery(); if (ObjectUtils.isNotNull(page.getName())) { query.like(AssessTemplate::getTemplateName, page.getName()); } query.orderByAsc(AssessTemplate::getStatus).orderByDesc(AssessTemplate::getCreateTime); Page res = this.page(page.getPageSo().toPage(), query); return res; } public String startStop(InspectItemDto dto) { Integer status = dto.getStatus(); AssessTemplate template = super.getById(dto.getId()); if (template == null) { throw new IllegalArgumentException("当前数据不存在"); } template.setStatus(status); boolean flag = super.updateById(template); if (flag) { return status == 0 ? "启用成功" : "禁用成功"; } return status == 0 ? "启用失败" : "禁用失败"; } public List queryIndicators(Long id) { return this.baseMapper.queryIndicators(id); } }