2243 lines
99 KiB
Java
2243 lines
99 KiB
Java
package com.ruoyi.system.controller;
|
||
|
||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||
import cn.hutool.core.bean.BeanUtil;
|
||
import cn.hutool.json.JSONArray;
|
||
import cn.hutool.json.JSONUtil;
|
||
import com.fasterxml.jackson.databind.JsonNode;
|
||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||
import com.google.gson.Gson;
|
||
import com.google.gson.JsonArray;
|
||
import com.google.gson.JsonElement;
|
||
import com.google.gson.JsonObject;
|
||
import com.kingdee.bos.webapi.entity.RepoRet;
|
||
import com.kingdee.bos.webapi.sdk.K3CloudApi;
|
||
import com.ruoyi.common.annotation.Log;
|
||
import com.ruoyi.common.annotation.RepeatSubmit;
|
||
import com.ruoyi.common.core.controller.BaseController;
|
||
import com.ruoyi.common.core.domain.PageQuery;
|
||
import com.ruoyi.common.core.domain.R;
|
||
import com.ruoyi.common.core.page.TableDataInfo;
|
||
import com.ruoyi.common.core.validate.AddGroup;
|
||
import com.ruoyi.common.core.validate.EditGroup;
|
||
import com.ruoyi.common.enums.BusinessType;
|
||
import com.ruoyi.system.domain.dto.*;
|
||
import com.ruoyi.common.utils.JdUtils;
|
||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||
import com.ruoyi.system.domain.BomDetails;
|
||
import com.ruoyi.system.domain.MaterialProperties;
|
||
import com.ruoyi.system.domain.ProcessOrderPro;
|
||
import com.ruoyi.system.domain.bo.BomDetailsBo;
|
||
import com.ruoyi.system.domain.vo.BomDetailsVo;
|
||
import com.ruoyi.system.domain.vo.ElectricalMaterialBomVO;
|
||
import com.ruoyi.system.mapper.BomDetailsMapper;
|
||
import com.ruoyi.system.mapper.ProcessOrderProMapper;
|
||
import com.ruoyi.system.runner.JdUtil;
|
||
import com.ruoyi.system.service.*;
|
||
import lombok.RequiredArgsConstructor;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.collections.MapUtils;
|
||
import org.apache.poi.ss.usermodel.Cell;
|
||
import org.apache.poi.ss.usermodel.Row;
|
||
import org.apache.poi.ss.usermodel.Sheet;
|
||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||
import org.springframework.http.MediaType;
|
||
import org.springframework.validation.annotation.Validated;
|
||
import org.springframework.web.bind.annotation.*;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import javax.validation.constraints.NotEmpty;
|
||
import javax.validation.constraints.NotNull;
|
||
import java.io.IOException;
|
||
import java.math.BigDecimal;
|
||
import java.util.*;
|
||
|
||
import static org.aspectj.bridge.MessageUtil.fail;
|
||
|
||
/**
|
||
* bom明细
|
||
*
|
||
* @author tzy
|
||
* @date 2024-04-08
|
||
*/
|
||
@Validated
|
||
@RequiredArgsConstructor
|
||
@RestController
|
||
@RequestMapping("/system/details")
|
||
@Slf4j
|
||
public class BomDetailsController extends BaseController {
|
||
|
||
private final IBomDetailsService iBomDetailsService;
|
||
|
||
private final IMaterialPropertiesService iMaterialPropertiesService;
|
||
|
||
private final IProcessRouteService iProcessRouteService;
|
||
|
||
private final IMaterialTotalService iMaterialTotalService;
|
||
|
||
private final IProcessOrderProService iProcessOrderProService;
|
||
|
||
private final ProcessOrderProMapper processOrderProMapper;
|
||
|
||
private final BomDetailsMapper bomDetailsMapper;
|
||
|
||
/**
|
||
* 查询bom明细列表
|
||
*/
|
||
@SaCheckPermission("system:details:list")
|
||
@GetMapping("/list")
|
||
public TableDataInfo<BomDetailsVo> list(BomDetailsBo bo, PageQuery pageQuery) {
|
||
try {
|
||
TableDataInfo<BomDetailsVo> bomDetailsVoTableDataInfo = iBomDetailsService.queryPageList(bo, pageQuery);
|
||
// 构建父子关系
|
||
Map<String, BomDetailsVo> bomMap = new HashMap<>();
|
||
List<BomDetailsVo> topLevelList = new ArrayList<>();
|
||
List<BomDetailsVo> rows = bomDetailsVoTableDataInfo.getRows();
|
||
for (BomDetailsVo bomDetailsVo : rows) {
|
||
String parentCodeAndName = String.format("%s_%s", bomDetailsVo.getFName(), bomDetailsVo.getFNumber());
|
||
BomDetailsVo parent = bomMap.get(parentCodeAndName);
|
||
if (parent == null) {
|
||
parent = new BomDetailsVo();
|
||
parent.setId(generateUniqueParentId(bomDetailsVo.getId()));
|
||
// parent.setUnitWeight(bomDetailsVo.getUnitWeight());
|
||
parent.setParentCodeAndName(parentCodeAndName);
|
||
parent.setFNumber(bomDetailsVo.getFNumber());
|
||
parent.setFName(bomDetailsVo.getFName());
|
||
parent.setUnitWeight(bomDetailsVo.getUnitWeight());
|
||
parent.setStats(bomDetailsVo.getStats());
|
||
parent.setMaterial(bomDetailsVo.getMaterial());
|
||
parent.setRemarks(bomDetailsVo.getRemarks());
|
||
parent.setTotalWeight(bomDetailsVo.getTotalWeight());
|
||
parent.setChildren(new ArrayList<>());
|
||
bomMap.put(parentCodeAndName, parent);
|
||
topLevelList.add(parent);
|
||
}
|
||
|
||
BomDetailsVo child = createChildVo(bomDetailsVo); // 重构子对象创建逻辑
|
||
parent.getChildren().add(child);
|
||
}
|
||
bomDetailsVoTableDataInfo.setRows(topLevelList);
|
||
return bomDetailsVoTableDataInfo;
|
||
} catch (Exception e) {
|
||
|
||
e.printStackTrace();
|
||
return new TableDataInfo<>();
|
||
}
|
||
}
|
||
|
||
private Long generateUniqueParentId(Long originalId) {
|
||
return originalId + 1000;
|
||
}
|
||
|
||
private BomDetailsVo createChildVo(BomDetailsVo bomDetailsVo) {
|
||
BomDetailsVo child = null;
|
||
child = new BomDetailsVo();
|
||
child.setId(bomDetailsVo.getId());
|
||
child.setPartNumber(bomDetailsVo.getPartNumber());
|
||
child.setName(bomDetailsVo.getName());
|
||
child.setQuantity(bomDetailsVo.getQuantity());
|
||
child.setDenominator(bomDetailsVo.getDenominator());
|
||
child.setStats(bomDetailsVo.getStats());
|
||
child.setMaterial(bomDetailsVo.getMaterial());
|
||
child.setRemarks(bomDetailsVo.getRemarks());
|
||
// child.setTotalWeight(bomDetailsVo.getTotalWeight());
|
||
child.setUnitWeight(bomDetailsVo.getUnitWeight());
|
||
|
||
// 其他必要的字段赋值
|
||
return child;
|
||
}
|
||
|
||
/**
|
||
* 导出bom明细列表
|
||
*/
|
||
@SaCheckPermission("system:details:export")
|
||
@Log(title = "bom明细", businessType = BusinessType.EXPORT)
|
||
@PostMapping("/export")
|
||
public void export(BomDetailsBo bo, HttpServletResponse response) {
|
||
List<BomDetailsVo> list = iBomDetailsService.queryList(bo);
|
||
ExcelUtil.exportExcel(list, "bom明细", BomDetailsVo.class, response);
|
||
}
|
||
|
||
/**
|
||
* 获取bom明细详细信息
|
||
*
|
||
* @param id 主键
|
||
*/
|
||
@SaCheckPermission("system:details:query")
|
||
@GetMapping("/{id}")
|
||
public R<BomDetailsVo> getInfo(@NotNull(message = "主键不能为空") @PathVariable Long id) {
|
||
return R.ok(iBomDetailsService.queryById(id));
|
||
}
|
||
|
||
/**
|
||
* 新增bom明细
|
||
*/
|
||
@SaCheckPermission("system:details:add")
|
||
@Log(title = "bom明细", businessType = BusinessType.INSERT)
|
||
@RepeatSubmit()
|
||
@PostMapping()
|
||
public R<Void> add(@Validated(AddGroup.class) @RequestBody BomDetailsBo bo) {
|
||
return toAjax(iBomDetailsService.insertByBo(bo));
|
||
}
|
||
|
||
/**
|
||
* 修改bom明细
|
||
*/
|
||
@SaCheckPermission("system:details:edit")
|
||
@Log(title = "bom明细", businessType = BusinessType.UPDATE)
|
||
@RepeatSubmit()
|
||
@PutMapping()
|
||
public R<Void> edit(@Validated(EditGroup.class) @RequestBody BomDetailsBo bo) {
|
||
return toAjax(iBomDetailsService.updateByBo(bo));
|
||
}
|
||
|
||
/**
|
||
* 删除bom明细
|
||
*
|
||
* @param ids 主键串
|
||
*/
|
||
@SaCheckPermission("system:details:remove")
|
||
@Log(title = "bom明细", businessType = BusinessType.DELETE)
|
||
@DeleteMapping("/{ids}")
|
||
public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
|
||
return toAjax(iBomDetailsService.deleteWithValidByIds(Arrays.asList(ids), true));
|
||
}
|
||
|
||
/**
|
||
* 导入BOM
|
||
* daorubaon
|
||
*
|
||
* @param file 导入文件
|
||
*/
|
||
|
||
@Log(title = "明细导入", businessType = BusinessType.IMPORT)
|
||
@SaCheckPermission("system:details:import")
|
||
@PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||
public R<Void> importData(@RequestPart("file") MultipartFile file) throws Exception {
|
||
List<BomDetailsVo> bomDetailsVos = ExcelUtil.importExcel(file.getInputStream(), BomDetailsVo.class);
|
||
List<String> missingFieldsWarnings = new ArrayList<>();
|
||
List<BomDetails> materialsToAdd = new ArrayList<>();
|
||
// 解析成品物料(从 Excel 第一 Sheet 第二行第二列、第三列读取)
|
||
HashMap<String, String> bomFinishedProduct = getBomFinishedProduct(file);
|
||
if (MapUtils.isNotEmpty(bomFinishedProduct)) {
|
||
int result = loadChengPinMaterialPreservation(bomFinishedProduct);
|
||
if (result == 1) {
|
||
log.info("✅ 成品父级物料新增成功: {}", bomFinishedProduct);
|
||
} else {
|
||
log.warn("⚠️ 成品父级物料保存失败: {}", bomFinishedProduct);
|
||
}
|
||
} else {
|
||
log.warn("⚠️ 未从 Excel 中读取到有效的成品物料信息");
|
||
}
|
||
|
||
for (BomDetailsVo bomDetailsvo : bomDetailsVos) {
|
||
BomDetails bomDetails = BeanUtil.toBean(bomDetailsvo, BomDetails.class);
|
||
|
||
// 校验属性、材质、数量是否为空,并记录提示信息
|
||
if (bomDetails.getStats() == null || bomDetails.getMaterial() == null || bomDetails.getQuantity() == null) {
|
||
String warningMessage = String.format("记录 %s 缺少必要字段: 属性=%s, 材质=%s, 数量=%s", bomDetails.getPartNumber(), bomDetails.getStats(), bomDetails.getMaterial(), bomDetails.getQuantity());
|
||
missingFieldsWarnings.add(warningMessage);
|
||
}
|
||
// 验证物料是否存在
|
||
if (bomDetails.getFNumber() != null && bomDetails.getFName() != null && bomDetails.getPartNumber() != null && bomDetails.getName() != null) {
|
||
//TODO 验证物料是否存在 这里存在问题
|
||
if (bomDetailsvo.getUnitWeight().equals("是")) {
|
||
continue;
|
||
} else if (bomDetailsvo.getUnitWeight().equals("否")) {
|
||
materialsToAdd.add(bomDetails);
|
||
} else if (bomDetailsvo.getUnitWeight().equals("编码名称不符")) {
|
||
materialsToAdd.add(bomDetails);
|
||
}
|
||
}
|
||
// 保存当前记录
|
||
BomDetailsVo bean = BeanUtil.toBean(bomDetails, BomDetailsVo.class);
|
||
iBomDetailsService.insertByVo(bean);
|
||
}
|
||
// 记录缺失字段的警告信息
|
||
if (!missingFieldsWarnings.isEmpty()) {
|
||
log.warn("导入时发现以下记录缺少必要字段: \n" + String.join("\n", missingFieldsWarnings));
|
||
}
|
||
ArrayList<BomDetails> bomDetails = new ArrayList<>();
|
||
// 统一新增不存在的物料
|
||
for (BomDetails material : materialsToAdd) {
|
||
// 替换属性编码(金蝶)
|
||
if (material == null) {
|
||
continue; // 如果 material 为空,则跳过当前循环
|
||
}
|
||
String state = determineState(material);
|
||
// 判断是否是电器物料
|
||
int result;
|
||
if (material.getTotalWeight().contains("DQ")) {
|
||
log.info("项目号,物料图号,物料名称, {},{},{}", material.getTotalWeight(), material.getPartNumber(), material.getName());
|
||
result = loadMaterialToDQ(material, state);
|
||
} else {
|
||
Double a = 0.0;
|
||
log.info("项目号,物料图号,物料名称, {},{},{}", material.getTotalWeight(), material.getPartNumber(), material.getName());
|
||
result = loadMaterialPreservation(material, state, a);
|
||
}
|
||
if (result == 1) {
|
||
log.info("项目号,物料图号,物料名称新增成功, {},{},{}", material.getTotalWeight(), material.getPartNumber(), material.getName());
|
||
material.setUnitWeight("新增成功");
|
||
bomDetails.add(material);
|
||
} else {
|
||
log.info("项目号,物料图号,物料名称新增失败, {},{},{}", material.getTotalWeight(), material.getPartNumber(), material.getName());
|
||
material.setUnitWeight("新增成功");
|
||
bomDetails.add(material);
|
||
}
|
||
BomDetailsBo bean = BeanUtil.toBean(bomDetails, BomDetailsBo.class);
|
||
iBomDetailsService.updateByBo(bean);
|
||
}
|
||
// 保存当前记录
|
||
|
||
return R.ok("导入成功");
|
||
}
|
||
|
||
/**
|
||
* @param file
|
||
*/
|
||
private HashMap<String, String> getBomFinishedProduct(MultipartFile file) throws IOException {
|
||
Sheet sheetAt = WorkbookFactory.create(file.getInputStream()).getSheetAt(0);
|
||
Row firstRow = sheetAt.getRow(1);
|
||
HashMap<String, String> chenpin = new HashMap<>();
|
||
// 获取第一行的第一列
|
||
Cell cell = firstRow.getCell(1);
|
||
log.info("获取到第一行第一列的值为:" + cell.toString());
|
||
|
||
Cell cell1 = firstRow.getCell(2);
|
||
log.info("获取到第一行第二列的值为:" + cell1.toString());
|
||
chenpin.put("fnumber", cell.toString());
|
||
chenpin.put("fname", cell1.toString());
|
||
// 获取单元格的值,假设它是字符串类型
|
||
return chenpin;
|
||
}
|
||
|
||
/**
|
||
* 获取属性 替换成金蝶属性编码
|
||
*
|
||
* @param stats
|
||
* @return
|
||
*/
|
||
public static String determineState(BomDetails stats) {
|
||
if (stats == null || stats.getStats().equals("外购") || stats.getFName().startsWith("009") ||
|
||
stats.getFName().startsWith("AA") || stats.getFName().startsWith("AB")
|
||
|| stats.getFName().startsWith("AC")) {
|
||
return "1";
|
||
} else if (stats.getStats().equals("自制")) {
|
||
return "2";
|
||
} else if (stats.getStats().equals("委外")) {
|
||
return "3";
|
||
}
|
||
return "1";
|
||
}
|
||
|
||
/* 触发金蝶物料清单按钮 */
|
||
@Log(title = "金蝶物料清单更新")
|
||
@SaCheckPermission("system:details:updateMaterial")
|
||
@PostMapping("/updateMaterial")
|
||
public R<List<BomDetails>> updateMaterial(@RequestParam String fnumbers) {
|
||
// 检查并添加缺失的引号
|
||
JSONArray jsonArray = new JSONArray(fnumbers);
|
||
List<BomDetails> bomDetailsList = new ArrayList<>();
|
||
for (int i = 0; i < jsonArray.size(); i++) {
|
||
String number = jsonArray.getStr(i);
|
||
// 去除字符串两端的引号y
|
||
number = number.replaceAll("^\"|\"$", "");
|
||
List<BomDetails> bomDetails = iBomDetailsService.selectByFNumber(number);
|
||
System.out.println(number);
|
||
if (bomDetails != null && !bomDetails.isEmpty()) {
|
||
// 物料清单保存方法
|
||
int i1 = loadBillOfMaterialsPreservation(bomDetails);
|
||
if (i1 == 1) {
|
||
return R.ok("bom上传成功");
|
||
} else if (i1 == 0) {
|
||
return R.fail("bom上传失败");
|
||
}
|
||
bomDetailsList.addAll(bomDetails);
|
||
}
|
||
}
|
||
return R.ok("bom上传成功", bomDetailsList);
|
||
}
|
||
|
||
/* 触发非标项目金蝶物料清单按钮 */
|
||
@Log(title = "非标金蝶物料清单更新")
|
||
@SaCheckPermission("system:details:updateFBMaterial")
|
||
@PostMapping("/updateFBMaterial")
|
||
public R updateFBMaterial(@RequestBody List<Map<String, String>> bomDetailParams) {
|
||
List<BomDetails> bomDetailsList = new ArrayList<>();
|
||
List<KindegeeLogDTO> logDTOS = new ArrayList<>();
|
||
List<String> failedMaterials = new ArrayList<>(); // 用于跟踪处理失败的物料
|
||
String totalWeight = "";
|
||
// 遍历前端传来的数据
|
||
for (Map<String, String> param : bomDetailParams) {
|
||
String fnumber = param.get("fnumber"); // 物料编码
|
||
String groupName = param.get("groupName"); // 物料编码
|
||
totalWeight = param.get("totalWeight"); // 生产令号
|
||
|
||
// 根据物料编码和生产令号查询
|
||
List<BomDetails> bomDetails = iBomDetailsService.selectByFNumberAndTotalWeight(fnumber, totalWeight);
|
||
log.info("处理物料编码: {}, 生产令号: {}", fnumber, totalWeight);
|
||
if (bomDetails != null && !bomDetails.isEmpty()) {
|
||
//TODO 处理父级物料
|
||
ProcessOrderPro bo = iProcessOrderProService.selectByProjectNumber(totalWeight);
|
||
|
||
// 第一步:处理所有物料的保存
|
||
for (BomDetails material : bomDetails) {
|
||
// 获取工艺表中的非委外工时
|
||
Double fbWorkTime = iProcessRouteService.getFbWorkTime(material);
|
||
if (material.getPartNumber() != null && material.getName() != null && material.getUnitWeight().equals("否")) {
|
||
String state = determineState(material);
|
||
//判断bom类型是生产还是电气
|
||
if (material.getBomType().equals("0")) {
|
||
try {
|
||
int result = loadMaterialPreservation(material, state, fbWorkTime);
|
||
if (result == 1) {
|
||
material.setUnitWeight("新增成功");
|
||
} else {
|
||
failedMaterials.add(material.getPartNumber());
|
||
}
|
||
// 更新物料状态
|
||
iBomDetailsService.updateByBo(BeanUtil.toBean(material, BomDetailsBo.class));
|
||
} catch (Exception e) {
|
||
failedMaterials.add(material.getPartNumber());
|
||
}
|
||
} else {
|
||
try {
|
||
int result = loadMaterialToDQ(material, state);
|
||
if (result == 1) {
|
||
material.setUnitWeight("新增成功");
|
||
} else {
|
||
failedMaterials.add(material.getPartNumber());
|
||
}
|
||
// 更新物料状态
|
||
iBomDetailsService.updateByBo(BeanUtil.toBean(material, BomDetailsBo.class));
|
||
} catch (Exception e) {
|
||
failedMaterials.add(material.getPartNumber());
|
||
}
|
||
}
|
||
|
||
} else {
|
||
failedMaterials.add(material.getPartNumber());
|
||
}
|
||
}
|
||
|
||
// 第二步:BOM校验和上传(在循环外部)
|
||
ValidateBomResult validateResult = validateBOM(fnumber, bomDetails);
|
||
boolean needUpload = !validateResult.isMatch();
|
||
if (needUpload) {
|
||
try {
|
||
// 物料清单保存方法,判断是电气还是生产
|
||
BOMUploadResult bomUploadResult = FBloadBillOfMaterialsPreservation(bomDetails, bo,groupName);
|
||
if (bomUploadResult.isSuccess()) {
|
||
KindegeeLogDTO logDTO = new KindegeeLogDTO();
|
||
logDTO.setProjectCode(bo.getProductionOrderNo());
|
||
logDTO.setMaterialCode(fnumber); // 使用物料编码而不是单个物料的编码
|
||
logDTO.setCode("200");
|
||
logDTO.setReason("成功上传"+"版本号:"+bomUploadResult.getNumber());
|
||
logDTOS.add(logDTO);
|
||
} else {
|
||
KindegeeLogDTO logDTO = new KindegeeLogDTO();
|
||
logDTO.setProjectCode(bo.getProductionOrderNo());
|
||
logDTO.setMaterialCode(fnumber);
|
||
logDTO.setCode("300");
|
||
logDTO.setReason(bomUploadResult.getErrorMessage());
|
||
logDTOS.add(logDTO);
|
||
}
|
||
bomDetailsList.addAll(bomDetails);
|
||
} catch (Exception e) {
|
||
log.error("保存BOM失败, 物料编码: {}, 错误: {}", fnumber, e.getMessage());
|
||
failedMaterials.add(fnumber);
|
||
}
|
||
} else {
|
||
KindegeeLogDTO logDTO = new KindegeeLogDTO();
|
||
logDTO.setProjectCode(bo.getProductionOrderNo());
|
||
logDTO.setMaterialCode(fnumber);
|
||
logDTO.setCode("100");
|
||
logDTO.setReason("BOM已存在且一致,版本号:" + validateResult.getVersion());
|
||
logDTOS.add(logDTO);
|
||
log.info("BOM已存在且一致,物料编码: {},跳过保存", fnumber);
|
||
}
|
||
}
|
||
}
|
||
//更新项目进度
|
||
ProcessOrderPro processOrderProBo = iProcessOrderProService.selectByProjectNumber(totalWeight);
|
||
|
||
processOrderProBo.setDrawingType(JSONUtil.toJsonStr(logDTOS));
|
||
processOrderProBo.setBomStatus(2L);
|
||
processOrderProMapper.updateById(processOrderProBo);
|
||
// 返回处理结果
|
||
return R.ok("成功", bomDetailsList);
|
||
|
||
}
|
||
|
||
private ValidateBomResult validateBOM(String fnumber, List<BomDetails> bomDetails) {
|
||
|
||
List<JdValidateBomDTO> JDBomList = JdUtil.getSelectBomList(fnumber);
|
||
|
||
if (JDBomList == null || JDBomList.isEmpty()) {
|
||
log.error("未在金蝶中找到相同的BOM,需要上传,物料编码: {}", fnumber);
|
||
return ValidateBomResult.notMatched();
|
||
}
|
||
|
||
// 子项排序:按 PartNumber -> Name -> PartdiagramCode -> PartdiagramName 保证顺序唯一
|
||
bomDetails.sort(Comparator.comparing(BomDetails::getPartNumber, Comparator.nullsFirst(String::compareTo))
|
||
.thenComparing(BomDetails::getName, Comparator.nullsFirst(String::compareTo))
|
||
.thenComparing(BomDetails::getPartdiagramCode, Comparator.nullsFirst(String::compareTo))
|
||
.thenComparing(BomDetails::getPartdiagramName, Comparator.nullsFirst(String::compareTo)));
|
||
|
||
log.info("开始验证BOM - 物料编码: {}, 金蝶BOM数量: {}, 输入BOM子项数量: {}",
|
||
fnumber, JDBomList.size(), bomDetails.size());
|
||
|
||
for (int bomIndex = 0; bomIndex < JDBomList.size(); bomIndex++) {
|
||
JdValidateBomDTO jdBom = JDBomList.get(bomIndex);
|
||
List<JdChildDTO> childs = jdBom.getChilds();
|
||
|
||
log.debug("正在比较第{}个金蝶BOM - 子项数量: {}", bomIndex + 1, childs.size());
|
||
|
||
childs.sort(Comparator.comparing(JdChildDTO::getPartNumber, Comparator.nullsFirst(String::compareTo))
|
||
.thenComparing(JdChildDTO::getName, Comparator.nullsFirst(String::compareTo))
|
||
.thenComparing(JdChildDTO::getPartdiagramCode, Comparator.nullsFirst(String::compareTo))
|
||
.thenComparing(JdChildDTO::getPartdiagramName, Comparator.nullsFirst(String::compareTo)));
|
||
|
||
if (childs.size() != bomDetails.size()) {
|
||
log.warn("BOM子项数量不一致 - 物料编码: {}, 金蝶BOM子项数量: {}, 输入BOM子项数量: {}",
|
||
fnumber, childs.size(), bomDetails.size());
|
||
continue; // 数量不一致,跳过当前金蝶BOM
|
||
}
|
||
|
||
boolean isMatch = true;
|
||
List<String> mismatchDetails = new ArrayList<>();
|
||
|
||
for (int i = 0; i < childs.size(); i++) {
|
||
JdChildDTO jdChild = childs.get(i);
|
||
BomDetails inputBomDetail = bomDetails.get(i);
|
||
|
||
List<String> itemMismatches = new ArrayList<>();
|
||
|
||
// 字符串比较(null/空格统一处理)
|
||
if (!equalsStr(jdChild.getPartNumber(), inputBomDetail.getPartNumber())) {
|
||
itemMismatches.add(String.format("PartNumber [金蝶:'%s' vs 输入:'%s']",
|
||
jdChild.getPartNumber(), inputBomDetail.getPartNumber()));
|
||
}
|
||
|
||
/* if (!equalsStr(jdChild.getName(), inputBomDetail.getName())) {
|
||
itemMismatches.add(String.format("Name [金蝶:'%s' vs 输入:'%s']",
|
||
jdChild.getName(), inputBomDetail.getName()));
|
||
}
|
||
*/
|
||
if (!equalsStr(jdChild.getPartdiagramCode(), inputBomDetail.getPartdiagramCode())) {
|
||
itemMismatches.add(String.format("PartdiagramCode [金蝶:'%s' vs 输入:'%s']",
|
||
jdChild.getPartdiagramCode(), inputBomDetail.getPartdiagramCode()));
|
||
}
|
||
|
||
/* if (!equalsStr(jdChild.getPartdiagramName(), inputBomDetail.getPartdiagramName())) {
|
||
itemMismatches.add(String.format("PartdiagramName [金蝶:'%s' vs 输入:'%s']",
|
||
jdChild.getPartdiagramName(), inputBomDetail.getPartdiagramName()));
|
||
}
|
||
*/
|
||
// 数值比较(BigDecimal + stripTrailingZeros)
|
||
BigDecimal jdQuantity = new BigDecimal(String.valueOf(jdChild.getQuantity())).stripTrailingZeros();
|
||
BigDecimal inputQuantity = new BigDecimal(String.valueOf(inputBomDetail.getQuantity())).stripTrailingZeros();
|
||
|
||
BigDecimal jdDenominator = new BigDecimal(String.valueOf(jdChild.getDenominator())).stripTrailingZeros();
|
||
BigDecimal inputDenominator = new BigDecimal(String.valueOf(inputBomDetail.getDenominator())).stripTrailingZeros();
|
||
|
||
if (jdQuantity.compareTo(inputQuantity) != 0) {
|
||
itemMismatches.add(String.format("Quantity [金蝶:%s vs 输入:%s]",
|
||
jdQuantity, inputQuantity));
|
||
}
|
||
|
||
if (jdDenominator.compareTo(inputDenominator) != 0) {
|
||
itemMismatches.add(String.format("Denominator [金蝶:%s vs 输入:%s]",
|
||
jdDenominator, inputDenominator));
|
||
}
|
||
|
||
// 如果有不匹配的字段,记录详细信息
|
||
if (!itemMismatches.isEmpty()) {
|
||
String mismatchInfo = String.format("第%d项不匹配: %s", i + 1, String.join(", ", itemMismatches));
|
||
mismatchDetails.add(mismatchInfo);
|
||
isMatch = false;
|
||
}
|
||
|
||
// 调试日志
|
||
log.debug("对比第{}项 -> PartNumber [{} vs {}], Name [{} vs {}], Code [{} vs {}], DiagramName [{} vs {}], Quantity [{} vs {}], Denominator [{} vs {}]",
|
||
i + 1,
|
||
jdChild.getPartNumber(), inputBomDetail.getPartNumber(),
|
||
jdChild.getName(), inputBomDetail.getName(),
|
||
jdChild.getPartdiagramCode(), inputBomDetail.getPartdiagramCode(),
|
||
jdChild.getPartdiagramName(), inputBomDetail.getPartdiagramName(),
|
||
jdQuantity, inputQuantity,
|
||
jdDenominator, inputDenominator);
|
||
}
|
||
|
||
// 如果不匹配,打印详细的不一致信息
|
||
if (!isMatch) {
|
||
log.warn("BOM不匹配详情 - 物料编码: {}", fnumber);
|
||
log.warn("金蝶BOM子项数量: {}, 输入BOM子项数量: {}", childs.size(), bomDetails.size());
|
||
for (String mismatch : mismatchDetails) {
|
||
log.warn(" {}", mismatch);
|
||
}
|
||
}
|
||
|
||
if (isMatch) {
|
||
log.info("BOM完全相同,物料编码: {},无需上传", fnumber);
|
||
// 记录BOM版本号
|
||
return ValidateBomResult.matched(jdBom.getFNumberVersion());
|
||
}
|
||
}
|
||
|
||
log.info("BOM不存在或不一致,物料编码: {},需要上传", fnumber);
|
||
return ValidateBomResult.notMatched(); // 所有BOM都不匹配
|
||
}
|
||
|
||
// null/空格统一处理方法
|
||
private boolean equalsStr(String a, String b) {
|
||
String s1 = (a == null || a.trim().isEmpty()) ? "" : a.trim();
|
||
String s2 = (b == null || b.trim().isEmpty()) ? "" : b.trim();
|
||
return s1.equals(s2);
|
||
}
|
||
|
||
|
||
/*
|
||
* 物料清单保存方法
|
||
*/
|
||
public int loadBillOfMaterialsPreservation(List<BomDetails> bomlist) {
|
||
// TODO: 实现加载和保存物料清单数据的逻辑
|
||
K3CloudApi client = new K3CloudApi();
|
||
// 创建一个空的JsonObject
|
||
JsonObject json = new JsonObject();
|
||
// 拿到第一个物料清单的父级物料编码
|
||
BomDetails bomDetails = bomlist.get(0);
|
||
String fName = bomDetails.getFName();
|
||
String fNumber = bomDetails.getFNumber();
|
||
// 验证物料是否存在
|
||
if (isMaterialVerification(fNumber, fName) == 0) {
|
||
log.debug("物料不存在");
|
||
// 增加父级物料图号
|
||
if (loadMaterialPreservation(bomDetails) == 1) {
|
||
log.debug("物料增加成功");
|
||
}
|
||
|
||
}
|
||
|
||
// 添加其他字段
|
||
json.addProperty("IsAutoSubmitAndAudit", "true");
|
||
// 创建Model对象,并加入JsonObject
|
||
JsonObject model = new JsonObject();
|
||
json.add("Model", model);
|
||
|
||
// 添加Model字段
|
||
model.addProperty("FID", 0);
|
||
// 创建FBILLTYPE对象,并加入Model
|
||
JsonObject fBillType = new JsonObject();
|
||
|
||
JsonObject fGroupType = new JsonObject();
|
||
model.add("FGroup", fGroupType);
|
||
fGroupType.addProperty("FNumber", "X007");
|
||
|
||
// 创建FMATERIALID对象,并加入Model
|
||
JsonObject fMaterialId = new JsonObject();
|
||
model.add("FMATERIALID", fMaterialId);
|
||
fMaterialId.addProperty("FNumber", bomDetails.getFNumber());
|
||
// 设置父级物料的单位
|
||
String unit = isMaterialVerification2(bomDetails.getFNumber());
|
||
log.debug("单位为:" + unit);
|
||
if (!unit.isEmpty()) {
|
||
// 创建FUNITID对象,并加入Model
|
||
JsonObject fUnitId = new JsonObject();
|
||
model.add("FUNITID", fUnitId);
|
||
fUnitId.addProperty("FNumber", unit);
|
||
} else {
|
||
// 创建FUNITID对象,并加入Model
|
||
JsonObject fUnitId = new JsonObject();
|
||
model.add("FUNITID", fUnitId);
|
||
fUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
// 创建FTreeEntity数组,并加入Model
|
||
JsonArray fTreeEntity = new JsonArray();
|
||
model.add("FTreeEntity", fTreeEntity);
|
||
ArrayList<JsonObject> fTreeEntityList = new ArrayList<>();
|
||
for (BomDetails details : bomlist) {
|
||
// 创建FTreeEntity对象,并加入FTreeEntity数组
|
||
JsonObject fTreeEntityItem = new JsonObject();
|
||
fTreeEntity.add(fTreeEntityItem);
|
||
// 添加FTreeEntity字段
|
||
fTreeEntityItem.addProperty("FReplaceGroup", 1);
|
||
fTreeEntityItem.addProperty("FMATERIALTYPE", "1");
|
||
// 创建FMATERIALIDCHILD对象,并加入FTreeEntity
|
||
JsonObject fMaterialIdChild = new JsonObject();
|
||
fTreeEntityItem.add("FMATERIALIDCHILD", fMaterialIdChild);
|
||
fMaterialIdChild.addProperty("FNumber", details.getPartNumber());
|
||
// 创建FCHILDUNITID对象,并加入FTreeEntity
|
||
String unit1 = isMaterialVerification2(details.getPartNumber());
|
||
if (!unit1.isEmpty()) {
|
||
JsonObject fChildUnitId = new JsonObject();
|
||
fTreeEntityItem.add("FCHILDUNITID", fChildUnitId);
|
||
fChildUnitId.addProperty("FNumber", unit1);
|
||
} else {
|
||
JsonObject fChildUnitId = new JsonObject();
|
||
fTreeEntityItem.add("FCHILDUNITID", fChildUnitId);
|
||
fChildUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
|
||
fTreeEntityItem.addProperty("F_HBYT_BJBM", details.getPartdiagramCode());
|
||
fTreeEntityItem.addProperty("F_HBYT_BJMC", details.getPartdiagramName());
|
||
fTreeEntityItem.addProperty("FDOSAGETYPE", "2");
|
||
fTreeEntityItem.addProperty("FNUMERATOR", details.getQuantity());
|
||
fTreeEntityItem.addProperty("FDENOMINATOR", details.getDenominator());
|
||
fTreeEntityList.add(fTreeEntityItem);
|
||
}
|
||
String jsonData = json.toString();
|
||
log.debug("打印json:" + jsonData);
|
||
System.out.println(jsonData);
|
||
try {
|
||
// 业务对象标识
|
||
String formId = "ENG_BOM";
|
||
// 调用接口
|
||
String resultJson = client.save(formId, jsonData);
|
||
|
||
// 用于记录结果
|
||
Gson gson = new Gson();
|
||
// 对返回结果进行解析和校验
|
||
RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
||
if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
|
||
log.debug("物料清单bom 保存成功===================>" + "图号:" + bomDetails.getFNumber());
|
||
return 1;
|
||
} else {
|
||
log.error("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
log.error("物料清单bom 保存失败===================>" + "图号:" + bomDetails.getFNumber());
|
||
return 0;
|
||
}
|
||
} catch (Exception e) {
|
||
R.fail(e.getMessage());
|
||
}
|
||
// 输出生成的Json
|
||
return 1;
|
||
}
|
||
|
||
// FBOM物料清单保存
|
||
public BOMUploadResult FBloadBillOfMaterialsPreservation(List<BomDetails> bomlist, ProcessOrderPro bo,String groupName) {
|
||
|
||
BomDetails bomDetails1 = bomlist.get(0);
|
||
int verification = isMaterialVerification(bomDetails1.getFNumber(), bomDetails1.getFName());
|
||
// 验证父级物料是否存在
|
||
if (verification == 2) {
|
||
log.debug("父级物料物料不存在");
|
||
// 父级物料不存在,即调用物料新增接口
|
||
int materialVerificationResult = loadFBMaterialPreservation(bomDetails1);
|
||
if (materialVerificationResult == 1) {
|
||
log.debug("父级物料保存成功");
|
||
} else {
|
||
log.error("父级物料保存失败");
|
||
}
|
||
}
|
||
|
||
// TODO: 实现加载和保存物料清单数据的逻辑
|
||
// 创建一个空的JsonObject
|
||
JsonObject json = new JsonObject();
|
||
|
||
// 添加其他字段
|
||
json.addProperty("IsAutoSubmitAndAudit", "true");
|
||
// 创建Model对象,并加入JsonObj ect
|
||
JsonObject model = new JsonObject();
|
||
json.add("Model", model);
|
||
|
||
// 添加Model字段
|
||
model.addProperty("FID", 0);
|
||
// 创建FBILLTYPE对象,并加入Model
|
||
JsonObject fBillType = new JsonObject();
|
||
|
||
JsonObject fGroupType = new JsonObject();
|
||
model.add("FGroup", fGroupType);
|
||
//分组
|
||
fGroupType.addProperty("FNumber", groupName);
|
||
// 创建FMATERIALID对象,并加入Model
|
||
JsonObject fMaterialId = new JsonObject();
|
||
model.add("FMATERIALID", fMaterialId);
|
||
fMaterialId.addProperty("FNumber", bomDetails1.getFNumber());
|
||
// 设置父级物料的单位
|
||
String unit = isMaterialVerification2(bomDetails1.getFNumber());
|
||
log.debug("单位为:" + unit);
|
||
if (!unit.isEmpty()) {
|
||
// 创建FUNITID对象,并加入Model
|
||
JsonObject fUnitId = new JsonObject();
|
||
model.add("FUNITID", fUnitId);
|
||
fUnitId.addProperty("FNumber", unit);
|
||
} else {
|
||
// 创建FUNITID对象,并加入Model
|
||
JsonObject fUnitId = new JsonObject();
|
||
model.add("FUNITID", fUnitId);
|
||
fUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
// 创建FTreeEntity数组,并加入Model
|
||
JsonArray fTreeEntity = new JsonArray();
|
||
model.add("FTreeEntity", fTreeEntity);
|
||
List<JsonObject> fTreeEntityList = new ArrayList<>();
|
||
for (BomDetails details : bomlist) {
|
||
if (bomlist.isEmpty()) {
|
||
return null;
|
||
}
|
||
// 创建FTreeEntity对象,并加入FTreeEntity数组
|
||
JsonObject fTreeEntityItem = new JsonObject();
|
||
fTreeEntity.add(fTreeEntityItem);
|
||
// 添加FTreeEntity字段
|
||
fTreeEntityItem.addProperty("FReplaceGroup", 1);
|
||
|
||
if (details != null) {
|
||
String partNumber = details.getPartNumber();
|
||
String remarks = details.getRemarks();
|
||
// 先设置默认值
|
||
String supplyType = " ";
|
||
if (partNumber != null) {
|
||
// 检查是否为安徒定购
|
||
if (iProcessRouteService.isAnTuDingGou(partNumber)) {
|
||
supplyType = "C";
|
||
}
|
||
// 检查是否为伊特
|
||
else if ("伊特".equals(remarks)) {
|
||
supplyType = "C";
|
||
}
|
||
}
|
||
fTreeEntityItem.addProperty("FSupplyType", supplyType);
|
||
}
|
||
fTreeEntityItem.addProperty("FMATERIALTYPE", "1");
|
||
// 创建FMATERIALIDCHILD对象,并加入FTreeEntity
|
||
JsonObject fMaterialIdChild = new JsonObject();
|
||
fTreeEntityItem.add("FMATERIALIDCHILD", fMaterialIdChild);
|
||
fMaterialIdChild.addProperty("FNumber", details.getPartNumber());
|
||
// 创建FCHILDUNITID对象,并加入FTreeEntity
|
||
String unit1 = isMaterialVerification2(details.getPartNumber());
|
||
if (!unit1.isEmpty()) {
|
||
JsonObject fChildUnitId = new JsonObject();
|
||
fTreeEntityItem.add("FCHILDUNITID", fChildUnitId);
|
||
fChildUnitId.addProperty("FNumber", unit1);
|
||
} else {
|
||
JsonObject fChildUnitId = new JsonObject();
|
||
fTreeEntityItem.add("FCHILDUNITID", fChildUnitId);
|
||
fChildUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
|
||
fTreeEntityItem.addProperty("F_HBYT_BJBM", details.getPartdiagramCode());
|
||
fTreeEntityItem.addProperty("F_HBYT_BJMC", details.getPartdiagramName());
|
||
fTreeEntityItem.addProperty("FDOSAGETYPE", "2");
|
||
fTreeEntityItem.addProperty("FNUMERATOR", details.getQuantity()); // 分子
|
||
fTreeEntityItem.addProperty("FDENOMINATOR", details.getDenominator());
|
||
|
||
// 添加货主信息 查看这个bom中是否符合货主信息
|
||
String materialCode = details.getPartNumber();
|
||
Boolean vmiByCode = iMaterialTotalService.getVMIByCode(materialCode);
|
||
if (vmiByCode) {
|
||
fTreeEntityItem.addProperty("FOWNERTYPEID", "BD_Supplier");
|
||
JsonObject FOWNERID = new JsonObject();
|
||
fTreeEntityItem.add("FOWNERID", FOWNERID);
|
||
FOWNERID.addProperty("FNumber", "GYS_070");
|
||
}
|
||
fTreeEntityList.add(fTreeEntityItem);
|
||
}
|
||
try {
|
||
String resultJson = new K3CloudApi().save("ENG_BOM", json.toString());
|
||
// 直接用 Jackson 解析
|
||
BOMUploadResult result = parseK3Response(resultJson);
|
||
if (result.isSuccess()) {
|
||
log.info("✅ BOM保存成功, 图号={}", bomDetails1.getFNumber());
|
||
} else {
|
||
log.error("❌ BOM保存失败, 图号={}, 错误={}", bomDetails1.getFNumber(), result.getErrorMessage());
|
||
}
|
||
return result;
|
||
} catch (Exception e) {
|
||
log.error("保存BOM异常,图号={}, 错误={}", bomDetails1.getFNumber(), e.getMessage(), e);
|
||
return BOMUploadResult.fail("保存BOM异常: " + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/*
|
||
* 父级物料保存接口
|
||
* 单位 是台
|
||
*/
|
||
public int loadMaterialPreservation(BomDetails bomDetails) {
|
||
K3CloudApi client = new K3CloudApi();
|
||
// 创建一个空的JsonObject
|
||
JsonObject json = new JsonObject();
|
||
|
||
// 添加IsAutoSubmitAndAudit字段
|
||
json.addProperty("IsAutoSubmitAndAudit", "true");
|
||
|
||
// 创建Model对象,并加入JsonObject
|
||
JsonObject model = new JsonObject();
|
||
// 添加Model字段
|
||
model.addProperty("FMATERIALID", 0);
|
||
model.addProperty("FNumber", bomDetails.getFNumber());
|
||
model.addProperty("FName", bomDetails.getFName());
|
||
json.add("Model", model);
|
||
MaterialProperties materialProperties = iMaterialPropertiesService.selectByAttribute(bomDetails.getMaterial());
|
||
JsonObject FSVRIAssistant = new JsonObject();
|
||
FSVRIAssistant.addProperty("FNumber", materialProperties.getMaterialAttributeId());
|
||
model.add("F_SVRI_Assistant", FSVRIAssistant);
|
||
|
||
// 创建FMaterialGroup对象,并加入Model
|
||
JsonObject fMaterialGroup = new JsonObject();
|
||
fMaterialGroup.addProperty("FNumber", "XM-100");
|
||
|
||
model.add("FMaterialGroup", fMaterialGroup);
|
||
|
||
model.addProperty("FIsHandleReserve", true);
|
||
|
||
// 创建SubHeadEntity对象,并加入Model
|
||
JsonObject subHeadEntity = new JsonObject();
|
||
model.add("SubHeadEntity", subHeadEntity);
|
||
|
||
subHeadEntity.addProperty("FErpClsID", "2");
|
||
subHeadEntity.addProperty("FFeatureItem", "1");
|
||
|
||
// 创建FCategoryID对象,并加入SubHeadEntity
|
||
JsonObject fCategoryID = new JsonObject();
|
||
fCategoryID.addProperty("FNumber", "CHLB05_SYS");
|
||
subHeadEntity.add("FCategoryID", fCategoryID);
|
||
|
||
// 创建FTaxRateId对象,并加入SubHeadEntity
|
||
JsonObject fTaxRateId = new JsonObject();
|
||
fTaxRateId.addProperty("FNUMBER", "SL02_SYS");
|
||
subHeadEntity.add("FTaxRateId", fTaxRateId);
|
||
|
||
// 创建FBaseUnitId对象,并加入SubHeadEntity
|
||
JsonObject fBaseUnitId = new JsonObject();
|
||
fBaseUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity.add("FBaseUnitId", fBaseUnitId);
|
||
|
||
subHeadEntity.addProperty("FIsPurchase", true);
|
||
subHeadEntity.addProperty("FIsInventory", true);
|
||
subHeadEntity.addProperty("FIsSubContract", true);
|
||
subHeadEntity.addProperty("FIsSale", true);
|
||
subHeadEntity.addProperty("FIsProduce", true);
|
||
|
||
// 创建SubHeadEntity1对象,并加入Model
|
||
JsonObject subHeadEntity1 = new JsonObject();
|
||
model.add("SubHeadEntity1", subHeadEntity1);
|
||
JsonObject fStoreUnitId = new JsonObject();
|
||
fStoreUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity1.add("FStoreUnitID", fStoreUnitId);
|
||
subHeadEntity1.addProperty("FUnitConvertDir", "1");
|
||
|
||
// 创建FStockId对象,并加入SubHeadEntity1
|
||
JsonObject fStockId = new JsonObject();
|
||
fStockId.addProperty("FNumber", "CK010");
|
||
subHeadEntity1.add("FStockId", fStockId);
|
||
|
||
// 创建FCurrencyId对象,并加入SubHeadEntity1
|
||
JsonObject fCurrencyId = new JsonObject();
|
||
fCurrencyId.addProperty("FNumber", "PRE001");
|
||
subHeadEntity1.add("FCurrencyId", fCurrencyId);
|
||
|
||
subHeadEntity1.addProperty("FIsSNPRDTracy", false);
|
||
subHeadEntity1.addProperty("FSNManageType", "1");
|
||
subHeadEntity1.addProperty("FSNGenerateTime", "1");
|
||
subHeadEntity1.addProperty("FBoxStandardQty", 0.0);
|
||
// 创建FPurchaseUnitId对象,并加入SubHeadEntity1
|
||
JsonObject fPurchaseUnitId = new JsonObject();
|
||
fPurchaseUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity1.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
|
||
// 创建SubHeadEntity3对象,并加入Model
|
||
JsonObject subHeadEntity3 = new JsonObject();
|
||
model.add("SubHeadEntity3", subHeadEntity3);
|
||
|
||
/*
|
||
* // 创建FPurchaseUnitId对象,并加入SubHeadEntity3
|
||
* JsonObject fPurchaseUnitId = new JsonObject();
|
||
* fPurchaseUnitId.addProperty("FNumber", "008");
|
||
* subHeadEntity3.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
*/
|
||
|
||
// 创建FPurchasePriceUnitId对象,并加入SubHeadEntity3
|
||
JsonObject fPurchasePriceUnitId = new JsonObject();
|
||
fPurchasePriceUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity3.add("FPurchasePriceUnitId", fPurchasePriceUnitId);
|
||
|
||
subHeadEntity3.addProperty("FIsQuota", false);
|
||
subHeadEntity3.addProperty("FQuotaType", "1");
|
||
|
||
// 创建SubHeadEntity6对象,并加入Model 检验项
|
||
JsonObject subHeadEntity6 = new JsonObject();
|
||
model.add("SubHeadEntity6", subHeadEntity6);
|
||
// 不同的属性不同的检验方案
|
||
if (bomDetails.getStats().equals("1")) {
|
||
// 外购
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
}
|
||
if (bomDetails.getStats().equals("2")) {
|
||
// 自制
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
if (bomDetails.getStats().equals("3")) {
|
||
// 委外
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckSubRtnMtrl", true);
|
||
}
|
||
// 库存检验
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
// 创建SubHeadEntity5对象,并加入Model
|
||
JsonObject subHeadEntity5 = new JsonObject();
|
||
model.add("SubHeadEntity5", subHeadEntity5);
|
||
|
||
// 创建FProduceUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fProduceUnitId = new JsonObject();
|
||
fProduceUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity5.add("FProduceUnitId", fProduceUnitId);
|
||
|
||
// 创建FProduceBillType对象,并加入SubHeadEntity5
|
||
JsonObject fProduceBillType = new JsonObject();
|
||
fProduceBillType.addProperty("FNUMBER", "SCDD05_SYS");
|
||
subHeadEntity5.add("FProduceBillType", fProduceBillType);
|
||
|
||
// 创建FBOMUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fBOMUnitId = new JsonObject();
|
||
fBOMUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity5.add("FBOMUnitId", fBOMUnitId);
|
||
|
||
subHeadEntity5.addProperty("FIsMainPrd", true);
|
||
subHeadEntity5.addProperty("FIssueType", "1");
|
||
|
||
// 创建FPickStockId对象,并加入SubHeadEntity5
|
||
JsonObject fPickStockId = new JsonObject();
|
||
fPickStockId.addProperty("FNumber", "CK012");
|
||
subHeadEntity1.add("FPickStockId", fPickStockId);
|
||
|
||
subHeadEntity5.addProperty("FOverControlMode", "1");
|
||
subHeadEntity5.addProperty("FStandHourUnitId", "3600");
|
||
subHeadEntity5.addProperty("FBackFlushType", "1");
|
||
String jsonData = json.toString();
|
||
System.out.println(jsonData);
|
||
try {
|
||
// 业务对象标识
|
||
String formId = "BD_MATERIAL";
|
||
// 调用接口
|
||
String resultJson = client.save(formId, jsonData);
|
||
// 用于记录结果
|
||
Gson gson = new Gson();
|
||
// 对返回结果进行解析和校验
|
||
RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
||
if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
|
||
|
||
System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
|
||
log.debug("接口返回结果: %s%n" + gson.toJson(repoRet.getResult()));
|
||
return 1;
|
||
} else {
|
||
fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
log.error("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus().getErrors().get(0)
|
||
.getMessage().contains("系统中已存在相同编码")));
|
||
return 0;
|
||
}
|
||
} catch (Exception e) {
|
||
fail(e.getMessage());
|
||
return 2;
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* FB父级物料保存接口
|
||
*/
|
||
public static int loadFBMaterialPreservation(BomDetails bomDetail) {
|
||
K3CloudApi client = new K3CloudApi();
|
||
// 创建一个空的JsonObject
|
||
JsonObject json = new JsonObject();
|
||
|
||
// 添加IsAutoSubmitAndAudit字段
|
||
json.addProperty("IsAutoSubmitAndAudit", "true");
|
||
|
||
// 创建Model对象,并加入JsonObject
|
||
JsonObject model = new JsonObject();
|
||
json.add("Model", model);
|
||
|
||
// 添加Model字段
|
||
model.addProperty("FMATERIALID", 0);
|
||
model.addProperty("FNumber", bomDetail.getFNumber());
|
||
model.addProperty("FName", bomDetail.getFName());
|
||
|
||
// 创建FMaterialGroup对象,并加入Model
|
||
JsonObject fMaterialGroup = new JsonObject();
|
||
fMaterialGroup.addProperty("FNumber", "A000106");
|
||
model.add("FMaterialGroup", fMaterialGroup);
|
||
|
||
model.addProperty("FIsHandleReserve", true);
|
||
|
||
// 创建SubHeadEntity对象,并加入Model
|
||
JsonObject subHeadEntity = new JsonObject();
|
||
model.add("SubHeadEntity", subHeadEntity);
|
||
|
||
subHeadEntity.addProperty("FErpClsID", "2");
|
||
subHeadEntity.addProperty("FFeatureItem", "1");
|
||
|
||
// 创建FCategoryID对象,并加入SubHeadEntity
|
||
JsonObject fCategoryID = new JsonObject();
|
||
fCategoryID.addProperty("FNumber", "CHLB05_SYS");// 产成品
|
||
subHeadEntity.add("FCategoryID", fCategoryID);
|
||
|
||
// 创建FTaxRateId对象,并加入SubHeadEntity
|
||
JsonObject fTaxRateId = new JsonObject();
|
||
fTaxRateId.addProperty("FNUMBER", "SL02_SYS");
|
||
subHeadEntity.add("FTaxRateId", fTaxRateId);
|
||
|
||
// 创建FBaseUnitId对象,并加入SubHeadEntity
|
||
JsonObject fBaseUnitId = new JsonObject();
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
subHeadEntity.add("FBaseUnitId", fBaseUnitId);
|
||
|
||
subHeadEntity.addProperty("FIsPurchase", true);
|
||
subHeadEntity.addProperty("FIsInventory", true);
|
||
subHeadEntity.addProperty("FIsSubContract", true);
|
||
subHeadEntity.addProperty("FIsSale", true);
|
||
subHeadEntity.addProperty("FIsProduce", true);
|
||
|
||
// 创建SubHeadEntity1对象,并加入Model
|
||
JsonObject subHeadEntity1 = new JsonObject();
|
||
model.add("SubHeadEntity1", subHeadEntity1);
|
||
JsonObject fStoreUnitId = new JsonObject();
|
||
fStoreUnitId.addProperty("FNumber", "jian");
|
||
subHeadEntity1.add("FStoreUnitID", fStoreUnitId);
|
||
subHeadEntity1.addProperty("FUnitConvertDir", "1");
|
||
|
||
// 创建FStockId对象,并加入SubHeadEntity1
|
||
JsonObject fStockId = new JsonObject();
|
||
// 判断是产成品还是企标
|
||
if (bomDetail.getRemarks() != null && bomDetail.getRemarks().equals("企标零件库")) {
|
||
String cangKu = "CK010";
|
||
fStockId.addProperty("FNumber", cangKu);
|
||
} else if (bomDetail.getRemarks() != null && bomDetail.getRemarks().equals("产成品库")) {
|
||
String cangKu = "CK011";
|
||
fStockId.addProperty("FNumber", cangKu);
|
||
}
|
||
subHeadEntity1.add("FStockId", fStockId);
|
||
|
||
// 创建FCurrencyId对象,并加入SubHeadEntity1
|
||
JsonObject fCurrencyId = new JsonObject();
|
||
fCurrencyId.addProperty("FNumber", "PRE001");
|
||
subHeadEntity1.add("FCurrencyId", fCurrencyId);
|
||
|
||
subHeadEntity1.addProperty("FIsSNPRDTracy", false);
|
||
subHeadEntity1.addProperty("FSNManageType", "1");
|
||
subHeadEntity1.addProperty("FSNGenerateTime", "1");
|
||
subHeadEntity1.addProperty("FBoxStandardQty", 0.0);
|
||
// 创建FPurchaseUnitId对象,并加入SubHeadEntity1
|
||
JsonObject fPurchaseUnitId = new JsonObject();
|
||
fPurchaseUnitId.addProperty("FNumber", "jian");
|
||
subHeadEntity1.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
|
||
// 创建SubHeadEntity3对象,并加入Model
|
||
JsonObject subHeadEntity3 = new JsonObject();
|
||
model.add("SubHeadEntity3", subHeadEntity3);
|
||
|
||
/*
|
||
* // 创建FPurchaseUnitId对象,并加入SubHeadEntity3
|
||
* JsonObject fPurchaseUnitId = new JsonObject();
|
||
* fPurchaseUnitId.addProperty("FNumber", "008");
|
||
* subHeadEntity3.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
*/
|
||
|
||
// 创建FPurchasePriceUnitId对象,并加入SubHeadEntity3
|
||
JsonObject fPurchasePriceUnitId = new JsonObject();
|
||
fPurchasePriceUnitId.addProperty("FNumber", "jian");
|
||
subHeadEntity3.add("FPurchasePriceUnitId", fPurchasePriceUnitId);
|
||
|
||
subHeadEntity3.addProperty("FIsQuota", false);
|
||
subHeadEntity3.addProperty("FQuotaType", "1");
|
||
|
||
// 创建SubHeadEntity6对象,并加入Model 检验项
|
||
JsonObject subHeadEntity6 = new JsonObject();
|
||
model.add("SubHeadEntity6", subHeadEntity6);
|
||
// 不同的属性不同的检验方案
|
||
if (bomDetail.getStats().equals("1")) {
|
||
// 外购
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
}
|
||
if (bomDetail.getStats().equals("2")) {
|
||
// 自制
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
if (bomDetail.getStats().equals("3")) {
|
||
// 委外
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckSubRtnMtrl", true);
|
||
}
|
||
// 库存检验
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
// 创建SubHeadEntity5对象,并加入Model
|
||
JsonObject subHeadEntity5 = new JsonObject();
|
||
model.add("SubHeadEntity5", subHeadEntity5);
|
||
|
||
// 创建FProduceUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fProduceUnitId = new JsonObject();
|
||
fProduceUnitId.addProperty("FNumber", "jian");
|
||
subHeadEntity5.add("FProduceUnitId", fProduceUnitId);
|
||
|
||
// 创建FProduceBillType对象,并加入SubHeadEntity5
|
||
JsonObject fProduceBillType = new JsonObject();
|
||
fProduceBillType.addProperty("FNUMBER", "SCDD05_SYS");
|
||
subHeadEntity5.add("FProduceBillType", fProduceBillType);
|
||
|
||
// 创建FBOMUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fBOMUnitId = new JsonObject();
|
||
fBOMUnitId.addProperty("FNumber", "jian");
|
||
subHeadEntity5.add("FBOMUnitId", fBOMUnitId);
|
||
|
||
subHeadEntity5.addProperty("FIsMainPrd", true);
|
||
subHeadEntity5.addProperty("FIssueType", "1");
|
||
|
||
// 创建FPickStockId对象,并加入SubHeadEntity5
|
||
JsonObject fPickStockId = new JsonObject();
|
||
fPickStockId.addProperty("FNumber", "CK012");
|
||
subHeadEntity1.add("FPickStockId", fPickStockId);
|
||
|
||
subHeadEntity5.addProperty("FOverControlMode", "1");
|
||
subHeadEntity5.addProperty("FStandHourUnitId", "3600");
|
||
subHeadEntity5.addProperty("FBackFlushType", "1");
|
||
String jsonData = json.toString();
|
||
System.out.println(jsonData);
|
||
try {
|
||
// 业务对象标识
|
||
String formId = "BD_MATERIAL";
|
||
// 调用接口
|
||
String resultJson = client.save(formId, jsonData);
|
||
// 用于记录结果
|
||
Gson gson = new Gson();
|
||
// 对返回结果进行解析和校验
|
||
RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
||
if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
|
||
System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
|
||
log.debug("接口返回结果: %s%n" + gson.toJson(repoRet.getResult()));
|
||
return 1;
|
||
} else {
|
||
fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
log.error("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
return 0;
|
||
}
|
||
} catch (Exception e) {
|
||
fail(e.getMessage());
|
||
return 0;
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* FB父级物料保存接口
|
||
*/
|
||
public int loadChengPinMaterialPreservation(HashMap<String, String> bomDetail) {
|
||
K3CloudApi client = new K3CloudApi();
|
||
// 创建一个空的JsonObject
|
||
JsonObject json = new JsonObject();
|
||
|
||
// 添加IsAutoSubmitAndAudit字段
|
||
json.addProperty("IsAutoSubmitAndAudit", "true");
|
||
|
||
// 创建Model对象,并加入JsonObject
|
||
JsonObject model = new JsonObject();
|
||
json.add("Model", model);
|
||
|
||
// 添加Model字段
|
||
model.addProperty("FMATERIALID", 0);
|
||
model.addProperty("FNumber", bomDetail.get("fnumber"));
|
||
model.addProperty("FName", bomDetail.get("fname"));
|
||
|
||
// 创建FMaterialGroup对象,并加入Model
|
||
JsonObject fMaterialGroup = new JsonObject();
|
||
fMaterialGroup.addProperty("FNumber", "A000106");
|
||
model.add("FMaterialGroup", fMaterialGroup);
|
||
|
||
model.addProperty("FIsHandleReserve", true);
|
||
|
||
// 创建SubHeadEntity对象,并加入Model
|
||
JsonObject subHeadEntity = new JsonObject();
|
||
model.add("SubHeadEntity", subHeadEntity);
|
||
|
||
subHeadEntity.addProperty("FErpClsID", "2");
|
||
subHeadEntity.addProperty("FFeatureItem", "1");
|
||
|
||
// 创建FCategoryID对象,并加入SubHeadEntity
|
||
JsonObject fCategoryID = new JsonObject();
|
||
fCategoryID.addProperty("FNumber", "CHLB05_SYS");// 产成品
|
||
subHeadEntity.add("FCategoryID", fCategoryID);
|
||
|
||
// 创建FTaxRateId对象,并加入SubHeadEntity
|
||
JsonObject fTaxRateId = new JsonObject();
|
||
fTaxRateId.addProperty("FNUMBER", "SL02_SYS");
|
||
subHeadEntity.add("FTaxRateId", fTaxRateId);
|
||
|
||
// 创建FBaseUnitId对象,并加入SubHeadEntity
|
||
JsonObject fBaseUnitId = new JsonObject();
|
||
fBaseUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity.add("FBaseUnitId", fBaseUnitId);
|
||
|
||
subHeadEntity.addProperty("FIsPurchase", true);
|
||
subHeadEntity.addProperty("FIsInventory", true);
|
||
// 成品不允许委外
|
||
// subHeadEntity.addProperty("FIsSubContract", true);
|
||
subHeadEntity.addProperty("FIsSale", true);
|
||
subHeadEntity.addProperty("FIsProduce", true);
|
||
|
||
// 创建SubHeadEntity1对象,并加入Model
|
||
JsonObject subHeadEntity1 = new JsonObject();
|
||
model.add("SubHeadEntity1", subHeadEntity1);
|
||
JsonObject fStoreUnitId = new JsonObject();
|
||
fStoreUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity1.add("FStoreUnitID", fStoreUnitId);
|
||
subHeadEntity1.addProperty("FUnitConvertDir", "1");
|
||
|
||
// 创建FStockId对象,并加入SubHeadEntity1
|
||
JsonObject fStockId = new JsonObject();
|
||
// 判断是产成品还是企标
|
||
String cangKu = "CK011";
|
||
fStockId.addProperty("FNumber", cangKu);
|
||
subHeadEntity1.add("FStockId", fStockId);
|
||
|
||
// 创建FCurrencyId对象,并加入SubHeadEntity1
|
||
JsonObject fCurrencyId = new JsonObject();
|
||
fCurrencyId.addProperty("FNumber", "PRE001");
|
||
subHeadEntity1.add("FCurrencyId", fCurrencyId);
|
||
|
||
subHeadEntity1.addProperty("FIsSNPRDTracy", false);
|
||
subHeadEntity1.addProperty("FSNManageType", "1");
|
||
subHeadEntity1.addProperty("FSNGenerateTime", "1");
|
||
subHeadEntity1.addProperty("FBoxStandardQty", 0.0);
|
||
// 创建FPurchaseUnitId对象,并加入SubHeadEntity1
|
||
JsonObject fPurchaseUnitId = new JsonObject();
|
||
fPurchaseUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity1.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
|
||
// 创建SubHeadEntity3对象,并加入Model
|
||
JsonObject subHeadEntity3 = new JsonObject();
|
||
model.add("SubHeadEntity3", subHeadEntity3);
|
||
|
||
/*
|
||
* // 创建FPurchaseUnitId对象,并加入SubHeadEntity3
|
||
* JsonObject fPurchaseUnitId = new JsonObject();
|
||
* fPurchaseUnitId.addProperty("FNumber", "008");
|
||
* subHeadEntity3.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
*/
|
||
|
||
// 创建FPurchasePriceUnitId对象,并加入SubHeadEntity3
|
||
JsonObject fPurchasePriceUnitId = new JsonObject();
|
||
fPurchasePriceUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity3.add("FPurchasePriceUnitId", fPurchasePriceUnitId);
|
||
|
||
subHeadEntity3.addProperty("FIsQuota", false);
|
||
subHeadEntity3.addProperty("FQuotaType", "1");
|
||
|
||
// 创建SubHeadEntity6对象,并加入Model 检验项
|
||
JsonObject subHeadEntity6 = new JsonObject();
|
||
model.add("SubHeadEntity6", subHeadEntity6);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturn", true);
|
||
|
||
// 创建SubHeadEntity5对象,并加入Model
|
||
JsonObject subHeadEntity5 = new JsonObject();
|
||
model.add("SubHeadEntity5", subHeadEntity5);
|
||
|
||
// 创建FProduceUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fProduceUnitId = new JsonObject();
|
||
fProduceUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity5.add("FProduceUnitId", fProduceUnitId);
|
||
|
||
// 创建FProduceBillType对象,并加入SubHeadEntity5
|
||
JsonObject fProduceBillType = new JsonObject();
|
||
fProduceBillType.addProperty("FNUMBER", "SCDD05_SYS");
|
||
subHeadEntity5.add("FProduceBillType", fProduceBillType);
|
||
|
||
// 创建FBOMUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fBOMUnitId = new JsonObject();
|
||
fBOMUnitId.addProperty("FNumber", "008");
|
||
subHeadEntity5.add("FBOMUnitId", fBOMUnitId);
|
||
|
||
subHeadEntity5.addProperty("FIsMainPrd", true);
|
||
subHeadEntity5.addProperty("FIssueType", "1");
|
||
|
||
// 创建FPickStockId对象,并加入SubHeadEntity5
|
||
JsonObject fPickStockId = new JsonObject();
|
||
fPickStockId.addProperty("FNumber", "CK012");
|
||
subHeadEntity1.add("FPickStockId", fPickStockId);
|
||
|
||
subHeadEntity5.addProperty("FOverControlMode", "1");
|
||
subHeadEntity5.addProperty("FStandHourUnitId", "3600");
|
||
subHeadEntity5.addProperty("FBackFlushType", "1");
|
||
String jsonData = json.toString();
|
||
System.out.println(jsonData);
|
||
try {
|
||
// 业务对象标识
|
||
String formId = "BD_MATERIAL";
|
||
// 调用接口
|
||
String resultJson = client.save(formId, jsonData);
|
||
// 用于记录结果
|
||
Gson gson = new Gson();
|
||
// 对返回结果进行解析和校验
|
||
RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
||
if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
|
||
System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
|
||
log.debug("接口返回结果: %s%n" + gson.toJson(repoRet.getResult()));
|
||
return 1;
|
||
} else {
|
||
fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
log.error("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
return 0;
|
||
}
|
||
} catch (Exception e) {
|
||
fail(e.getMessage());
|
||
return 0;
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 物料验证
|
||
* 验证物料在金蝶中是否存在
|
||
*
|
||
* @return
|
||
*/
|
||
public static int isMaterialVerification(String DrawingNumber, String name) {
|
||
if (DrawingNumber == null || DrawingNumber.isEmpty() || name == null || name.isEmpty()) {
|
||
return 2;
|
||
}
|
||
JsonArray jsonArray = JdUtils.loadMaterialQuery(DrawingNumber, name);
|
||
if (jsonArray == null) {
|
||
return 2;
|
||
} else {
|
||
for (JsonElement jsonElement : jsonArray) {
|
||
String FNumber = jsonElement.getAsJsonObject().get("FNumber").getAsString();
|
||
String FName = jsonElement.getAsJsonObject().get("FName").getAsString();
|
||
String Funit = jsonElement.getAsJsonObject().get("FBaseUnitId.FNumber").getAsString();
|
||
log.debug("图号为:" + FNumber);
|
||
log.debug("物料为:" + FName);
|
||
log.debug("单位为:" + Funit);
|
||
|
||
// 检查名称是否一致
|
||
if (FNumber.equals(DrawingNumber) && !FName.equals(name)) {
|
||
return 3; // 编码相同但名称不同
|
||
}
|
||
}
|
||
return 1;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* x
|
||
* 物料验证
|
||
* 获取单位
|
||
*/
|
||
public static String isMaterialVerification2(String DrawingNumber) {
|
||
if (DrawingNumber == null || DrawingNumber.isEmpty()) {
|
||
return "jian";
|
||
}
|
||
JsonArray jsonArray = JdUtils.loadMaterialQueryDrawingNumber(DrawingNumber);
|
||
if (jsonArray == null) {
|
||
return "jian";
|
||
} else {
|
||
String Funit = null;
|
||
for (JsonElement jsonElement : jsonArray) {
|
||
String FNumber = jsonElement.getAsJsonObject().get("FNumber").getAsString();
|
||
String FName = jsonElement.getAsJsonObject().get("FName").getAsString();
|
||
Funit = jsonElement.getAsJsonObject().get("FBaseUnitId.FNumber").getAsString();
|
||
log.debug("图号为:" + FNumber);
|
||
log.debug("物料为:" + FName);
|
||
log.debug("单位为:" + Funit);
|
||
}
|
||
return Funit;
|
||
}
|
||
}
|
||
|
||
public int loadMaterialPreservation(BomDetails bomDetails1, String states, Double fbWorkTime) {
|
||
K3CloudApi client = new K3CloudApi();
|
||
JsonObject json = new JsonObject();
|
||
json.addProperty("IsAutoSubmitAndAudit", "true");
|
||
|
||
JsonObject model = new JsonObject();
|
||
json.add("Model", model);
|
||
|
||
model.addProperty("FMATERIALID", 0);
|
||
//单重
|
||
if (!(bomDetails1.getDanZhong() == null) && !(bomDetails1.getSingleWeghit() == null)) {
|
||
model.addProperty("F_HBYT_DZ", bomDetails1.getSingleWeghit());
|
||
} else {
|
||
model.addProperty("F_HBYT_DZ", bomDetails1.getDanZhong());
|
||
}
|
||
model.addProperty("FSpecification", bomDetails1.getRemarks());
|
||
model.addProperty("FNumber", bomDetails1.getPartNumber());
|
||
model.addProperty("FName", bomDetails1.getName());
|
||
MaterialProperties materialProperties = iMaterialPropertiesService.selectByAttribute(bomDetails1.getMaterial());
|
||
if (materialProperties != null) {
|
||
JsonObject FSVRIAssistant = new JsonObject();
|
||
FSVRIAssistant.addProperty("FNumber", materialProperties.getMaterialAttributeId());
|
||
model.add("F_SVRI_Assistant", FSVRIAssistant);
|
||
} else {
|
||
// 没写材料为默认为空
|
||
JsonObject FSVRIAssistant = new JsonObject();
|
||
FSVRIAssistant.addProperty("FNumber", "17");
|
||
model.add("F_SVRI_Assistant", FSVRIAssistant);
|
||
}
|
||
JsonObject fMaterialGroup = new JsonObject();
|
||
fMaterialGroup.addProperty("FNumber", "YT100.01");
|
||
model.add("FMaterialGroup", fMaterialGroup);
|
||
|
||
model.addProperty("FIsHandleReserve", true);
|
||
|
||
JsonObject subHeadEntity = new JsonObject();
|
||
model.add("SubHeadEntity", subHeadEntity);
|
||
|
||
subHeadEntity.addProperty("FErpClsID", states);
|
||
subHeadEntity.addProperty("FFeatureItem", "1");
|
||
|
||
JsonObject fCategoryID = new JsonObject();
|
||
if (states.equals("2") || states.equals("3")) {
|
||
fCategoryID.addProperty("FNumber", "007");
|
||
} else {
|
||
fCategoryID.addProperty("FNumber", "006");
|
||
}
|
||
|
||
subHeadEntity.add("FCategoryID", fCategoryID);
|
||
|
||
JsonObject fTaxRateId = new JsonObject();
|
||
fTaxRateId.addProperty("FNUMBER", "SL02_SYS");
|
||
subHeadEntity.add("FTaxRateId", fTaxRateId);
|
||
|
||
JsonObject fBaseUnitId = new JsonObject();
|
||
subHeadEntity.add("FBaseUnitId", fBaseUnitId);
|
||
if (bomDetails1.getPartNumber().startsWith("015") || bomDetails1.getName().contains("磨光棒")) {
|
||
if (bomDetails1.getWareHouse() != null) {
|
||
if (bomDetails1.getWareHouse().equals("KG")) {
|
||
fBaseUnitId.addProperty("FNumber", "004");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("根")) {
|
||
fBaseUnitId.addProperty("FNumber", "003");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("mm")) {
|
||
fBaseUnitId.addProperty("FNumber", "005");
|
||
}
|
||
}
|
||
} else {
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
|
||
if (states.equals("1")) {
|
||
subHeadEntity.addProperty("FIsPurchase", true);
|
||
subHeadEntity.addProperty("FIsSale", true);
|
||
subHeadEntity.addProperty("FIsInventory", true);
|
||
} else {
|
||
subHeadEntity.addProperty("FIsPurchase", true);
|
||
subHeadEntity.addProperty("FIsInventory", true);
|
||
subHeadEntity.addProperty("FIsSubContract", true);
|
||
subHeadEntity.addProperty("FIsSale", true);
|
||
subHeadEntity.addProperty("FIsProduce", true);
|
||
|
||
}
|
||
|
||
// 创建SubHeadEntity1对象,并加入Model
|
||
JsonObject subHeadEntity1 = new JsonObject();
|
||
model.add("SubHeadEntity1", subHeadEntity1);
|
||
JsonObject fStoreUnitId = new JsonObject();
|
||
subHeadEntity1.add("FStoreUnitID", fStoreUnitId);
|
||
// 如果是原材料的话且
|
||
if (bomDetails1.getPartNumber().startsWith("015") || bomDetails1.getName().contains("磨光棒")) {
|
||
if (bomDetails1.getWareHouse() != null) {
|
||
if (bomDetails1.getWareHouse().equals("KG")) {
|
||
fStoreUnitId.addProperty("FNumber", "004");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("根")) {
|
||
fStoreUnitId.addProperty("FNumber", "003");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("mm")) {
|
||
fStoreUnitId.addProperty("FNumber", "005");
|
||
}
|
||
}
|
||
} else {
|
||
fStoreUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
|
||
subHeadEntity1.addProperty("FUnitConvertDir", "1");
|
||
|
||
// 创建FStockId对象,并加入SubHeadEntity1
|
||
// 仓库代码为 半成品库007
|
||
JsonObject fStockId = new JsonObject();
|
||
fStockId.addProperty("FNumber", "007");
|
||
subHeadEntity1.add("FStockId", fStockId);
|
||
|
||
// 创建FCurrencyId对象,并加入SubHeadEntity1
|
||
JsonObject fCurrencyId = new JsonObject();
|
||
fCurrencyId.addProperty("FNumber", "PRE001");
|
||
subHeadEntity1.add("FCurrencyId", fCurrencyId);
|
||
|
||
subHeadEntity1.addProperty("FIsSNPRDTracy", false);
|
||
subHeadEntity1.addProperty("FSNManageType", "1");
|
||
subHeadEntity1.addProperty("FSNGenerateTime", "1");
|
||
subHeadEntity1.addProperty("FBoxStandardQty", 0.0);
|
||
// 创建FPurchaseUnitId对象,并加入SubHeadEntity1
|
||
JsonObject fPurchaseUnitId = new JsonObject();
|
||
fPurchaseUnitId.addProperty("FNumber", "jian");
|
||
if (bomDetails1.getPartNumber().startsWith("015") || bomDetails1.getName().contains("磨光棒")) {
|
||
if (bomDetails1.getWareHouse() != null) {
|
||
if (bomDetails1.getWareHouse().equals("KG")) {
|
||
fPurchaseUnitId.addProperty("FNumber", "004");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("根")) {
|
||
fPurchaseUnitId.addProperty("FNumber", "003");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("mm")) {
|
||
fPurchaseUnitId.addProperty("FNumber", "005");
|
||
}
|
||
}
|
||
} else {
|
||
fPurchaseUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
subHeadEntity1.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
|
||
// 创建SubHeadEntity3对象,并加入Model
|
||
JsonObject subHeadEntity3 = new JsonObject();
|
||
model.add("SubHeadEntity3", subHeadEntity3);
|
||
|
||
// 创建FPurchasePriceUnitId对象,并加入SubHeadEntity3
|
||
JsonObject fPurchasePriceUnitId = new JsonObject();
|
||
fPurchasePriceUnitId.addProperty("FNumber", "jian");
|
||
if (bomDetails1.getPartNumber().startsWith("015") || bomDetails1.getName().contains("磨光棒")) {
|
||
if (bomDetails1.getWareHouse() != null) {
|
||
if (bomDetails1.getWareHouse().equals("KG")) {
|
||
fPurchasePriceUnitId.addProperty("FNumber", "004");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("根")) {
|
||
fPurchasePriceUnitId.addProperty("FNumber", "003");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("mm")) {
|
||
fPurchasePriceUnitId.addProperty("FNumber", "005");
|
||
}
|
||
}
|
||
} else {
|
||
fPurchasePriceUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
|
||
subHeadEntity3.add("FPurchasePriceUnitId", fPurchasePriceUnitId);
|
||
|
||
subHeadEntity3.addProperty("FIsQuota", false);
|
||
subHeadEntity3.addProperty("FQuotaType", "1");
|
||
|
||
JsonObject subHeadEntity6 = new JsonObject();
|
||
model.add("SubHeadEntity6", subHeadEntity6);
|
||
// 不同的属性不同的检验方案
|
||
if (states.equals("1")) {
|
||
// 外购
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
}
|
||
if (states.equals("2")) {
|
||
// 自制
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
if (states.equals("3")) {
|
||
// 委外
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
// 库存检验
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
// 创建SubHeadEntity5对象,并加入Model
|
||
JsonObject subHeadEntity5 = new JsonObject();
|
||
model.add("SubHeadEntity5", subHeadEntity5);
|
||
|
||
// 创建FProduceUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fProduceUnitId = new JsonObject();
|
||
fProduceUnitId.addProperty("FNumber", "jian");
|
||
if (bomDetails1.getPartNumber().startsWith("015") || bomDetails1.getName().contains("磨光棒")) {
|
||
if (bomDetails1.getWareHouse() != null) {
|
||
if (bomDetails1.getWareHouse().equals("KG")) {
|
||
fProduceUnitId.addProperty("FNumber", "004");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("根")) {
|
||
fProduceUnitId.addProperty("FNumber", "003");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("mm")) {
|
||
fProduceUnitId.addProperty("FNumber", "005");
|
||
}
|
||
}
|
||
} else {
|
||
fProduceUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
subHeadEntity5.add("FProduceUnitId", fProduceUnitId);
|
||
// 实际作工时,并加入SubHeadEntity5
|
||
|
||
// 创建FProduceBillType对象,并加入SubHeadEntity5
|
||
JsonObject fProduceBillType = new JsonObject();
|
||
fProduceBillType.addProperty("FNUMBER", "SCDD05_SYS");
|
||
subHeadEntity5.add("FProduceBillType", fProduceBillType);
|
||
|
||
// 创建FBOMUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fBOMUnitId = new JsonObject();
|
||
fBOMUnitId.addProperty("FNumber", "jian");
|
||
if (bomDetails1.getPartNumber().startsWith("015") || bomDetails1.getName().contains("磨光棒")) {
|
||
if (bomDetails1.getWareHouse() != null) {
|
||
if (bomDetails1.getWareHouse().equals("KG")) {
|
||
fBOMUnitId.addProperty("FNumber", "004");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("根")) {
|
||
fBOMUnitId.addProperty("FNumber", "003");
|
||
}
|
||
if (bomDetails1.getWareHouse().equals("mm")) {
|
||
fBOMUnitId.addProperty("FNumber", "005");
|
||
}
|
||
}
|
||
|
||
} else {
|
||
fBOMUnitId.addProperty("FNumber", "jian");
|
||
}
|
||
subHeadEntity5.add("FBOMUnitId", fBOMUnitId);
|
||
|
||
if (states.equals("1")) {
|
||
subHeadEntity5.addProperty("FIsMainPrd", false);
|
||
} else {
|
||
subHeadEntity5.addProperty("FIsMainPrd", true);
|
||
}
|
||
subHeadEntity5.addProperty("FIssueType", "1");
|
||
|
||
// 创建FPickStockId对象,并加入SubHeadEntity5
|
||
JsonObject fPickStockId = new JsonObject();
|
||
fPickStockId.addProperty("FNumber", " 010");
|
||
subHeadEntity1.add("FPickStockId", fPickStockId);
|
||
|
||
subHeadEntity5.addProperty("FOverControlMode", "1");
|
||
// 标准人员实作工时
|
||
subHeadEntity5.addProperty("FStdLaborProcessTime", fbWorkTime);
|
||
subHeadEntity5.addProperty("FStandHourUnitId", "60");
|
||
subHeadEntity5.addProperty("FBackFlushType", "1");
|
||
String jsonData = json.toString();
|
||
System.out.println(jsonData);
|
||
try {
|
||
// 业务对象标识
|
||
String formId = "BD_MATERIAL";
|
||
// 调用接口
|
||
String resultJson = client.save(formId, jsonData);
|
||
// 用于记录结果
|
||
Gson gson = new Gson();
|
||
// 对返回结果进行解析和校验
|
||
RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
||
if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
|
||
System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
|
||
log.info("接口返回结果: %s%n" + gson.toJson(repoRet.getResult()));
|
||
return 1;
|
||
} else {
|
||
fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
log.error("接口返回结果: 失败 " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
return 0;
|
||
}
|
||
} catch (Exception e) {
|
||
fail(e.getMessage());
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
/**
|
||
* / 创建电气物料
|
||
*/
|
||
|
||
public int loadMaterialToDQ(BomDetails bomDetails1, String states) {
|
||
K3CloudApi client = new K3CloudApi();
|
||
// 创建一个空的JsonObject
|
||
JsonObject json = new JsonObject();
|
||
// 添加IsAutoSubmitAndAudit字段
|
||
json.addProperty("IsAutoSubmitAndAudit", "true");
|
||
|
||
// 创建Model对象,并加入JsonObject
|
||
JsonObject model = new JsonObject();
|
||
json.add("Model", model);
|
||
|
||
// 添加Model字段
|
||
model.addProperty("FMATERIALID", 0);
|
||
model.addProperty("FSpecification", bomDetails1.getMaterial());// 规格 为存入的材质字段
|
||
model.addProperty("F_HBYT_PP", bomDetails1.getWareHouse());// 品牌 为存入的仓库字段
|
||
model.addProperty("FNumber", bomDetails1.getPartNumber());
|
||
model.addProperty("FName", bomDetails1.getName());
|
||
MaterialProperties materialProperties = iMaterialPropertiesService.selectByAttribute(bomDetails1.getMaterial());
|
||
if (materialProperties != null) {
|
||
JsonObject FSVRIAssistant = new JsonObject();
|
||
FSVRIAssistant.addProperty("FNumber", materialProperties.getMaterialAttributeId());
|
||
model.add("F_SVRI_Assistant", FSVRIAssistant);
|
||
} else {
|
||
// 没写材料为默认为空
|
||
JsonObject FSVRIAssistant = new JsonObject();
|
||
FSVRIAssistant.addProperty("FNumber", "17");
|
||
model.add("F_SVRI_Assistant", FSVRIAssistant);
|
||
}
|
||
// 创建FMaterialGroup对象,并加入Model
|
||
JsonObject fMaterialGroup = new JsonObject();
|
||
fMaterialGroup.addProperty("FNumber", "YT100.01");
|
||
model.add("FMaterialGroup", fMaterialGroup);
|
||
|
||
model.addProperty("FIsHandleReserve", true);
|
||
|
||
// 创建SubHeadEntity对象,并加入Model
|
||
JsonObject subHeadEntity = new JsonObject();
|
||
model.add("SubHeadEntity", subHeadEntity);
|
||
|
||
subHeadEntity.addProperty("FErpClsID", states);
|
||
subHeadEntity.addProperty("FFeatureItem", "1");
|
||
|
||
// 创建FCategoryID对象,并加入SubHeadEntity
|
||
JsonObject fCategoryID = new JsonObject();
|
||
if (states.equals("2") || states.equals("3")) {
|
||
fCategoryID.addProperty("FNumber", "007");
|
||
} else {
|
||
fCategoryID.addProperty("FNumber", "006");
|
||
}
|
||
|
||
subHeadEntity.add("FCategoryID", fCategoryID);
|
||
|
||
// 创建FTaxRateId对象,并加入SubHeadEntity
|
||
JsonObject fTaxRateId = new JsonObject();
|
||
fTaxRateId.addProperty("FNUMBER", "SL02_SYS");
|
||
subHeadEntity.add("FTaxRateId", fTaxRateId);
|
||
|
||
// 创建FBaseUnitId对象,并加入SubHeadEntity
|
||
JsonObject fBaseUnitId = new JsonObject();
|
||
switch (bomDetails1.getWareHouse()) {// 单位
|
||
case "把":
|
||
fBaseUnitId.addProperty("FNumber", "002");
|
||
break;
|
||
case "包":
|
||
fBaseUnitId.addProperty("FNumber", "012");
|
||
break;
|
||
case "个":
|
||
fBaseUnitId.addProperty("FNumber", "001");
|
||
break;
|
||
case "根":
|
||
fBaseUnitId.addProperty("FNumber", "003");
|
||
break;
|
||
case "米":
|
||
fBaseUnitId.addProperty("FNumber", "005");
|
||
break;
|
||
case "卷":
|
||
fBaseUnitId.addProperty("FNumber", "020");
|
||
break;
|
||
case "盒":
|
||
fBaseUnitId.addProperty("FNumber", "014");
|
||
break;
|
||
case "件":
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
break;
|
||
case "盘":
|
||
fBaseUnitId.addProperty("FNumber", "011");
|
||
break;
|
||
case "瓶":
|
||
fBaseUnitId.addProperty("FNumber", "016");
|
||
break;
|
||
case "条":
|
||
fBaseUnitId.addProperty("FNumber", "017");
|
||
break;
|
||
case "套":
|
||
fBaseUnitId.addProperty("FNumber", "007");
|
||
break;
|
||
}
|
||
subHeadEntity.add("FBaseUnitId", fBaseUnitId);
|
||
if (states.equals("1")) {
|
||
subHeadEntity.addProperty("FIsPurchase", true);
|
||
subHeadEntity.addProperty("FIsSale", true);
|
||
subHeadEntity.addProperty("FIsInventory", true);
|
||
} else {
|
||
subHeadEntity.addProperty("FIsPurchase", true);
|
||
subHeadEntity.addProperty("FIsInventory", true);
|
||
subHeadEntity.addProperty("FIsSubContract", true);
|
||
subHeadEntity.addProperty("FIsSale", true);
|
||
subHeadEntity.addProperty("FIsProduce", true);
|
||
|
||
}
|
||
|
||
// 创建SubHeadEntity1对象,并加入Model
|
||
JsonObject subHeadEntity1 = new JsonObject();
|
||
model.add("SubHeadEntity1", subHeadEntity1);
|
||
JsonObject fStoreUnitId = new JsonObject();
|
||
switch (bomDetails1.getWareHouse()) {
|
||
case "把":
|
||
fBaseUnitId.addProperty("FNumber", "002");
|
||
break;
|
||
case "包":
|
||
fBaseUnitId.addProperty("FNumber", "012");
|
||
break;
|
||
case "个":
|
||
fBaseUnitId.addProperty("FNumber", "001");
|
||
break;
|
||
case "根":
|
||
fBaseUnitId.addProperty("FNumber", "003");
|
||
break;
|
||
case "米":
|
||
fBaseUnitId.addProperty("FNumber", "005");
|
||
break;
|
||
case "卷":
|
||
fBaseUnitId.addProperty("FNumber", "020");
|
||
break;
|
||
case "盒":
|
||
fBaseUnitId.addProperty("FNumber", "014");
|
||
break;
|
||
case "件":
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
break;
|
||
case "盘":
|
||
fBaseUnitId.addProperty("FNumber", "011");
|
||
break;
|
||
case "瓶":
|
||
fBaseUnitId.addProperty("FNumber", "016");
|
||
break;
|
||
case "条":
|
||
fBaseUnitId.addProperty("FNumber", "017");
|
||
break;
|
||
case "套":
|
||
fBaseUnitId.addProperty("FNumber", "007");
|
||
break;
|
||
}
|
||
subHeadEntity1.add("FStoreUnitID", fStoreUnitId);
|
||
subHeadEntity1.addProperty("FUnitConvertDir", "1");
|
||
|
||
// 创建FStockId对象,并加入SubHeadEntity1
|
||
// 仓库代码为 半成品库007
|
||
JsonObject fStockId = new JsonObject();
|
||
fStockId.addProperty("FNumber", "007");
|
||
subHeadEntity1.add("FStockId", fStockId);
|
||
|
||
// 创建FCurrencyId对象,并加入SubHeadEntity1
|
||
JsonObject fCurrencyId = new JsonObject();
|
||
fCurrencyId.addProperty("FNumber", "PRE001");
|
||
subHeadEntity1.add("FCurrencyId", fCurrencyId);
|
||
|
||
subHeadEntity1.addProperty("FIsSNPRDTracy", false);
|
||
subHeadEntity1.addProperty("FSNManageType", "1");
|
||
subHeadEntity1.addProperty("FSNGenerateTime", "1");
|
||
subHeadEntity1.addProperty("FBoxStandardQty", 0.0);
|
||
// 创建FPurchaseUnitId对象,并加入SubHeadEntity1
|
||
JsonObject fPurchaseUnitId = new JsonObject();
|
||
switch (bomDetails1.getWareHouse()) {
|
||
case "把":
|
||
fBaseUnitId.addProperty("FNumber", "002");
|
||
break;
|
||
case "包":
|
||
fBaseUnitId.addProperty("FNumber", "012");
|
||
break;
|
||
case "个":
|
||
fBaseUnitId.addProperty("FNumber", "001");
|
||
break;
|
||
case "根":
|
||
fBaseUnitId.addProperty("FNumber", "003");
|
||
break;
|
||
case "米":
|
||
fBaseUnitId.addProperty("FNumber", "005");
|
||
break;
|
||
case "卷":
|
||
fBaseUnitId.addProperty("FNumber", "020");
|
||
break;
|
||
case "盒":
|
||
fBaseUnitId.addProperty("FNumber", "014");
|
||
break;
|
||
case "件":
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
break;
|
||
case "盘":
|
||
fBaseUnitId.addProperty("FNumber", "011");
|
||
break;
|
||
case "瓶":
|
||
fBaseUnitId.addProperty("FNumber", "016");
|
||
break;
|
||
case "条":
|
||
fBaseUnitId.addProperty("FNumber", "017");
|
||
break;
|
||
case "套":
|
||
fBaseUnitId.addProperty("FNumber", "007");
|
||
break;
|
||
}
|
||
subHeadEntity1.add("FPurchaseUnitId", fPurchaseUnitId);
|
||
|
||
// 创建SubHeadEntity3对象,并加入Model
|
||
JsonObject subHeadEntity3 = new JsonObject();
|
||
model.add("SubHeadEntity3", subHeadEntity3);
|
||
|
||
// 创建FPurchasePriceUnitId对象,并加入SubHeadEntity3
|
||
JsonObject fPurchasePriceUnitId = new JsonObject();
|
||
switch (bomDetails1.getWareHouse()) {
|
||
case "把":
|
||
fBaseUnitId.addProperty("FNumber", "002");
|
||
break;
|
||
case "包":
|
||
fBaseUnitId.addProperty("FNumber", "012");
|
||
break;
|
||
case "个":
|
||
fBaseUnitId.addProperty("FNumber", "001");
|
||
break;
|
||
case "根":
|
||
fBaseUnitId.addProperty("FNumber", "003");
|
||
break;
|
||
case "米":
|
||
fBaseUnitId.addProperty("FNumber", "005");
|
||
break;
|
||
case "卷":
|
||
fBaseUnitId.addProperty("FNumber", "020");
|
||
break;
|
||
case "盒":
|
||
fBaseUnitId.addProperty("FNumber", "014");
|
||
break;
|
||
case "件":
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
break;
|
||
case "盘":
|
||
fBaseUnitId.addProperty("FNumber", "011");
|
||
break;
|
||
case "瓶":
|
||
fBaseUnitId.addProperty("FNumber", "016");
|
||
break;
|
||
case "条":
|
||
fBaseUnitId.addProperty("FNumber", "017");
|
||
break;
|
||
case "套":
|
||
fBaseUnitId.addProperty("FNumber", "007");
|
||
break;
|
||
}
|
||
subHeadEntity3.add("FPurchasePriceUnitId", fPurchasePriceUnitId);
|
||
|
||
subHeadEntity3.addProperty("FIsQuota", false);
|
||
subHeadEntity3.addProperty("FQuotaType", "1");
|
||
|
||
JsonObject subHeadEntity6 = new JsonObject();
|
||
model.add("SubHeadEntity6", subHeadEntity6);
|
||
// 不同的属性不同的检验方案
|
||
if (states.equals("1")) {
|
||
// 外购
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
}
|
||
if (states.equals("2")) {
|
||
// 自制
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
if (states.equals("3")) {
|
||
// 委外
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
subHeadEntity6.addProperty("FCheckStock", true);
|
||
// 创建SubHeadEntity5对象,并加入Model
|
||
JsonObject subHeadEntity5 = new JsonObject();
|
||
model.add("SubHeadEntity5", subHeadEntity5);
|
||
|
||
// 创建FProduceUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fProduceUnitId = new JsonObject();
|
||
switch (bomDetails1.getWareHouse()) {
|
||
case "把":
|
||
fBaseUnitId.addProperty("FNumber", "002");
|
||
break;
|
||
case "包":
|
||
fBaseUnitId.addProperty("FNumber", "012");
|
||
break;
|
||
case "个":
|
||
fBaseUnitId.addProperty("FNumber", "001");
|
||
break;
|
||
case "根":
|
||
fBaseUnitId.addProperty("FNumber", "003");
|
||
break;
|
||
case "米":
|
||
fBaseUnitId.addProperty("FNumber", "005");
|
||
break;
|
||
case "卷":
|
||
fBaseUnitId.addProperty("FNumber", "020");
|
||
break;
|
||
case "盒":
|
||
fBaseUnitId.addProperty("FNumber", "014");
|
||
break;
|
||
case "件":
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
break;
|
||
case "盘":
|
||
fBaseUnitId.addProperty("FNumber", "011");
|
||
break;
|
||
case "瓶":
|
||
fBaseUnitId.addProperty("FNumber", "016");
|
||
break;
|
||
case "条":
|
||
fBaseUnitId.addProperty("FNumber", "017");
|
||
break;
|
||
case "套":
|
||
fBaseUnitId.addProperty("FNumber", "007");
|
||
break;
|
||
}
|
||
subHeadEntity5.add("FProduceUnitId", fProduceUnitId);
|
||
|
||
// 创建FProduceBillType对象,并加入SubHeadEntity5
|
||
JsonObject fProduceBillType = new JsonObject();
|
||
fProduceBillType.addProperty("FNUMBER", "SCDD05_SYS");
|
||
subHeadEntity5.add("FProduceBillType", fProduceBillType);
|
||
|
||
// 创建FBOMUnitId对象,并加入SubHeadEntity5
|
||
JsonObject fBOMUnitId = new JsonObject();
|
||
switch (bomDetails1.getWareHouse()) {
|
||
case "把":
|
||
fBaseUnitId.addProperty("FNumber", "002");
|
||
break;
|
||
case "包":
|
||
fBaseUnitId.addProperty("FNumber", "012");
|
||
break;
|
||
case "个":
|
||
fBaseUnitId.addProperty("FNumber", "001");
|
||
break;
|
||
case "根":
|
||
fBaseUnitId.addProperty("FNumber", "003");
|
||
break;
|
||
case "米":
|
||
fBaseUnitId.addProperty("FNumber", "005");
|
||
break;
|
||
case "卷":
|
||
fBaseUnitId.addProperty("FNumber", "020");
|
||
break;
|
||
case "盒":
|
||
fBaseUnitId.addProperty("FNumber", "014");
|
||
break;
|
||
case "件":
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
break;
|
||
case "盘":
|
||
fBaseUnitId.addProperty("FNumber", "011");
|
||
break;
|
||
case "瓶":
|
||
fBaseUnitId.addProperty("FNumber", "016");
|
||
break;
|
||
case "条":
|
||
fBaseUnitId.addProperty("FNumber", "017");
|
||
break;
|
||
case "套":
|
||
fBaseUnitId.addProperty("FNumber", "007");
|
||
break;
|
||
}
|
||
subHeadEntity5.add("FBOMUnitId", fBOMUnitId);
|
||
subHeadEntity5.addProperty("FIsMainPrd", !states.equals("1"));
|
||
subHeadEntity5.addProperty("FIssueType", "1");
|
||
|
||
// 创建FPickStockId对象,并加入SubHeadEntity5
|
||
JsonObject fPickStockId = new JsonObject();
|
||
fPickStockId.addProperty("FNumber", "CK010");
|
||
subHeadEntity1.add("FPickStockId", fPickStockId);
|
||
|
||
subHeadEntity5.addProperty("FOverControlMode", "1");
|
||
subHeadEntity5.addProperty("FStandHourUnitId", "60");
|
||
subHeadEntity5.addProperty("FBackFlushType", "1");
|
||
String jsonData = json.toString();
|
||
try {
|
||
// 业务对象标识
|
||
String formId = "BD_MATERIAL";
|
||
// 调用接口
|
||
String resultJson = client.save(formId, jsonData);
|
||
// 用于记录结果
|
||
Gson gson = new Gson();
|
||
// 对返回结果进行解析和校验
|
||
RepoRet repoRet = gson.fromJson(resultJson, RepoRet.class);
|
||
if (repoRet.getResult().getResponseStatus().isIsSuccess()) {
|
||
System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
|
||
log.info("接口返回结果: %s%n" + gson.toJson(repoRet.getResult()));
|
||
return 1;
|
||
} else {
|
||
fail("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
log.error("接口返回结果: 失败 " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
return 0;
|
||
}
|
||
} catch (Exception e) {
|
||
fail(e.getMessage());
|
||
}
|
||
return 1;
|
||
}
|
||
|
||
public BOMUploadResult parseK3Response(String jsonResponse) {
|
||
try {
|
||
ObjectMapper mapper = new ObjectMapper();
|
||
JsonNode root = mapper.readTree(jsonResponse);
|
||
JsonNode result = root.path("Result");
|
||
JsonNode responseStatus = result.path("ResponseStatus");
|
||
|
||
boolean isSuccess = responseStatus.path("IsSuccess").asBoolean(false);
|
||
if (isSuccess) {
|
||
String id = result.path("Id").asText();
|
||
String number = result.path("Number").asText();
|
||
return BOMUploadResult.success(id, number);
|
||
} else {
|
||
JsonNode errors = responseStatus.path("Errors");
|
||
String errorMsg = (errors != null && errors.isArray() && !errors.isEmpty())
|
||
? errors.toString()
|
||
: "未知错误";
|
||
return BOMUploadResult.fail(errorMsg);
|
||
}
|
||
} catch (Exception e) {
|
||
return BOMUploadResult.fail("解析返回信息失败: " + e.getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 导入BOM
|
||
* daorubaon
|
||
*
|
||
* @param file 导入文件
|
||
*/
|
||
|
||
@Log(title = "导入电气bom", businessType = BusinessType.IMPORT)
|
||
@SaCheckPermission("system:details:importElectricalBom")
|
||
@PostMapping(value = "/importElectricalBom", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||
public void importElectricalBom(@RequestPart("file") MultipartFile file) throws Exception {
|
||
List<ElectricalMaterialBomVO> electricalMaterialBomVOS = ExcelUtil.importExcel(file.getInputStream(), ElectricalMaterialBomVO.class);
|
||
List<BomDetails> list = new ArrayList<>();
|
||
for (ElectricalMaterialBomVO bomVO : electricalMaterialBomVOS) {
|
||
BomDetails bomDetails = new BomDetails();
|
||
bomDetails.setTotalWeight(bomVO.getProductionOrderNo());
|
||
bomDetails.setFNumber(bomVO.getParentDrawingNo());
|
||
bomDetails.setFName(bomVO.getParentPart());
|
||
bomDetails.setPartNumber(bomVO.getDrawingNo());
|
||
bomDetails.setName(bomVO.getDrawingName());
|
||
bomDetails.setMaterial(bomVO.getModel());//
|
||
bomDetails.setWareHouse(bomVO.getBrand());
|
||
bomDetails.setStats("外购");
|
||
String quantity = bomVO.getQuantity().toString();
|
||
bomDetails.setQuantity(quantity);
|
||
bomDetails.setRemarks(bomVO.getUnit());
|
||
bomDetails.setUpdateTime(new Date());
|
||
bomDetails.setBomType("1");//0 是生产bom 1 是电气bom
|
||
list.add(bomDetails);
|
||
}
|
||
List<BomDetailsVo> bomDetailsVos1 = BeanUtil.copyToList(list, BomDetailsVo.class);
|
||
List<BomDetails> bomDetails = saveBomDetails(bomDetailsVos1);
|
||
bomDetailsMapper.insertBatch(bomDetails);
|
||
|
||
}
|
||
|
||
// 保存到 BomDetails 表中
|
||
//TODO: 使用本地库加速
|
||
private List<BomDetails> saveBomDetails(List<BomDetailsVo> bomDetailsVos) {
|
||
List<BomDetails> materialsToAdd = new ArrayList<>();
|
||
for (BomDetailsVo bomDetailsVo : bomDetailsVos) {
|
||
BomDetails bomDetails = BeanUtil.toBean(bomDetailsVo, BomDetails.class);
|
||
// 验证物料是否存在
|
||
int materialVerification = isMaterialVerification(bomDetails.getPartNumber(), bomDetails.getName());
|
||
if (materialVerification == 1) {
|
||
bomDetails.setUnitWeight("是");
|
||
materialsToAdd.add(bomDetails);
|
||
} else if (materialVerification == 2) {
|
||
bomDetails.setUnitWeight("否");
|
||
materialsToAdd.add(bomDetails);
|
||
} else if (materialVerification == 3) {
|
||
bomDetails.setUnitWeight("编码名称不符");
|
||
materialsToAdd.add(bomDetails);
|
||
}
|
||
}
|
||
return materialsToAdd;
|
||
}
|
||
@Log(title = "推送工艺工序")
|
||
@SaCheckPermission("system:route:viewGetBomUploadStatus")
|
||
@PostMapping("/viewGetBomUploadStatus")
|
||
public R<String> viewGetBomUploadStatus(@RequestParam String rooteProdet) {
|
||
return iProcessRouteService.viewGetBomUploadStatus(rooteProdet);
|
||
}
|
||
|
||
}
|