|
|
|
@ -7,10 +7,16 @@ import com.xujie.sys.modules.scheduling.entity.SchedulingData; |
|
|
|
import com.xujie.sys.modules.scheduling.entity.SchedulingRecordData; |
|
|
|
import com.xujie.sys.modules.scheduling.mapper.SchedulingMapper; |
|
|
|
import com.xujie.sys.modules.scheduling.service.SchedulingService; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
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.InputStream; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
@ -177,5 +183,90 @@ public class SchedulingServiceImpl implements SchedulingService { |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional |
|
|
|
public R uploadTemplateExcel(MultipartFile file, SchedulingData data) { |
|
|
|
try { |
|
|
|
// 转流 |
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
// 读取工作簿 |
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook(is); |
|
|
|
// 读取工作表 |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0); |
|
|
|
// 获取行数 |
|
|
|
int rows = sheet.getPhysicalNumberOfRows(); |
|
|
|
// 声明对象 |
|
|
|
SchedulingData schedulingData = null; |
|
|
|
//排除标准数据下的空白行数据 |
|
|
|
int nonEmptyRows = 0; |
|
|
|
for (int i = 0; i < rows; i++) { |
|
|
|
XSSFRow row = sheet.getRow(i); |
|
|
|
if (row != null && row.getCell(0) != null && StringUtils.isNotBlank(row.getCell(0).toString())) { |
|
|
|
nonEmptyRows++; |
|
|
|
} |
|
|
|
} |
|
|
|
for (int j = 1; j < nonEmptyRows; j++) { |
|
|
|
// 实例化对象 |
|
|
|
schedulingData = new SchedulingData(); |
|
|
|
// 获得该行 |
|
|
|
XSSFRow row = sheet.getRow(j); |
|
|
|
//截取site和bu |
|
|
|
String[] split = data.getBu().split("_"); |
|
|
|
// 为对象赋值 |
|
|
|
schedulingData.setSite(split[0]); |
|
|
|
schedulingData.setBuNo(split[1]); |
|
|
|
String classesDesc = row.getCell(0).getStringCellValue(); |
|
|
|
if ("白班".equals(classesDesc)) { |
|
|
|
if ("01-Label".equals(split[1])){ |
|
|
|
schedulingData.setClassesCode("A001"); |
|
|
|
} |
|
|
|
if ("02-Hardtag".equals(split[1])){ |
|
|
|
schedulingData.setClassesCode("B001"); |
|
|
|
} |
|
|
|
if ("03-RFID".equals(split[1])){ |
|
|
|
schedulingData.setClassesCode("C001"); |
|
|
|
} |
|
|
|
} else if ("夜班".equals(classesDesc)){ |
|
|
|
if ("01-Label".equals(split[1])){ |
|
|
|
schedulingData.setClassesCode("A002"); |
|
|
|
} |
|
|
|
if ("02-Hardtag".equals(split[1])){ |
|
|
|
schedulingData.setClassesCode("B002"); |
|
|
|
} |
|
|
|
if ("03-RFID".equals(split[1])){ |
|
|
|
schedulingData.setClassesCode("C002"); |
|
|
|
} |
|
|
|
}else { |
|
|
|
throw new RuntimeException("第" + j + "行 班次有误,请检查后重新上传"); |
|
|
|
} |
|
|
|
schedulingData.setDate(row.getCell(1).getDateCellValue()); |
|
|
|
schedulingMapper.saveSchedulingHeader(schedulingData); |
|
|
|
int id = schedulingData.getId(); |
|
|
|
int cells = row.getLastCellNum(); |
|
|
|
int actualCellCount = 0; |
|
|
|
for (int i = 0; i < cells; i++) { |
|
|
|
if (row.getCell(i) != null && StringUtils.isNotBlank(row.getCell(i).toString())) { |
|
|
|
actualCellCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 2; i < actualCellCount; i++) { |
|
|
|
SchedulingRecordData schedulingRecordData = new SchedulingRecordData(); |
|
|
|
schedulingRecordData.setHeadId(id); |
|
|
|
schedulingRecordData.setIsHoliday("N"); |
|
|
|
String adminId = row.getCell(i).getStringCellValue(); |
|
|
|
schedulingRecordData.setAdminId(adminId); |
|
|
|
String username = schedulingMapper.queryUserDisplayName(adminId); |
|
|
|
if (Objects.isNull(username) || username.isEmpty()) { |
|
|
|
throw new RuntimeException("第" + j + "行 第"+(i+1)+"列人员编码不存在,请检查后重新上传"); |
|
|
|
} |
|
|
|
schedulingRecordData.setAdminName(username); |
|
|
|
schedulingMapper.saveSchedulingRecord(schedulingRecordData); |
|
|
|
} |
|
|
|
} |
|
|
|
}catch (Exception e){ |
|
|
|
throw new RuntimeException("上传失败:" + e.getMessage()); |
|
|
|
} |
|
|
|
return R.ok(); |
|
|
|
} |
|
|
|
|
|
|
|
} |