From 9da24a8dfa3766cec565b092fc105f7f006de070 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期三, 21 八月 2024 11:52:25 +0800 Subject: [PATCH] 合同考核点位在线率记录 --- ycl-server/src/main/java/com/ycl/platform/service/impl/YwPointServiceImpl.java | 81 +++++++++++++++++++++++++++++++++++----- 1 files changed, 70 insertions(+), 11 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/YwPointServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/YwPointServiceImpl.java index 258f830..e41a9c8 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/YwPointServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/YwPointServiceImpl.java @@ -1,16 +1,21 @@ package com.ycl.platform.service.impl; +import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ycl.dataListener.CurrencyDataListener; import com.ycl.platform.base.BaseSelect; 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.BatchEditPointForm; import com.ycl.platform.domain.form.YwPointForm; import com.ycl.platform.domain.query.YwPointQuery; import com.ycl.platform.domain.vo.YwPointVO; +import com.ycl.platform.domain.excel.PointExport; +import com.ycl.platform.domain.excel.PointSelectHandler; import com.ycl.platform.mapper.YwPeopleMapper; import com.ycl.platform.mapper.YwPointMapper; import com.ycl.platform.service.YwPointService; @@ -20,15 +25,21 @@ import com.ycl.system.page.PageUtil; import com.ycl.utils.DateUtils; import com.ycl.utils.SecurityUtils; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; +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; import java.util.stream.Collectors; /** @@ -53,6 +64,9 @@ @Override public Result add(YwPointForm form) { YwPoint entity = YwPointForm.getEntityByForm(form, null); + Date now = new Date(); + entity.setCreateTime(now); + entity.setUpdateTime(now); if(baseMapper.insert(entity) > 0) { return Result.ok("娣诲姞鎴愬姛"); } @@ -66,6 +80,9 @@ .forEach(form -> { YwPoint entity = YwPointForm.getEntityByForm(form, null); entity.setStatus("鏈紑濮�"); + Date now = new Date(); + entity.setCreateTime(now); + entity.setUpdateTime(now); baseMapper.insert(entity); }); return Result.ok("娣诲姞鎴愬姛"); @@ -78,6 +95,7 @@ new LambdaUpdateChainWrapper<>(baseMapper) .in(YwPoint::getId, form.getIds()) .set(YwPoint::getUnitId, form.getUnitId()) + .set(YwPoint::getUpdateTime, new Date()) .update(); } else { new LambdaUpdateChainWrapper<>(baseMapper) @@ -85,6 +103,7 @@ .set(YwPoint::getUnitId, form.getUnitId()) .set(YwPoint::getStartTime, null) .set(YwPoint::getEndTime, null) + .set(YwPoint::getUpdateTime, new Date()) .update(); } return Result.ok("淇敼鎴愬姛"); @@ -100,7 +119,8 @@ YwPoint entity = baseMapper.selectById(form.getId()); Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); BeanUtils.copyProperties(form, entity); - entity.setPointTag(form.getPointTag().stream().collect(Collectors.joining(","))); + Date now = new Date(); + entity.setUpdateTime(now); baseMapper.updateById(entity); return Result.ok("淇敼鎴愬姛"); } @@ -140,11 +160,6 @@ 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()); } @@ -158,9 +173,6 @@ 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())); } @@ -208,11 +220,58 @@ } @Override - public boolean updateRecovery(List<Integer> pointIds, int recovery) { + public boolean updateRecovery(List<String> serialNumberList, int recovery) { return new LambdaUpdateChainWrapper<>(baseMapper) - .in(YwPoint::getId, pointIds) + .in(YwPoint::getSerialNumber, serialNumberList) .set(YwPoint::getRecovery, recovery) + .set(YwPoint::getUpdateTime, new Date()) .set(recovery == 0, YwPoint::getRecoveryTime, DateUtils.getNowDate()) .update(); } + + @Override + public List<YwPoint> home() { + return baseMapper.home(); + } + + @Override + public void export(YwPointQuery query, HttpServletResponse response) throws IOException { + // 瀵煎嚭鏁版嵁 + List<PointExport> exportData = baseMapper.export(query); + + EasyExcel.write(response.getOutputStream(), PointExport.class) + .sheet("鐐逛綅鏇存崲杩愮淮鍗曚綅") + .doWrite(exportData); + } + + @Override + public Result importData(MultipartFile file, Integer unitId, Date startTime, Date endTime, Boolean provinceTag, Boolean importantCommandImageTag) throws IOException { + Consumer<List<PointExport>> consumer = (dataList) -> { + this.updatePoint(dataList, unitId, startTime, endTime, provinceTag, importantCommandImageTag); + }; + 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, Date startTime, Date endTime, Boolean provinceTag, Boolean importantCommandImageTag) { + if (CollectionUtils.isEmpty(dataList)) { + throw new RuntimeException("瀵煎叆鏁版嵁涓嶈兘涓虹┖"); + } + List<String> pointList = dataList.stream().map(PointExport::getSerialNumber).collect(Collectors.toList()); + new LambdaUpdateChainWrapper<>(baseMapper) + .in(YwPoint::getSerialNumber, pointList) + .set(YwPoint::getUnitId, unitId) + .set(YwPoint::getStartTime, startTime) + .set(YwPoint::getEndTime, endTime) + .set(YwPoint::getProvinceTag, provinceTag) + .set(YwPoint::getImportantCommandImageTag, importantCommandImageTag) + .update(); + } + } -- Gitblit v1.8.0