1825 lines
77 KiB
Java
1825 lines
77 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 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.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.bo.BomDetailsBo;
|
||
import com.ruoyi.system.domain.vo.BomDetailsVo;
|
||
import com.ruoyi.system.runner.JdUtil;
|
||
import com.ruoyi.system.service.IBomDetailsService;
|
||
import com.ruoyi.system.service.IMaterialPropertiesService;
|
||
import com.ruoyi.system.service.IProcessRouteService;
|
||
import lombok.RequiredArgsConstructor;
|
||
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.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
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.util.*;
|
||
|
||
import static org.aspectj.bridge.MessageUtil.fail;
|
||
|
||
/**
|
||
* bom明细
|
||
*
|
||
* @author ruoyi
|
||
* @date 2024-04-08
|
||
*/
|
||
@Validated
|
||
@RequiredArgsConstructor
|
||
@RestController
|
||
@RequestMapping("/system/details")
|
||
public class BomDetailsController extends BaseController {
|
||
|
||
private final IBomDetailsService iBomDetailsService;
|
||
|
||
private final IMaterialPropertiesService iMaterialPropertiesService ;
|
||
|
||
private final IProcessRouteService iProcessRouteService;
|
||
private static final Logger log = LoggerFactory.getLogger(BomDetailsController.class);
|
||
|
||
|
||
/**
|
||
* 查询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<>();
|
||
//成品物料
|
||
HashMap<String, String> bomFinishedProduct = getBomFinishedProduct(file);
|
||
//新增成品父级物流
|
||
if (loadChengPinMaterialPreservation(bomFinishedProduct)==1){
|
||
log.info("新增成品父级物流成功");
|
||
}
|
||
// loadChengPinMaterialPreservation()
|
||
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) {
|
||
int verification = isMaterialVerification(bomDetails.getPartNumber(), bomDetails.getName());
|
||
if (verification == 1) {
|
||
bomDetails.setUnitWeight("是");
|
||
} else {
|
||
if (bomDetails.getStats() == null || bomDetails.getStats().equals("外购") || bomDetails.getFName().startsWith("009") || bomDetails.getFName().startsWith("AA")
|
||
|| bomDetails.getFName().startsWith("AB") || bomDetails.getFName().startsWith("AC")|| bomDetails.getFName().startsWith("015")) {
|
||
materialsToAdd.add(bomDetails);
|
||
} else if (bomDetails.getStats().equals("自制")) {
|
||
materialsToAdd.add(bomDetails);
|
||
} else if (bomDetails.getStats().equals("委外")) {
|
||
materialsToAdd.add(bomDetails);
|
||
}
|
||
bomDetails.setUnitWeight("否");
|
||
}
|
||
}
|
||
|
||
// 保存当前记录
|
||
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);
|
||
log.info("开始新增不存在的物料==> 物料图号: " + material.getPartNumber() + " 物料名称: " + material.getName());
|
||
System.out.println("state:=======================>" + state);
|
||
//判断是否是电器物料
|
||
int result;
|
||
if (material.getTotalWeight().contains("DQ")){
|
||
log.info("开始新增不存在的电气物料==> 物料图号: " + material.getPartNumber() + " 物料名称: " + material.getName());
|
||
result = loadMaterialToDQ(material, state);
|
||
}else{
|
||
log.info("开始新增不存在的物料==> 物料图号: " + material.getPartNumber() + " 物料名称: " + material.getName());
|
||
result = loadMaterialPreservation(material, state);
|
||
}
|
||
if (result == 1) {
|
||
log.info("新增物料成功==> 物料图号: " + material.getPartNumber() + " 物料名称: " + material.getName());
|
||
material.setUnitWeight("新增成功");
|
||
bomDetails.add(material);
|
||
} else {
|
||
log.error("新增物料失败==> 物料图号: " + 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:updateMaterial")
|
||
@PostMapping("/updateFBMaterial")
|
||
public R updateFBMaterial(@RequestBody List<Map<String, String>> bomDetailParams) {
|
||
List<BomDetails> bomDetailsList = new ArrayList<>();
|
||
|
||
// 遍历前端传来的数据
|
||
for (Map<String, String> param : bomDetailParams) {
|
||
String fnumber = param.get("fnumber"); // 物料编码
|
||
String totalWeight = param.get("totalWeight"); // 生产令号
|
||
|
||
// 根据物料编码和生产令号查询
|
||
List<BomDetails> bomDetails = iBomDetailsService.selectByFNumberAndTotalWeight(fnumber, totalWeight);
|
||
|
||
System.out.println("处理物料编码:" + fnumber + ", 生产令号:" + totalWeight);
|
||
|
||
if (bomDetails != null && !bomDetails.isEmpty()) {
|
||
// 物料清单保存方法
|
||
FBloadBillOfMaterialsPreservation(bomDetails);
|
||
bomDetailsList.addAll(bomDetails);
|
||
}
|
||
}
|
||
return R.ok("成功",bomDetailsList);
|
||
}
|
||
|
||
|
||
/*s
|
||
物料清单保存方法
|
||
*/
|
||
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");
|
||
/*model.addProperty("FCfgBomId", 0);
|
||
model.addProperty("FYIELDRATE", 100.0);*/
|
||
// 创建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 void FBloadBillOfMaterialsPreservation(List<BomDetails> bomlist) {
|
||
|
||
BomDetails bomDetails1 = bomlist.get(0);
|
||
int verification = isMaterialVerification(bomDetails1.getFNumber(), bomDetails1.getFName());
|
||
// 验证父级物料是否存在
|
||
if (verification==0){
|
||
log.debug("父级物料物料不存在");
|
||
//父级物料不存在,即调用物料新增接口
|
||
int materialVerificationResult = loadFBMaterialPreservation(bomDetails1);
|
||
if (materialVerificationResult ==1){
|
||
log.debug("父级物料保存成功");
|
||
}else {
|
||
log.error("父级物料保存失败");
|
||
}
|
||
}
|
||
|
||
|
||
// TODO: 实现加载和保存物料清单数据的逻辑
|
||
K3CloudApi client = new K3CloudApi();
|
||
// 创建一个空的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", "TT001");
|
||
/*model.addProperty("FCfgBomId", 0);
|
||
model.addProperty("FYIELDRATE", 100.0);*/
|
||
// 创建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);
|
||
ArrayList<JsonObject> fTreeEntityList = new ArrayList<>();
|
||
for (BomDetails details : bomlist) {
|
||
if (bomlist.isEmpty()) {
|
||
return;
|
||
}
|
||
// 创建FTreeEntity对象,并加入FTreeEntity数组
|
||
JsonObject fTreeEntityItem = new JsonObject();
|
||
fTreeEntity.add(fTreeEntityItem);
|
||
// 添加FTreeEntity字段
|
||
fTreeEntityItem.addProperty("FReplaceGroup", 1);
|
||
|
||
if (details.getPartNumber() != null){
|
||
if (iProcessRouteService.isAnTuDingGou(details.getPartNumber())) {
|
||
fTreeEntityItem.addProperty("FSupplyType", "C");
|
||
} else if (details.getRemarks().equals("伊特")) {
|
||
|
||
fTreeEntityItem.addProperty("FSupplyType", "C");
|
||
|
||
} else{
|
||
fTreeEntityItem.addProperty("FSupplyType", " ");
|
||
}
|
||
}
|
||
|
||
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()) {
|
||
System.out.printf("接口返回结果: %s%n", gson.toJson(repoRet.getResult()));
|
||
log.debug("物料清单bom 保存成功===================>" + "图号:" + bomDetails1.getFNumber());
|
||
} else {
|
||
log.error("接口返回结果: " + gson.toJson(repoRet.getResult().getResponseStatus()));
|
||
log.error("物料清单bom 保存失败===================>" + "图号:" + bomDetails1.getFNumber());
|
||
}
|
||
} catch (Exception e) {
|
||
R.fail(e.getMessage());
|
||
}
|
||
// 输出生成的Json
|
||
}
|
||
|
||
/*父级物料保存接口
|
||
单位 是台
|
||
* */
|
||
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);
|
||
}
|
||
// 创建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);
|
||
}
|
||
if (bomDetail.getStats().equals("2")){
|
||
//自制
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
if (bomDetail.getStats().equals("3")){
|
||
//委外
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckSubRtnMtrl", 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 0;
|
||
} 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);
|
||
}
|
||
return 1;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 物料验证
|
||
* 获取单位
|
||
*/
|
||
public static String isMaterialVerification2(String DrawingNumber) {
|
||
if (DrawingNumber == null || DrawingNumber.isEmpty()) {
|
||
return "不存在";
|
||
}
|
||
JsonArray jsonArray = JdUtils.loadMaterialQueryDrawingNumber(DrawingNumber);
|
||
if (jsonArray == null) {
|
||
return "不存在";
|
||
} 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) {
|
||
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.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);
|
||
}
|
||
// 创建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();
|
||
fBaseUnitId.addProperty("FNumber", "jian");
|
||
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();
|
||
fStoreUnitId.addProperty("FNumber", "jian");
|
||
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();
|
||
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");
|
||
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);
|
||
}
|
||
if (states.equals("2")){
|
||
//自制
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
if (states.equals("3")){
|
||
//委外
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", 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);
|
||
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("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.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.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);
|
||
}
|
||
// 创建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);
|
||
}
|
||
if (states.equals("2")){
|
||
//自制
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", true);
|
||
}
|
||
if (states.equals("3")){
|
||
//委外
|
||
subHeadEntity6.addProperty("FCheckIncoming", true);
|
||
subHeadEntity6.addProperty("FCheckProduct", true);
|
||
subHeadEntity6.addProperty("FCheckReturnMtrl", 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);
|
||
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", "CK010");
|
||
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.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;
|
||
}
|
||
|
||
|
||
}
|