|
@@ -1,33 +1,32 @@
|
|
|
package com.ruoyi.project.sems.controller;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
-import java.text.DateFormat;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.ruoyi.project.sems.domain.TMeasureThickness;
|
|
|
-import com.ruoyi.project.sems.service.ITMeasureThicknessService;
|
|
|
-import org.apache.poi.ss.formula.functions.T;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
+import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
|
|
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
|
|
-import com.ruoyi.project.sems.domain.TMeasureRecord;
|
|
|
-import com.ruoyi.project.sems.service.ITMeasureRecordService;
|
|
|
import com.ruoyi.framework.web.controller.BaseController;
|
|
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
|
|
-import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
+import com.ruoyi.project.sems.domain.TMeasureRecord;
|
|
|
+import com.ruoyi.project.sems.domain.TMeasureThickness;
|
|
|
+import com.ruoyi.project.sems.service.ITMeasureRecordService;
|
|
|
+import com.ruoyi.project.sems.service.ITMeasureThicknessService;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.DateFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 测厚记录Controller
|
|
@@ -37,18 +36,17 @@ import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/sems/measure-record")
|
|
|
-public class TMeasureRecordController extends BaseController
|
|
|
-{
|
|
|
+public class TMeasureRecordController extends BaseController {
|
|
|
@Autowired
|
|
|
private ITMeasureRecordService tMeasureRecordService;
|
|
|
@Autowired
|
|
|
private ITMeasureThicknessService tMeasureThicknessService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询测厚记录列表
|
|
|
*/
|
|
|
@GetMapping("/list")
|
|
|
- public TableDataInfo list(TMeasureRecord tMeasureRecord)
|
|
|
- {
|
|
|
+ public TableDataInfo list(TMeasureRecord tMeasureRecord) {
|
|
|
startPage();
|
|
|
List<TMeasureRecord> list = tMeasureRecordService.selectTMeasureRecordList(tMeasureRecord);
|
|
|
return getDataTable(list);
|
|
@@ -59,8 +57,7 @@ public class TMeasureRecordController extends BaseController
|
|
|
*/
|
|
|
@Log(title = "测厚记录", businessType = BusinessType.EXPORT)
|
|
|
@GetMapping("/export")
|
|
|
- public AjaxResult export(TMeasureRecord tMeasureRecord)
|
|
|
- {
|
|
|
+ public AjaxResult export(TMeasureRecord tMeasureRecord) {
|
|
|
List<TMeasureRecord> list = tMeasureRecordService.selectTMeasureRecordList(tMeasureRecord);
|
|
|
ExcelUtil<TMeasureRecord> util = new ExcelUtil<TMeasureRecord>(TMeasureRecord.class);
|
|
|
return util.exportExcel(list, "measure-record");
|
|
@@ -70,8 +67,7 @@ public class TMeasureRecordController extends BaseController
|
|
|
* 获取测厚记录详细信息
|
|
|
*/
|
|
|
@GetMapping(value = "/{id}")
|
|
|
- public AjaxResult getInfo(@PathVariable("id") Long id)
|
|
|
- {
|
|
|
+ public AjaxResult getInfo(@PathVariable("id") Long id) {
|
|
|
return AjaxResult.success(tMeasureRecordService.selectTMeasureRecordById(id));
|
|
|
}
|
|
|
|
|
@@ -80,13 +76,12 @@ public class TMeasureRecordController extends BaseController
|
|
|
*/
|
|
|
@Log(title = "测厚记录", businessType = BusinessType.INSERT)
|
|
|
@PostMapping
|
|
|
- public AjaxResult add(@RequestBody TMeasureRecord tMeasureRecord)
|
|
|
- {
|
|
|
+ public AjaxResult add(@RequestBody TMeasureRecord tMeasureRecord) {
|
|
|
tMeasureRecordService.insertTMeasureRecord(tMeasureRecord);
|
|
|
String measureId = tMeasureRecord.getMeasureId();
|
|
|
try {
|
|
|
updateMeasure(measureId);
|
|
|
- }catch (Exception e) {
|
|
|
+ } catch (Exception e) {
|
|
|
logger.error(JSON.toJSONString(e));
|
|
|
}
|
|
|
return toAjax(1);
|
|
@@ -97,11 +92,10 @@ public class TMeasureRecordController extends BaseController
|
|
|
*/
|
|
|
@Log(title = "测厚记录", businessType = BusinessType.UPDATE)
|
|
|
@PutMapping
|
|
|
- public AjaxResult edit(@RequestBody TMeasureRecord tMeasureRecord)
|
|
|
- {
|
|
|
+ public AjaxResult edit(@RequestBody TMeasureRecord tMeasureRecord) {
|
|
|
tMeasureRecordService.updateTMeasureRecord(tMeasureRecord);
|
|
|
String measureId = tMeasureRecord.getMeasureId();
|
|
|
- updateMeasure(measureId);
|
|
|
+ updateMeasure(measureId);
|
|
|
return toAjax(1);
|
|
|
}
|
|
|
|
|
@@ -109,15 +103,14 @@ public class TMeasureRecordController extends BaseController
|
|
|
* 删除测厚记录
|
|
|
*/
|
|
|
@Log(title = "测厚记录", businessType = BusinessType.DELETE)
|
|
|
- @DeleteMapping("/{ids}")
|
|
|
- public AjaxResult remove(@PathVariable Long[] ids)
|
|
|
- {
|
|
|
+ @DeleteMapping("/{ids}")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
int res = tMeasureRecordService.deleteTMeasureRecordByIds(ids);
|
|
|
return toAjax(res);
|
|
|
}
|
|
|
|
|
|
- public void updateMeasure(String id){
|
|
|
- TMeasureThickness thickness = tMeasureThicknessService.selectTMeasureThicknessById(Long.parseLong(id));
|
|
|
+ public void updateMeasure(String id) {
|
|
|
+ TMeasureThickness thickness = tMeasureThicknessService.selectTMeasureThicknessById(Long.parseLong(id));
|
|
|
TMeasureRecord t = new TMeasureRecord();
|
|
|
t.setMeasureId(id);
|
|
|
List<TMeasureRecord> list = tMeasureRecordService.selectTMeasureRecordList(t);
|
|
@@ -127,40 +120,40 @@ public class TMeasureRecordController extends BaseController
|
|
|
//短期速率
|
|
|
TMeasureRecord r1 = list.get(0);
|
|
|
TMeasureRecord r2 = list.get(1);
|
|
|
- BigDecimal i =new BigDecimal(r2.getMeasureValue()).setScale(4,BigDecimal.ROUND_HALF_DOWN).subtract(new BigDecimal(r1.getMeasureValue()).setScale(4,BigDecimal.ROUND_HALF_DOWN));
|
|
|
- int day = formatDate(r1.getMeasureDate(),r2.getMeasureDate());
|
|
|
+ BigDecimal i = new BigDecimal(r2.getMeasureValue()).setScale(4, BigDecimal.ROUND_HALF_DOWN).subtract(new BigDecimal(r1.getMeasureValue()).setScale(4, BigDecimal.ROUND_HALF_DOWN));
|
|
|
+ int day = formatDate(r1.getMeasureDate(), r2.getMeasureDate());
|
|
|
logger.info(i + "----" + day);
|
|
|
- BigDecimal di = new BigDecimal(day).divide(new BigDecimal(365),4,BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal di = new BigDecimal(day).divide(new BigDecimal(365), 4, BigDecimal.ROUND_HALF_DOWN);
|
|
|
logger.info(di + "----");
|
|
|
- BigDecimal st = i.divide(di,3,BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal st = i.divide(di, 3, BigDecimal.ROUND_HALF_DOWN);
|
|
|
logger.info(st + "----");
|
|
|
thickness.setStCorrosion(String.valueOf(st));
|
|
|
//长期速率
|
|
|
- TMeasureRecord r3 = list.get(list.size()-1);
|
|
|
- BigDecimal i1 = new BigDecimal(r3.getMeasureValue()).setScale(4,BigDecimal.ROUND_HALF_DOWN).subtract(new BigDecimal(r1.getMeasureValue()).setScale(4,BigDecimal.ROUND_HALF_DOWN));
|
|
|
- int day1 = formatDate(r1.getMeasureDate(),r3.getMeasureDate());
|
|
|
+ TMeasureRecord r3 = list.get(list.size() - 1);
|
|
|
+ BigDecimal i1 = new BigDecimal(r3.getMeasureValue()).setScale(4, BigDecimal.ROUND_HALF_DOWN).subtract(new BigDecimal(r1.getMeasureValue()).setScale(4, BigDecimal.ROUND_HALF_DOWN));
|
|
|
+ int day1 = formatDate(r1.getMeasureDate(), r3.getMeasureDate());
|
|
|
logger.info(i1 + "----" + day1);
|
|
|
- BigDecimal di2 = new BigDecimal(day1).divide(new BigDecimal(365),4,BigDecimal.ROUND_HALF_DOWN);
|
|
|
- BigDecimal lt = i1.divide(di2,3,BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal di2 = new BigDecimal(day1).divide(new BigDecimal(365), 4, BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal lt = i1.divide(di2, 3, BigDecimal.ROUND_HALF_DOWN);
|
|
|
logger.info(lt + "----");
|
|
|
thickness.setLtCorrosion(String.valueOf(lt));
|
|
|
//预估寿命
|
|
|
BigDecimal e;
|
|
|
- if (lt.compareTo(st) > 0){
|
|
|
- e =lt;
|
|
|
- }else {
|
|
|
+ if (lt.compareTo(st) > 0) {
|
|
|
+ e = lt;
|
|
|
+ } else {
|
|
|
e = st;
|
|
|
- };
|
|
|
- BigDecimal cc = new BigDecimal(r1.getMeasureValue()).subtract(new BigDecimal(thickness.getThicknessMin()));
|
|
|
+ }
|
|
|
+ BigDecimal cc = new BigDecimal(r1.getMeasureValue()).subtract(new BigDecimal(thickness.getThicknessMin()));
|
|
|
logger.info(cc + "----");
|
|
|
- BigDecimal est = cc.divide(e,2,BigDecimal.ROUND_HALF_DOWN);
|
|
|
+ BigDecimal est = cc.divide(e, 2, BigDecimal.ROUND_HALF_DOWN);
|
|
|
thickness.setEstRemain(String.valueOf(est));
|
|
|
}
|
|
|
}
|
|
|
tMeasureThicknessService.updateTMeasureThickness(thickness);
|
|
|
}
|
|
|
|
|
|
- private int formatDate(Date nowDate, Date sqlDate){
|
|
|
+ private int formatDate(Date nowDate, Date sqlDate) {
|
|
|
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
String newDate = df.format(nowDate);
|
|
|
String sqlDate1 = df.format(sqlDate);
|
|
@@ -170,9 +163,82 @@ public class TMeasureRecordController extends BaseController
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
- Long time = nowDate.getTime();
|
|
|
- Long time2 = sqlDate.getTime();
|
|
|
- int day = (int) ((time - time2) / (24*3600*1000));
|
|
|
+ Long time = nowDate.getTime();
|
|
|
+ Long time2 = sqlDate.getTime();
|
|
|
+ int day = (int) ((time - time2) / (24 * 3600 * 1000));
|
|
|
return day;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入
|
|
|
+ */
|
|
|
+ @Log(title = "定点测厚批量导入更新", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping("/importForUpdate")
|
|
|
+ public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ //获取操作人员ID
|
|
|
+ Long userId = getUserId();
|
|
|
+ //报错行数统计
|
|
|
+ List<Integer> failRow = new ArrayList<Integer>();
|
|
|
+ Workbook workbook = ExcelUtils.getWorkBook(file);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ List<TMeasureRecord> list = new ArrayList<>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+
|
|
|
+ int rowNum = sheet.getPhysicalNumberOfRows();
|
|
|
+ int failNumber = 0;
|
|
|
+ for (int i = 1; i < rowNum; i++) {
|
|
|
+ try {
|
|
|
+ logger.info("读取行数:" + i);
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ int cellNum = row.getPhysicalNumberOfCells();
|
|
|
+ TMeasureRecord entity = new TMeasureRecord();
|
|
|
+ for (int j = 0; j < cellNum; j++) {
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ if (cell == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ logger.info("cellValue:" + cellValue);
|
|
|
+ if (j == 0) {
|
|
|
+ entity.setMeasureId(cellValue);
|
|
|
+ } else if (j == 1) {
|
|
|
+ entity.setMeasureValue(Double.parseDouble(cellValue));
|
|
|
+ } else if (j == 2) {
|
|
|
+ entity.setMeasureDate(sdf.parse(cellValue));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ entity.setCreaterCode(userId);
|
|
|
+ logger.info("entity:" + entity);
|
|
|
+ list.add(entity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ logger.info("e:" + JSON.toJSONString(e));
|
|
|
+ failRow.add(i + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int successNumber = 0;
|
|
|
+ int failNum = 0;
|
|
|
+ for (TMeasureRecord t : list
|
|
|
+ ) {
|
|
|
+ failNum++;
|
|
|
+ try {
|
|
|
+ //保存测厚记录
|
|
|
+ String measureId = t.getMeasureId();
|
|
|
+ Long id = this.tMeasureThicknessService.selectByTagNo(measureId);
|
|
|
+ t.setMeasureId(id + "");
|
|
|
+ this.tMeasureRecordService.insertTMeasureRecord(t);
|
|
|
+ this.updateMeasure(id + "");
|
|
|
+ successNumber++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ logger.info("e:" + e);
|
|
|
+ failRow.add(failNum + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("list:" + JSON.toJSONString(list));
|
|
|
+ logger.info("successNumber:" + String.valueOf(successNumber));
|
|
|
+ logger.info("failNumber:" + String.valueOf(failNumber));
|
|
|
+ logger.info("failRow:" + String.valueOf(failRow));
|
|
|
+ return AjaxResult.success(String.valueOf(successNumber), failRow);
|
|
|
+ }
|
|
|
}
|