126 lines
4.5 KiB
Java
126 lines
4.5 KiB
Java
package com.gunshi.project.xyt.service;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
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.AssessTaskMapper;
|
|
import com.gunshi.project.xyt.mapper.AssessTemplateMapper;
|
|
import com.gunshi.project.xyt.model.AssessIndicator;
|
|
import com.gunshi.project.xyt.model.AssessTask;
|
|
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.Map;
|
|
import java.util.Objects;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 描述: 考核模板
|
|
* author: xusan
|
|
* date: 2024-09-04 13:42:40
|
|
*/
|
|
@Service
|
|
@Slf4j
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class AssessTemplateService extends ServiceImpl<AssessTemplateMapper, AssessTemplate>
|
|
{
|
|
@Autowired
|
|
private AssessTemplateIndicatorRelService relService;
|
|
|
|
@Autowired
|
|
private AssessIndicatorService indicatorService;
|
|
|
|
@Autowired
|
|
private AssessTaskMapper taskMapper;
|
|
|
|
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<AssessTemplate> pageQuery(AttCctvBasePage page) {
|
|
LambdaQueryWrapper<AssessTemplate> query = Wrappers.lambdaQuery();
|
|
if (ObjectUtils.isNotNull(page.getName())) {
|
|
query.like(AssessTemplate::getTemplateName, page.getName());
|
|
}
|
|
query.orderByAsc(AssessTemplate::getStatus).orderByDesc(AssessTemplate::getCreateTime);
|
|
Page<AssessTemplate> res = this.page(page.getPageSo().toPage(), query);
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
|
fillUsedInfo(res.getRecords());
|
|
}
|
|
return res;
|
|
}
|
|
|
|
private void fillUsedInfo(List<AssessTemplate> records) {
|
|
List<Long> ids = records.stream().map(AssessTemplate::getId).collect(Collectors.toList());
|
|
List<AssessTask> list = taskMapper.selectList(new QueryWrapper<AssessTask>().in("template_id", ids));
|
|
Map<Long, Long> map = list.stream().collect(Collectors.groupingBy(AssessTask::getTemplateId, Collectors.counting()));
|
|
for (AssessTemplate record : records) {
|
|
record.setIsUsed(map.containsKey(record.getId()) ? 1 : 0);
|
|
}
|
|
}
|
|
|
|
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<AssessIndicator> queryIndicators(Long id) {
|
|
List<AssessIndicator> list = this.baseMapper.queryIndicators(id);
|
|
if(CollectionUtils.isEmpty(list)){
|
|
return list;
|
|
}
|
|
indicatorService.fillRating(list);
|
|
return list;
|
|
}
|
|
|
|
public List<AssessTemplate> listByType(Integer templateFreq) {
|
|
return this.list(new QueryWrapper<AssessTemplate>().eq("template_freq",templateFreq));
|
|
}
|
|
}
|
|
|
|
|