| | |
| | | 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.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; |
| | |
| | | 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("添加成功"); |
| | | } |
| | |
| | | public Result update(ReportForm form) { |
| | | |
| | | Report entity = baseMapper.selectById(form.getId()); |
| | | |
| | | // 为空抛IllegalArgumentException,做全局异常处理 |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | if (baseMapper.updateById(entity) > 0) { |
| | | return Result.ok("修改成功"); |
| | | 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.error("修改失败"); |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public Result page(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 Result.ok(); |
| | | } |
| | | } |
| | | 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 Result.ok(); |
| | | } |
| | | } |
| | | |
| | | 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 Result.ok().data(vos).total(page.getTotal()); |
| | | IPage<ReportVO> page = PageUtil.getPage(query, ReportVO.class); |
| | | baseMapper.page(page, query); |
| | | return Result.ok().data(page).total(page.getTotal()); |
| | | } |
| | | |
| | | /** |
| | |
| | | .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("操作成功"); |
| | | } |
| | | } |