From 3e9a6da99aae968123ee7bca352fc08becd7f1f2 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期四, 29 八月 2024 17:29:21 +0800 Subject: [PATCH] 工单过程图接口更换 --- ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java | 181 +++++++++++++++++++++++++++++++++----------- 1 files changed, 134 insertions(+), 47 deletions(-) diff --git a/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java b/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java index a18f98b..2ccf8e2 100644 --- a/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java +++ b/ycl-server/src/main/java/com/ycl/platform/service/impl/ReportServiceImpl.java @@ -1,34 +1,41 @@ package com.ycl.platform.service.impl; -import com.ycl.platform.domain.entity.Region; +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.YwUnit; -import com.ycl.platform.mapper.RegionMapper; +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.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.ycl.platform.domain.form.ReportForm; -import com.ycl.platform.domain.vo.ReportVO; -import com.ycl.platform.domain.query.ReportQuery; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import com.baomidou.mybatisplus.core.metadata.IPage; import com.ycl.system.page.PageUtil; -import org.springframework.stereotype.Service; -import org.springframework.security.core.context.SecurityContextHolder; +import com.ycl.utils.DateUtils; +import com.ycl.utils.SecurityUtils; +import com.ycl.utils.html.EscapeUtil; +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.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; + import java.util.ArrayList; +import java.util.Date; +import java.util.List; import java.util.Objects; import java.util.stream.Collectors; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; -import lombok.RequiredArgsConstructor; /** * 鎶ュ 鏈嶅姟瀹炵幇绫� @@ -40,10 +47,9 @@ @RequiredArgsConstructor public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService { - private final ReportMapper reportMapper; private final YwUnitMapper unitMapper; + private final YwPointMapper ywpointMapper; private final YwPeopleMapper peopleMapper; - private final RegionMapper regionMapper; /** * 娣诲姞 @@ -52,13 +58,65 @@ */ @Override public Result add(ReportForm form) { - form.setPeopleId(1); - form.setUnitId(2); + 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.randomNO()); + Date now = new Date(); + entity.setCreateTime(now); + 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.randomNO()); + entity.setCreateTime(DateUtils.getNowDate()); + entity.setUpdateTime(DateUtils.getNowDate()); + reports.add(entity); + }); + if (saveBatch(reports)) { + return Result.ok("鎴愬姛瀵煎叆" + list.size() + "鏉℃暟鎹�"); + } + return Result.error("瀵煎叆澶辫触"); } /** @@ -70,14 +128,26 @@ public Result update(ReportForm form) { Report entity = baseMapper.selectById(form.getId()); - // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 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()) { + // 濡傛灉鏄湭瀹℃牳閫氳繃锛岃繘琛屼慨鏀癸紝閭d箞鐩存帴鏂板锛堜负浜嗕繚瀛樺鏍歌褰曪級 + 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("淇敼鎴愬姛"); } /** @@ -113,29 +183,10 @@ */ @Override public Result page(ReportQuery query) { - - 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()) - .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()); - Region region = regionMapper.selectById(vo.getPointId()); - vo.setPointName(region.getFullName()); - 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); + page.getRecords().forEach(item -> item.setErrorType(ErrorTypeEnum.getEnumValue(item.getErrorType()))); + return Result.ok().data(page).total(page.getTotal()); } /** @@ -166,4 +217,40 @@ .collect(Collectors.toList()); return Result.ok().data(vos); } + + @Override + public List<ReportVO> export(ReportQuery query) { + IPage<ReportVO> page = PageUtil.getPage(query, ReportVO.class); + page.setSize(-1); + baseMapper.page(page, query); + page.getRecords().forEach(item -> { + item.setErrorType(ErrorTypeEnum.getEnumValue(item.getErrorType())); + item.setReportContent(EscapeUtil.clean(item.getReportContent())); + }); + return page.getRecords(); + } + + + @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("鎿嶄綔鎴愬姛"); + } } -- Gitblit v1.8.0