|
|
|
@ -25,6 +25,8 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springblade.scheduling.scheduling.controller; |
|
|
|
package org.springblade.scheduling.scheduling.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
|
|
|
@ -34,6 +36,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import jakarta.validation.Valid; |
|
|
|
import jakarta.validation.Valid; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springblade.core.boot.ctrl.BladeController; |
|
|
|
import org.springblade.core.boot.ctrl.BladeController; |
|
|
|
import org.springblade.core.excel.util.ExcelUtil; |
|
|
|
import org.springblade.core.excel.util.ExcelUtil; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
import org.springblade.core.mp.support.Condition; |
|
|
|
@ -43,20 +46,25 @@ import org.springblade.core.secure.annotation.IsAdmin; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
import org.springblade.core.tool.utils.DateUtil; |
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
import org.springblade.desk.basic.pojo.entity.OemCraftAbilityEntity; |
|
|
|
import org.springblade.desk.basic.constant.ExcelConst; |
|
|
|
import org.springblade.desk.basic.pojo.entity.WorkCenter; |
|
|
|
|
|
|
|
import org.springblade.scheduling.pojo.entity.CraftAbilityEntity; |
|
|
|
|
|
|
|
import org.springblade.scheduling.pojo.entity.QualityGradeEntity; |
|
|
|
import org.springblade.scheduling.pojo.entity.QualityGradeEntity; |
|
|
|
import org.springblade.scheduling.scheduling.excel.QualityGradeExcel; |
|
|
|
import org.springblade.scheduling.scheduling.excel.QualityGradeExcel; |
|
|
|
import org.springblade.scheduling.scheduling.service.IQualityGradeService; |
|
|
|
import org.springblade.scheduling.scheduling.service.IQualityGradeService; |
|
|
|
import org.springblade.scheduling.scheduling.vo.QualityGradeVO; |
|
|
|
import org.springblade.scheduling.scheduling.vo.QualityGradeVO; |
|
|
|
import org.springblade.scheduling.scheduling.wrapper.QualityGradeWrapper; |
|
|
|
import org.springblade.scheduling.scheduling.wrapper.QualityGradeWrapper; |
|
|
|
|
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
|
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
|
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.net.URLEncoder; |
|
|
|
import java.util.List; |
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -292,4 +300,105 @@ public class QualityGradeController extends BladeController { |
|
|
|
return R.data(list); |
|
|
|
return R.data(list); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@PostMapping("/importExcel") |
|
|
|
|
|
|
|
@ApiOperationSupport(order = 72) |
|
|
|
|
|
|
|
@Operation(summary = "导入Excel", description = "MultipartFile") |
|
|
|
|
|
|
|
public R importExcel(@RequestParam("file") MultipartFile file) { |
|
|
|
|
|
|
|
importExcelCheck(file); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<QualityGradeEntity> list = ExcelUtil.read(file, QualityGradeEntity.class); |
|
|
|
|
|
|
|
if (CollUtil.isEmpty(list)){ |
|
|
|
|
|
|
|
return R.fail("导入数据为空"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
list.forEach(s -> { |
|
|
|
|
|
|
|
String type = s.getType(); |
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(type)) { |
|
|
|
|
|
|
|
List<String> typeCodes = new ArrayList<>(); |
|
|
|
|
|
|
|
List<String> typeNames = new ArrayList<>(); |
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : QualityGradeEntity.typeMap.entrySet()) { |
|
|
|
|
|
|
|
if (type.contains(entry.getValue())) { |
|
|
|
|
|
|
|
typeCodes.add(entry.getKey()); |
|
|
|
|
|
|
|
typeNames.add(entry.getValue()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!typeCodes.isEmpty()) { |
|
|
|
|
|
|
|
s.setType(String.join(",", typeCodes)); |
|
|
|
|
|
|
|
s.setTypeNames(String.join(",", typeNames)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// isLocal
|
|
|
|
|
|
|
|
String isLocal = s.getIsLocal(); |
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(isLocal)) { |
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : QualityGradeEntity.isLocalMap.entrySet()) { |
|
|
|
|
|
|
|
if (entry.getValue().equals(isLocal)) { |
|
|
|
|
|
|
|
s.setIsLocal(entry.getKey()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// isThickness
|
|
|
|
|
|
|
|
String isThickness = s.getIsThickness(); |
|
|
|
|
|
|
|
if (StrUtil.isNotEmpty(isThickness)) { |
|
|
|
|
|
|
|
for (Map.Entry<String, String> entry : QualityGradeEntity.isThicknessMap.entrySet()) { |
|
|
|
|
|
|
|
if (entry.getValue().equals(isThickness)) { |
|
|
|
|
|
|
|
s.setIsThickness(entry.getKey()); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return R.data(qualityGradeService.saveBatch(list)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public static R importExcelCheck(MultipartFile file) { |
|
|
|
|
|
|
|
if (file.isEmpty()) { |
|
|
|
|
|
|
|
return R.fail("请上传文件"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String fileName = file.getOriginalFilename(); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(fileName)) { |
|
|
|
|
|
|
|
return R.fail("文件名为空"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (!StringUtils.endsWith(fileName, ExcelConst.EXT_XLS) && |
|
|
|
|
|
|
|
!StringUtils.endsWith(fileName, ExcelConst.EXT_XLSX)) { |
|
|
|
|
|
|
|
return R.fail("格式不正确"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 下载模板 |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@IsAdmin |
|
|
|
|
|
|
|
@GetMapping("/downloadTemplate") |
|
|
|
|
|
|
|
@ApiOperationSupport(order = 9) |
|
|
|
|
|
|
|
@Operation(summary = "导出模板", description = "导出模板") |
|
|
|
|
|
|
|
public ResponseEntity<org.springframework.core.io.Resource> exportQualityGrade(HttpServletResponse response) { |
|
|
|
|
|
|
|
return downloadXlsTemplate( |
|
|
|
|
|
|
|
"Excel/质量等级表数据导入模板.xlsx", |
|
|
|
|
|
|
|
"导入模版-质量等级表数据.xlsx"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static ResponseEntity<Resource> downloadXlsTemplate(String path, String downloadFileName) { |
|
|
|
|
|
|
|
if (StringUtils.isAnyBlank(path, downloadFileName)) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("path or downloadFileName is null"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 读取resource下的Excel文件,路径从resource根目录开始。
|
|
|
|
|
|
|
|
org.springframework.core.io.Resource resource = new ClassPathResource(path); |
|
|
|
|
|
|
|
// 检查文件是否存在。
|
|
|
|
|
|
|
|
if (!resource.exists()) { |
|
|
|
|
|
|
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 构建响应头。
|
|
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
|
|
// 文件名编码,解决中文乱码问题。
|
|
|
|
|
|
|
|
String encodedFileName = URLEncoder.encode(downloadFileName, StandardCharsets.UTF_8) |
|
|
|
|
|
|
|
.replaceAll("\\+", "%20"); |
|
|
|
|
|
|
|
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedFileName + "\""); |
|
|
|
|
|
|
|
// 返回文件流
|
|
|
|
|
|
|
|
return ResponseEntity.ok() |
|
|
|
|
|
|
|
.headers(headers) |
|
|
|
|
|
|
|
.contentType(MediaType.parseMediaType(ExcelConst.CONTENT_TYPE_XLSX)) |
|
|
|
|
|
|
|
.body(resource); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|