|
@@ -1,31 +1,46 @@
|
|
|
package com.jpsoft.excellent.modules;
|
|
|
|
|
|
-import com.jpsoft.excellent.modules.base.entity.Incident;
|
|
|
-import com.jpsoft.excellent.modules.base.entity.IncidentStep;
|
|
|
-import com.jpsoft.excellent.modules.base.entity.Person;
|
|
|
-import com.jpsoft.excellent.modules.base.service.IncidentService;
|
|
|
-import com.jpsoft.excellent.modules.base.service.IncidentStepService;
|
|
|
-import com.jpsoft.excellent.modules.base.service.PersonService;
|
|
|
+import com.jpsoft.excellent.config.OSSConfig;
|
|
|
+import com.jpsoft.excellent.modules.base.entity.*;
|
|
|
+import com.jpsoft.excellent.modules.base.service.*;
|
|
|
import com.jpsoft.excellent.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.excellent.modules.common.utils.DES3;
|
|
|
+import com.jpsoft.excellent.modules.common.utils.OSSUtil;
|
|
|
+import com.jpsoft.excellent.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.excellent.modules.common.utils.SMSUtil;
|
|
|
+import com.jpsoft.excellent.modules.sys.entity.DataDictionary;
|
|
|
import com.jpsoft.excellent.modules.sys.entity.User;
|
|
|
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.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/text")
|
|
|
@Api(description = "测试")
|
|
|
public class textController {
|
|
|
+ private Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
@Value("${jwt.secret}")
|
|
|
private String jwtSecret;
|
|
|
@Autowired
|
|
|
+ private OSSConfig ossConfig;
|
|
|
+ @Autowired
|
|
|
private UserService userService;
|
|
|
@Autowired
|
|
|
private PersonService personService;
|
|
@@ -33,6 +48,10 @@ public class textController {
|
|
|
private IncidentService incidentService;
|
|
|
@Autowired
|
|
|
private IncidentStepService incidentStepService;
|
|
|
+ @Autowired
|
|
|
+ private AreaService areaService;
|
|
|
+ @Autowired
|
|
|
+ private WorkStationService workStationService;
|
|
|
|
|
|
@ApiOperation(value="短信发送")
|
|
|
@RequestMapping(value = "sendSMS",method = RequestMethod.POST)
|
|
@@ -133,4 +152,168 @@ public class textController {
|
|
|
|
|
|
return msgResult;
|
|
|
}
|
|
|
+
|
|
|
+ @ApiOperation(value="导入区域")
|
|
|
+ @PostMapping("importArea")
|
|
|
+ public MessageResult<String> importArea(MultipartFile uploadFile, @RequestAttribute String subject){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ POIUtils poiUtils = new POIUtils(uploadFile.getInputStream());
|
|
|
+ Sheet sheet1 = poiUtils.getSheetAt(0);
|
|
|
+
|
|
|
+ int affectCount = 0;
|
|
|
+ int failCount = 0;
|
|
|
+ int validateColIndex = 3;
|
|
|
+
|
|
|
+ for(int rowIndex=1; rowIndex<=sheet1.getLastRowNum(); rowIndex++){
|
|
|
+ try {
|
|
|
+ String strLv1 = poiUtils.getCellValue(0,rowIndex,0).toString();
|
|
|
+ String strLv2 = poiUtils.getCellValue(0,rowIndex,1).toString();
|
|
|
+ String strLv3 = poiUtils.getCellValue(0,rowIndex,2).toString();
|
|
|
+
|
|
|
+ Area area1 = areaService.getByName(strLv1);
|
|
|
+ if(area1 == null){
|
|
|
+ area1 = new Area();
|
|
|
+ area1.setId(UUID.randomUUID().toString());
|
|
|
+ area1.setDelFlag(false);
|
|
|
+ area1.setCreateBy(subject);
|
|
|
+ area1.setCreateTime(new Date());
|
|
|
+ area1.setParentId(null);
|
|
|
+ area1.setName(strLv1);
|
|
|
+ areaService.insert(area1);
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ Area area2 = areaService.getByName(strLv2);
|
|
|
+ if(area2 == null){
|
|
|
+ area2 = new Area();
|
|
|
+ area2.setId(UUID.randomUUID().toString());
|
|
|
+ area2.setDelFlag(false);
|
|
|
+ area2.setCreateBy(subject);
|
|
|
+ area2.setCreateTime(new Date());
|
|
|
+ area2.setParentId(area1.getId());
|
|
|
+ area2.setName(strLv2);
|
|
|
+ areaService.insert(area2);
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+
|
|
|
+ Area area3 = areaService.getByName(strLv3);
|
|
|
+ if(area3 == null){
|
|
|
+ area3 = new Area();
|
|
|
+ area3.setId(UUID.randomUUID().toString());
|
|
|
+ area3.setDelFlag(false);
|
|
|
+ area3.setCreateBy(subject);
|
|
|
+ area3.setCreateTime(new Date());
|
|
|
+ area3.setParentId(area2.getId());
|
|
|
+ area3.setName(strLv3);
|
|
|
+ areaService.insert(area3);
|
|
|
+ affectCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch(Exception innerEx){
|
|
|
+ failCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value="更新站点区域")
|
|
|
+ @RequestMapping(value = "updateStation",method = RequestMethod.POST)
|
|
|
+ public MessageResult updateStation(@RequestAttribute String subject){
|
|
|
+ MessageResult msgResult = new MessageResult();
|
|
|
+
|
|
|
+ try {
|
|
|
+ Integer count = 0;
|
|
|
+ List<WorkStation> workStations = workStationService.list();
|
|
|
+ for(WorkStation workStation : workStations){
|
|
|
+ if(workStation.getStationName().indexOf("镇") > 0) {
|
|
|
+ String stationName = workStation.getStationName().substring(0, workStation.getStationName().indexOf("镇")+1);
|
|
|
+
|
|
|
+ Area area = areaService.getByName(stationName);
|
|
|
+ if(area != null) {
|
|
|
+ workStation.setAreaId(area.getId());
|
|
|
+ workStationService.update(workStation);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ area = areaService.getByName(workStation.getAreaId());
|
|
|
+ if(area != null) {
|
|
|
+ workStation.setAreaId(area.getId());
|
|
|
+ workStationService.update(workStation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if(workStation.getStationName().indexOf("乡") > 0) {
|
|
|
+ String stationName = workStation.getStationName().substring(0, workStation.getStationName().indexOf("乡")+1);
|
|
|
+
|
|
|
+ Area area = areaService.getByName(stationName);
|
|
|
+ if(area != null) {
|
|
|
+ workStation.setAreaId(area.getId());
|
|
|
+ workStationService.update(workStation);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ area = areaService.getByName(workStation.getAreaId());
|
|
|
+ if(area != null) {
|
|
|
+ workStation.setAreaId(area.getId());
|
|
|
+ workStationService.update(workStation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ Area area = areaService.getByName(workStation.getAreaId());
|
|
|
+ if(area != null) {
|
|
|
+ workStation.setAreaId(area.getId());
|
|
|
+ workStationService.update(workStation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setMessage("更新数据"+count+"条。");
|
|
|
+ }
|
|
|
+ catch(Exception ex){
|
|
|
+ msgResult.setResult(false);
|
|
|
+ msgResult.setMessage(ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
}
|