|
|
|
|
@ -1,18 +1,26 @@
|
|
|
|
|
package com.biutag.supervision.controller.data; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.io.FileUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import com.alibaba.excel.EasyExcel; |
|
|
|
|
import com.alibaba.excel.ExcelReader; |
|
|
|
|
import com.alibaba.excel.context.AnalysisContext; |
|
|
|
|
import com.alibaba.excel.read.listener.ReadListener; |
|
|
|
|
import com.alibaba.excel.read.metadata.ReadSheet; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.biutag.supervision.constants.enums.DepartLevelEnum; |
|
|
|
|
import com.biutag.supervision.constants.enums.InitialPetition; |
|
|
|
|
import com.biutag.supervision.pojo.Result; |
|
|
|
|
import com.biutag.supervision.pojo.dto.DataPetitionComplaintAddDto; |
|
|
|
|
import com.biutag.supervision.pojo.dto.DataPetitionComplaintImportDto; |
|
|
|
|
import com.biutag.supervision.pojo.entity.DataPetitionComplaint; |
|
|
|
|
import com.biutag.supervision.pojo.entity.SupDepart; |
|
|
|
|
import com.biutag.supervision.pojo.param.DataPetitionComplaintQueryParam; |
|
|
|
|
import com.biutag.supervision.service.DataPetitionComplaintService; |
|
|
|
|
import com.biutag.supervision.service.SupDepartService; |
|
|
|
|
import jakarta.validation.ConstraintViolation; |
|
|
|
|
import jakarta.validation.Validator; |
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
@ -21,6 +29,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Set; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* |
|
|
|
|
@ -35,6 +45,10 @@ public class DataPetitionComplaintController {
|
|
|
|
|
|
|
|
|
|
private final DataPetitionComplaintService dataPetitionComplaintService; |
|
|
|
|
|
|
|
|
|
private final SupDepartService departService; |
|
|
|
|
|
|
|
|
|
private final Validator validator; |
|
|
|
|
|
|
|
|
|
@GetMapping |
|
|
|
|
public Result<Page<DataPetitionComplaint>> list(DataPetitionComplaintQueryParam queryParam) { |
|
|
|
|
return Result.success(dataPetitionComplaintService.page(queryParam)); |
|
|
|
|
@ -47,16 +61,49 @@ public class DataPetitionComplaintController {
|
|
|
|
|
if (!"xls".equals(fileNameType) && !"xlsx".equals(fileNameType)) { |
|
|
|
|
throw new RuntimeException("仅支持 xls/xlsx 格式文件的导入"); |
|
|
|
|
} |
|
|
|
|
List<SupDepart> secondDeparts = departService.listByLevel(List.of(DepartLevelEnum.SECOND.getValue())); |
|
|
|
|
|
|
|
|
|
List<DataPetitionComplaintImportDto> list = new ArrayList<>(); |
|
|
|
|
ExcelReader excelReader = EasyExcel.read(file.getInputStream(), DataPetitionComplaintImportDto.class, new ReadListener<DataPetitionComplaintImportDto>() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void invoke(DataPetitionComplaintImportDto data, AnalysisContext analysisContext) { |
|
|
|
|
if ("是".equals(data.getEntanglementVisitsLabel())) { |
|
|
|
|
data.setEntanglementVisits(true); |
|
|
|
|
} |
|
|
|
|
if ("否".equals(data.getEntanglementVisitsLabel())) { |
|
|
|
|
data.setEntanglementVisits(false); |
|
|
|
|
} |
|
|
|
|
if ("是".equals(data.getMassVisitsLabel())) { |
|
|
|
|
data.setMassVisits(true); |
|
|
|
|
} |
|
|
|
|
if ("否".equals(data.getMassVisitsLabel())) { |
|
|
|
|
data.setMassVisits(false); |
|
|
|
|
} |
|
|
|
|
data.setInitialPetition(InitialPetition.getValue(data.getInitialPetition())); |
|
|
|
|
|
|
|
|
|
String secondDepartId = secondDeparts.stream() |
|
|
|
|
.filter(item -> item.getShortName().equals(data.getComplainedSecondDepartName())).findFirst() |
|
|
|
|
.map(SupDepart::getId).orElse(""); |
|
|
|
|
data.setComplainedSecondDepartId(secondDepartId); |
|
|
|
|
if (StrUtil.isNotBlank(secondDepartId)) { |
|
|
|
|
String complainedThirdDepartId = departService.list(new LambdaQueryWrapper<SupDepart>().eq(SupDepart::getPid, secondDepartId) |
|
|
|
|
.like(SupDepart::getShortName, data.getComplainedThirdDepartName())) |
|
|
|
|
.stream().findFirst().map(SupDepart::getId).orElse(""); |
|
|
|
|
data.setComplainedThirdDepartId(complainedThirdDepartId); |
|
|
|
|
} |
|
|
|
|
Set<ConstraintViolation<DataPetitionComplaintImportDto>> validate = validator.validate(data); |
|
|
|
|
if (!validate.isEmpty()) { |
|
|
|
|
String message = validate.stream().map(ConstraintViolation::getMessage).collect(Collectors.joining("\n")); |
|
|
|
|
data.setErrMsg(message); |
|
|
|
|
data.setState("fail"); |
|
|
|
|
} else { |
|
|
|
|
data.setState("success"); |
|
|
|
|
} |
|
|
|
|
list.add(data); |
|
|
|
|
} |
|
|
|
|
@Override |
|
|
|
|
public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}).build(); |
|
|
|
|
ReadSheet sheet = EasyExcel.readSheet(0).build(); |
|
|
|
|
|