东方骏驰工价计算历史人员相关代码同步

东方骏驰
Chengliang 8 months ago
parent 80b285ce56
commit a029071999

@ -0,0 +1,14 @@
package com.api.kqsolution.web;
import javax.ws.rs.Path;
/**
* @Author liang.cheng
* @Date 2024/9/2 10:17 AM
* @Description: TODO
* @Version 1.0
*/
@Path("/kqsolution/projectPrice")
public class ProjectPriceAction extends com.engine.kqsolution.web.ProjectPriceAction {
}

@ -0,0 +1,31 @@
package com.engine.kqsolution.service;
import java.util.Map;
/**
* @Author liang.cheng
* @Date 2024/9/2 10:19 AM
* @Description: TODO
* @Version 1.0
*/
public interface ProjectPriceService {
/**
* @Description: 线
* @Author: liang.cheng
* @Date: 2024/9/2 10:30 AM
* @param: [params]
* @return: java.util.Map<java.lang.String,java.lang.Object>
*/
Map<String,Object> signData(Map<String, Object> params);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/9/3 10:22 AM
* @param: [month, cx]
* @return: void
*/
void deleteHData(String month,String cx);
}

@ -0,0 +1,707 @@
package com.engine.kqsolution.service.impl;
import cn.hutool.core.date.DateUtil;
import com.engine.core.impl.Service;
import com.engine.kqsolution.service.ProjectPriceService;
import com.weaver.general.BaseBean;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetDataSource;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.Util;
import weaver.interfaces.dfjc.entity.ProWagDetPO;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author liang.cheng
* @Date 2024/9/2 10:19 AM
* @Description: SyncDfjcUatBatch.jsp
* @Version 1.0
*/
public class ProjectPriceServiceImpl extends Service implements ProjectPriceService {
@Override
public Map<String, Object> signData(Map<String, Object> params) {
RecordSetDataSource rsds = new RecordSetDataSource();
Map<String, Object> result = new HashMap<>();
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
String projectValue = Util.null2String(params.get("projectValue"));
String fromdate = Util.null2String(params.get("fromdate"));
String todate = Util.null2String(params.get("todate"));
String month = Util.null2String(params.get("month"));
String today = DateUtil.format(new Date(),"yyyy-MM-dd");
try {
//根据条线筛选更新数据(台账按钮操作)
List<String> lhidList = new ArrayList<>();
if (StringUtils.isNotEmpty(projectValue)) {
//根据条线删除历史数据
deleteHData(month,projectValue);
rs.executeQuery("select lhid from uf_cpdjb where cx = ?",projectValue);
while (rs.next()) {
lhidList.add(Util.null2String(rs.getString("lhid")));
}
}
result.put("lhids",lhidList);
//计算出开始日期和结束日期之间的每个日期
List<String> everyDate = getEveryDate(fromdate, todate);
for ( String syncdate : everyDate ) {
String nowYear = syncdate.substring(0,4);
String nowMonth = syncdate.substring(0,7);
//获取基础数据
List<Map<String, String>> baseDatasList = new ArrayList<>();
Map<String, String> baseDataMap = new HashMap<>();
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";
if (CollectionUtils.isNotEmpty(lhidList)) {
List<String> quotedList = lhidList.stream()
.map(s -> "'" + s + "'")
.collect(Collectors.toList());
String str = String.join(",", quotedList);
acqBaseDatasSql = acqBaseDatasSql + " and a.item in ("+str+")";
}
rsds.executeQueryWithDatasource( acqBaseDatasSql, "u9", syncdate);
while (rsds.next()) {
String lhid = Util.null2String(rsds.getString("Item"));//料号id
String rksl = Util.null2String(rsds.getString("EligibleQty"));//入库数量
if ( StringUtils.isNotBlank(lhid) && StringUtils.isNotBlank(rksl)) {
baseDataMap = new HashMap<>();
baseDataMap.put("lhid",lhid);
baseDataMap.put("rksl",rksl);
baseDatasList.add(baseDataMap);
}
}
result.put("data",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 ";
rs.executeQuery( scqunitPriceSql);
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 ( StringUtils.isNotBlank(lhid) && StringUtils.isNotBlank(cx) && StringUtils.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);
}
}
//获取料号和各单价的对应关系
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 (StringUtils.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 = ? ";
//获取当前月份的产线工价数据
List<ProWagDetPO> proDetList = getProDets(acqProMainByMonthSql, acqProDetBatSql, nowMonth, unitPricesMap, rs);
//根据料号id处理
for ( Map<String,String> baseData:baseDatasList) {
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 ( StringUtils.isBlank(rklbz2) && StringUtils.isBlank(rklbz3)) {
stepUnitPriceFlag = false;
}
//是否虚拟产线
boolean virProLineFlag = true;
if ( StringUtils.isBlank(xncx)) {
virProLineFlag = false;
}
Integer mainId = -1;
rs.executeQuery( acqProMainSql, cx, nowMonth);
while (rs.next()) {
mainId = Util.getIntValue( Util.null2String( rs.getString("id")));
}
Integer tempMainId = -1;
if ( mainId == -1) {//主表没有该产线的数据
mainId = Util.getIntValue( addProMainData(cx, nowMonth, rs));
if (cx.equals("13")) {
tempMainId = mainId;
}
}
if ( !stepUnitPriceFlag ) {//非阶梯单价--直接插入一行明细
if ( tempMainId > 0 ) {
}
//计算入库金额
BigDecimal depAmount = new BigDecimal(0);
if ( StringUtils.isNotBlank(rksl) && StringUtils.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 ( StringUtils.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)) && ( StringUtils.isNotBlank(rklbz2) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz2))) ) {
unPr = Double.valueOf(dj2);
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz2)) && (StringUtils.isNotBlank(rklbz3) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz3)))) {
unPr = Double.valueOf(dj3);
}
}
//计算入库金额
BigDecimal depAmount = new BigDecimal(0);
if ( StringUtils.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) )
.collect(Collectors.toList());
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 ( StringUtils.isBlank(dj2) ) {
unPr = Double.valueOf(dj);
} else {
if (rkclSum < Double.parseDouble(rklbz1)) {
unPr = Double.valueOf(dj);
} else if ((rkclSum >= Double.parseDouble(rklbz1)) && (StringUtils.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2)))) {
unPr = Double.valueOf(dj2);
} else if ((rkclSum >= Double.parseDouble(rklbz2)) && (StringUtils.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 ( StringUtils.isBlank(dj2) ) {
unPr = Double.valueOf(dj);
} else {
if (rkclSum < Double.parseDouble(rklbz1)) {
unPr = Double.valueOf(dj);
} else if ((rkclSum >= Double.parseDouble(rklbz1)) && (StringUtils.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2)))) {
unPr = Double.valueOf(dj2);
} else if ((rkclSum >= Double.parseDouble(rklbz2)) && (StringUtils.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)) && ( StringUtils.isNotBlank(rklbz2) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz2))) ) {
unPr = Double.valueOf(dj2);
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz2)) && (StringUtils.isNotBlank(rklbz3) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz3)))) {
unPr = Double.valueOf(dj3);
}
//计算入库金额
BigDecimal depAmount = new BigDecimal(0);
if ( StringUtils.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)) && ( StringUtils.isNotBlank(rklbz2) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz2))) ) {
unPr = Double.valueOf(dj2);
} else if ( (Double.parseDouble(rksl) >= Double.parseDouble(rklbz2)) && (StringUtils.isNotBlank(rklbz3) && (Double.parseDouble(rksl) < Double.parseDouble(rklbz3)))) {
unPr = Double.valueOf(dj3);
}
//计算入库金额
BigDecimal depAmount = new BigDecimal(0);
if ( StringUtils.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)) && ( StringUtils.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2))) ) {
unPr = Double.valueOf(dj2);
stage = "dj2";
} else if ( (rkclSum >= Double.parseDouble(rklbz2)) && (StringUtils.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 ( StringUtils.isBlank(dj2) ) {
unPrTmp = Double.valueOf(dj);
} else {
if (rkclSum < Double.parseDouble(rklbz1)) {
unPrTmp = Double.valueOf(dj);
} else if ((rkclSum >= Double.parseDouble(rklbz1)) && (StringUtils.isNotBlank(rklbz2) && (rkclSum < Double.parseDouble(rklbz2)))) {
unPrTmp = Double.valueOf(dj2);
} else if ((rkclSum >= Double.parseDouble(rklbz2)) && (StringUtils.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 (StringUtils.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) {
e.printStackTrace();
}
return result;
}
@Override
public void deleteHData(String month, String cx) {
RecordSet rs = new RecordSet();
StringBuilder sb = new StringBuilder();
sb.append("select id from uf_cxgj where scyf = ?");
if (StringUtils.isNotEmpty(cx)) {
sb.append(" and cxmc = ").append(cx);
}
rs.executeQuery(sb.toString(),month);
List<String> ids = new ArrayList<>();
while (rs.next()) {
ids.add(Util.null2String(rs.getString("id")));
}
if (CollectionUtils.isNotEmpty(ids)) {
for (String id : ids) {
rs.executeUpdate("delete from uf_cxgj whee scyf = ?",month);
rs.executeUpdate("delete from uf_cxgj_dt1 where mainid = ?",id);
}
}
}
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 (StringUtils.isNotBlank(id)) {
proMainList.add(id);
}
}
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 (StringUtils.isNotBlank(mainid) && StringUtils.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) {
e.printStackTrace();
}
return proDetList;
}
}

@ -0,0 +1,50 @@
package com.engine.kqsolution.web;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.kqsolution.service.ProjectPriceService;
import com.engine.kqsolution.service.impl.ProjectPriceServiceImpl;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;
/**
* @Author liang.cheng
* @Date 2024/9/2 10:18 AM
* @Description:
* @Version 1.0
*/
public class ProjectPriceAction {
private ProjectPriceService getService(User user) {
return ServiceUtil.getService(ProjectPriceServiceImpl.class, user);
}
@POST
@Path("/sign")
@Produces(MediaType.TEXT_PLAIN)
public String customSignData(@Context HttpServletRequest request, @Context HttpServletResponse response){
Map<String, Object> data = new HashMap<>(8);
try {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> map = ParamUtil.request2Map(request);
data.putAll(getService(user).signData(map));
data.put("status", true);
} catch (Exception e) {
data.put("status", false);
data.put("msg", "catch exception : " + e.getMessage());
}
return JSONObject.toJSONString(data, SerializerFeature.DisableCircularReferenceDetect);
}
}

@ -0,0 +1,50 @@
package weaver.interfaces.kqsolution.crob;
import com.engine.kqsolution.service.impl.ProjectPriceServiceImpl;
import weaver.conn.RecordSet;
import weaver.interfaces.schedule.BaseCronJob;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
/**
* @Author liang.cheng
* @Date 2024/9/2 10:08 AM
* @Description: 线
* @Version 1.0
*/
public class ProjectPriceCrob extends BaseCronJob {
@Override
public void execute() {
RecordSet rs = new RecordSet();
ProjectPriceServiceImpl project = new ProjectPriceServiceImpl();
LocalDate today = LocalDate.now();
LocalDate firstDayOfMonth = today.withDayOfMonth(1);
LocalDate lastDayOfMonth = today.withDayOfMonth(today.lengthOfMonth());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String firstDay = firstDayOfMonth.format(formatter);
String lastDay = lastDayOfMonth.format(formatter);
Map<String,Object> params = new HashMap<>();
params.put("fromdate",firstDay);
params.put("todate",lastDay);
//todo 执行前先删除历史数据 主表 明细表
// 获取当前月份的格式化字符串
DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM");
String currentMonth = today.format(formatter1);
project.deleteHData(currentMonth,"");
project.signData(params);
}
}
Loading…
Cancel
Save