| | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.function.Consumer; |
| | |
| | | YwPoint entity = baseMapper.selectById(form.getId()); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | BeanUtils.copyProperties(form, entity); |
| | | entity.setPointTag(form.getPointTag().stream().collect(Collectors.joining(","))); |
| | | baseMapper.updateById(entity); |
| | | return Result.ok("修改成功"); |
| | | } |
| | |
| | | public Result page(YwPointQuery query) { |
| | | IPage<YwPointVO> page = PageUtil.getPage(query, YwPointVO.class); |
| | | baseMapper.page(page, query); |
| | | page.getRecords().stream().forEach(point -> { |
| | | if (StringUtils.hasText(point.getPointTagString())) { |
| | | point.setPointTags(point.getPointTagString().split(",")); |
| | | } |
| | | }); |
| | | return Result.ok().data(page.getRecords()).total(page.getTotal()); |
| | | } |
| | | |
| | |
| | | YwPoint entity = baseMapper.selectById(id); |
| | | Assert.notNull(entity, "记录不存在"); |
| | | YwPointVO vo = YwPointVO.getVoByEntity(entity, null); |
| | | if (StringUtils.hasText(entity.getPointTag())) { |
| | | vo.setPointTags(entity.getPointTag().split(",")); |
| | | } |
| | | if (Objects.nonNull(entity.getDeptId())) { |
| | | vo.setDeptIds(sysDeptMapper.selectParents(entity.getDeptId())); |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result importData(MultipartFile file, Integer unitId) throws IOException { |
| | | public Result importData(MultipartFile file, Integer unitId, Date startTime, Date endTime) throws IOException { |
| | | Consumer<List<PointExport>> consumer = (dataList) -> { |
| | | this.updatePoint(dataList, unitId); |
| | | this.updatePoint(dataList, unitId, startTime, endTime); |
| | | }; |
| | | EasyExcel.read(file.getInputStream(), PointExport.class , new CurrencyDataListener(consumer)).headRowNumber(1).doReadAll(); |
| | | return Result.ok(); |
| | |
| | | * @param dataList |
| | | * @param unitId |
| | | */ |
| | | private void updatePoint(List<PointExport> dataList, Integer unitId) { |
| | | private void updatePoint(List<PointExport> dataList, Integer unitId, Date startTime, Date endTime) { |
| | | if (CollectionUtils.isEmpty(dataList)) { |
| | | throw new RuntimeException("导入数据不能为空"); |
| | | } |
| | |
| | | new LambdaUpdateChainWrapper<>(baseMapper) |
| | | .in(YwPoint::getSerialNumber, pointList) |
| | | .set(YwPoint::getUnitId, unitId) |
| | | .set(YwPoint::getStartTime, startTime) |
| | | .set(YwPoint::getEndTime, endTime) |
| | | .update(); |
| | | } |
| | | |