|
@@ -7,6 +7,7 @@ import com.jpsoft.excellent.modules.base.dto.ShowCountDTO;
|
|
|
import com.jpsoft.excellent.modules.base.entity.*;
|
|
|
import com.jpsoft.excellent.modules.base.service.*;
|
|
|
import com.jpsoft.excellent.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.excellent.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.excellent.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.excellent.modules.common.dto.Sort;
|
|
|
import com.jpsoft.excellent.modules.common.dto.MessageResult;
|
|
@@ -18,6 +19,8 @@ import com.jpsoft.excellent.modules.sys.service.DataDictionaryService;
|
|
|
import com.jpsoft.excellent.modules.sys.service.UserRoleService;
|
|
|
import com.jpsoft.excellent.modules.sys.service.UserService;
|
|
|
import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
@@ -26,6 +29,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
@@ -929,4 +933,234 @@ public class IncidentController {
|
|
|
|
|
|
return strDate + random;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value="导入案件")
|
|
|
+ @PostMapping("importXls")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "uploadFile",value = "上传文件", required = true,paramType="form", dataType = "__file")
|
|
|
+ })
|
|
|
+ public MessageResult<String> importXls(MultipartFile uploadFile, @RequestAttribute String subject){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(0);
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 14;
|
|
|
+
|
|
|
+ for(int rowIndex=1; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
+ try {
|
|
|
+ String strBatch = poiUtils.getCellValue(0,rowIndex,0).toString();
|
|
|
+ String strSerialNo = poiUtils.getCellValue(0,rowIndex,1).toString();
|
|
|
+ String strComplainant = poiUtils.getCellValue(0,rowIndex,2).toString();
|
|
|
+ String strComplainantPhone = poiUtils.getCellValue(0,rowIndex,3).toString();
|
|
|
+ String strProblem = poiUtils.getCellValue(0,rowIndex,4).toString();
|
|
|
+ String strArea = poiUtils.getCellValue(0,rowIndex,5).toString();
|
|
|
+ String strSpecialClass = poiUtils.getCellValue(0,rowIndex,6).toString();
|
|
|
+ String strSuggestedDate = poiUtils.getCellValue(0,rowIndex,7).toString();
|
|
|
+ String strOrg = poiUtils.getCellValue(0,rowIndex,8).toString();
|
|
|
+ String strWarnDate1 = poiUtils.getCellValue(0,rowIndex,9).toString();
|
|
|
+ String strWarnDate2 = poiUtils.getCellValue(0,rowIndex,10).toString();
|
|
|
+ String strWarnDate3 = poiUtils.getCellValue(0,rowIndex,11).toString();
|
|
|
+ String strAllotedDate = poiUtils.getCellValue(0,rowIndex,12).toString();
|
|
|
+ String strRemark = poiUtils.getCellValue(0,rowIndex,13).toString();
|
|
|
+
|
|
|
+ //案件信息
|
|
|
+ Incident incident = new Incident();
|
|
|
+ incident.setId(UUID.randomUUID().toString());
|
|
|
+ incident.setIsFinished("1");
|
|
|
+ incident.setDelFlag(false);
|
|
|
+ incident.setCreateBy(subject);
|
|
|
+ incident.setCreateTime(new Date());
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strBatch)){
|
|
|
+ incident.setBatch(strBatch);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写批次!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strSerialNo)){
|
|
|
+ incident.setSerialNo(strSerialNo);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写序号!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strComplainant)){
|
|
|
+ incident.setComplainant(strComplainant);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写联系人!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strComplainantPhone)){
|
|
|
+ incident.setComplainantPhone(strComplainantPhone);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写联系电话!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strProblem)){
|
|
|
+ incident.setProblem(strProblem);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写主要问题!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strArea)){
|
|
|
+ DataDictionary dataDictionary = dataDictionaryService.findByName(strArea);
|
|
|
+ if(dataDictionary != null) {
|
|
|
+ incident.setAreaId(dataDictionary.getValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写所属区域!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strSpecialClass)){
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ String[] names = strSpecialClass.split(",");
|
|
|
+ for(String name : names) {
|
|
|
+ DataDictionary dataDictionary = dataDictionaryService.findByName(name);
|
|
|
+ if(dataDictionary != null) {
|
|
|
+ ids.add(dataDictionary.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ incident.setSpecialClassId(String.join(",",ids));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写跟踪专班!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strSuggestedDate)){
|
|
|
+ incident.setSuggestedDate(sdf.parse(strSuggestedDate));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写建议办结时限!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strRemark)){
|
|
|
+ incident.setRemark(strRemark);
|
|
|
+ }
|
|
|
+
|
|
|
+ //案件步骤
|
|
|
+ IncidentStep incidentStep = new IncidentStep();
|
|
|
+ incidentStep.setId(UUID.randomUUID().toString());
|
|
|
+ incidentStep.setIncidentId(incident.getId());
|
|
|
+ incidentStep.setCreateBy(subject);
|
|
|
+ incidentStep.setCreateTime(new Date());
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strOrg)){
|
|
|
+ List<String> ids = new ArrayList<>();
|
|
|
+ String[] names = strOrg.split(",");
|
|
|
+ for(String name : names) {
|
|
|
+ Organization organization = organizationService.findByName(name);
|
|
|
+ if(organization != null) {
|
|
|
+ ids.add(organization.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ incidentStep.setOrgId(String.join(",",ids));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写交办单位!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strWarnDate1)){
|
|
|
+ incidentStep.setWarnDate1(sdf.parse(strWarnDate1));
|
|
|
+ incidentStep.setIsWarned1(false);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写第一次提醒时间!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strWarnDate2)){
|
|
|
+ incidentStep.setWarnDate2(sdf.parse(strWarnDate2));
|
|
|
+ incidentStep.setIsWarned2(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strWarnDate3)){
|
|
|
+ incidentStep.setWarnDate3(sdf.parse(strWarnDate3));
|
|
|
+ incidentStep.setIsWarned3(false);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(strAllotedDate)){
|
|
|
+ incidentStep.setAllotedDate(sdf.parse(strAllotedDate));
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ sheet1.getRow(rowIndex).createCell(validateColIndex).setCellValue("请填写到期时间!");
|
|
|
+ failCount++;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ incidentService.insert(incident);
|
|
|
+ incidentStepService.insert(incidentStep);
|
|
|
+
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+ catch(Exception innerEx){
|
|
|
+ logger.error(innerEx.getMessage(),innerEx);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (failCount>0){
|
|
|
+ //有导入失败的记录
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条,有" + failCount + "条数据未导入成功,错误原因请查看报表。");
|
|
|
+
|
|
|
+ //todo 只保留错误数据的sheet
|
|
|
+ Workbook wb = poiUtils.exportErrorXls(0,validateColIndex,1 + affectCount + failCount);
|
|
|
+
|
|
|
+ //todo 将wb保存到oss
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ wb.write(output);
|
|
|
+
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ //格式化holidayInfo
|
|
|
+ SimpleDateFormat sim = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ String fileName = "error" + sim.format(new Date()) + ".xls";
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"excellent",fileName,input);
|
|
|
+
|
|
|
+ //todo 返回导入失败报表下载链接
|
|
|
+ msgResult.setData(downloadUrl);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("数据成功导入" + affectCount + "条");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ logger.error(ex.getMessage(),ex);
|
|
|
+
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|