| | |
| | | package com.example.server.progressTrack.service; |
| | | |
| | | import com.example.client.dto.ColumnDto; |
| | | import com.example.client.dto.JComboBoxItem; |
| | | import com.example.client.service.BaseService; |
| | | import com.example.client.utils.UUIDUtil; |
| | | import com.example.server.ExportExcel.dto.ExcelColumnDto; |
| | | import com.example.server.ExportExcel.dto.ExprotExcelDto; |
| | | import com.example.server.ExportExcel.method.ExcelExport; |
| | | import com.example.server.cabin.service.CabinService; |
| | | import com.example.server.progressTrack.Dto.StatistDismantDto; |
| | | import com.example.server.progressTrack.dao.DjJdgzDismantTrackDao; |
| | | import com.example.server.progressTrack.dao.DjJdgzHandoverDao; |
| | | import com.example.server.progressTrack.model.DjJdgzDismantTrack; |
| | | import com.example.server.progressTrack.model.DjJdgzHandover; |
| | | import com.example.server.progressTrack.model.DjJdgzNetworkLevel3; |
| | | import com.example.server.progressTrack.model.DjJdgzTrackRecord; |
| | | import com.example.server.utils.FileUtils; |
| | | import com.example.server.utils.ImportUtil; |
| | | import com.example.server.utils.TreeFieldUtils; |
| | | import com.example.server.utils.UUIDUtil; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.apache.poi.ss.usermodel.Row; |
| | | import org.apache.poi.ss.usermodel.Sheet; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | | import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | /** |
| | | * dj_jdgz_track_record |
| | | * |
| | | * @author zt generator |
| | | * @author zt generator |
| | | * @since 1.0.0 2024-12-17 |
| | | */ |
| | | @Service |
| | | public class DjJdgzDismantTrackService extends BaseService<DjJdgzDismantTrackDao, DjJdgzDismantTrack> { |
| | | @Autowired |
| | | DjJdgzNetworkLevel3Service djJdgzNetworkLevel3Service; |
| | | @Autowired |
| | | CabinService cabinService; |
| | | |
| | | public List<DjJdgzDismantTrack> getList(Long level3Id, Long cabinId) { |
| | | return baseDao.getList(level3Id,cabinId); |
| | | return baseDao.getList(level3Id, cabinId); |
| | | } |
| | | |
| | | public void save(List<DjJdgzDismantTrack> list) { |
| | | for (DjJdgzDismantTrack data : list) { |
| | | if (data.getId() != null) { |
| | | this.update(data); |
| | | } else { |
| | | this.insert(data); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | public String importExcel(String path) { |
| | | String result = "true"; |
| | | Integer sum = 0; // 总共的条数 |
| | | Integer suc = 0; // 成功的条数 |
| | | Integer err = 0; // 失败的条数 |
| | | Map<String, Object> errMap = new HashMap<>(); |
| | | MultipartFile mutFile = null; |
| | | try { |
| | | mutFile = FileUtils.convertFileToMultipartFile(path); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String sheetName = null; |
| | | int row1 = 0; |
| | | try { |
| | | // 获取导入文件的后缀名 |
| | | String fileName = mutFile.getOriginalFilename(); |
| | | Workbook workbook = null; |
| | | //解决excel版本问题 |
| | | if (fileName != null && fileName.endsWith(".xls")) { |
| | | workbook = new HSSFWorkbook(mutFile.getInputStream()); |
| | | } else if (fileName != null && fileName.endsWith(".xlsx")) { |
| | | workbook = new XSSFWorkbook(mutFile.getInputStream()); |
| | | } |
| | | assert workbook != null; //断言如果[boolean表达式]为true,则程序继续执行。 如果为false,则程序抛出AssertionError,并终止执行。 |
| | | |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | int num = sheet.getLastRowNum(); // 一共有多少行 |
| | | sheetName = sheet.getSheetName(); //获取当前sheet名称 |
| | | sum = sum + num; |
| | | |
| | | List<DjJdgzNetworkLevel3> list = djJdgzNetworkLevel3Service.getList(null, null, null, null, null,null,null,null); |
| | | JComboBoxItem[] list1 = cabinService.getList(); |
| | | |
| | | |
| | | Map<String, Long> level3Map = new HashMap<>(); |
| | | Map<String, Long> cabinMap = new HashMap<>(); |
| | | Map<String, Integer> statusMap = new HashMap<>(); |
| | | statusMap.put("进行中",0); |
| | | statusMap.put("已完成",1); |
| | | |
| | | for (DjJdgzNetworkLevel3 level3 : list) { |
| | | level3Map.put(level3.getName(), level3.getId()); |
| | | } |
| | | for (JComboBoxItem item : list1) { |
| | | cabinMap.put(item.getName(), item.getId()); |
| | | } |
| | | |
| | | String curSbName = ""; |
| | | Long curSbId = null; |
| | | |
| | | for (int j = 2; j <= num; j++) { |
| | | DjJdgzDismantTrack data = new DjJdgzDismantTrack(); |
| | | |
| | | boolean isErr = false; |
| | | row1 = j + 1; |
| | | String pattern = "yyyy-MM-dd"; |
| | | Row row = sheet.getRow(j); |
| | | |
| | | String sbName = ImportUtil.getCellValue(row, 0, pattern); |
| | | String name = ImportUtil.getCellValue(row, 1, pattern); |
| | | String cabin = ImportUtil.getCellValue(row, 2, pattern); |
| | | String cxTime = ImportUtil.getCellValue(row, 3, pattern); |
| | | String cxUnit = ImportUtil.getCellValue(row, 4, pattern); |
| | | String cxStaff = ImportUtil.getCellValue(row, 5, pattern); |
| | | String cxAssis = ImportUtil.getCellValue(row, 6, pattern); |
| | | String ccTime = ImportUtil.getCellValue(row, 7, pattern); |
| | | String ccUnit = ImportUtil.getCellValue(row, 8, pattern); |
| | | String ccStaff = ImportUtil.getCellValue(row, 9, pattern); |
| | | String ccAssis = ImportUtil.getCellValue(row, 10, pattern); |
| | | String tzTime = ImportUtil.getCellValue(row, 11, pattern); |
| | | String czr = ImportUtil.getCellValue(row, 12, pattern); |
| | | String tzWeight = ImportUtil.getCellValue(row, 13, pattern); |
| | | String tzAssis = ImportUtil.getCellValue(row, 14, pattern); |
| | | String rkTime = ImportUtil.getCellValue(row, 15, pattern); |
| | | String rkStaff = ImportUtil.getCellValue(row, 16, pattern); |
| | | String local = ImportUtil.getCellValue(row, 17, pattern); |
| | | String statusStr = ImportUtil.getCellValue(row, 18, pattern); |
| | | |
| | | if (StringUtils.isBlank(sbName)) { |
| | | if (StringUtils.isBlank(curSbName)) { |
| | | result = "第" + j + "行" + "设备不能为空"; |
| | | isErr = true; |
| | | } else { |
| | | sbName = curSbName; |
| | | curSbId = level3Map.get(sbName); |
| | | } |
| | | } else { |
| | | if (StringUtils.isBlank(curSbName) || !sbName.equals(curSbName)) { |
| | | curSbName = sbName; |
| | | if (level3Map.get(curSbName) == null) { |
| | | result = "第" + j + "行" + "设备不存在"; |
| | | isErr = true; |
| | | } else { |
| | | curSbId = level3Map.get(curSbName); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Long id = UUIDUtil.generateId(); |
| | | if (StringUtils.isEmpty(name)) { |
| | | result = "第" + j + "行" + "子部件名称不能为空"; |
| | | isErr = true; |
| | | } else { |
| | | data.setId(id); |
| | | data.setName(name); |
| | | data.setLevel3NetworkId(curSbId); |
| | | baseDao.deleteByName(name); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(cabin)) { |
| | | result = "第" + j + "行" + "舱室不能为空"; |
| | | isErr = true; |
| | | } else { |
| | | if (cabinMap.get(cabin) == null) { |
| | | result = "第" + j + "行" + "舱室不存在"; |
| | | isErr = true; |
| | | } else { |
| | | Long cabinId = cabinMap.get(cabin); |
| | | data.setCabinId(cabinId); |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(cxTime)) { |
| | | if (cxTime.matches("[0-9/]+")) { |
| | | cxTime = cxTime.replace("/", "-"); |
| | | data.setDismantTime(cxTime); |
| | | } else if (cxTime.matches("[0-9.]+")) { |
| | | cxTime = cxTime.replace(".", "-"); |
| | | data.setDismantTime(cxTime); |
| | | } else if (cxTime.matches("[0-9-]+")) { |
| | | data.setDismantTime(cxTime); |
| | | } else { |
| | | result = "第" + j + "行" + "拆卸时间日期格式不规范"; |
| | | isErr = true; |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(cxUnit)) { |
| | | data.setDismantUnit(cxUnit); |
| | | } |
| | | if (StringUtils.isNotBlank(cxStaff)) { |
| | | data.setDismantStaff(cxStaff); |
| | | } |
| | | if (StringUtils.isNotBlank(cxAssis)) { |
| | | data.setDismantAssistant(cxAssis); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(ccTime)) { |
| | | if (ccTime.matches("[0-9/]+")) { |
| | | ccTime = ccTime.replace("/", "-"); |
| | | data.setExitTime(ccTime); |
| | | } else if (ccTime.matches("[0-9.]+")) { |
| | | ccTime = ccTime.replace(".", "-"); |
| | | data.setExitTime(ccTime); |
| | | } else if (ccTime.matches("[0-9-]+")) { |
| | | data.setExitTime(ccTime); |
| | | } else { |
| | | result = "第" + j + "行" + "出舱时间日期格式不规范"; |
| | | isErr = true; |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(ccUnit)) { |
| | | data.setExitUnit(ccUnit); |
| | | } |
| | | if (StringUtils.isNotBlank(ccStaff)) { |
| | | data.setExitStaff(ccStaff); |
| | | } |
| | | if (StringUtils.isNotBlank(ccAssis)) { |
| | | data.setExitAssistant(ccAssis); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(tzTime)) { |
| | | if (tzTime.matches("[0-9/]+")) { |
| | | tzTime = tzTime.replace("/", "-"); |
| | | data.setReturnWeightTime(tzTime); |
| | | } else if (tzTime.matches("[0-9.]+")) { |
| | | tzTime = tzTime.replace(".", "-"); |
| | | data.setReturnWeightTime(tzTime); |
| | | } else if (tzTime.matches("[0-9-]+")) { |
| | | data.setReturnWeightTime(tzTime); |
| | | } else { |
| | | result = "第" + j + "行" + "退重时间日期格式不规范"; |
| | | isErr = true; |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(czr)) { |
| | | data.setWeigher(czr); |
| | | } |
| | | if (StringUtils.isNotBlank(tzWeight)) { |
| | | data.setReturnWeight(tzWeight); |
| | | } |
| | | if (StringUtils.isNotBlank(tzAssis)) { |
| | | data.setReturnWeightAssistant(tzAssis); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(rkTime)) { |
| | | if (rkTime.matches("[0-9/]+")) { |
| | | rkTime = rkTime.replace("/", "-"); |
| | | data.setWarehouseTime(rkTime); |
| | | } else if (rkTime.matches("[0-9.]+")) { |
| | | rkTime = rkTime.replace(".", "-"); |
| | | data.setWarehouseTime(rkTime); |
| | | } else if (rkTime.matches("[0-9-]+")) { |
| | | data.setWarehouseTime(rkTime); |
| | | } else { |
| | | result = "第" + j + "行" + "入库时间日期格式不规范"; |
| | | isErr = true; |
| | | } |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(rkStaff)) { |
| | | data.setWarehouseStaff(rkStaff); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(local)) { |
| | | data.setCurrentLocation(local); |
| | | } |
| | | if (StringUtils.isNotBlank(statusStr)) { |
| | | data.setStatus(statusMap.get(statusStr)); |
| | | } |
| | | |
| | | if (!isErr) { |
| | | this.insert(data); |
| | | } |
| | | if (isErr) { |
| | | err++; |
| | | continue; |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | result = "导入" + row1 + "行数据时检测到异常,中断导入操作。"; |
| | | } |
| | | |
| | | suc = sum - err; |
| | | |
| | | return result; |
| | | } |
| | | |
| | | public void exportExcel(String filePath, Long deptId, Long teamGroupId, Long level1NetworkId, Long level3NetworkId, Integer status) { |
| | | List<ExprotExcelDto> dtos = new ArrayList<>(); |
| | | |
| | | Map<Integer, String> statusMap = new HashMap<>(); |
| | | statusMap.put(0, "进行中"); |
| | | statusMap.put(1, "已完成"); |
| | | |
| | | ExprotExcelDto dto = new ExprotExcelDto(); |
| | | dto.setSheetName("拆卸进度明细"); |
| | | List<ExcelColumnDto> columnDto = new ArrayList<>(); |
| | | |
| | | columnDto.add(new ExcelColumnDto("一级节点", "Level1NodeName", 20, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("二级节点", "Level2NodeName", 20, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("设备名称", "Level3NetworkName", 20, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("部门", "deptName", 20, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("专业", "teamGroupName", 20, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("舱室", "cabinName", 10, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("子部件名称", "name", 25, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("拆卸时间", "dismantTime", 15, HorizontalAlignment.CENTER)); |
| | | columnDto.add(new ExcelColumnDto("拆卸单位", "dismantUnit", 25, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("拆卸人员", "dismantStaff", 15, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("拆卸助修T员", "dismantAssistant", 10, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("出舱时间", "exitTime", 10, HorizontalAlignment.CENTER)); |
| | | columnDto.add(new ExcelColumnDto("出舱单位", "exitUnit", 10, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("出舱人员", "exitStaff", 15, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("出舱助修T员", "exitAssistant", 20, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("退重时间", "returnWeightTime", 20, HorizontalAlignment.CENTER)); |
| | | columnDto.add(new ExcelColumnDto("称重员", "weigher", 15, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("退重重量", "returnWeight", 15, HorizontalAlignment.RIGHT)); |
| | | columnDto.add(new ExcelColumnDto("退重助修T员", "returnWeightAssistant", 20, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("入库时间", "warehouseTime", 15, HorizontalAlignment.CENTER)); |
| | | columnDto.add(new ExcelColumnDto("入库人员", "warehouseStaff", 15, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("当前存放位置", "currentLocation", 15, HorizontalAlignment.LEFT)); |
| | | columnDto.add(new ExcelColumnDto("状态", "currStatus", 10, HorizontalAlignment.CENTER)); |
| | | |
| | | List<DjJdgzDismantTrack> list = baseDao.getdata(deptId,teamGroupId, level1NetworkId, level3NetworkId, status); |
| | | |
| | | for (int i = 0; i < list.size(); i++) { |
| | | DjJdgzDismantTrack data = list.get(i); |
| | | |
| | | if (data.getStatus() != null) { |
| | | data.setCurrStatus(statusMap.get(data.getStatus())); |
| | | } |
| | | } |
| | | String[] filed = {"Level1NodeName", "Level2NodeName", "Level3NetworkName"}; |
| | | TreeFieldUtils.build(list, filed); |
| | | dto.setColumnDto(columnDto); |
| | | //dto.setValues(content); |
| | | dto.setDataList(list); |
| | | |
| | | |
| | | /* ExprotExcelDto dto2 = new ExprotExcelDto(); |
| | | dto2.setSheetName("节点汇总"); |
| | | List<ExcelColumnDto> columnDto2 = new ArrayList<>(); |
| | | List<DjJdgzTrackRecord> list2 = baseDao.getSummaryData(teamgroupId, level1NetworkId, level3NetworkId, level3NodeId, status, beginDate, endDate, istq); |
| | | |
| | | |
| | | columnDto2.add(new ExcelColumnDto("一级节点", "Level1NodeName", 25, HorizontalAlignment.LEFT)); |
| | | columnDto2.add(new ExcelColumnDto("二级节点", "Level2NodeName", 25, HorizontalAlignment.LEFT)); |
| | | columnDto2.add(new ExcelColumnDto("三级网络名称\n" + "(设备名称)", "Level3NetworkName", 25, HorizontalAlignment.LEFT)); |
| | | columnDto2.add(new ExcelColumnDto("三级节点", "Level3NodeName", 15, HorizontalAlignment.LEFT)); |
| | | columnDto2.add(new ExcelColumnDto("计划\n" + "完成时间", "RequiredCompletionTime", 12, HorizontalAlignment.CENTER)); |
| | | columnDto2.add(new ExcelColumnDto("是否脱期", "Istq", 5, HorizontalAlignment.CENTER)); |
| | | columnDto2.add(new ExcelColumnDto("脱期次数", "Tqcs", 5, HorizontalAlignment.RIGHT)); |
| | | columnDto2.add(new ExcelColumnDto("最大预计\n" + "完成时间", "Maxtime", 12, HorizontalAlignment.CENTER)); |
| | | columnDto2.add(new ExcelColumnDto("最大脱期天数", "MaxDay", 10, HorizontalAlignment.RIGHT)); |
| | | columnDto2.add(new ExcelColumnDto("最新预计\n" + "完成时间", "Zxtime", 12, HorizontalAlignment.CENTER)); |
| | | columnDto2.add(new ExcelColumnDto("最新脱期天数", "ZxDay", 10, HorizontalAlignment.RIGHT)); |
| | | |
| | | TreeFieldUtils.build(list2, filed); |
| | | dto2.setColumnDto(columnDto2); |
| | | //dto2.setValues(content2); |
| | | dto2.setDataList(list2);*/ |
| | | |
| | | dtos.add(dto); |
| | | //dtos.add(dto2); |
| | | try { |
| | | ExcelExport.getHSSFWorkbook(filePath, dtos); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public List<StatistDismantDto> getStatist(Long level1Id) { |
| | | return baseDao.getStatist(level1Id); |
| | | } |
| | | |
| | | public Boolean getStatus(Long level3NetworkId) { |
| | | return baseDao.getStatus(level3NetworkId); |
| | | } |
| | | |
| | | public void delete(Long id) { |
| | | baseDao.deleteById(id); |
| | | } |
| | | |
| | | public List<StatistDismantDto> getStatist2(Long level1Id, Long id) { |
| | | return baseDao.getStatist2(level1Id,id); |
| | | } |
| | | } |