Commit 3d819ae6 by 宋祥

1.修复采购收货问题

parent 2a1f8824
......@@ -189,6 +189,9 @@
<isNotEmpty prepend=" AND " property="primaryIds">
PRIMARY_ID IN <iterate open="(" close=")" conjunction="," property="primaryIds">#primaryIds[]#</iterate>
</isNotEmpty>
<isNotEmpty prepend=" AND " property="receiveNos">
RECEIVE_NO IN <iterate open="(" close=")" conjunction="," property="receiveNos">#receiveNos[]#</iterate>
</isNotEmpty>
</sql>
<sql id="updateRevise">
......
......@@ -2,6 +2,7 @@ package com.baosight.hggp.hg.cg.utils;
import com.baosight.hggp.hg.cg.domain.*;
import com.baosight.hggp.hg.cg.tools.HGCGTools;
import com.baosight.hggp.hg.constant.HGConstant;
import com.baosight.hggp.hg.utils.HGUtils;
import com.baosight.hggp.util.DateUtils;
import com.baosight.hggp.util.MapUtils;
......@@ -87,7 +88,33 @@ public class HGCGUtils {
// db数据
return HGCGTools.HgCg002.map(contractNos);
}
/**
* 锁并且获取数据
*
* @param ids
* @return
*/
public static Map<Long, HGCG002A> lockGetDataById(List<Long> ids) {
// 锁
HGCGTools.HgCg002.lockById(ids);
// db数据
return HGCGTools.HgCg002.mapByIds(ids);
}
/**
* 锁并且获取数据
*
* @param ids
* @return
*/
public static List<HGCG002A> lockGetDatasById(List<Long> ids) {
// 锁
HGCGTools.HgCg002.lockById(ids);
// db数据
return HGCGTools.HgCg002.listByIds(ids);
}
}
/**
......@@ -155,7 +182,7 @@ public class HGCGUtils {
public static Map<String, HGCG003> lockGetDataEp(List<? extends HGCG003> fCg003s) {
return lockGetData(ObjectUtils.listEpKey(fCg003s, HGCG003.FIELD_RECEIVE_NO));
}
/**
* 锁并且获取数据
*
......@@ -168,7 +195,32 @@ public class HGCGUtils {
// db数据
return HGCGTools.HgCg003.map(receiveNos);
}
/**
* 根据明细状态计算主状态
*
* @param statuses
* @return
*/
public static Integer calcStatus(List<Integer> statuses) {
Integer status;
// 明细只有一种状态时,主状态与明细一致;明细状态存在多种时,取最低的状态
if (statuses.size() != 1) {
if (statuses.contains(HGConstant.CgReceiveStatus.S_2)) {
status = HGConstant.CgReceiveStatus.S_2;
} else if (statuses.contains(HGConstant.CgReceiveStatus.S_3)) {
status = HGConstant.CgReceiveStatus.S_3;
} else if (statuses.contains(HGConstant.CgReceiveStatus.S_4)) {
status = HGConstant.CgReceiveStatus.S_4;
} else {
status = HGConstant.CgReceiveStatus.S_5;
}
} else {
status = statuses.get(0);
}
return status;
}
}
/**
......
......@@ -189,11 +189,14 @@ public class ServiceHGKC001 extends ServiceBase {
HGKC001 dbKc001 = dbKc001Map.get(depositNo);
dbKc001.setDeleteFlag(DeleteFlagEnum.REMOVE.getCode());
DaoUtils.update(HGKC001.DELETE, dbKc001);
// 扣减库存
HGKCUtils.HgKc010.updateInv(dbKc001.getCompanyCode(), dbKc001.getWhCode(), dbKc001.getInventCode(),
dbKc001.getDepositQty().negate(), dbKc001.getDepositWeight().negate());
// 已提交状态需要扣减库存
if (HGConstant.ProductStatus.YTJ.equals(dbKc001.getSubmitStatus())) {
HGKCUtils.HgKc010.updateInv(dbKc001.getCompanyCode(), dbKc001.getWhCode(), dbKc001.getInventCode(),
dbKc001.getDepositQty().negate(), dbKc001.getDepositWeight().negate());
}
// 更新收货单状态
HGCGTools.HgCg003.updateStatus(dbKc001.getReceiveNo(), HGConstant.CgReceiveStatus.S_2);
HGCGTools.HgCg003.updateStatus(dbKc001.getReceiveNo(), HGConstant.CgReceiveStatus.S_0);
HGCGTools.HgCg003B.updateStatus(dbKc001.getReceiveDetailId(), HGConstant.CgReceiveStatus.S_2);
}
}
......
......@@ -21,6 +21,7 @@ import com.baosight.hggp.hg.pz.domain.HGPZ007;
import com.baosight.hggp.hg.pz.tools.HGPZTools;
import com.baosight.hggp.hg.sc.domain.HGSC008;
import com.baosight.hggp.hg.sc.tools.HGSCTools;
import com.baosight.hggp.hg.zl.domain.HGZL001;
import com.baosight.hggp.hg.zl.domain.HGZL002;
import com.baosight.hggp.hg.zl.domain.HGZL004;
import com.baosight.hggp.util.AssertUtils;
......@@ -105,19 +106,23 @@ public class HGKCTools {
List<HGKC001> results = list(depositNos);
return results.stream().collect(Collectors.toMap(HGKC001::getDepositNo, item -> item));
}
/**
* 生产入库(入库质检单)
*
* @param dbCg003B
*/
public static void putInStorageData(HGCG003B dbCg003B) {
public static void putInStorageData(HGZL001 fZl001, HGCG003B dbCg003B) {
// 无合格数量时,不入库
if (fZl001.getQualifyQty().compareTo(BigDecimal.ZERO) < 1) {
return;
}
HGKC001 newKc001 = BeanUtils.copy(dbCg003B, HGKC001.class);
newKc001.setDepositDate(DateUtils.shortDate());
newKc001.setDepositNo(SequenceGenerator.getNextSequence(HGConstant.SequenceId.CG_DEPOSIT_NO));
newKc001.setDepositQty(dbCg003B.getDepositQty());
newKc001.setDepositQty(fZl001.getQualifyQty());
newKc001.setDepositUnitWeight(dbCg003B.getReceiveUnitWeight());
newKc001.setDepositWeight(dbCg003B.getDepositQty().multiply(dbCg003B.getReceiveUnitWeight()));
newKc001.setDepositWeight(fZl001.getQualifyQty().multiply(dbCg003B.getReceiveUnitWeight()));
newKc001.setDeleteFlag(DeleteFlagEnum.UN_REMOVE.getCode());
newKc001.setSubmitStatus(HGConstant.ProductStatus.WTJ);
newKc001.setStorageType(HGConstant.StorageType.RK);
......
......@@ -283,7 +283,7 @@ public class HGKCUtils {
* @param weight
*/
public static void updateInv(String companyCode, String whCode, String inventCode, BigDecimal qty,
BigDecimal unitWeight, BigDecimal weight) {
BigDecimal unitWeight, BigDecimal weight) {
HGKC010 newKc010 = buildBean(companyCode, whCode, inventCode, qty, unitWeight, weight);
// 参数校验
checkUpdateInv(companyCode, whCode, inventCode, qty, weight);
......
......@@ -159,44 +159,40 @@ public class ServiceHGSC003 extends ServiceBase {
DaoUtils.update(HGSC003.UPDATE_BLUEPRINT_STATUS, hgsc003);
}
inInfo.setStatus(EiConstant.STATUS_SUCCESS);
inInfo.setMsgByKey("ep.1000", new String[]{String.valueOf(i), I18nMessages.getText("label.update", "修改")});
inInfo.setMsgByKey("ep.1000", new String[]{String.valueOf(i), I18nMessages.getText("label.update", "修改")});
} catch (PlatException e) {
e.printStackTrace();
inInfo.setStatus(EiConstant.STATUS_FAILURE);
ErrorCodeUtils.handleUpdateException(inInfo,i,e);
logError("修改失败", e.getMessage());
return inInfo;
e.printStackTrace();
inInfo.setStatus(EiConstant.STATUS_FAILURE);
ErrorCodeUtils.handleUpdateException(inInfo, i, e);
logError("修改失败", e.getMessage());
return inInfo;
}
return inInfo;
return inInfo;
}
/**
* 项目档案下拉框
* @param inInfo
* @return
*/
public EiInfo projComboBox(EiInfo inInfo){
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
String companyCode = MapUtils.getString(queryMap, HGSC001.FIELD_company_code);
String approvalStatus = MapUtils.getString(queryMap, HGSC001.FIELD_approval_status);
Map map = new HashMap();
map.put(HGSC001.FIELD_account_code, UserSessionUtils.getAccountCode());
map.put(HGSC001.FIELD_company_code, companyCode);
map.put(HGSC001.FIELD_approval_status, approvalStatus);
CommonMethod.initBlock(inInfo, Arrays.asList(DdynamicEnum.PROJ_RECORD_BY_ROLE_BLOCK_ID), map,false);
return inInfo;
}
/**
* 蓝图查询下拉框
* @param inInfo
* @return
*/
public EiInfo blueprintComboBox(EiInfo inInfo){
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
String companyCode = MapUtils.getString(queryMap, HGSC003.FIELD_company_code);
String blueprintStatus = MapUtils.getString(queryMap, HGSC003.FIELD_blueprint_status);
/**
* 项目档案下拉框
*
* @param inInfo
* @return
*/
public EiInfo projComboBox(EiInfo inInfo) {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
queryMap.put(HGSC001.FIELD_account_code, UserSessionUtils.getAccountCode());
CommonMethod.initBlock(inInfo, Arrays.asList(DdynamicEnum.PROJ_RECORD_BY_ROLE_BLOCK_ID), queryMap, false);
return inInfo;
}
/**
* 蓝图查询下拉框
*
* @param inInfo
* @return
*/
public EiInfo blueprintComboBox(EiInfo inInfo) {
Map queryMap = EiInfoUtils.getFirstRow(inInfo);
String companyCode = MapUtils.getString(queryMap, HGSC003.FIELD_company_code);
String blueprintStatus = MapUtils.getString(queryMap, HGSC003.FIELD_blueprint_status);
String projCode = MapUtils.getString(queryMap, HGSC003.FIELD_proj_code);
Map map = new HashMap();
map.put(HGSC003.FIELD_account_code, UserSessionUtils.getAccountCode());
......
......@@ -78,7 +78,7 @@
proj_code = #projCode#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="projName">
proj_name like ('%$projName$%')
proj_name like '%$projName$%'
</isNotEmpty>
<isNotEmpty prepend=" AND " property="projType">
proj_type = #projType#
......
......@@ -1329,7 +1329,8 @@ public class HGSCTools {
}
}
}
return workHour.get().divide(baseWorkHour, 0, ROUND_DOWN);
System.out.println(workHour.toString());
return workHour.get();
}
/**
......
......@@ -29,6 +29,9 @@
<isNotEmpty prepend=" AND " property="accountCode">
ACCOUNT_CODE = #accountCode#
</isNotEmpty>
<isNotEmpty prepend=" AND " property="receiveUserName">
USER_NAME LIKE CONCAT('%', #accountCode#, '%')
</isNotEmpty>
</sql>
<!-- 查询用户信息 -->
......
......@@ -7,6 +7,7 @@ import com.baosight.hggp.core.dao.DaoUtils;
import com.baosight.hggp.core.enums.DeleteFlagEnum;
import com.baosight.hggp.core.security.UserSessionUtils;
import com.baosight.hggp.hg.cg.domain.HGCG002;
import com.baosight.hggp.hg.cg.domain.HGCG002A;
import com.baosight.hggp.hg.cg.domain.HGCG002B;
import com.baosight.hggp.hg.cg.domain.HGCG003;
import com.baosight.hggp.hg.cg.domain.HGCG003B;
......@@ -23,6 +24,7 @@ import com.baosight.hggp.util.CommonMethod;
import com.baosight.hggp.util.EiInfoUtils;
import com.baosight.hggp.util.LogUtils;
import com.baosight.hggp.util.MapUtils;
import com.baosight.hggp.util.ObjectUtils;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.service.impl.ServiceBase;
......@@ -206,13 +208,18 @@ public class ServiceHGZL001 extends ServiceBase {
List<HGZL001> fZl001s = MapUtils.toDaoEPBases(inInfo, HGZL001.class);
Map<String, HGZL001> dbZl001Map = HGZLUtils.HgZl001.lockGetDataEp(fZl001s);
// 获取收货明细数据
List<Long> receiveDetailIds = fZl001s.stream().map(HGZL001::getReceiveDetailId)
.collect(Collectors.toList());
List<Long> receiveDetailIds = ObjectUtils.listEpKey(fZl001s, "receiveDetailId");
Map<Long, HGCG003B> dbCg003BMap = HGCGUtils.HgCg003B.lockGetData(receiveDetailIds);
// 合同明细数据
List<Long> contractDetailIds = ObjectUtils.listEpKey(dbCg003BMap.values(), "contractDetailId");
Map<Long, HGCG002B> dbCg002BMap = HGCGUtils.HgCg002B.lockGetData(contractDetailIds);
// 合同主信息
List<Long> primaryIds = ObjectUtils.listEpKey(dbCg002BMap.values(), "primaryId");
List<HGCG002A> dbCg002As = HGCGUtils.HgCg002.lockGetDatasById(primaryIds);
// 数据校验
this.checkProcessData(fZl001s, dbZl001Map, dbCg003BMap);
// 保存数据
this.saveProcessData(fZl001s, dbZl001Map, dbCg003BMap);
this.saveProcessData(fZl001s, dbZl001Map, dbCg003BMap, dbCg002BMap, dbCg002As);
inInfo = this.query(inInfo);
inInfo.setStatus(EiConstant.STATUS_DEFAULT);
inInfo.setMsg("操作成功!本次对[" + fZl001s.size() + "]条数据处理成功!");
......@@ -253,9 +260,11 @@ public class ServiceHGZL001 extends ServiceBase {
* @param fZl001s
* @param dbZl001Map
* @param dbCg003BMap
* @param dbCg002BMap
* @param dbCg002As
*/
private void saveProcessData(List<HGZL001> fZl001s, Map<String, HGZL001> dbZl001Map,
Map<Long, HGCG003B> dbCg003BMap) {
Map<Long, HGCG003B> dbCg003BMap, Map<Long, HGCG002B> dbCg002BMap, List<HGCG002A> dbCg002As) {
for (HGZL001 fZl001 : fZl001s) {
// 更新质检单状态
String checkNo = fZl001.getCheckNo();
......@@ -264,13 +273,14 @@ public class ServiceHGZL001 extends ServiceBase {
dbZl001.setUnqualifyQty(fZl001.getUnqualifyQty());
dbZl001.setStatus(CommonConstant.YesNo.YES_1);
DaoUtils.update(HGSqlConstant.HgZl001.PROCESS, dbZl001);
// 更新收货明细
this.updateReceiveDetail(fZl001, dbCg003BMap);
// 更新收货明细
this.updateReceiveDetail(fZl001, dbCg003BMap, dbCg002BMap);
}
// 更新收货单主表信息
this.updateReceiveMain(fZl001s);
// 质检修改合同状态
this.updateContract(fZl001s, dbCg003BMap);
// 更新收货单主表信息,收货单号去重
List<String> receiveNos = ObjectUtils.listEpKey(fZl001s, "receiveNo");
HGCGTools.HgCg003.updateReceiveMain(receiveNos);
// 质检修改主合同状态
HGCGTools.HgCg002.updateReceiveMain(dbCg002As);
}
/**
......@@ -278,88 +288,20 @@ public class ServiceHGZL001 extends ServiceBase {
*
* @param fZl001
* @param dbCg003BMap
* @param dbCg002BMap
*/
private void updateReceiveDetail(HGZL001 fZl001, Map<Long, HGCG003B> dbCg003BMap) {
private void updateReceiveDetail(HGZL001 fZl001, Map<Long, HGCG003B> dbCg003BMap, Map<Long, HGCG002B> dbCg002BMap) {
Long receiveDetailId = fZl001.getReceiveDetailId();
HGCG003B dbCg003B = dbCg003BMap.get(receiveDetailId);
// 更新采购收货明细的入库数量
Map<String, Object> paramDetailMap = new HashMap<>();
paramDetailMap.put(HGCG003B.FIELD_ID, receiveDetailId);
paramDetailMap.put(HGCG003B.FIELD_STATUS, HGConstant.CgReceiveStatus.S_4);
paramDetailMap.put(HGCG003B.FIELD_DELIVER_QTY, fZl001.getUnqualifyQty());
paramDetailMap.put(HGCG003B.FIELD_DEPOSIT_QTY, fZl001.getQualifyQty());
DaoUtils.update(HGSqlConstant.HgCg003B.UPDATE_CONFIRM, paramDetailMap);
HGCGTools.HgCg003B.updateDeposit(receiveDetailId, fZl001.getQualifyQty(), fZl001.getUnqualifyQty());
// 更新合同明细的收货数量
HGCG002B dbCg002B = dbCg002BMap.get(dbCg003B.getContractDetailId());
BigDecimal unqualifyQty = fZl001.getUnqualifyQty().negate();
BigDecimal unqualifyWeight = unqualifyQty.multiply(dbCg003B.getReceiveUnitWeight());
HGCGTools.HgCg002B.updateReceive(dbCg002B, unqualifyQty, unqualifyWeight);
// 生成采购入库单
HGKCTools.HgKc001.putInStorageData(dbCg003BMap.get(receiveDetailId));
}
/**
* 更新收货单状态
*
* @param fZl001s
*/
public void updateReceiveMain(List<HGZL001> fZl001s) {
// 收货单号去重
List<String> receiveNos = fZl001s.stream().map(item -> item.getReceiveNo()).distinct()
.collect(Collectors.toList());
if (CollectionUtils.isEmpty(receiveNos)) {
return;
}
// 收货单主表信息
List<HGCG003> dbCg003s = HGCGTools.HgCg003.list(receiveNos);
// 收货单子表信息
List<Long> primaryIds = dbCg003s.stream().map(item -> item.getId()).collect(Collectors.toList());
Map<Long, List<HGCG003B>> dbCg003BMap = HGCGTools.HgCg003B.mapByPrimaryIds(primaryIds);
for (HGCG003 dbCg003 : dbCg003s) {
List<HGCG003B> dbCg003Bs = dbCg003BMap == null ? null : dbCg003BMap.get(dbCg003.getId());
AssertUtils.isEmpty(dbCg003Bs, String.format("采购收货单【%s】无明细数据,请检查", dbCg003.getReceiveNo()));
// 过滤出质检中的收货单
boolean bool = dbCg003Bs.stream().anyMatch(dbCg003B
-> HGConstant.CgReceiveStatus.S_3.equals(dbCg003B.getStatus()));
// 如果不存在质检中的收货明细了,则主表为质检完成
if (!bool) {
Map<String, Object> paramDetailMap = new HashMap<>();
paramDetailMap.put(HGCG003.FIELD_RECEIVE_NO, dbCg003.getReceiveNo());
paramDetailMap.put(HGCG003.FIELD_STATUS, HGConstant.CgReceiveStatus.S_4);
BigDecimal depositQtySum = dbCg003Bs.stream().map(HGCG003B::getDepositQty)
.reduce(BigDecimal.ZERO, BigDecimal::add);
paramDetailMap.put(HGCG003.FIELD_DEPOSIT_QTY, depositQtySum);
BigDecimal deliverQtySum = dbCg003Bs.stream().map(HGCG003B::getDeliverQty)
.reduce(BigDecimal.ZERO, BigDecimal::add);
paramDetailMap.put(HGCG003.FIELD_DELIVER_QTY, deliverQtySum);
DaoUtils.update(HGSqlConstant.HgCg003.UPDATE_CONFIRM, paramDetailMap);
}
}
}
/**
* 修改合同状态
*
* @param fZl001s
* @param dbCg003BMap
*/
public void updateContract(List<HGZL001> fZl001s, Map<Long, HGCG003B> dbCg003BMap) {
// 获取收货明细数据
List<HGCG003B> dbCg003Bs = dbCg003BMap.values().stream().collect(Collectors.toList());
// 获取合同明细
List<Long> contractDetailIds = dbCg003Bs.stream().map(HGCG003B::getContractDetailId).distinct()
.collect(Collectors.toList());
Map<Long, HGCG002B> dbCg002BMap = HGCGTools.HgCg002B.map(contractDetailIds);
// 合同主表信息
List<Long> contractIds = dbCg002BMap.values().stream().map(item -> item.getPrimaryId())
.collect(Collectors.toList());
Map<Long, HGCG002> dbCg002Map = HGCGTools.HgCg002.mapByIds(contractIds);
for (HGZL001 fZl001 : fZl001s) {
// 关联获取到收货明细
HGCG003B dbCg003B = dbCg003BMap.get(fZl001.getReceiveDetailId());
BigDecimal unqualifyQty = fZl001.getUnqualifyQty().negate();
BigDecimal unqualifyWeight = unqualifyQty.multiply(dbCg003B.getReceiveUnitWeight());
// 关联获取到合同明细
HGCG002B dbCg002B = dbCg002BMap.get(dbCg003B.getContractDetailId());
HGCGTools.HgCg002B.updateReceive(dbCg002B, unqualifyQty, unqualifyWeight);
// 修改主表信息
HGCG002 dbCg002 = dbCg002Map.get(dbCg002B.getPrimaryId());
HGCGTools.HgCg002.updateReceive(dbCg002, unqualifyQty, unqualifyWeight);
}
HGKCTools.HgKc001.putInStorageData(fZl001, dbCg003B);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment