|
@@ -0,0 +1,223 @@
|
|
|
+package com.rongwei.bscommon.sys.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.rongwei.bscommon.sys.dao.EquFrockTestRecordDao;
|
|
|
+import com.rongwei.bscommon.sys.service.EquFrockTestRecordService;
|
|
|
+import com.rongwei.bscommon.sys.utils.CommonUtils;
|
|
|
+import com.rongwei.bscommon.sys.utils.DateUtils;
|
|
|
+import com.rongwei.bscommon.sys.utils.ExcelUtils;
|
|
|
+import com.rongwei.bscommon.sys.utils.StringUtil;
|
|
|
+import com.rongwei.bsentity.domain.EquFrockListDo;
|
|
|
+import com.rongwei.bsentity.domain.EquFrockTestRecordDo;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
+import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class EquFrockTestRecordServiceImpl extends ServiceImpl<EquFrockTestRecordDao, EquFrockTestRecordDo> implements EquFrockTestRecordService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquFrockTestRecordDao equFrockTestRecordDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EquFrockTestRecordService equFrockTestRecordService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public R importEquFrockTestRecord(MultipartFile file) {
|
|
|
+ StringBuilder allStrBuilder = new StringBuilder();
|
|
|
+ List<EquFrockTestRecordDo> equFrockTestRecordDos = new ArrayList<>();
|
|
|
+ try {
|
|
|
+ Sheet sheet = new XSSFWorkbook(file.getInputStream()).getSheetAt(0);
|
|
|
+ int lastRowNum = sheet.getLastRowNum();
|
|
|
+
|
|
|
+ //获取系统所有的工装编号
|
|
|
+ List<EquFrockListDo> equFrockListDoList = equFrockTestRecordDao.getAllFrocknum();
|
|
|
+
|
|
|
+ //获取已检测的工装编号
|
|
|
+ List<EquFrockTestRecordDo> equFrockTestRecordDoList = equFrockTestRecordDao.getFrockRecord();
|
|
|
+
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SysUserVo currentUser = CommonUtils.getCurrentUser();
|
|
|
+ Date date = new Date();
|
|
|
+
|
|
|
+ for (int i = 2; i <= lastRowNum; i++) {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ EquFrockTestRecordDo equFrockTestRecordDo = new EquFrockTestRecordDo();
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ if (ExcelUtils.isRowEmpty(row)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String ownedfactory = row.getCell(1) == null ? "" : row.getCell(1).toString().trim();
|
|
|
+ String frockname = row.getCell(2) == null ? "" : row.getCell(2).toString().trim();
|
|
|
+ String usedept = row.getCell(3) == null ? "" : row.getCell(3).toString().trim();
|
|
|
+ String frocknum = row.getCell(4) == null ? "" : row.getCell(4).toString().trim();
|
|
|
+ String belongequname = row.getCell(5) == null ? "" : row.getCell(5).toString().trim();
|
|
|
+ String exctestdate = row.getCell(6) == null ? "" : String.valueOf(DateUtils.importExcelFormatExcel((XSSFCell) row.getCell(6)));
|
|
|
+ String diameter = row.getCell(7) == null ? "" : row.getCell(7).toString().trim();
|
|
|
+ String hs1 = row.getCell(8) == null ? "" : row.getCell(8).toString().trim();
|
|
|
+ String hs2 = row.getCell(9) == null ? "" : row.getCell(9).toString().trim();
|
|
|
+ String hs3 = row.getCell(10) == null ? "" : row.getCell(10).toString().trim();
|
|
|
+ String hs4 = row.getCell(11) == null ? "" : row.getCell(11).toString().trim();
|
|
|
+ String hs5 = row.getCell(12) == null ? "" : row.getCell(12).toString().trim();
|
|
|
+ String hs6 = row.getCell(13) == null ? "" : row.getCell(13).toString().trim();
|
|
|
+ String hs7 = row.getCell(14) == null ? "" : row.getCell(14).toString().trim();
|
|
|
+ String hs8 = row.getCell(15) == null ? "" : row.getCell(15).toString().trim();
|
|
|
+ String hs9 = row.getCell(16) == null ? "" : row.getCell(16).toString().trim();
|
|
|
+ String state = row.getCell(17) == null ? "" : row.getCell(17).toString().trim();
|
|
|
+ String remark = row.getCell(18) == null ? "" : row.getCell(18).toString().trim();
|
|
|
+ if (StringUtils.isBlank(ownedfactory)) {
|
|
|
+ stringBuilder.append("所属工厂不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(frockname)) {
|
|
|
+ stringBuilder.append("工装名称不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(usedept)) {
|
|
|
+ stringBuilder.append("使用车间不能为空 ");
|
|
|
+ }
|
|
|
+ String testdate = "";
|
|
|
+ if (StringUtils.isBlank(exctestdate)) {
|
|
|
+ stringBuilder.append("检定日期不能为空 ");
|
|
|
+ } else {
|
|
|
+ testdate = dateFormat.format(DateUtils.importExcelFormatExcel((XSSFCell) row.getCell(6))).split(" ")[0];
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(frocknum)) {
|
|
|
+ stringBuilder.append("工装编号不能为空 ");
|
|
|
+ } else {
|
|
|
+ if (equFrockListDoList.stream().anyMatch(item -> item.getFrocknum().equals(frocknum))) {
|
|
|
+ if (equFrockTestRecordDoList.stream().anyMatch(item -> item.getFrocknum().equals(frocknum) && item.getTestdate().toString().equals(exctestdate))) {
|
|
|
+ stringBuilder.append(frockname + "(" + frocknum + ")已存在" + testdate + "的检测记录,不可重复导入 ");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("工装编号" + frocknum + "在系统中不存在 ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(belongequname)) {
|
|
|
+ stringBuilder.append("工装所属不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(state)) {
|
|
|
+ stringBuilder.append("状态不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(diameter)) {
|
|
|
+ diameter = StringUtil.formatDecimal(diameter);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("直径mm不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs1)) {
|
|
|
+ hs1 = StringUtil.formatDecimal(hs1);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS1)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs2)) {
|
|
|
+ hs2 = StringUtil.formatDecimal(hs2);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS2)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs3)) {
|
|
|
+ hs3 = StringUtil.formatDecimal(hs3);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS3)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs4)) {
|
|
|
+ hs4 = StringUtil.formatDecimal(hs4);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS4)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs5)) {
|
|
|
+ hs5 = StringUtil.formatDecimal(hs5);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS5)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs6)) {
|
|
|
+ hs6 = StringUtil.formatDecimal(hs6);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS6)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs7)) {
|
|
|
+ hs7 = StringUtil.formatDecimal(hs7);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS7)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs8)) {
|
|
|
+ hs8 = StringUtil.formatDecimal(hs8);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS8)不能为空 ");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(hs9)) {
|
|
|
+ hs9 = StringUtil.formatDecimal(hs9);
|
|
|
+ } else {
|
|
|
+ stringBuilder.append("检测硬度值(HS9)不能为空 ");
|
|
|
+ }
|
|
|
+ if (equFrockTestRecordDos.stream().anyMatch(item -> item.getFrocknum().equals(frocknum) && item.getTestdate().toString().equals(exctestdate))) {
|
|
|
+ stringBuilder.append("工装编号" + frocknum + "、检定日期" + testdate + "数据重复");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.isNotBlank(stringBuilder)) {
|
|
|
+ allStrBuilder.append("第").append(i + 1).append("行").append(stringBuilder).append("<br>");
|
|
|
+ } else {
|
|
|
+ equFrockTestRecordDo.setId(SecurityUtil.getUUID())
|
|
|
+ .setTenantid(currentUser.getOrganizationDoList().get(0).getFullpid().split(",")[1])
|
|
|
+ .setCreatedate(date)
|
|
|
+ .setModifydate(date)
|
|
|
+ .setCreateusername(currentUser.getName())
|
|
|
+ .setCreateuserid(currentUser.getId())
|
|
|
+ .setModifyusername(currentUser.getName())
|
|
|
+ .setModifyuserid(currentUser.getId())
|
|
|
+ .setOwnedfactory(ownedfactory)
|
|
|
+ .setFrockname(frockname)
|
|
|
+ .setUsedept(usedept)
|
|
|
+ .setFrocknum(frocknum)
|
|
|
+ .setBelongequname(belongequname)
|
|
|
+ .setTestdate(dateFormat.parse(testdate + " 00:00:00"))
|
|
|
+ .setDiameter(new BigDecimal(diameter))
|
|
|
+ .setHs1(BigDecimal.valueOf(Double.parseDouble(hs1)))
|
|
|
+ .setHs2(BigDecimal.valueOf(Double.parseDouble(hs2)))
|
|
|
+ .setHs3(BigDecimal.valueOf(Double.parseDouble(hs3)))
|
|
|
+ .setHs4(BigDecimal.valueOf(Double.parseDouble(hs4)))
|
|
|
+ .setHs5(BigDecimal.valueOf(Double.parseDouble(hs5)))
|
|
|
+ .setHs6(BigDecimal.valueOf(Double.parseDouble(hs6)))
|
|
|
+ .setHs7(BigDecimal.valueOf(Double.parseDouble(hs7)))
|
|
|
+ .setHs8(BigDecimal.valueOf(Double.parseDouble(hs8)))
|
|
|
+ .setHs9(BigDecimal.valueOf(Double.parseDouble(hs9)))
|
|
|
+ .setState(state)
|
|
|
+ .setRemark(remark);
|
|
|
+ equFrockTestRecordDos.add(equFrockTestRecordDo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException | ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ String errMsg = allStrBuilder.toString();
|
|
|
+ if (StringUtils.isNotBlank(errMsg)) {
|
|
|
+ return R.error(errMsg);
|
|
|
+ } else {
|
|
|
+ if (equFrockTestRecordDos.size() > 0) {
|
|
|
+ if (equFrockTestRecordService.saveOrUpdateBatch(equFrockTestRecordDos)) {
|
|
|
+ return R.ok();
|
|
|
+ } else {
|
|
|
+ return R.error("上传失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.ok("没有可上传的数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|