|
|
@@ -0,0 +1,528 @@
|
|
|
+package com.qlm.service.impl;
|
|
|
+
|
|
|
+import com.jfinal.kit.StrKit;
|
|
|
+import com.jfinal.plugin.activerecord.Db;
|
|
|
+import com.jfinal.plugin.activerecord.Page;
|
|
|
+import com.jfinal.plugin.activerecord.Record;
|
|
|
+import com.qlm.common.ApiResponse;
|
|
|
+import com.qlm.common.PageResult;
|
|
|
+import com.qlm.dto.LineProductDto;
|
|
|
+import com.qlm.dto.LineProductImportDto;
|
|
|
+import com.qlm.service.ILineProductService;
|
|
|
+import com.qlm.tools.EasyExcelUtil;
|
|
|
+import com.qlm.tools.WxUtil;
|
|
|
+import com.qlm.oss.OssUtil;
|
|
|
+import com.jfinal.upload.UploadFile;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 产线产品关联服务实现类
|
|
|
+ */
|
|
|
+public class LineProductServiceImpl implements ILineProductService {
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(LineProductServiceImpl.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse saveLineProduct(LineProductDto lineProductDto) {
|
|
|
+ try {
|
|
|
+ // 数据验证
|
|
|
+ if (lineProductDto.getFactoryId() == null) {
|
|
|
+ return ApiResponse.error("工厂ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineProductDto.getWorkshopId() == null) {
|
|
|
+ return ApiResponse.error("车间ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineProductDto.getLineId() == null) {
|
|
|
+ return ApiResponse.error("产线ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineProductDto.getProductId() == null) {
|
|
|
+ return ApiResponse.error("产品ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查关联是否已存在
|
|
|
+ Record existRecord = Db.findFirst("select 1 from t_line_product where line_id = ? and product_id = ?",
|
|
|
+ lineProductDto.getLineId(), lineProductDto.getProductId());
|
|
|
+ if (existRecord != null) {
|
|
|
+ return ApiResponse.error("该产线与产品的关联已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取工厂名称
|
|
|
+ Record factory = Db.findById("t_factory", lineProductDto.getFactoryId());
|
|
|
+ if (factory == null) {
|
|
|
+ return ApiResponse.error("未找到指定的工厂信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取车间名称
|
|
|
+ Record workshop = Db.findById("t_workshop", lineProductDto.getWorkshopId());
|
|
|
+ if (workshop == null) {
|
|
|
+ return ApiResponse.error("未找到指定的车间信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取产线名称
|
|
|
+ Record line = Db.findById("t_production_line", lineProductDto.getLineId());
|
|
|
+ if (line == null) {
|
|
|
+ return ApiResponse.error("未找到指定的产线信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取产品名称
|
|
|
+ Record product = Db.findById("t_jz_product", lineProductDto.getProductId());
|
|
|
+ if (product == null) {
|
|
|
+ return ApiResponse.error("未找到指定的产品信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存数据
|
|
|
+ Record record = new Record();
|
|
|
+ record.set("factory_id", lineProductDto.getFactoryId());
|
|
|
+ record.set("factory_name", factory.getStr("factory_name"));
|
|
|
+ record.set("workshop_id", lineProductDto.getWorkshopId());
|
|
|
+ record.set("workshop_name", workshop.getStr("workshop_name"));
|
|
|
+ record.set("line_id", lineProductDto.getLineId());
|
|
|
+ record.set("line_name", line.getStr("line_name"));
|
|
|
+ record.set("product_id", lineProductDto.getProductId());
|
|
|
+ record.set("product_name", product.getStr("product_name"));
|
|
|
+ record.set("operator", lineProductDto.getOperator());
|
|
|
+
|
|
|
+ boolean result = Db.save("t_line_product", record);
|
|
|
+ if (result) {
|
|
|
+ return ApiResponse.success("保存成功");
|
|
|
+ } else {
|
|
|
+ return ApiResponse.error("保存失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("保存产线产品关联信息异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse deleteLineProduct(Integer id) {
|
|
|
+ try {
|
|
|
+ // 删除数据
|
|
|
+ int result = Db.update("delete from t_line_product where id = ?", id);
|
|
|
+ if (result > 0) {
|
|
|
+ return ApiResponse.success("删除成功");
|
|
|
+ } else {
|
|
|
+ return ApiResponse.error("删除失败或未找到该关联记录");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("删除产线产品关联信息异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse getLineProductById(Integer id) {
|
|
|
+ try {
|
|
|
+ String sql = "select * from t_line_product where id = ?";
|
|
|
+ Record record = Db.findFirst(sql, id);
|
|
|
+ if (record == null) {
|
|
|
+ return ApiResponse.error("未找到该产线产品关联信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ LineProductDto lineProductDto = convertRecordToDto(record);
|
|
|
+ return ApiResponse.success(lineProductDto);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("获取产线产品关联信息异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public PageResult<LineProductDto> listLineProduct(int pageNumber, int pageSize, Long factoryId, Long workshopId, Long lineId, Long productId) {
|
|
|
+ try {
|
|
|
+ // 构建查询条件
|
|
|
+ StringBuilder sqlWhere = new StringBuilder(" from t_line_product where 1=1 ");
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+
|
|
|
+ if (factoryId != null) {
|
|
|
+ sqlWhere.append(" and factory_id = ? ");
|
|
|
+ params.add(factoryId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (workshopId != null) {
|
|
|
+ sqlWhere.append(" and workshop_id = ? ");
|
|
|
+ params.add(workshopId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineId != null) {
|
|
|
+ sqlWhere.append(" and line_id = ? ");
|
|
|
+ params.add(lineId);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (productId != null) {
|
|
|
+ sqlWhere.append(" and product_id = ? ");
|
|
|
+ params.add(productId);
|
|
|
+ }
|
|
|
+
|
|
|
+ sqlWhere.append(" order by created_time desc ");
|
|
|
+
|
|
|
+ // 执行分页查询
|
|
|
+ Page<Record> recordPage = Db.paginate(pageNumber, pageSize,
|
|
|
+ "select * ",
|
|
|
+ sqlWhere.toString(),
|
|
|
+ params.toArray());
|
|
|
+
|
|
|
+ if (recordPage == null) {
|
|
|
+ return new PageResult<>(0, pageNumber, pageSize, new ArrayList<>());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 转换为Dto对象
|
|
|
+ List<LineProductDto> lineProductDtoList = new ArrayList<>();
|
|
|
+ for (Record record : recordPage.getList()) {
|
|
|
+ lineProductDtoList.add(convertRecordToDto(record));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建新的Page对象,包含Dto列表
|
|
|
+ return new PageResult<>(recordPage.getTotalRow(),
|
|
|
+ recordPage.getPageNumber(),
|
|
|
+ recordPage.getPageSize(),
|
|
|
+ lineProductDtoList);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("查询产线产品关联列表异常:", e);
|
|
|
+ return new PageResult<>(0, pageNumber, pageSize, new ArrayList<>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse getAllFactories(String keyword) {
|
|
|
+ try {
|
|
|
+ StringBuilder sql = new StringBuilder("select id, factory_name from t_factory where status = 1 ");
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+
|
|
|
+ if (StrKit.notBlank(keyword)) {
|
|
|
+ sql.append(" and factory_name like ? ");
|
|
|
+ params.add("%" + keyword + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ sql.append(" order by factory_name asc ");
|
|
|
+ List<Record> records = Db.find(sql.toString(), params.toArray());
|
|
|
+ return ApiResponse.success(records);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("获取工厂列表异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse getWorkshopsByFactoryId(Long factoryId) {
|
|
|
+ try {
|
|
|
+ StringBuilder sql = new StringBuilder("select id, workshop_name from t_workshop where status = 1");
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+ if (factoryId != null) {
|
|
|
+ sql.append(" and factory_id = ? ");
|
|
|
+ params.add(factoryId);
|
|
|
+ }
|
|
|
+ List<Record> records = Db.find(sql.toString(), params.toArray());
|
|
|
+ return ApiResponse.success(records);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("根据工厂ID获取车间列表异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse getLinesByWorkshopId(Long workshopId) {
|
|
|
+ try {
|
|
|
+ StringBuilder sql = new StringBuilder("select id, line_name as lineName from t_production_line where status = 1");
|
|
|
+ List<Object>params = new ArrayList<>();
|
|
|
+ if(workshopId != null){
|
|
|
+ sql.append(" and workshop_id = ? ");
|
|
|
+ params.add(workshopId);
|
|
|
+ }
|
|
|
+ List<Record> records = Db.find(sql.toString(), params.toArray());
|
|
|
+ return ApiResponse.success(records);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("根据车间ID获取产线列表异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse getAllProducts(String keyword) {
|
|
|
+ try {
|
|
|
+ StringBuilder sql = new StringBuilder("select id, product_name from t_jz_product where status = 1 ");
|
|
|
+ List<Object> params = new ArrayList<>();
|
|
|
+
|
|
|
+ if (StrKit.notBlank(keyword)) {
|
|
|
+ sql.append(" and product_name like ? ");
|
|
|
+ params.add("%" + keyword + "%");
|
|
|
+ }
|
|
|
+
|
|
|
+ sql.append(" order by product_name asc ");
|
|
|
+ List<Record> records = Db.find(sql.toString(), params.toArray());
|
|
|
+ return ApiResponse.success(records);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("获取产品列表异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将Record转换为LineProductDto的工具方法
|
|
|
+ * @param record
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private LineProductDto convertRecordToDto(Record record) {
|
|
|
+ LineProductDto dto = new LineProductDto();
|
|
|
+ dto.setId(WxUtil.getInt("id",record).longValue());
|
|
|
+ dto.setFactoryId(WxUtil.getInt("factory_id", record).longValue());
|
|
|
+ dto.setFactoryName(record.getStr("factory_name"));
|
|
|
+ dto.setWorkshopId(WxUtil.getInt("workshop_id", record).longValue());
|
|
|
+ dto.setWorkshopName(record.getStr("workshop_name"));
|
|
|
+ dto.setLineId(WxUtil.getInt("line_id", record).longValue());
|
|
|
+ dto.setLineName(record.getStr("line_name"));
|
|
|
+ dto.setProductId(WxUtil.getInt("product_id", record).longValue());
|
|
|
+ dto.setProductName(record.getStr("product_name"));
|
|
|
+ dto.setCreatedTime(record.getDate("created_time"));
|
|
|
+ dto.setUpdatedTime(record.getDate("updated_time"));
|
|
|
+ dto.setOperator(record.getStr("operator"));
|
|
|
+ return dto;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse updateLineProduct(LineProductDto lineProductDto) {
|
|
|
+ try {
|
|
|
+ // 数据验证
|
|
|
+ if (lineProductDto.getId() == null) {
|
|
|
+ return ApiResponse.error("ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineProductDto.getFactoryId() == null) {
|
|
|
+ return ApiResponse.error("工厂ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineProductDto.getWorkshopId() == null) {
|
|
|
+ return ApiResponse.error("车间ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineProductDto.getLineId() == null) {
|
|
|
+ return ApiResponse.error("产线ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (lineProductDto.getProductId() == null) {
|
|
|
+ return ApiResponse.error("产品ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查记录是否存在
|
|
|
+ Record existRecord = Db.findById("t_line_product", lineProductDto.getId());
|
|
|
+ if (existRecord == null) {
|
|
|
+ return ApiResponse.error("未找到该产线产品关联记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查关联是否已存在(排除当前记录)
|
|
|
+ Record duplicateRecord = Db.findFirst(
|
|
|
+ "select 1 from t_line_product where line_id = ? and product_id = ? and id != ?",
|
|
|
+ lineProductDto.getLineId(), lineProductDto.getProductId(), lineProductDto.getId());
|
|
|
+ if (duplicateRecord != null) {
|
|
|
+ return ApiResponse.error("该产线与产品的关联已存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取工厂名称
|
|
|
+ Record factory = Db.findById("t_factory", lineProductDto.getFactoryId());
|
|
|
+ if (factory == null) {
|
|
|
+ return ApiResponse.error("未找到指定的工厂信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取车间名称
|
|
|
+ Record workshop = Db.findById("t_workshop", lineProductDto.getWorkshopId());
|
|
|
+ if (workshop == null) {
|
|
|
+ return ApiResponse.error("未找到指定的车间信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取产线名称
|
|
|
+ Record line = Db.findById("t_production_line", lineProductDto.getLineId());
|
|
|
+ if (line == null) {
|
|
|
+ return ApiResponse.error("未找到指定的产线信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取产品名称
|
|
|
+ Record product = Db.findById("t_jz_product", lineProductDto.getProductId());
|
|
|
+ if (product == null) {
|
|
|
+ return ApiResponse.error("未找到指定的产品信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新数据
|
|
|
+ Record record = new Record();
|
|
|
+ record.set("id", lineProductDto.getId());
|
|
|
+ record.set("factory_id", lineProductDto.getFactoryId());
|
|
|
+ record.set("factory_name", factory.getStr("factory_name"));
|
|
|
+ record.set("workshop_id", lineProductDto.getWorkshopId());
|
|
|
+ record.set("workshop_name", workshop.getStr("workshop_name"));
|
|
|
+ record.set("line_id", lineProductDto.getLineId());
|
|
|
+ record.set("line_name", line.getStr("line_name"));
|
|
|
+ record.set("product_id", lineProductDto.getProductId());
|
|
|
+ record.set("product_name", product.getStr("product_name"));
|
|
|
+ record.set("operator", lineProductDto.getOperator());
|
|
|
+ record.set("updated_time", new java.util.Date());
|
|
|
+
|
|
|
+ boolean result = Db.update("t_line_product", record);
|
|
|
+ if (result) {
|
|
|
+ return ApiResponse.success("更新成功");
|
|
|
+ } else {
|
|
|
+ return ApiResponse.error("更新失败");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("修改产线产品关联信息异常:", e);
|
|
|
+ return ApiResponse.error("系统异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ApiResponse importLineProduct(List<LineProductImportDto> importList, String operator) {
|
|
|
+ List<LineProductImportDto> errorList = new ArrayList<>();
|
|
|
+ int successCount = 0;
|
|
|
+ ApiResponse response = ApiResponse.success();
|
|
|
+ Record record = new Record();
|
|
|
+ record.set("successCount", successCount);
|
|
|
+ record.set("errorCount", 0);
|
|
|
+ for (LineProductImportDto importDto : importList) {
|
|
|
+ try {
|
|
|
+ // 验证必填字段
|
|
|
+ if (StrKit.isBlank(importDto.getFactoryCode())) {
|
|
|
+ importDto.setErrorMsg("工厂编号不能为空");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StrKit.isBlank(importDto.getWorkshopCode())) {
|
|
|
+ importDto.setErrorMsg("车间编号不能为空");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StrKit.isBlank(importDto.getLineCode())) {
|
|
|
+ importDto.setErrorMsg("产线编号不能为空");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StrKit.isBlank(importDto.getProductCode())) {
|
|
|
+ importDto.setErrorMsg("产品编号不能为空");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取各ID
|
|
|
+ Long factoryId = getFactoryIdByCode(importDto.getFactoryCode());
|
|
|
+ if (factoryId == null) {
|
|
|
+ importDto.setErrorMsg("未找到工厂编号对应的工厂");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long workshopId = getWorkshopIdByCode(importDto.getWorkshopCode());
|
|
|
+ if (workshopId == null) {
|
|
|
+ importDto.setErrorMsg("未找到车间编号对应的车间");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long lineId = getLineIdByCode(importDto.getLineCode());
|
|
|
+ if (lineId == null) {
|
|
|
+ importDto.setErrorMsg("未找到产线编号对应的产线");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ Long productId = getProductIdByCode(importDto.getProductCode());
|
|
|
+ if (productId == null) {
|
|
|
+ importDto.setErrorMsg("未找到产品编号对应的产品");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查关联是否已存在
|
|
|
+ Record existRecord = Db.findFirst("select 1 from t_line_product where line_id = ? and product_id = ?",
|
|
|
+ lineId, productId);
|
|
|
+ if (existRecord != null) {
|
|
|
+ importDto.setErrorMsg("该产线与产品的关联已存在");
|
|
|
+ errorList.add(importDto);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取名称信息
|
|
|
+ Record factory = Db.findById("t_factory", factoryId);
|
|
|
+ Record workshop = Db.findById("t_workshop", workshopId);
|
|
|
+ Record line = Db.findById("t_production_line", lineId);
|
|
|
+ Record product = Db.findById("t_jz_product", productId);
|
|
|
+
|
|
|
+ // 保存数据
|
|
|
+ Record addrRecord = new Record();
|
|
|
+ addrRecord.set("factory_id", factoryId);
|
|
|
+ addrRecord.set("factory_name", factory.getStr("factory_name"));
|
|
|
+ addrRecord.set("workshop_id", workshopId);
|
|
|
+ addrRecord.set("workshop_name", workshop.getStr("workshop_name"));
|
|
|
+ addrRecord.set("line_id", lineId);
|
|
|
+ addrRecord.set("line_name", line.getStr("line_name"));
|
|
|
+ addrRecord.set("product_id", productId);
|
|
|
+ addrRecord.set("product_name", product.getStr("product_name"));
|
|
|
+ addrRecord.set("operator", operator);
|
|
|
+
|
|
|
+ boolean result = Db.save("t_line_product", addrRecord);
|
|
|
+ if (result) {
|
|
|
+ successCount++;
|
|
|
+ } else {
|
|
|
+ importDto.setErrorMsg("保存失败");
|
|
|
+ errorList.add(importDto);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("导入产线产品关联信息异常:", e);
|
|
|
+ importDto.setErrorMsg("系统异常:" + e.getMessage());
|
|
|
+ errorList.add(importDto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ record.set("successCount", successCount);
|
|
|
+ if (!errorList.isEmpty()) {
|
|
|
+ record.set("errorCount", errorList.size());
|
|
|
+ try {
|
|
|
+ String errorFileName = "line_product_import_error_" + System.currentTimeMillis() + ".xlsx";
|
|
|
+ InputStream errorInputStream = EasyExcelUtil.export(errorList, "导入错误数据", LineProductImportDto.class);
|
|
|
+ // 上传到OSS
|
|
|
+ String ossUrl = OssUtil.upload(errorInputStream, errorFileName);
|
|
|
+ // 添加到响应
|
|
|
+ record.set("errorFileUrl", ossUrl);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("导出错误数据并上传到OSS异常:", e);
|
|
|
+ record.set("errorMsg", "导出错误数据并上传到OSS异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ response.setData(record);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getFactoryIdByCode(String factoryCode) {
|
|
|
+ Record record = Db.findFirst("select id from t_factory where factory_code = ?", factoryCode);
|
|
|
+ return record != null ? WxUtil.getInt("id", record).longValue() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getWorkshopIdByCode(String workshopCode) {
|
|
|
+ Record record = Db.findFirst("select id from t_workshop where workshop_code = ?", workshopCode);
|
|
|
+ return record != null ? WxUtil.getInt("id", record).longValue() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getLineIdByCode(String lineCode) {
|
|
|
+ Record record = Db.findFirst("select id from t_production_line where line_code = ?", lineCode);
|
|
|
+ return record != null ? WxUtil.getInt("id", record).longValue() : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Long getProductIdByCode(String productCode) {
|
|
|
+ Record record = Db.findFirst("select id from t_jz_product where product_no = ?", productCode);
|
|
|
+ return record != null ? WxUtil.getInt("id", record).longValue() : null;
|
|
|
+ }
|
|
|
+}
|