110 lines
3.9 KiB
Java
110 lines
3.9 KiB
Java
|
|
package com.gunshi.project.hsz.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.hsz.entity.so.AttCctvBasePage;
|
||
|
|
import com.gunshi.project.hsz.mapper.RiskControlInfoMapper;
|
||
|
|
import com.gunshi.project.hsz.model.BzDictRel;
|
||
|
|
import com.gunshi.project.hsz.model.RiskControlInfo;
|
||
|
|
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-08-22 14:17:28
|
||
|
|
*/
|
||
|
|
@Service
|
||
|
|
@Slf4j
|
||
|
|
@Transactional(rollbackFor = Exception.class)
|
||
|
|
public class RiskControlInfoService extends ServiceImpl<RiskControlInfoMapper, RiskControlInfo>
|
||
|
|
{
|
||
|
|
@Autowired
|
||
|
|
private FileAssociationsService fileService;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private BzDictRelService bzDictRelService;
|
||
|
|
|
||
|
|
public RiskControlInfo saveData(RiskControlInfo dto) {
|
||
|
|
dto.setId(IdWorker.getId());
|
||
|
|
dto.setCreateDate(new Date());
|
||
|
|
boolean result = this.save(dto);
|
||
|
|
if (result) {
|
||
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf(dto.getId()));
|
||
|
|
bzDictRelService.saveRel(dto.getResult(),dto.getId(),getGroupId());
|
||
|
|
}
|
||
|
|
return dto;
|
||
|
|
}
|
||
|
|
|
||
|
|
public RiskControlInfo updateData(RiskControlInfo dto) {
|
||
|
|
if (Objects.isNull(this.getById(dto.getId()))) {
|
||
|
|
throw new IllegalArgumentException("当前数据不存在");
|
||
|
|
}
|
||
|
|
boolean result = this.updateById(dto);
|
||
|
|
if (result) {
|
||
|
|
fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf(dto.getId()));
|
||
|
|
bzDictRelService.updateRel(dto.getResult(),dto.getId(),getGroupId());
|
||
|
|
}
|
||
|
|
return dto;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Boolean delData(Long id) {
|
||
|
|
if (Objects.isNull(this.getById(id))) {
|
||
|
|
throw new IllegalArgumentException("当前数据不存在");
|
||
|
|
}
|
||
|
|
boolean data = this.removeById(id);
|
||
|
|
if (data) {
|
||
|
|
fileService.deleteFile(getGroupId(), id.toString());
|
||
|
|
bzDictRelService.deleteRel(id);
|
||
|
|
}
|
||
|
|
return data;
|
||
|
|
}
|
||
|
|
|
||
|
|
public String getGroupId() {
|
||
|
|
return "riskControlInfo";
|
||
|
|
}
|
||
|
|
|
||
|
|
public Page<RiskControlInfo> pageQuery(AttCctvBasePage page) {
|
||
|
|
LambdaQueryWrapper<RiskControlInfo> query = Wrappers.lambdaQuery();
|
||
|
|
if (ObjectUtils.isNotNull(page.getMenuId())) {
|
||
|
|
query.eq(RiskControlInfo::getMenuId, page.getMenuId());
|
||
|
|
}
|
||
|
|
query.orderByDesc(RiskControlInfo::getCreateDate);
|
||
|
|
Page<RiskControlInfo> res = this.page(page.getPageSo().toPage(), query);
|
||
|
|
if (res.getRecords() != null && res.getRecords().size() > 0) {
|
||
|
|
fillAttach(res.getRecords());
|
||
|
|
fillRel(res.getRecords());
|
||
|
|
}
|
||
|
|
return res;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void fillRel(List<RiskControlInfo> records) {
|
||
|
|
List<Long> ids = records.stream().map(RiskControlInfo::getId).collect(Collectors.toList());
|
||
|
|
List<BzDictRel> relList = this.baseMapper.queryRelList(ids);
|
||
|
|
Map<Long, List<BzDictRel>> map = relList.stream().collect(Collectors.groupingBy(BzDictRel::getBusinessId));
|
||
|
|
for (RiskControlInfo record : records) {
|
||
|
|
record.setResult(map.get(record.getId()));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void fillAttach(List<RiskControlInfo> ret) {
|
||
|
|
for (RiskControlInfo record : ret) {
|
||
|
|
record.setFiles(fileService.getFiles(getGroupId(), String.valueOf(record.getId())));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|