You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
712 lines
40 KiB
Plaintext
712 lines
40 KiB
Plaintext
<%@ page import="weaver.general.BaseBean" %>
|
|
<%@ page import="weaver.conn.RecordSetDataSource" %>
|
|
<%@ page import="cn.hutool.core.date.DateUtil" %>
|
|
<%@ page import="java.util.*" %>
|
|
<%@ page import="weaver.general.Util" %>
|
|
<%@ page import="com.wbi.util.StringUtil" %>
|
|
<%@ page import="java.math.BigDecimal" %>
|
|
<%@ page import="java.math.RoundingMode" %>
|
|
<%@ page import="java.util.stream.Collectors" %>
|
|
<%@ page import="weaver.formmode.setup.ModeRightInfo" %>
|
|
<%@ page import="weaver.conn.RecordSet" %>
|
|
<%@ page import="weaver.interfaces.dfjc.entity.ProWagDetPO" %>
|
|
<%@ page import="com.google.gson.Gson" %>
|
|
<%@ page import="java.time.format.DateTimeFormatter" %>
|
|
<%@ page import="java.time.LocalDate" %>
|
|
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
|
|
|
|
<%
|
|
|
|
out.print("-----------SyncDfjcUatBatch start-------------");
|
|
BaseBean basebean = new BaseBean();
|
|
|
|
String fromdate = request.getParameter("fromdate");
|
|
String todate = request.getParameter("todate");
|
|
RecordSetDataSource rsds = new RecordSetDataSource();
|
|
RecordSet rs = new RecordSet();
|
|
//获取当前年月日
|
|
String today = DateUtil.format(new Date(),"yyyy-MM-dd");
|
|
// //获取当前年月
|
|
// String nowMonth = DateUtil.format(new Date(),"yyyy-MM");
|
|
// //获取当前年
|
|
// String nowYear = DateUtil.format(new Date(),"yyyy");
|
|
|
|
try {
|
|
basebean.writeLog("------------SyncDfjcUatBatch Try-----------");
|
|
|
|
//计算出开始日期和结束日期之间的每个日期
|
|
|
|
List<String> everyDate = getEveryDate(fromdate, todate);
|
|
|
|
for ( String syncdate : everyDate ) {
|
|
basebean.writeLog("syncdate: " + syncdate);
|
|
|
|
//2023-11-22
|
|
String nowYear = syncdate.substring(0,4);
|
|
basebean.writeLog("nowYear: " + nowYear);
|
|
|
|
String nowMonth = syncdate.substring(0,7);
|
|
basebean.writeLog("nowMonth: " + nowMonth);
|
|
|
|
//获取基础数据
|
|
List<Map<String, String>> baseDatasList = new ArrayList<>();
|
|
Map<String, String> baseDataMap = new HashMap<>();
|
|
//// String acqBaseDatasSql = " select lhid, rksl from uf_u9dddj where rksj = ?";
|
|
//String acqBaseDatasSql = " SELECT Item, EligibleQty from MO_CompleteRpt WHERE CAST(ActualRcvTime AS DATE) = ? and DocState = 3";
|
|
|
|
String acqBaseDatasSql = " SELECT a.id,a.docstate,a.HandleDept, a.item,a.ActualRcvTime,a.EligibleQty,b.BusinessType FROM MO_CompleteRpt a LEFT JOIN MO_CompleteRptDocType b ON a.CompleteDocType=b.ID WHERE b.BusinessType<>48 and CAST(ActualRcvTime AS DATE) = ? and DocState = 3";
|
|
|
|
|
|
//// rs.executeQuery(acqBaseDatasSql,nowDate);
|
|
rsds.executeQueryWithDatasource( acqBaseDatasSql, "u9", syncdate);
|
|
while (rsds.next()) {
|
|
String lhid = Util.null2String(rsds.getString("Item"));//料号id
|
|
String rksl = Util.null2String(rsds.getString("EligibleQty"));//入库数量
|
|
if ( StringUtil.isNotBlank(lhid) && StringUtil.isNotBlank(rksl)) {
|
|
baseDataMap = new HashMap<>();
|
|
baseDataMap.put("lhid",lhid);
|
|
baseDataMap.put("rksl",rksl);
|
|
baseDatasList.add(baseDataMap);
|
|
}
|
|
}
|
|
basebean.writeLog("------baseDatasList.size: " + baseDatasList.size() );
|
|
basebean.writeLog("------baseDatasList: " + baseDatasList );
|
|
|
|
//获取产品单价台账
|
|
Map<String, Map<String, String>> unitPricesMap = new HashMap<>();
|
|
Map<String, String> unitPriceMap = new HashMap<>();
|
|
// String scqunitPriceSql = "select id, lhid, lh, lp, cx, xncx, rklbz1, dj, rklbz2, dj2, rklbz3, dj3 from uf_cpdjb where djnd = ?";
|
|
String scqunitPriceSql = "select id, lhid, lh, lp, cx, xncx, rklbz1, dj, rklbz2, dj2, rklbz3, dj3 from uf_cpdjb ";
|
|
boolean b = rs.executeQuery( scqunitPriceSql);
|
|
basebean.writeLog("------b: " + b );
|
|
while (rs.next()) {
|
|
String id = Util.null2String(rs.getString("id"));//产品单价id
|
|
String lhid = Util.null2String(rs.getString("lhid"));//料号id
|
|
String lh = Util.null2String(rs.getString("lh"));//料号
|
|
String lp = Util.null2String(rs.getString("lp"));//料品
|
|
String cx = Util.null2String(rs.getString("cx"));//产线
|
|
String xncx = Util.null2String(rs.getString("xncx"));//虚拟产线
|
|
String rklbz1 = Util.null2String(rs.getString("rklbz1"));//入库量标准1
|
|
String dj = Util.null2String(rs.getString("dj"));//单价1
|
|
String rklbz2 = Util.null2String(rs.getString("rklbz2"));//入库量标准2
|
|
String dj2 = Util.null2String(rs.getString("dj2"));//单价2
|
|
String rklbz3 = Util.null2String(rs.getString("rklbz3"));//入库量标准3
|
|
String dj3 = Util.null2String(rs.getString("dj3"));//单价3
|
|
if ( StringUtil.isNotBlank(lhid) && StringUtil.isNotBlank(cx) && StringUtil.isNotBlank(lp) ) {
|
|
unitPriceMap = new HashMap<>();
|
|
unitPriceMap.put("id",id);
|
|
unitPriceMap.put("lhid",lhid);
|
|
unitPriceMap.put("lh",lh);
|
|
unitPriceMap.put("lp",lp);
|
|
unitPriceMap.put("cx",cx);
|
|
unitPriceMap.put("xncx",xncx);
|
|
unitPriceMap.put("rklbz1",rklbz1);
|
|
unitPriceMap.put("dj",dj);
|
|
unitPriceMap.put("rklbz2",rklbz2);
|
|
unitPriceMap.put("dj2",dj2);
|
|
unitPriceMap.put("rklbz3",rklbz3);
|
|
unitPriceMap.put("dj3",dj3);
|
|
unitPricesMap.put(lhid,unitPriceMap);
|
|
}
|
|
}
|
|
|
|
basebean.writeLog("------unitPricesMap: " + new Gson().toJson(unitPricesMap));
|
|
|
|
//获取料号和各单价的对应关系
|
|
Map<String, Map<String, String>> lpToDjMap = new HashMap<>();
|
|
|
|
for (Map.Entry<String, Map<String, String>> entry : unitPricesMap.entrySet()) {
|
|
String lp = entry.getValue().get("lp");
|
|
String dj = entry.getValue().get("dj");
|
|
String dj2 = entry.getValue().get("dj2");
|
|
String dj3 = entry.getValue().get("dj3");
|
|
|
|
if (lpToDjMap.containsKey(lp)) {
|
|
Map<String, String> djMap = lpToDjMap.get(lp);
|
|
djMap.put("dj", dj);
|
|
djMap.put("dj2", dj2);
|
|
djMap.put("dj3", dj3);
|
|
} else {
|
|
Map<String, String> djMap = new HashMap<>();
|
|
djMap.put("dj", dj);
|
|
djMap.put("dj2", dj2);
|
|
djMap.put("dj3", dj3);
|
|
lpToDjMap.put(lp, djMap);
|
|
}
|
|
}
|
|
|
|
//获取虚拟产线和料品的对应关系
|
|
Map<String, List<String>> xncxToLpMap = new HashMap<>();
|
|
|
|
for (Map.Entry<String, Map<String, String>> entry : unitPricesMap.entrySet()) {
|
|
|
|
String xncx = entry.getValue().get("xncx");
|
|
String lp = entry.getValue().get("lp");
|
|
|
|
if (StringUtil.isNotBlank(xncx)) {
|
|
if (xncxToLpMap.containsKey(xncx)) {
|
|
List<String> lpList = xncxToLpMap.get(xncx);
|
|
lpList.add(lp);
|
|
} else {
|
|
List<String> lpList = new ArrayList<>();
|
|
lpList.add(lp);
|
|
xncxToLpMap.put(xncx, lpList);
|
|
}
|
|
}
|
|
}
|
|
|
|
//获取产线工价台账
|
|
// String checkProSql = "select count(*) as number from uf_cxgj where cxmc = ? and scyf = ? ";
|
|
|
|
//产线工价主表
|
|
String acqProMainSql = "select id from uf_cxgj where cxmc = ? and scyf = ?";
|
|
String acqProMainByMonthSql = "select id from uf_cxgj where scyf = ?";
|
|
|
|
//产线工价明细表
|
|
// String acqProDetSql = "select id, lh, lp, rkrq, cpdj, rkcl, rkje from uf_cxgj_dt1 where mainId = ?";
|
|
String acqProDetBatSql = "select id, mainid, lh, lp, rkrq, cpdj, rkcl, rkje from uf_cxgj_dt1 where mainid in ";
|
|
|
|
//产线工价明细表插入
|
|
String addProDetSql = "insert into uf_cxgj_dt1 ( mainid, lh, lp, rkrq, cpdj, rkcl, rkje ) values ( ?, ?, ?, ?, ?, ?, ? )";
|
|
|
|
//产线工价明细表修改
|
|
String editProDetSql = "update uf_cxgj_dt1 set cpdj = ? ,rkje = ? where id = ? ";
|
|
|
|
//获取当前月份的产线工价数据
|
|
// out.print("------getProDets start");
|
|
List<ProWagDetPO> proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
// out.print("------proDetList: " + proDetList );
|
|
|
|
//根据料号id处理
|
|
for ( Map<String,String> baseData:baseDatasList) {
|
|
basebean.writeLog("=================== " );
|
|
basebean.writeLog("------baseData: " + baseData );
|
|
String lhid = baseData.get("lhid");//料号id
|
|
String rksl = baseData.get("rksl");//入库数量
|
|
Map<String, String> unitPriceTmpMap = unitPricesMap.get(lhid);
|
|
|
|
if ( unitPriceTmpMap == null || unitPriceTmpMap.isEmpty() ) {
|
|
continue;
|
|
}
|
|
|
|
String id = unitPriceTmpMap.get("id");//产品单价id
|
|
String lp = unitPriceTmpMap.get("lp");//料品
|
|
String lh = unitPriceTmpMap.get("lh");//料号
|
|
String cx = unitPriceTmpMap.get("cx");//产线
|
|
String xncx = unitPriceTmpMap.get("xncx");//虚拟产线
|
|
String rklbz1 = unitPriceTmpMap.get("rklbz1");//标准1
|
|
String rklbz2 = unitPriceTmpMap.get("rklbz2");//标准2
|
|
String rklbz3 = unitPriceTmpMap.get("rklbz3");//标准3
|
|
String dj = unitPriceTmpMap.get("dj");//单价1
|
|
String dj2 = unitPriceTmpMap.get("dj2");//单价2
|
|
String dj3 = unitPriceTmpMap.get("dj3");//单价3
|
|
|
|
//是否阶梯单价
|
|
boolean stepUnitPriceFlag = true;
|
|
if ( StringUtil.isBlank(rklbz2) && StringUtil.isBlank(rklbz3)) {
|
|
stepUnitPriceFlag = false;
|
|
}
|
|
basebean.writeLog("------stepUnitPriceFlag: " + stepUnitPriceFlag );
|
|
|
|
//是否虚拟产线
|
|
boolean virProLineFlag = true;
|
|
if ( StringUtil.isBlank(xncx)) {
|
|
virProLineFlag = false;
|
|
}
|
|
basebean.writeLog("------virProLineFlag: " + virProLineFlag );
|
|
|
|
Integer mainId = -1;
|
|
rs.executeQuery( acqProMainSql, cx, nowMonth);
|
|
while (rs.next()) {
|
|
mainId = Util.getIntValue( Util.null2String( rs.getString("id")));
|
|
}
|
|
basebean.writeLog("------mainId: " + mainId );
|
|
|
|
Integer tempMainId = -1;
|
|
if ( mainId == -1) {//主表没有该产线的数据
|
|
mainId = Util.getIntValue( addProMainData(cx, nowMonth, rs));
|
|
if (cx.equals("13")) {
|
|
tempMainId = mainId;
|
|
}
|
|
}
|
|
basebean.writeLog("------mainId: " + mainId );
|
|
|
|
if ( !stepUnitPriceFlag ) {//非阶梯单价--直接插入一行明细
|
|
if ( tempMainId > 0 ) {
|
|
out.print("--dj:" + dj + "--");
|
|
out.print("--dj2:" + dj2 + "--");
|
|
out.print("--dj3:" + dj3 + "--");
|
|
}
|
|
|
|
//计算入库金额
|
|
BigDecimal depAmount = new BigDecimal(0);
|
|
if ( StringUtil.isNotBlank(rksl) && StringUtil.isNotBlank(dj)) {
|
|
BigDecimal depNum = new BigDecimal(rksl);
|
|
BigDecimal uniPri = new BigDecimal(dj);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
|
|
rs.executeUpdate( addProDetSql, mainId, id, lp, syncdate, dj, rksl, depAmount);
|
|
proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
|
|
} else {//阶梯单价
|
|
//虚拟产线
|
|
if ( !virProLineFlag ) {
|
|
//非虚拟产线,找同料号的明细
|
|
if ( proDetList.isEmpty()) {//明细表没有数据
|
|
Double unPr= 0.0;
|
|
if ( StringUtil.isBlank(dj2) ) {
|
|
unPr = Double.valueOf(dj);
|
|
} else {
|
|
if ( Double.parseDouble(rksl) < Double.parseDouble(rklbz1) ) {
|
|
unPr = Double.valueOf(dj);
|
|
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz1)) && ( StringUtil.isNotBlank(rklbz2) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz2))) ) {
|
|
unPr = Double.valueOf(dj2);
|
|
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz3)))) {
|
|
unPr = Double.valueOf(dj3);
|
|
}
|
|
}
|
|
|
|
//计算入库金额
|
|
BigDecimal depAmount = new BigDecimal(0);
|
|
if ( StringUtil.isNotBlank(rksl) && unPr > 0 ) {
|
|
BigDecimal depNum = new BigDecimal(rksl);
|
|
BigDecimal uniPri = new BigDecimal(unPr);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
rs.executeUpdate( addProDetSql, mainId, id, lp, syncdate, unPr, rksl, depAmount);
|
|
proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
|
|
} else {
|
|
String finalMainId = Util.null2String(mainId);
|
|
List<ProWagDetPO> proWList = proDetList.stream()
|
|
// .filter(pro -> pro.getMainId().equals(finalMainId) && pro.getLp() != null && pro.getLp().equals(lp))
|
|
.filter(pro -> pro.getMainId().equals(finalMainId) )
|
|
.collect(Collectors.toList());
|
|
// if ( proWList.isEmpty()) {//没有同产线的明细
|
|
// Double unPr= 0.0;
|
|
// if ( StringUtil.isBlank(dj2) ) {
|
|
// unPr = Double.valueOf(dj);
|
|
// } else {
|
|
// if (Double.parseDouble(rksl) < Double.parseDouble(rklbz1)) {
|
|
// unPr = Double.valueOf(dj);
|
|
// } else if ((Double.parseDouble(rksl) >= Double.parseDouble(rklbz1)) && (StringUtil.isNotBlank(rklbz2) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz2)))) {
|
|
// unPr = Double.valueOf(dj2);
|
|
// } else if ((Double.parseDouble(rksl) >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz3)))) {
|
|
// unPr = Double.valueOf(dj3);
|
|
// }
|
|
// }
|
|
// //计算入库金额
|
|
// BigDecimal depAmount = new BigDecimal(0);
|
|
// if ( StringUtil.isNotBlank(rksl) && unPr > 0 ) {
|
|
// BigDecimal depNum = new BigDecimal(rksl);
|
|
// BigDecimal uniPri = new BigDecimal(unPr);
|
|
// depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
// }
|
|
// rs.executeUpdate( addProDetSql, mainId, id, lp, syncdate, unPr, rksl, depAmount);
|
|
// proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
//
|
|
// } else {
|
|
// 存在同产线的明细
|
|
Double unPr= 0.0;
|
|
List<String> rkcls = proWList.stream()
|
|
.map(pro -> pro.getStorageNumber())
|
|
.collect(Collectors.toList());
|
|
Double rkclSum = rkcls.stream()
|
|
.map(str -> Double.parseDouble(str))
|
|
.reduce(0.0, Double::sum);
|
|
|
|
rkclSum = rkclSum + Double.parseDouble(rksl);
|
|
|
|
if ( StringUtil.isBlank(dj2) ) {
|
|
unPr = Double.valueOf(dj);
|
|
} else {
|
|
if (rkclSum < Double.parseDouble(rklbz1)) {
|
|
unPr = Double.valueOf(dj);
|
|
} else if ((rkclSum >= Double.parseDouble(rklbz1)) && (StringUtil.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2)))) {
|
|
unPr = Double.valueOf(dj2);
|
|
} else if ((rkclSum >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (rkclSum < Double.parseDouble(rklbz3)))) {
|
|
unPr = Double.valueOf(dj3);
|
|
}
|
|
}
|
|
//计算入库金额
|
|
BigDecimal depAmount = new BigDecimal(0);
|
|
if ( Double.parseDouble(rksl) > 0 && unPr > 0 ) {
|
|
BigDecimal depNum = new BigDecimal(rksl);
|
|
BigDecimal uniPri = new BigDecimal(unPr);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
rs.executeUpdate( addProDetSql, mainId, id, lp, syncdate, unPr, rksl, depAmount);
|
|
//处理历史明细
|
|
List<List> oldDetDatas = new ArrayList<>();
|
|
List<String> detIds = proWList.stream()
|
|
.map(pro -> pro.getId())
|
|
.collect(Collectors.toList());
|
|
Map<String, String> StoNumMap = proWList.stream()
|
|
.filter(pro -> detIds.contains(pro.getId()))
|
|
.collect(Collectors.toMap(
|
|
ProWagDetPO::getId,
|
|
ProWagDetPO::getStorageNumber
|
|
));
|
|
for (String detId : detIds) {
|
|
Integer stoNum = Util.getIntValue(StoNumMap.get(detId));
|
|
|
|
//同产线的总量 rkclSum
|
|
//获取该料品的入库数量标准和单价
|
|
for (ProWagDetPO pro : proWList) {
|
|
if (pro.getId().equals(detId)) {
|
|
pro.getLhid();
|
|
}
|
|
}
|
|
unitPriceTmpMap = unitPricesMap.get(lhid);
|
|
|
|
if ( unitPriceTmpMap == null || unitPriceTmpMap.isEmpty() ) {
|
|
continue;
|
|
}
|
|
|
|
id = unitPriceTmpMap.get("id");//产品单价id
|
|
lp = unitPriceTmpMap.get("lp");//料品
|
|
lh = unitPriceTmpMap.get("lh");//料号
|
|
cx = unitPriceTmpMap.get("cx");//产线
|
|
xncx = unitPriceTmpMap.get("xncx");//虚拟产线
|
|
rklbz1 = unitPriceTmpMap.get("rklbz1");//标准1
|
|
rklbz2 = unitPriceTmpMap.get("rklbz2");//标准2
|
|
rklbz3 = unitPriceTmpMap.get("rklbz3");//标准3
|
|
dj = unitPriceTmpMap.get("dj");//单价1
|
|
dj2 = unitPriceTmpMap.get("dj2");//单价2
|
|
dj3 = unitPriceTmpMap.get("dj3");//单价3
|
|
|
|
if ( StringUtil.isBlank(dj2) ) {
|
|
unPr = Double.valueOf(dj);
|
|
} else {
|
|
if (rkclSum < Double.parseDouble(rklbz1)) {
|
|
unPr = Double.valueOf(dj);
|
|
} else if ((rkclSum >= Double.parseDouble(rklbz1)) && (StringUtil.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2)))) {
|
|
unPr = Double.valueOf(dj2);
|
|
} else if ((rkclSum >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (rkclSum < Double.parseDouble(rklbz3)))) {
|
|
unPr = Double.valueOf(dj3);
|
|
}
|
|
}
|
|
|
|
//计算入库金额
|
|
depAmount = new BigDecimal(0);
|
|
if ( stoNum > 0 && unPr > 0 ) {
|
|
BigDecimal depNum = new BigDecimal(stoNum);
|
|
BigDecimal uniPri = new BigDecimal(unPr);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
List tempList = new ArrayList<>();
|
|
tempList.add(unPr);
|
|
tempList.add(depAmount);
|
|
tempList.add(detId);
|
|
oldDetDatas.add(tempList);
|
|
// }
|
|
|
|
rs.executeBatchSql( editProDetSql, oldDetDatas);
|
|
proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
if ( proDetList.isEmpty()) {
|
|
Double unPr= 0.0;
|
|
if ( Double.parseDouble(rksl) < Double.parseDouble(rklbz1) ) {
|
|
unPr = Double.valueOf(dj);
|
|
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz1)) && ( StringUtil.isNotBlank(rklbz2) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz2))) ) {
|
|
unPr = Double.valueOf(dj2);
|
|
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz3)))) {
|
|
unPr = Double.valueOf(dj3);
|
|
}
|
|
//计算入库金额
|
|
BigDecimal depAmount = new BigDecimal(0);
|
|
if ( StringUtil.isNotBlank(rksl) && unPr > 0 ) {
|
|
BigDecimal depNum = new BigDecimal(rksl);
|
|
BigDecimal uniPri = new BigDecimal(unPr);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
rs.executeUpdate( addProDetSql, mainId, id, lp, syncdate, unPr, rksl, depAmount);
|
|
proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
} else {
|
|
String finalMainId = Util.null2String(mainId);
|
|
List<String> lpTmpList = xncxToLpMap.get(xncx);
|
|
List<ProWagDetPO> proWList = proDetList.stream()
|
|
.filter(pro -> pro.getMainId().equals(finalMainId) && pro.getLp() != null && lpTmpList.contains(pro.getLp()))
|
|
// .filter(pro -> pro.getMainId().equals(finalMainId))
|
|
.collect(Collectors.toList());
|
|
if ( proWList.isEmpty()) {//没有同虚拟产线的明细
|
|
Double unPr= 0.0;
|
|
if ( Double.parseDouble(rksl) < Double.parseDouble(rklbz1) ) {
|
|
unPr = Double.valueOf(dj);
|
|
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz1)) && ( StringUtil.isNotBlank(rklbz2) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz2))) ) {
|
|
unPr = Double.valueOf(dj2);
|
|
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz3)))) {
|
|
unPr = Double.valueOf(dj3);
|
|
}
|
|
//计算入库金额
|
|
BigDecimal depAmount = new BigDecimal(0);
|
|
if ( StringUtil.isNotBlank(rksl) && unPr > 0 ) {
|
|
BigDecimal depNum = new BigDecimal(rksl);
|
|
BigDecimal uniPri = new BigDecimal(unPr);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
rs.executeUpdate( addProDetSql, mainId, id, lp, syncdate, unPr, rksl, depAmount);
|
|
proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
|
|
} else {//存在同虚拟产线
|
|
Double unPr= 0.0;
|
|
String stage = "dj";
|
|
List<String> rkcls = proWList.stream()
|
|
.map(pro -> pro.getStorageNumber())
|
|
.collect(Collectors.toList());
|
|
Double rkclSum = rkcls.stream()
|
|
.map(str -> Double.parseDouble(str))
|
|
.reduce(0.0, Double::sum);
|
|
|
|
rkclSum = rkclSum + Double.parseDouble(rksl);
|
|
|
|
if ( rkclSum < Double.parseDouble(rklbz1) ) {
|
|
unPr = Double.valueOf(dj);
|
|
} else if ( (rkclSum >= Double.parseDouble(rklbz1)) && ( StringUtil.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2))) ) {
|
|
unPr = Double.valueOf(dj2);
|
|
stage = "dj2";
|
|
} else if ( (rkclSum >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (rkclSum < Double.parseDouble(rklbz3)))) {
|
|
unPr = Double.valueOf(dj3);
|
|
stage = "dj3";
|
|
}
|
|
//计算入库金额
|
|
BigDecimal depAmount = new BigDecimal(0);
|
|
if ( Double.parseDouble(rksl) > 0 && unPr > 0 ) {
|
|
BigDecimal depNum = new BigDecimal(rksl);
|
|
BigDecimal uniPri = new BigDecimal(unPr);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
rs.executeUpdate( addProDetSql, mainId, id, lp, syncdate, unPr, rksl, depAmount);
|
|
proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
//处理历史明细
|
|
List<List> oldDetDatas = new ArrayList<>();
|
|
List<String> detIds = proWList.stream()
|
|
.map(pro -> pro.getId())
|
|
.collect(Collectors.toList());
|
|
Map<String, Map<String, Object>> idToLpStoNumMap = proWList.stream()
|
|
.filter(proWagDetPO -> detIds.contains(proWagDetPO.getId()))
|
|
.collect(Collectors.toMap(
|
|
proWagDetPO -> proWagDetPO.getId(),
|
|
proWagDetPO -> {
|
|
Map<String, Object> innerMap = new HashMap<>();
|
|
innerMap.put("lp", proWagDetPO.getLp());
|
|
innerMap.put("storageNumber", proWagDetPO.getStorageNumber());
|
|
return innerMap;
|
|
}
|
|
));
|
|
for (String detId : detIds) {
|
|
Map<String, Object> innerMap = idToLpStoNumMap.get(detId);
|
|
//计算入库金额
|
|
depAmount = new BigDecimal(0);
|
|
String lpTmp = Util.null2String(innerMap.get("lp"));
|
|
Integer stoNumTmp = Util.getIntValue( Util.null2String(innerMap.get("storageNumber")));
|
|
|
|
// Map<String, String> djTmpMap = lpToDjMap.get(lpTmp);
|
|
// Double unPrTmp = Util.getDoubleValue(djTmpMap.get(stage));
|
|
|
|
//获取该料品的入库数量标准和单价
|
|
for (ProWagDetPO pro : proWList) {
|
|
if (pro.getId().equals(detId)) {
|
|
pro.getLhid();
|
|
}
|
|
}
|
|
unitPriceTmpMap = unitPricesMap.get(lhid);
|
|
|
|
if ( unitPriceTmpMap == null || unitPriceTmpMap.isEmpty() ) {
|
|
continue;
|
|
}
|
|
|
|
id = unitPriceTmpMap.get("id");//产品单价id
|
|
lp = unitPriceTmpMap.get("lp");//料品
|
|
lh = unitPriceTmpMap.get("lh");//料号
|
|
cx = unitPriceTmpMap.get("cx");//产线
|
|
xncx = unitPriceTmpMap.get("xncx");//虚拟产线
|
|
rklbz1 = unitPriceTmpMap.get("rklbz1");//标准1
|
|
rklbz2 = unitPriceTmpMap.get("rklbz2");//标准2
|
|
rklbz3 = unitPriceTmpMap.get("rklbz3");//标准3
|
|
dj = unitPriceTmpMap.get("dj");//单价1
|
|
dj2 = unitPriceTmpMap.get("dj2");//单价2
|
|
dj3 = unitPriceTmpMap.get("dj3");//单价3
|
|
|
|
Double unPrTmp = 0.00;
|
|
|
|
if ( StringUtil.isBlank(dj2) ) {
|
|
unPrTmp = Double.valueOf(dj);
|
|
} else {
|
|
if (rkclSum < Double.parseDouble(rklbz1)) {
|
|
unPrTmp = Double.valueOf(dj);
|
|
} else if ((rkclSum >= Double.parseDouble(rklbz1)) && (StringUtil.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2)))) {
|
|
unPrTmp = Double.valueOf(dj2);
|
|
} else if ((rkclSum >= Double.parseDouble(rklbz2)) && (StringUtil.isNotBlank(rklbz3) && (rkclSum < Double.parseDouble(rklbz3)))) {
|
|
unPrTmp = Double.valueOf(dj3);
|
|
}
|
|
}
|
|
|
|
if ( stoNumTmp > 0 && unPrTmp > 0 ) {
|
|
BigDecimal depNum = new BigDecimal(stoNumTmp);
|
|
BigDecimal uniPri = new BigDecimal(unPrTmp);
|
|
depAmount = depNum.multiply(uniPri).setScale(2, RoundingMode.HALF_UP);
|
|
}
|
|
List tempList = new ArrayList<>();
|
|
tempList.add(unPrTmp);
|
|
tempList.add(depAmount);
|
|
tempList.add(detId);
|
|
oldDetDatas.add(tempList);
|
|
}
|
|
|
|
rs.executeBatchSql( editProDetSql, oldDetDatas);
|
|
proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
List<String> mainidList = new ArrayList<>();
|
|
rs.executeQuery( acqProMainByMonthSql, nowMonth);
|
|
while (rs.next()) {
|
|
String id = Util.null2String(rs.getString("id"));
|
|
if (StringUtil.isNotBlank(id)) {
|
|
mainidList.add(id);
|
|
}
|
|
}
|
|
if ( !mainidList.isEmpty()) {
|
|
String editProMainSql = "update uf_cxgj set lrrq = ? , cxzgj = (SELECT sum( rkje ) AS cxzgj FROM uf_cxgj_dt1 WHERE mainid = ?), rkzcl = (SELECT sum( rkcl ) AS rkzcl FROM uf_cxgj_dt1 WHERE mainid = ?) where id = ?";
|
|
for (String mainid:mainidList) {
|
|
rs.executeUpdate( editProMainSql, today, mainid, mainid, mainid);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}catch (Exception e) {
|
|
basebean.writeLog("SyncDfjcUatBatch Exception: " + e);
|
|
out.print("-----SyncDfjcUatBatch Exception: " + e);
|
|
}
|
|
|
|
out.print("=========SyncDfjcUatBatch End==========");
|
|
%>
|
|
|
|
<%!
|
|
BaseBean basebean = new BaseBean();
|
|
|
|
public List<String> getEveryDate(String fromDate, String toDate) {
|
|
List<String> everyDate = new ArrayList<>();
|
|
|
|
// 创建一个格式化器
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
// 将字符串转换为 LocalDate 对象
|
|
LocalDate startLocalDate = LocalDate.parse(fromDate, formatter);
|
|
LocalDate endLocalDate = LocalDate.parse(toDate, formatter);
|
|
|
|
// 创建一个列表来存储日期
|
|
List<LocalDate> dates = new ArrayList<>();
|
|
|
|
// 计算并添加所有日期
|
|
for (LocalDate date = startLocalDate; date.isBefore(endLocalDate.plusDays(1)); date = date.plusDays(1)) {
|
|
dates.add(date);
|
|
}
|
|
|
|
DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
for (LocalDate date : dates) {
|
|
everyDate.add(date.format(df));
|
|
}
|
|
|
|
return everyDate;
|
|
}
|
|
|
|
|
|
public String addProMainData(String cx, String nowMonth, RecordSet rs){
|
|
String result = "";
|
|
String addProMainSql = "insert into uf_cxgj (lrr,lrrq,cxmc,scyf,formmodeid,modedatacreater,modedatacreatertype,modedatacreatedate,modedatacreatetime,modeuuid) " +
|
|
" values (?,?,?,?,?,?,?,?,?,?)";
|
|
String acqMainIdSql = "select id from uf_cxgj where modeuuid = ? ";
|
|
|
|
String formmodeid = "48";
|
|
String nowDate = DateUtil.format(new Date(),"yyyy-MM-dd");
|
|
String nowTime = DateUtil.format(new Date(),"HH:mm:ss");
|
|
UUID uuid = UUID.randomUUID();
|
|
String modeuuid = uuid.toString();
|
|
boolean addFlag = rs.executeUpdate( addProMainSql, 1, nowDate, cx, nowMonth, formmodeid, 1, 0, nowDate, nowTime, modeuuid);
|
|
if ( addFlag) {
|
|
rs.executeQuery( acqMainIdSql, modeuuid);
|
|
while ( rs.next()) {
|
|
result = Util.null2String( rs.getString("id"));
|
|
}
|
|
}
|
|
|
|
//权限重构
|
|
ModeRightInfo modeRightInfo = new ModeRightInfo();
|
|
modeRightInfo.setNewRight(true);
|
|
modeRightInfo.editModeDataShare( 1, Integer.parseInt(formmodeid), Integer.parseInt(result));
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<ProWagDetPO> getProDets(String acqProMainByMonthSql, String acqProDetBatSql, String nowMonth, Map<String, Map<String, String>> unitPricesMap, RecordSet rs) {
|
|
List<String> proMainList = new ArrayList<>();
|
|
List<ProWagDetPO> proDetList = new ArrayList<>();
|
|
try {
|
|
rs.executeQuery(acqProMainByMonthSql, nowMonth);
|
|
while ( rs.next()) {
|
|
String id = Util.null2String(rs.getString("id"));
|
|
if ( StringUtil.isNotBlank(id)) {
|
|
proMainList.add(id);
|
|
}
|
|
}
|
|
basebean.writeLog("============getProDets proMainList:"+ proMainList);
|
|
basebean.writeLog("============getProDets proMainList:"+ proMainList.size());
|
|
if ( !proMainList.isEmpty()) {
|
|
ProWagDetPO po = null;
|
|
String sqlWhere = String.join(",",proMainList);
|
|
acqProDetBatSql = acqProDetBatSql + "( " + sqlWhere + " )";
|
|
rs.executeQuery(acqProDetBatSql);
|
|
while ( rs.next()) {
|
|
String id = Util.null2String(rs.getString("id"));//明细ID
|
|
String mainid = Util.null2String(rs.getString("mainid"));
|
|
String lhid = Util.null2String(rs.getString("lh"));
|
|
String lp = Util.null2String(rs.getString("lp"));
|
|
String rkrq = Util.null2String(rs.getString("rkrq"));
|
|
String cpdj = Util.null2String(rs.getString("cpdj"));
|
|
String rkcl = Util.null2String(rs.getString("rkcl"));//入库产量
|
|
String rkje = Util.null2String(rs.getString("rkje"));
|
|
if ( StringUtil.isNotBlank(mainid) && StringUtil.isNotBlank(lhid)) {
|
|
po = new ProWagDetPO();
|
|
po.setId(id);
|
|
po.setMainId(mainid);
|
|
po.setLhid(lhid);
|
|
po.setLp(lp);
|
|
po.setStorageDate(rkrq);
|
|
po.setUnitPrice(cpdj);
|
|
po.setStorageNumber(rkcl);
|
|
po.setStorageAmount(rkje);
|
|
|
|
Map<String, String> tmpMap = unitPricesMap.get(lhid);
|
|
if ( tmpMap != null && !tmpMap.isEmpty()) {
|
|
String lh = tmpMap.get("lh");
|
|
po.setLh(lh);
|
|
}
|
|
|
|
proDetList.add(po);
|
|
}
|
|
}
|
|
}
|
|
}catch (Exception e) {
|
|
basebean.writeLog("getProDets exception: " + e);
|
|
}
|
|
return proDetList;
|
|
}
|
|
%>
|