package com.ycl.platform.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ycl.platform.domain.entity.Report;
|
import com.ycl.platform.domain.entity.YwPeople;
|
import com.ycl.platform.domain.entity.YwPoint;
|
import com.ycl.platform.domain.entity.YwUnit;
|
import com.ycl.platform.domain.form.ReportAuditingForm;
|
import com.ycl.platform.domain.form.ReportForm;
|
import com.ycl.platform.domain.query.ReportQuery;
|
import com.ycl.platform.domain.vo.ReportVO;
|
import com.ycl.platform.mapper.ReportMapper;
|
import com.ycl.platform.mapper.YwPeopleMapper;
|
import com.ycl.platform.mapper.YwPointMapper;
|
import com.ycl.platform.mapper.YwUnitMapper;
|
import com.ycl.platform.service.ReportService;
|
import com.ycl.system.Result;
|
import com.ycl.system.page.PageUtil;
|
import com.ycl.utils.SecurityUtils;
|
import com.ycl.utils.uuid.IdUtils;
|
import lombok.RequiredArgsConstructor;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.Assert;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 报备 服务实现类
|
*
|
* @author xp
|
* @since 2024-03-19
|
*/
|
@Service
|
@RequiredArgsConstructor
|
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService {
|
|
private final YwUnitMapper unitMapper;
|
private final YwPointMapper ywpointMapper;
|
private final YwPeopleMapper peopleMapper;
|
|
/**
|
* 添加
|
* @param form
|
* @return
|
*/
|
@Override
|
public Result add(ReportForm form) {
|
Long userId = SecurityUtils.getUserId();
|
YwPeople people = new LambdaQueryChainWrapper<>(peopleMapper).eq(YwPeople::getUserId, userId).one();
|
form.setPeopleId(people.getId());
|
form.setUnitId(people.getBelongUnit());
|
Report entity = ReportForm.getEntityByForm(form, null);
|
entity.setStatus(0);
|
entity.setIdentify(IdUtils.timeAddRandomNO(3));
|
Date now = new Date();
|
entity.setCreateTime(now);
|
entity.setUpdateTime(now);
|
if(baseMapper.insert(entity) > 0) {
|
return Result.ok("添加成功");
|
}
|
return Result.error("添加失败");
|
}
|
|
/**
|
* 修改
|
* @param form
|
* @return
|
*/
|
@Override
|
public Result update(ReportForm form) {
|
|
Report entity = baseMapper.selectById(form.getId());
|
// 为空抛IllegalArgumentException,做全局异常处理
|
Assert.notNull(entity, "记录不存在");
|
Date now = new Date();
|
entity.setUpdateTime(now);
|
if (0 == entity.getStatus()) {
|
// 待审核的直接改
|
BeanUtils.copyProperties(form, entity);
|
baseMapper.updateById(entity);
|
} else if (2 == entity.getStatus()) {
|
// 如果是未审核通过,进行修改,那么直接新增(为了保存审核记录)
|
Report report = new Report();
|
BeanUtils.copyProperties(entity, report);
|
BeanUtils.copyProperties(form, report);
|
report.setId(null);
|
report.setStatus(0);
|
report.setAuditingTime(null);
|
report.setAuditOpinion(null);
|
baseMapper.insert(report);
|
}
|
return Result.ok("修改成功");
|
}
|
|
/**
|
* 批量删除
|
* @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(ReportQuery query) {
|
IPage<ReportVO> page = PageUtil.getPage(query, ReportVO.class);
|
baseMapper.page(page, query);
|
return Result.ok().data(page).total(page.getTotal());
|
}
|
|
/**
|
* 根据id查找
|
* @param id
|
* @return
|
*/
|
@Override
|
public Result detail(String id) {
|
|
Report entity = baseMapper.selectById(id);
|
Assert.notNull(entity, "记录不存在");
|
ReportVO vo = ReportVO.getVoByEntity(entity, null);
|
return Result.ok().data(vo);
|
}
|
|
/**
|
* 列表
|
* @return
|
*/
|
@Override
|
public Result all() {
|
List<Report> entities = baseMapper.selectList(null);
|
List<ReportVO> vos = entities.stream()
|
.map(
|
entity -> ReportVO.getVoByEntity(entity, null)
|
)
|
.collect(Collectors.toList());
|
return Result.ok().data(vos);
|
}
|
|
public List<ReportVO> export(ReportQuery query) {
|
|
if (StringUtils.isNotBlank(query.getPointId())) {
|
LambdaQueryWrapper<YwPoint> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.like(YwPoint::getPointName, query.getPointId());
|
query.setPointIdList(ywpointMapper.selectList(queryWrapper).stream().map(YwPoint::getId).collect(Collectors.toList()));
|
if(CollectionUtils.isEmpty(query.getPointIdList())) {
|
return new ArrayList<>();
|
}
|
}
|
if (StringUtils.isNotBlank(query.getPeopleId())) {
|
LambdaQueryWrapper<YwPeople> queryWrapper = new LambdaQueryWrapper<>();
|
queryWrapper.like(YwPeople::getYwPersonName, query.getPeopleId());
|
query.setPeopleIdList(peopleMapper.selectList(queryWrapper).stream().map(YwPeople::getId).collect(Collectors.toList()));
|
if(CollectionUtils.isEmpty(query.getPeopleIdList())) {
|
return new ArrayList<>();
|
}
|
}
|
|
IPage<Report> page = new LambdaQueryChainWrapper<>(baseMapper)
|
.eq(StringUtils.isNotBlank(query.getReportType()), Report::getReportType, query.getReportType())
|
// .le(Objects.nonNull(query.getBeginCreateTime()), Report::getBeginCreateTime, query.getBeginCreateTime())
|
// .ge(Objects.nonNull(query.getEndCreateTime()), Report::getEndCreateTime, query.getEndCreateTime())
|
.in(!CollectionUtils.isEmpty(query.getPointIdList()), Report::getPointId, query.getPointIdList())
|
.in(!CollectionUtils.isEmpty(query.getPeopleIdList()), Report::getPeopleId, query.getPeopleIdList())
|
.orderByDesc(Report::getCreateTime)
|
.page(PageUtil.getPage(query, Report.class));
|
|
List<ReportVO> vos = page.getRecords().stream()
|
.map(
|
entity -> {
|
ReportVO vo = ReportVO.getVoByEntity(entity, null);
|
YwUnit unit = unitMapper.selectById(vo.getUnitId());
|
vo.setUnitName(unit.getUnitName());
|
YwPeople ywPeople = peopleMapper.selectById(vo.getPeopleId());
|
vo.setPeopleName(ywPeople.getYwPersonName());
|
YwPoint ywPoint = ywpointMapper.selectById(vo.getPointId());
|
vo.setPointName(ywPoint.getPointName());
|
return vo;
|
}
|
)
|
.collect(Collectors.toList());
|
return vos;
|
}
|
|
|
@Override
|
public Result auditingRecord(Integer id) {
|
List<ReportVO> reportList = baseMapper.examineRecord(id);
|
return Result.ok().data(reportList);
|
}
|
|
@Override
|
public Result auditing(ReportAuditingForm form) {
|
Report report = baseMapper.selectById(form.getId());
|
if (Objects.isNull(report)) {
|
throw new RuntimeException("审核的报备不存在");
|
}
|
if (form.getAuditingResult()) {
|
report.setStatus(1);
|
} else {
|
report.setStatus(2);
|
}
|
report.setAuditOpinion(form.getAuditOpinion());
|
report.setAuditingTime(new Date());
|
baseMapper.updateById(report);
|
return Result.ok("操作成功");
|
}
|
}
|