| | |
| | | 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.dto.ReportImportDTO; |
| | | 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.service.ReportService; |
| | | import com.ycl.system.Result; |
| | | import com.ycl.system.page.PageUtil; |
| | | import com.ycl.utils.DateUtils; |
| | | import com.ycl.utils.SecurityUtils; |
| | | import com.ycl.utils.poi.ExcelUtil; |
| | | import com.ycl.utils.uuid.IdUtils; |
| | | import enumeration.general.ErrorTypeEnum; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | 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.transaction.annotation.Transactional; |
| | | import org.springframework.util.Assert; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Result add(ReportForm form) { |
| | | if (Objects.isNull(form.getPointId())) { |
| | | throw new RuntimeException("点位不能为空"); |
| | | } |
| | | 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.setSerialNumber(form.getPointId()); |
| | | entity.setErrorType(String.join(",", form.getErrorType())); |
| | | entity.setStatus(0); |
| | | entity.setIdentify(IdUtils.timeAddRandomNO(3)); |
| | | Date now = new Date(); |
| | |
| | | entity.setUpdateTime(now); |
| | | if(baseMapper.insert(entity) > 0) { |
| | | return Result.ok("添加成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | public void importTemplate(HttpServletResponse response) { |
| | | ExcelUtil<ReportImportDTO> excelUtil = new ExcelUtil<>(ReportImportDTO.class); |
| | | excelUtil.exportExcel(response, null, "报备导入模板"); |
| | | } |
| | | |
| | | @Override |
| | | @SneakyThrows |
| | | @Transactional |
| | | public Result importData(ReportForm form) { |
| | | if (Objects.isNull(form.getImportPointId())) { |
| | | throw new RuntimeException("点位不能为空"); |
| | | } |
| | | Long userId = SecurityUtils.getUserId(); |
| | | YwPeople people = new LambdaQueryChainWrapper<>(peopleMapper).eq(YwPeople::getUserId, userId).one(); |
| | | form.setPeopleId(people.getId()); |
| | | form.setUnitId(people.getBelongUnit()); |
| | | // 读取excel数据 |
| | | ExcelUtil<ReportImportDTO> excelUtil = new ExcelUtil<>(ReportImportDTO.class); |
| | | List<ReportImportDTO> list = excelUtil.importExcel(form.getImportPointId().getInputStream()); |
| | | // 批量插入 |
| | | ArrayList<Report> reports = new ArrayList<>(); |
| | | long l = System.currentTimeMillis(); |
| | | list.forEach( item -> { |
| | | Report entity = ReportForm.getEntityByForm(form, null); |
| | | entity.setImportBatchNumber(String.valueOf(l)); |
| | | entity.setSerialNumber(item.getSerialNumber()); |
| | | entity.setStatus(0); |
| | | entity.setIdentify(IdUtils.timeAddRandomNO(3)); |
| | | entity.setCreateTime(DateUtils.getNowDate()); |
| | | entity.setUpdateTime(DateUtils.getNowDate()); |
| | | reports.add(entity); |
| | | }); |
| | | if (saveBatch(reports)) { |
| | | return Result.ok("导入成功"); |
| | | } |
| | | return Result.error("添加失败"); |
| | | } |
| | |
| | | public Result page(ReportQuery query) { |
| | | IPage<ReportVO> page = PageUtil.getPage(query, ReportVO.class); |
| | | baseMapper.page(page, query); |
| | | page.getRecords().forEach(item -> item.setErrorType(ErrorTypeEnum.getEnumValue(item.getErrorType()))); |
| | | return Result.ok().data(page).total(page.getTotal()); |
| | | } |
| | | |
| | |
| | | .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.getPointIdList()), Report::getPointId, query.getPointIdList()) |
| | | .in(!CollectionUtils.isEmpty(query.getPeopleIdList()), Report::getPeopleId, query.getPeopleIdList()) |
| | | .orderByDesc(Report::getCreateTime) |
| | | .page(PageUtil.getPage(query, Report.class)); |
| | |
| | | vo.setUnitName(unit.getUnitName()); |
| | | YwPeople ywPeople = peopleMapper.selectById(vo.getPeopleId()); |
| | | vo.setPeopleName(ywPeople.getYwPersonName()); |
| | | YwPoint ywPoint = ywpointMapper.selectById(vo.getPointId()); |
| | | vo.setPointName(ywPoint.getPointName()); |
| | | // YwPoint ywPoint = ywpointMapper.selectById(vo.getPointId()); |
| | | // vo.setPointName(ywPoint.getPointName()); |
| | | return vo; |
| | | } |
| | | ) |