Browse Source

2024.11.18 文档收集优化

java8
yuejiayang 1 year ago
parent
commit
931a5c1749
  1. 19
      src/main/java/com/xujie/sys/modules/part/controller/PartInformationController.java
  2. 6
      src/main/java/com/xujie/sys/modules/part/service/PartCostHistService.java
  3. 77
      src/main/java/com/xujie/sys/modules/part/service/impl/PartCostHistServiceImpl.java

19
src/main/java/com/xujie/sys/modules/part/controller/PartInformationController.java

@ -5,17 +5,16 @@ import com.xujie.sys.common.utils.PageUtils;
import com.xujie.sys.common.utils.R;
import com.xujie.sys.modules.base.entity.Chooselist;
import com.xujie.sys.modules.base.service.ChooselistService;
import com.xujie.sys.modules.orderIssure.entity.PartData;
import com.xujie.sys.modules.part.data.PartCostHistData;
import com.xujie.sys.modules.part.entity.*;
import com.xujie.sys.modules.part.service.PartCostHistService;
import com.xujie.sys.modules.part.service.PartInformationService;
import com.xujie.sys.modules.part.vo.AgentInformationVo;
import com.xujie.sys.modules.part.vo.LocationInformationVo;
import com.xujie.sys.modules.part.vo.ManufacturerInformationVo;
import com.xujie.sys.modules.part.vo.PartInformationVo;
import com.xujie.sys.modules.part.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.text.DecimalFormat;
import java.util.Date;
@ -490,4 +489,16 @@ public class PartInformationController {
List<PartCostHistData> rows = partCostHistService.costHistorySearch(data);
return R.ok().put("rows", rows);
}
/**
* 根据Excel批量修改物料成本
* @param file
* @param data
* @return
*/
@PostMapping("/savePartCostComponentByExcel")
public R saveBomComponentByExcel(@RequestParam(value = "file") MultipartFile file, @ModelAttribute PartInformationEntity data){
partCostHistService.savePartCostComponentByExcel(file, data);
return R.ok();
}
}

6
src/main/java/com/xujie/sys/modules/part/service/PartCostHistService.java

@ -1,7 +1,11 @@
package com.xujie.sys.modules.part.service;
import com.xujie.sys.modules.orderIssure.entity.PartData;
import com.xujie.sys.modules.part.data.PartCostHistData;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xujie.sys.modules.part.entity.PartInformationEntity;
import com.xujie.sys.modules.part.vo.BomComponentVo;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
@ -13,4 +17,6 @@ import java.util.List;
public interface PartCostHistService extends IService<PartCostHistData> {
List<PartCostHistData> costHistorySearch(PartCostHistData data);
void savePartCostComponentByExcel(MultipartFile file, PartInformationEntity data);
}

77
src/main/java/com/xujie/sys/modules/part/service/impl/PartCostHistServiceImpl.java

@ -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());
}
}
}

Loading…
Cancel
Save