|
|
@ -6,27 +6,42 @@ import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.NumberUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.nl.b_lms.storage_manage.ios.enums.IOSEnum; |
|
|
|
import org.nl.b_lms.pdm.subpackagerelation.dao.PdmBiSubpackagerelation; |
|
|
|
import org.nl.b_lms.pdm.subpackagerelation.service.IpdmBiSubpackagerelationService; |
|
|
|
import org.nl.b_lms.storage_manage.ios.service.iostorInv.IStIvtIostorinvOutService; |
|
|
|
import org.nl.b_lms.storage_manage.ios.service.iostorInv.IStIvtProductplandtlService; |
|
|
|
import org.nl.b_lms.storage_manage.ios.service.iostorInv.IStIvtProductplanmstService; |
|
|
|
import org.nl.b_lms.storage_manage.ios.service.iostorInv.dao.StIvtProductplandtl; |
|
|
|
import org.nl.b_lms.storage_manage.ios.service.iostorInv.dao.StIvtProductplanmst; |
|
|
|
import org.nl.b_lms.storage_manage.md.dao.MdMeMaterialBase; |
|
|
|
import org.nl.b_lms.storage_manage.md.dao.MdPbMeasureunit; |
|
|
|
import org.nl.b_lms.storage_manage.md.service.MaterialbaseService; |
|
|
|
import org.nl.b_lms.storage_manage.md.service.MdPbMeasureunitService; |
|
|
|
import org.nl.b_lms.storage_manage.st.dao.StIvtStructivt; |
|
|
|
import org.nl.b_lms.storage_manage.st.service.StIvtBsrealstorattrService; |
|
|
|
import org.nl.b_lms.storage_manage.st.service.StIvtStructivtService; |
|
|
|
import org.nl.common.domain.query.PageQuery; |
|
|
|
import org.nl.common.utils.CodeUtil; |
|
|
|
import org.nl.common.utils.SecurityUtils; |
|
|
|
import org.nl.modules.common.exception.BadRequestException; |
|
|
|
import org.nl.common.utils.CodeUtil; |
|
|
|
import org.nl.modules.wql.WQL; |
|
|
|
import org.nl.modules.wql.core.bean.WQLObject; |
|
|
|
import org.nl.modules.wql.util.WqlUtil; |
|
|
|
import org.nl.system.service.user.ISysUserService; |
|
|
|
import org.nl.wms.basedata.st.service.impl.UserStorServiceImpl; |
|
|
|
import org.nl.wms.st.instor.service.RecutPlanService; |
|
|
|
import org.nl.wms.st.instor.service.dto.RecutPlanPageParam; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.domain.Pageable; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
/** |
|
|
@ -42,52 +57,41 @@ public class RecutPlanServiceImpl implements RecutPlanService { |
|
|
|
private IStIvtIostorinvOutService iStIvtIostorinvOutService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ISysUserService iSysUserService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> pageQuery(Map whereJson, Pageable page) { |
|
|
|
HashMap<String, String> map = new HashMap<>(whereJson); |
|
|
|
map.put("flag", "1"); |
|
|
|
if (StrUtil.isNotEmpty(map.get("bill_code"))) { |
|
|
|
map.put("bill_code", "%" + map.get("bill_code") + "%"); |
|
|
|
} |
|
|
|
if (StrUtil.isNotEmpty(map.get("material_code"))) { |
|
|
|
map.put("material_code", "%" + map.get("material_code") + "%"); |
|
|
|
} |
|
|
|
if (StrUtil.isNotEmpty(map.get("pcsn"))) { |
|
|
|
map.put("pcsn", (String) whereJson.get("pcsn")); |
|
|
|
} |
|
|
|
private StIvtBsrealstorattrService bsrealstorattrService; |
|
|
|
|
|
|
|
//获取人员对应的仓库
|
|
|
|
UserStorServiceImpl userStorService = new UserStorServiceImpl(); |
|
|
|
String in_stor_id = userStorService.getInStor(); |
|
|
|
|
|
|
|
if (ObjectUtil.isNotEmpty(in_stor_id)) { |
|
|
|
map.put("in_stor_id", in_stor_id); |
|
|
|
} |
|
|
|
@Autowired |
|
|
|
private IStIvtProductplanmstService productplanmstService; |
|
|
|
@Autowired |
|
|
|
private IStIvtProductplandtlService productplandtlService; |
|
|
|
@Autowired |
|
|
|
private IpdmBiSubpackagerelationService subpackagerelationService; |
|
|
|
@Autowired |
|
|
|
private StIvtStructivtService structivtService; |
|
|
|
@Autowired |
|
|
|
private MaterialbaseService materialbaseService; |
|
|
|
@Autowired |
|
|
|
private MdPbMeasureunitService measureunitService; |
|
|
|
|
|
|
|
JSONObject jo = WQL.getWO("QST_IVT_PRODUCTPLAN").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "plan_id desc"); |
|
|
|
return jo; |
|
|
|
@Override |
|
|
|
public IPage<StIvtProductplanmst> pageQuery(RecutPlanPageParam param, PageQuery page) { |
|
|
|
List<String> storeForUser = bsrealstorattrService.getStoreForUser(SecurityUtils.getCurrentUserId()); |
|
|
|
param.setIn_stor_id(storeForUser); |
|
|
|
IPage<StIvtProductplanmst> pages = new Page<>(page.getPage() + 1, page.getSize()); |
|
|
|
pages = productplanmstService.returnCutplanPage(pages, param); |
|
|
|
return pages; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void deleteAll(Long[] ids) { |
|
|
|
WQLObject wo_mst = WQLObject.getWQLObject("st_ivt_productplanmst"); |
|
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject(); |
|
|
|
jsonObject.put("is_delete", "1"); |
|
|
|
for (Long plan_id : ids) { |
|
|
|
wo_mst.update(jsonObject, "plan_id = '" + plan_id + "'"); |
|
|
|
} |
|
|
|
productplanmstService.update(new LambdaUpdateWrapper<StIvtProductplanmst>() |
|
|
|
.set(StIvtProductplanmst::getIs_delete, "1") |
|
|
|
.in(StIvtProductplanmst::getPlan_id, Arrays.asList(ids))); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void insertDtl(JSONObject map) { |
|
|
|
//主表
|
|
|
|
WQLObject wo_mst = WQLObject.getWQLObject("st_ivt_productplanmst"); |
|
|
|
|
|
|
|
JSONArray rows = map.getJSONArray("tableData"); |
|
|
|
map.remove("tableData"); |
|
|
|
String currentUserId = SecurityUtils.getCurrentUserId(); |
|
|
@ -111,7 +115,7 @@ public class RecutPlanServiceImpl implements RecutPlanService { |
|
|
|
//调用明细处理方法
|
|
|
|
JSONObject ret = this.insertDtlByRows(mst_jo, rows); |
|
|
|
mst_jo.put("total_qty", ret.getDoubleValue("total_qty")); |
|
|
|
wo_mst.insert(mst_jo); |
|
|
|
productplanmstService.save(mst_jo.toJavaObject(StIvtProductplanmst.class)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -121,7 +125,6 @@ public class RecutPlanServiceImpl implements RecutPlanService { |
|
|
|
*/ |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public JSONObject insertDtlByRows(JSONObject jsonMst, JSONArray rows) { |
|
|
|
WQLObject wo_dtl = WQLObject.getWQLObject("st_ivt_productplandtl"); |
|
|
|
|
|
|
|
//定义返回数据
|
|
|
|
JSONObject ret = new JSONObject(); |
|
|
@ -141,7 +144,7 @@ public class RecutPlanServiceImpl implements RecutPlanService { |
|
|
|
jsonDtl.put("qty", json.getDoubleValue("qty")); |
|
|
|
jsonDtl.put("remark", json.getString("remark")); |
|
|
|
jsonDtl.put("status", "10"); |
|
|
|
wo_dtl.insert(jsonDtl); |
|
|
|
productplandtlService.save(jsonDtl.toJavaObject(StIvtProductplandtl.class)); |
|
|
|
|
|
|
|
total_qty = NumberUtil.add(total_qty, json.getDoubleValue("qty")); |
|
|
|
|
|
|
@ -152,54 +155,40 @@ public class RecutPlanServiceImpl implements RecutPlanService { |
|
|
|
|
|
|
|
@Override |
|
|
|
public JSONArray getOutBillDtl(Map whereJson) { |
|
|
|
whereJson.put("flag", "2"); |
|
|
|
JSONArray jo = WQL.getWO("QST_IVT_PRODUCTPLAN") |
|
|
|
.addParamMap((HashMap) whereJson) |
|
|
|
.process() |
|
|
|
.getResultJSONArray(0); |
|
|
|
return jo; |
|
|
|
return productplanmstService.getOutBillDtl(whereJson); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void update(JSONObject whereJson) { |
|
|
|
//主表
|
|
|
|
WQLObject wo_mst = WQLObject.getWQLObject("st_ivt_productplanmst"); |
|
|
|
//主表
|
|
|
|
WQLObject wo_dtl = WQLObject.getWQLObject("st_ivt_productplandtl"); |
|
|
|
|
|
|
|
String currentUserId = SecurityUtils.getCurrentUserId(); |
|
|
|
String nickName = SecurityUtils.getCurrentNickName(); |
|
|
|
String now = DateUtil.now(); |
|
|
|
String plan_id = (String) whereJson.get("plan_id"); |
|
|
|
String plan_id = whereJson.getString("plan_id"); |
|
|
|
//查询主表
|
|
|
|
JSONObject jo_mst = wo_mst.query("plan_id='" + plan_id + "'").uniqueResult(0); |
|
|
|
|
|
|
|
StIvtProductplanmst productplanmst = productplanmstService.getById(plan_id); |
|
|
|
//删除所有明细
|
|
|
|
wo_dtl.delete("plan_id = '" + plan_id + "'"); |
|
|
|
productplandtlService.remove(new LambdaQueryWrapper<StIvtProductplandtl>() |
|
|
|
.eq(StIvtProductplandtl::getPlan_id, plan_id)); |
|
|
|
|
|
|
|
//获取明细
|
|
|
|
JSONArray rows = whereJson.getJSONArray("tableData"); |
|
|
|
//调用明细处理方法
|
|
|
|
JSONObject ret = this.insertDtlByRows(jo_mst, rows); |
|
|
|
jo_mst.put("remark", whereJson.get("remark")); |
|
|
|
jo_mst.put("biz_date", whereJson.get("biz_date")); |
|
|
|
jo_mst.put("detail_count", rows.size()); |
|
|
|
jo_mst.put("total_qty", ret.getString("total_qty")); |
|
|
|
jo_mst.put("update_optid", currentUserId + ""); |
|
|
|
jo_mst.put("update_optname", nickName); |
|
|
|
jo_mst.put("update_time", now); |
|
|
|
JSONObject ret = this.insertDtlByRows((JSONObject) JSON.toJSON(productplanmst), rows); |
|
|
|
productplanmst.setRemark(whereJson.getString("remark")); |
|
|
|
productplanmst.setBiz_date(whereJson.getString("biz_date")); |
|
|
|
productplanmst.setDetail_count(BigDecimal.valueOf(rows.size())); |
|
|
|
productplanmst.setTotal_qty(ret.getBigDecimal("total_qty")); |
|
|
|
productplanmst.setUpdate_optid(currentUserId); |
|
|
|
productplanmst.setUpdate_optname(nickName); |
|
|
|
productplanmst.setUpdate_time(now); |
|
|
|
//更新主表
|
|
|
|
wo_mst.update(jo_mst); |
|
|
|
productplanmstService.updateById(productplanmst); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void createBill(JSONObject whereJson) { |
|
|
|
|
|
|
|
WQLObject dtl_wo = WQLObject.getWQLObject("st_ivt_productplandtl"); |
|
|
|
WQLObject mst_wo = WQLObject.getWQLObject("st_ivt_productplanmst"); |
|
|
|
|
|
|
|
JSONArray rows = whereJson.getJSONArray("rows"); |
|
|
|
JSONObject mst_jo = whereJson.getJSONObject("mst_jo"); |
|
|
|
|
|
|
@ -221,73 +210,70 @@ public class RecutPlanServiceImpl implements RecutPlanService { |
|
|
|
if (StrUtil.isEmpty("sap_pcsn")) { |
|
|
|
throw new BadRequestException("请求参数SAP批次不能为空!"); |
|
|
|
} |
|
|
|
JSONObject sub_jo = WQLObject.getWQLObject("PDM_BI_SubPackageRelation").query("sap_pcsn = '" + sap_pcsn + "'").uniqueResult(0); |
|
|
|
PdmBiSubpackagerelation sub_jo = subpackagerelationService.getOne( |
|
|
|
new LambdaQueryWrapper<PdmBiSubpackagerelation>() |
|
|
|
.eq(PdmBiSubpackagerelation::getSap_pcsn, sap_pcsn), false); |
|
|
|
if (ObjectUtil.isEmpty(sub_jo)) { |
|
|
|
throw new BadRequestException("LMS中不存在SAP批次为【" + sap_pcsn + "】的包装关系"); |
|
|
|
} |
|
|
|
String container_name = sub_jo.getString("container_name"); |
|
|
|
JSONObject struct_ivt = WQLObject.getWQLObject("st_ivt_structivt").query("pcsn = '" + container_name + "'").uniqueResult(0); |
|
|
|
String container_name = sub_jo.getContainer_name(); |
|
|
|
StIvtStructivt struct_ivt = structivtService.getOneByPcsn(container_name, false); |
|
|
|
if (ObjectUtil.isEmpty(struct_ivt)) { |
|
|
|
throw new BadRequestException("SAP批次为【" + sap_pcsn + "】的成品卷不存在或已经出库!"); |
|
|
|
} else { |
|
|
|
if (struct_ivt.getDoubleValue("frozen_qty") > 0) { |
|
|
|
if (struct_ivt.getFrozen_qty().doubleValue() > 0) { |
|
|
|
throw new BadRequestException("SAP批次为【" + sap_pcsn + "】的成品卷已经被分配或出库中"); |
|
|
|
} else { |
|
|
|
JSONObject dtl = new JSONObject(); |
|
|
|
//查询该物料
|
|
|
|
JSONObject mater_jo = WQLObject.getWQLObject("md_me_materialbase").query("material_code = '" + sub_jo.getString("product_name") + "'").uniqueResult(0); |
|
|
|
MdMeMaterialBase mater_jo = materialbaseService.getOne(new LambdaQueryWrapper<MdMeMaterialBase>() |
|
|
|
.eq(MdMeMaterialBase::getMaterial_code, sub_jo.getProduct_name()), false); |
|
|
|
if (ObjectUtil.isEmpty(mater_jo)) { |
|
|
|
throw new BadRequestException("未查询到物料:" + sub_jo.getString("product_name") + ",信息!"); |
|
|
|
throw new BadRequestException("未查询到物料:" + sub_jo.getProduct_name() + ",信息!"); |
|
|
|
} |
|
|
|
dtl.put("material_id", mater_jo.getString("material_id")); |
|
|
|
dtl.put("material_id", mater_jo.getMaterial_id()); |
|
|
|
dtl.put("pcsn", container_name); |
|
|
|
dtl.put("box_no", sub_jo.getString("package_box_sn")); |
|
|
|
JSONObject unit = WQLObject.getWQLObject("md_pb_measureunit").query("measure_unit_id = '" + mater_jo.getString("base_unit_id") + "'").uniqueResult(0); |
|
|
|
dtl.put("box_no", sub_jo.getPackage_box_sn()); |
|
|
|
MdPbMeasureunit unit = measureunitService.getById(mater_jo.getBase_unit_id()); |
|
|
|
if (ObjectUtil.isEmpty(unit)) { |
|
|
|
throw new BadRequestException("未查询到物料计量单位:" + mater_jo.getString("base_unit_id") + ",信息!"); |
|
|
|
throw new BadRequestException("未查询到物料计量单位:" + mater_jo.getBase_unit_id() + ",信息!"); |
|
|
|
} |
|
|
|
dtl.put("qty_unit_id", unit.getString("measure_unit_id")); |
|
|
|
dtl.put("qty_unit_name", unit.getString("unit_name")); |
|
|
|
dtl.put("plan_qty", sub_jo.getString("net_weight")); |
|
|
|
dtl.put("qty_unit_id", unit.getMeasure_unit_id()); |
|
|
|
dtl.put("qty_unit_name", unit.getUnit_name()); |
|
|
|
dtl.put("plan_qty", sub_jo.getNet_weight()); |
|
|
|
dtls.add(dtl); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//将已经生成的明细状态变更为完成
|
|
|
|
HashMap map = new HashMap<>(); |
|
|
|
map.put("status", "99"); |
|
|
|
dtl_wo.update(map, "plan_id = '" + mst_jo.getString("plan_id") + "' AND pcsn = '" + sap_pcsn + "'"); |
|
|
|
productplandtlService.update(new LambdaUpdateWrapper<StIvtProductplandtl>() |
|
|
|
.set(StIvtProductplandtl::getStatus, "99") |
|
|
|
.eq(StIvtProductplandtl::getPlan_id, mst_jo.getString("plan_id")) |
|
|
|
.eq(StIvtProductplandtl::getPcsn, sap_pcsn)); |
|
|
|
|
|
|
|
//判断是否全部变更为99
|
|
|
|
JSONArray dtl_rows = dtl_wo.query("plan_id = '" + mst_jo.getString("plan_id") + "' AND status < '99' ").getResultJSONArray(0); |
|
|
|
List<StIvtProductplandtl> dtl_rows = productplandtlService.list(new LambdaQueryWrapper<StIvtProductplandtl>() |
|
|
|
.eq(StIvtProductplandtl::getPlan_id, mst_jo.getString("plan_id")) |
|
|
|
.lt(StIvtProductplandtl::getStatus, "99")); |
|
|
|
if (dtl_rows.size() > 0) { |
|
|
|
//主表更新为出库中
|
|
|
|
HashMap mst_map = new HashMap<>(); |
|
|
|
mst_map.put("bill_status", "20"); |
|
|
|
mst_wo.update(mst_map, "plan_id = '" + mst_jo.getString("plan_id") + "'"); |
|
|
|
productplanmstService.update(new LambdaUpdateWrapper<StIvtProductplanmst>() |
|
|
|
.set(StIvtProductplanmst::getBill_status, "20") |
|
|
|
.eq(StIvtProductplanmst::getPlan_id, mst_jo.getString("plan_id"))); |
|
|
|
} else { |
|
|
|
HashMap mst_map = new HashMap<>(); |
|
|
|
mst_map.put("bill_status", "99"); |
|
|
|
mst_map.put("confirm_optid", SecurityUtils.getCurrentUserId()); |
|
|
|
mst_map.put("confirm_optname", SecurityUtils.getCurrentNickName()); |
|
|
|
mst_map.put("confirm_time", DateUtil.now()); |
|
|
|
mst_wo.update(mst_map, "plan_id = '" + mst_jo.getString("plan_id") + "'"); |
|
|
|
productplanmstService.update(new LambdaUpdateWrapper<StIvtProductplanmst>() |
|
|
|
.set(StIvtProductplanmst::getBill_status, "99") |
|
|
|
.set(StIvtProductplanmst::getUpdate_optid, SecurityUtils.getCurrentUserId()) |
|
|
|
.set(StIvtProductplanmst::getUpdate_optname, SecurityUtils.getCurrentNickName()) |
|
|
|
.set(StIvtProductplanmst::getUpdate_time, DateUtil.now()) |
|
|
|
.eq(StIvtProductplanmst::getPlan_id, mst_jo.getString("plan_id"))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!dtls.isEmpty()) { |
|
|
|
// 判断仓库是否是二期仓库
|
|
|
|
if (mst_jo.getString("stor_id").equals(IOSEnum.STOR_ID.code("二期"))) { |
|
|
|
jsonMst.put("tableData", dtls); |
|
|
|
String iostorinv_id = iStIvtIostorinvOutService.insertMst(jsonMst); |
|
|
|
|
|
|
|
//调用自动分配
|
|
|
|
JSONObject out_jo = new JSONObject(); |
|
|
|
out_jo.put("iostorinv_id", iostorinv_id); |
|
|
|
out_jo.put("div_type", "1"); |
|
|
|
// 改为手动分配
|
|
|
|
// iStIvtIostorinvOutService.allDiv(out_jo);
|
|
|
|
} |
|
|
|
iStIvtIostorinvOutService.insertMst(jsonMst); |
|
|
|
// hint: 手动分配,不自动分配
|
|
|
|
|
|
|
|
} else { |
|
|
|
throw new BadRequestException("推送失败!SAP推送的子卷明细不符合出库状态!"); |
|
|
@ -298,14 +284,12 @@ public class RecutPlanServiceImpl implements RecutPlanService { |
|
|
|
@Override |
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void auditOut(JSONObject whereJson) { |
|
|
|
WQLObject mst = WQLObject.getWQLObject("st_ivt_productplanmst"); |
|
|
|
|
|
|
|
// 更新主表为完成
|
|
|
|
JSONObject param = new JSONObject(); |
|
|
|
param.put("bill_status", "99"); |
|
|
|
param.put("confirm_optid", SecurityUtils.getCurrentUserId()); |
|
|
|
param.put("confirm_optname", SecurityUtils.getCurrentNickName()); |
|
|
|
param.put("confirm_time", DateUtil.now()); |
|
|
|
mst.update(param, "plan_id = '" + whereJson.getString("plan_id") + "'"); |
|
|
|
productplanmstService.update(new LambdaUpdateWrapper<StIvtProductplanmst>() |
|
|
|
.set(StIvtProductplanmst::getBill_status, "99") |
|
|
|
.set(StIvtProductplanmst::getUpdate_optid, SecurityUtils.getCurrentUserId()) |
|
|
|
.set(StIvtProductplanmst::getUpdate_optname, SecurityUtils.getCurrentNickName()) |
|
|
|
.set(StIvtProductplanmst::getUpdate_time, DateUtil.now()) |
|
|
|
.eq(StIvtProductplanmst::getPlan_id, whereJson.getString("plan_id"))); |
|
|
|
} |
|
|
|
} |
|
|
|