|
|
|
@ -2,11 +2,24 @@ package com.xujie.sys.modules.part.service.impl; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
import com.xujie.sys.modules.orderIssure.entity.PartData; |
|
|
|
import com.xujie.sys.modules.part.data.PartCostHistData; |
|
|
|
import com.xujie.sys.modules.part.entity.PartInformationEntity; |
|
|
|
import com.xujie.sys.modules.part.mapper.PartInformationMapper; |
|
|
|
import com.xujie.sys.modules.part.service.PartCostHistService; |
|
|
|
import com.xujie.sys.modules.part.mapper.PartCostHistMapper; |
|
|
|
import com.xujie.sys.modules.part.vo.BomComponentVo; |
|
|
|
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.web.multipart.MultipartFile; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
@ -18,12 +31,76 @@ import java.util.List; |
|
|
|
public class PartCostHistServiceImpl extends ServiceImpl<PartCostHistMapper, PartCostHistData> |
|
|
|
implements PartCostHistService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PartInformationMapper partInformationMapper; |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<PartCostHistData> costHistorySearch(PartCostHistData data) { |
|
|
|
QueryWrapper<PartCostHistData> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("site", data.getSite()).eq("partno", data.getPartno()).orderByDesc("createdate"); |
|
|
|
return baseMapper.selectList(queryWrapper); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void savePartCostComponentByExcel(MultipartFile file, PartInformationEntity data) { |
|
|
|
try { |
|
|
|
// 转流 |
|
|
|
InputStream is = file.getInputStream(); |
|
|
|
// 读取工作簿 |
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook(is); |
|
|
|
// 读取工作表 |
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0); |
|
|
|
// 获取行数 |
|
|
|
int rows = sheet.getPhysicalNumberOfRows(); |
|
|
|
// 遍历每一行(从第二行开始) |
|
|
|
for (int j = 1; j < rows; j++) { |
|
|
|
// 创建对象 |
|
|
|
PartInformationEntity task = new PartInformationEntity(); |
|
|
|
// 获得该行 |
|
|
|
XSSFRow row = sheet.getRow(j); |
|
|
|
// 为对象赋值 |
|
|
|
task.setSite(data.getSite()); // site |
|
|
|
if (row.getCell(0) == null) { |
|
|
|
throw new RuntimeException("BU不能为空!"); |
|
|
|
} |
|
|
|
task.setBuNo(row.getCell(0).getStringCellValue()); // BU |
|
|
|
if (row.getCell(1) == null) { |
|
|
|
throw new RuntimeException("物料编码不能为空!"); |
|
|
|
} |
|
|
|
task.setPartNo(row.getCell(1).getStringCellValue()); // 物料编码 |
|
|
|
if (row.getCell(2) == null || row.getCell(2).getStringCellValue().equals("")) { |
|
|
|
task.setStandardCost(BigDecimal.valueOf(0)); |
|
|
|
} else { |
|
|
|
task.setStandardCost(BigDecimal.valueOf(Long.parseLong(row.getCell(2).getStringCellValue()))); //单位标准成本 |
|
|
|
} |
|
|
|
if (row.getCell(3) == null) { |
|
|
|
task.setStandardCostCurrency(""); |
|
|
|
} else { |
|
|
|
task.setStandardCostCurrency(row.getCell(3).getStringCellValue()); // 标准成本货币 |
|
|
|
} |
|
|
|
if (row.getCell(3) == null || row.getCell(3).getStringCellValue().equals("")) { |
|
|
|
task.setActualCost(BigDecimal.valueOf(0)); |
|
|
|
} else { |
|
|
|
task.setActualCost(BigDecimal.valueOf(Long.parseLong(row.getCell(4).getStringCellValue()))); // 单位报价成本 |
|
|
|
} |
|
|
|
if (row.getCell(4) == null) { |
|
|
|
task.setActualCostCurrency(""); |
|
|
|
} else { |
|
|
|
task.setActualCostCurrency(row.getCell(5).getStringCellValue()); // 报价成本货币 |
|
|
|
} |
|
|
|
task.setUpdateBy(data.getUpdateBy()); |
|
|
|
task.setUpdateDate(new Date()); |
|
|
|
QueryWrapper<PartInformationEntity> queryWrapper = new QueryWrapper<>(); |
|
|
|
queryWrapper.eq("site", task.getSite()).eq("part_no", task.getPartNo()); |
|
|
|
PartInformationEntity partInformationEntity = partInformationMapper.selectOne(queryWrapper); |
|
|
|
|
|
|
|
task.setId(partInformationEntity.getId()); |
|
|
|
partInformationMapper.updateById(task); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException("导入失败:"+e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|