Browse Source

profitStatus

wfg 3 months ago
parent
commit
d3fd0a71d6

+ 2 - 1
blade-service/blade-los/src/main/java/org/springblade/los/business/sea/service/IDataProcessingService.java

@@ -4,6 +4,7 @@ import org.springblade.los.check.entity.LosAuditPathsLevels;
 import org.springblade.los.finance.fee.entity.FeeCenter;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author :jixinyuan
@@ -13,5 +14,5 @@ public interface IDataProcessingService {
 
 	 List<LosAuditPathsLevels> toExamine(List<LosAuditPathsLevels> auditPathsLevels, String deptId);
 
-	String profitStatus(Long id, String businessType, List<FeeCenter> feeCenterList);
+	Map<String,Object> profitStatus(Long id, String businessType, List<FeeCenter> feeCenterList);
 }

+ 333 - 1
blade-service/blade-los/src/main/java/org/springblade/los/business/sea/service/impl/DataProcessingImplService.java

@@ -5,6 +5,9 @@ import lombok.AllArgsConstructor;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.los.Util.IDeptUtils;
+import org.springblade.los.Util.MagicValues;
+import org.springblade.los.basic.corps.entity.BCorps;
+import org.springblade.los.basic.corps.service.IBCorpsService;
 import org.springblade.los.business.sea.service.IDataProcessingService;
 import org.springblade.los.check.entity.LosAuditPathsLevels;
 import org.springblade.los.finance.fee.entity.FeeCenter;
@@ -12,7 +15,12 @@ import org.springblade.system.user.entity.User;
 import org.springblade.system.user.feign.IUserClient;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.math.RoundingMode;
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -28,6 +36,8 @@ public class DataProcessingImplService implements IDataProcessingService {
 
 	private final IDeptUtils deptUtils;
 
+	private final IBCorpsService bCorpsService;
+
 
 	@Override
 	public List<LosAuditPathsLevels> toExamine(List<LosAuditPathsLevels> auditPathsLevels, String deptId) {
@@ -78,7 +88,329 @@ public class DataProcessingImplService implements IDataProcessingService {
 	}
 
 	@Override
-	public String profitStatus(Long id, String businessType, List<FeeCenter> feeCenterList) {
+	public Map<String,Object> profitStatus(Long id, String businessType, List<FeeCenter> feeCenterList) {
+		if(ObjectUtils.isNull(id) || id<=0){
+			throw new RuntimeException("PS: 缺少业务 id!");
+		}
+		if(ObjectUtils.isNull(businessType) || businessType.isEmpty()){
+			throw new RuntimeException("PS: 缺少业务类型!");
+		}
+
+		List<FeeCenter> fcList = ObjectUtils.isNotNull(feeCenterList) ? feeCenterList : new ArrayList<>();
+		if(fcList.isEmpty()){
+
+		}
+
+		if("SE,SI".contains(businessType)){
+			return profitStatus_HY(id, businessType, fcList);
+		}else if("SEA".equals(businessType) || "SEI".equals(businessType)){
+			return profitStatus_HY(id, businessType, fcList);
+		}
+
+/*
+		// 费用名称
+		// 1722822288795000833	O/F		海运费	145
+		// 1722823384343011329	P/S		P/S		220
+		// 1746015648988901393	HP/S	HP/S	623
+		// 特殊 PS 客户名称
+		// 1425		W0077	W0077
+		// 1561		W0091	W0091
+		// 3415		W0256	W0256
+		// 5110		W0312	W0312
+		// 6363		W0380	W0380
+		// 10120	W0582	W0582
+		// 11794	W0643	W0643
+		// 12247	W0661	W0661
+		// 12431	W0675	W0675
+		// 12731	W0689	W0689
+		String specPScorpIds = ",1425,1561,3415,5110,6363,10120,11794,12247,12431,12731,";
+
+		BigDecimal usdOFProfit = new BigDecimal(BigInteger.ZERO);
+		BigDecimal ofInAmtProfit = new BigDecimal(BigInteger.ZERO);
+		Integer ofCNYCount = 0;
+
+		BigDecimal HPSProfit = new BigDecimal(BigInteger.ZERO);
+		BigDecimal specProfit = new BigDecimal(BigInteger.ZERO);
+		BigDecimal specInAmtProfit = new BigDecimal(BigInteger.ZERO);
+
+		BigDecimal psProfit = new BigDecimal(BigInteger.ZERO);
+		BigDecimal psInAmtProfit = new BigDecimal(BigInteger.ZERO);
+
+		// 特殊ps客户 Id
+		Long specPSCorpId = 0L;
+		// 高收退费客户 Id
+		Long hpsCorpId = 0L;
+
+		for (FeeCenter fee : fcList) {
+			if (specPSCorpId == 0 && ObjectUtils.isNotNull(fee.getCorpId())) {
+				if (specPScorpIds.indexOf("," + fee.getCorpId().toString() + ",") >= 0) {
+					specPSCorpId = fee.getCorpId();
+				}
+			}
+			BigDecimal amt = fee.getAmount();
+			if (MagicValues.C.equals(fee.getDc())) {
+				amt = amt.multiply(new BigDecimal(-1));
+			}
+			if (MagicValues.USD.equals(fee.getCurCode())) {
+				if ("O/F".equals(fee.getFeeCode())) {
+					// 145
+					usdOFProfit = usdOFProfit.add(amt);
+				}
+				if ("P/S".equals(fee.getFeeCode())) {
+					// 220
+					psProfit = psProfit.subtract(amt);
+				}
+				if ("HP/S".equals(fee.getFeeCode())) {
+					if (hpsCorpId == 0 && ObjectUtils.isNotNull(fee.getCorpId())) {
+						hpsCorpId = fee.getCorpId();
+					}
+					// 623
+					HPSProfit = HPSProfit.add(amt);
+					specProfit = specProfit.subtract(amt);
+				}
+			} else {
+				if ("O/F".equals(fee.getFeeCode())) {
+					// 145
+					ofInAmtProfit = ofInAmtProfit.add(amt.divide(new BigDecimal("6.8"), 2, BigDecimal.ROUND_HALF_UP));
+					ofCNYCount += 1;
+				}
+				if ("P/S".equals(fee.getFeeCode())) {
+					// 220
+					psInAmtProfit = psInAmtProfit.add(amt);
+				}
+				if ("HP/S".equals(fee.getFeeCode())) {
+					if (hpsCorpId == 0 && ObjectUtils.isNotNull(fee.getCorpId())) {
+						hpsCorpId = fee.getCorpId();
+					}
+					// 623
+					specInAmtProfit = specInAmtProfit.subtract(amt);
+				}
+			}
+		}
+
+		// 提取客户 PsRate
+		BCorps bCorps11 = bCorpsService.getById(item.getCorpId());
+		BigDecimal PsRate = new BigDecimal(BigInteger.ZERO);
+		Integer corpIsDC = 0;
+		if (ObjectUtils.isNotNull(bCorps11)) {
+			if("外部报价".equals(item.getQuotationMethod())){
+				PsRate = new BigDecimal(bCorps11.getPsRateExternal());
+			}else {
+				PsRate = new BigDecimal(bCorps11.getPsRate());
+			}
+			if (ObjectUtils.isNotNull(bCorps11.getCorpTypeName()) && bCorps11.getCorpTypeName().contains("国内直接客户")) {
+				corpIsDC = 1;
+			}
+		}
+		BigDecimal specPsRate = new BigDecimal(BigInteger.ZERO);
+		Boolean isPS = false;
+
+		if (specPSCorpId > 0) {
+			BCorps bCorps12 = bCorpsService.getById(specPSCorpId);
+			if (ObjectUtils.isNotNull(bCorps12)) {
+				specPsRate = new BigDecimal(bCorps12.getPsRate());
+			}
+		}
+
+		if (hpsCorpId > 0) {
+			BCorps bCorps13 = bCorpsService.getById(hpsCorpId);
+			if (ObjectUtils.isNotNull(bCorps13)) {
+				Long ownerCorpId = ObjectUtils.isNotNull(bCorps13.getCorpId()) ? bCorps13.getCorpId() : 0L;
+				if (ownerCorpId.equals(item.getCorpId()) || ownerCorpId.equals(item.getCarrierId()) || hpsCorpId.equals(item.getCorpId())) {
+					isPS = ObjectUtils.isNotNull(bCorps13.getIsPs()) && bCorps13.getIsPs() == 1;
+				}
+			}
+		}
+
+		String ps_text = ofCNYCount > 0 ? "(应收/应付)存在RMB海运费" : "";
+		String ps_remarks = "";
+		String ps_ps = "";
+		String ps_spec = "";
+
+		usdOFProfit = usdOFProfit.setScale(2, RoundingMode.HALF_UP);
+		ofInAmtProfit = ofInAmtProfit.setScale(2, RoundingMode.HALF_UP);
+		psInAmtProfit = psInAmtProfit.setScale(2, RoundingMode.HALF_UP);
+		psProfit = psProfit.setScale(2, RoundingMode.HALF_UP);
+		HPSProfit = HPSProfit.setScale(2, RoundingMode.HALF_UP);
+		PsRate = PsRate.setScale(2, RoundingMode.HALF_UP);
+		specPsRate = specPsRate.setScale(2, RoundingMode.HALF_UP);
+		specProfit = specProfit.setScale(2, RoundingMode.HALF_UP);
+		specInAmtProfit = specInAmtProfit.setScale(2, RoundingMode.HALF_UP);
+		if (psInAmtProfit.compareTo(BigDecimal.ZERO) != 0) {
+			ps_remarks += " PS不能出现 RMB 费用\r\n";
+		}
+
+		if ("CC".equals(item.getMpaymode()) && psProfit.compareTo(BigDecimal.ZERO) != 0) {
+			ps_remarks += " 主单付费方式为CC 不能出现PS\r\n";
+		}
+
+		if (("PP".equals(item.getMpaymode()) && (MagicValues.DD.equals(item.getBillType()) || MagicValues.MM.equals(item.getBillType())))
+			|| ("CC".equals(item.getMpaymode()) && ObjectUtils.isNotNull(item.getHblno()))) {
+			if (specPScorpIds.contains("," + specPSCorpId.toString() + ",")) {
+				if (usdOFProfit.compareTo(BigDecimal.ZERO) != 0) {
+					BigDecimal tt1 = usdOFProfit.add(ofInAmtProfit).add(HPSProfit).setScale(2, BigDecimal.ROUND_HALF_UP);
+					if (tt1.compareTo(BigDecimal.ZERO) != 0) {
+						BigDecimal pt1 = psProfit.divide(tt1, 2, BigDecimal.ROUND_HALF_UP);
+						if (pt1.compareTo(specPsRate) > 0) {
+							BigDecimal psr1 = new BigDecimal(1).subtract(pt1).setScale(2, BigDecimal.ROUND_HALF_UP);
+							ps_remarks += " PS比例高,公司比例: " + psr1.toString() + " 系统比例为:" + specPsRate.toString() + "\r\n";
+							BigDecimal psr2 = new BigDecimal(1).subtract(specPsRate).setScale(2, BigDecimal.ROUND_HALF_UP);
+							ps_ps += "公司分成比例:" + psr1.toString() + " (" + psr2.toString() + ")\r\n";
+						}
+					}
+				}
+			} else {
+				if (usdOFProfit.compareTo(BigDecimal.ZERO) != 0) {
+					BigDecimal tt1 = usdOFProfit.add(ofInAmtProfit).add(HPSProfit).setScale(2, BigDecimal.ROUND_HALF_UP);
+					if (tt1.compareTo(BigDecimal.ZERO) != 0) {
+						BigDecimal pt1 = psProfit.divide(tt1, 4, BigDecimal.ROUND_HALF_UP);
+						if (pt1.compareTo(PsRate) > 0) {
+							BigDecimal psr1 = new BigDecimal(1).subtract(pt1).setScale(2, BigDecimal.ROUND_HALF_UP);
+							ps_remarks += " PS比例高,公司比例: " + psr1.toString() + " 系统比例为:" + specPsRate.toString() + "\r\n";
+							BigDecimal psr2 = new BigDecimal(1).subtract(PsRate).setScale(2, BigDecimal.ROUND_HALF_UP);
+							ps_ps += "公司分成比例:" + psr1.toString() + " (" + psr2.toString() + ")\r\n";
+						}
+					}
+				}
+			}
+		} else {
+			if (psProfit.compareTo(BigDecimal.ZERO) != 0) {
+				ps_remarks += "只有预付、直单和主单,或分单和到付才可以输入PS\r\n";
+			}
+		}
+
+		BigDecimal tt2 = specProfit.add(specInAmtProfit).setScale(2, BigDecimal.ROUND_HALF_UP);
+		if (tt2.compareTo(BigDecimal.ZERO) == 1) {
+			if (isPS == true) {
+				ps_spec += "存在高收退费\r\n";
+			} else {
+				ps_remarks += "不应该存在高收退费\r\n";
+				ps_spec += "不应该存在高收退费\r\n";
+			}
+		}
+
+		ps_remarks = ps_remarks.trim();
+		ps_ps = ps_ps.trim();
+		item.setProfitStatus("");
+		item.setProfitRemarks(ps_remarks.trim());
+		item.setProfitSpec(ps_ps.trim() + "\r\n" + ps_spec.trim());
+		item.setText(ps_text);
+		item.setCorpIsDC(corpIsDC);
+		item.setIfDCCorp(corpIsDC == 1 ? "DC" : "");
+
+		//   FOverFeeLimit:=Trim(GetSysConst('SEA_ISSUEBILL_OVERFEE_LIMIT', '100000'));
+		// 判断是否国内直客
+
+		BigDecimal sumUSDDr = new BigDecimal(BigInteger.ZERO);
+		BigDecimal sumCNYDr = new BigDecimal(BigInteger.ZERO);
+		BigDecimal sumLocDr = new BigDecimal(BigInteger.ZERO);
+
+		BigDecimal sumUSDCr = new BigDecimal(BigInteger.ZERO);
+		BigDecimal sumCNYCr = new BigDecimal(BigInteger.ZERO);
+		BigDecimal sumLocCr = new BigDecimal(BigInteger.ZERO);
+
+		BigDecimal sumOFPS = new BigDecimal(BigInteger.ZERO);
+		if (item.equals(bills)) {
+			// 当前单据,计算 ProfitStatus
+			for (FeeCenter fee : allFeeCenter) {
+				if (MagicValues.C.equals(fee.getDc()) && "P/S".equals(fee.getFeeCode())) {
+					// if("USD".equals(fee.getCurCode())){
+					sumOFPS = sumOFPS.add(fee.getAmountLoc()).setScale(2, BigDecimal.ROUND_HALF_UP);
+				}
+
+				if (MagicValues.D.equals(fee.getDc())) {
+					if ("USD".equals(fee.getCurCode())) {
+						sumUSDDr = sumUSDDr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
+					} else {
+						sumCNYDr = sumCNYDr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
+					}
+					sumLocDr = sumLocDr.add(fee.getAmountLoc()).setScale(2, BigDecimal.ROUND_HALF_UP);
+				}
+
+				if (MagicValues.C.equals(fee.getDc())) {
+					if ("USD".equals(fee.getCurCode())) {
+						sumUSDCr = sumUSDCr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
+					} else {
+						sumCNYCr = sumCNYCr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
+					}
+					sumLocCr = sumLocCr.add(fee.getAmountLoc()).setScale(2, BigDecimal.ROUND_HALF_UP);
+				}
+			}
+
+
+			BigDecimal sumProfitUSD = sumUSDDr.subtract(sumUSDCr).setScale(2, BigDecimal.ROUND_HALF_UP);
+			BigDecimal sumProfitCNY = sumCNYDr.subtract(sumCNYCr).setScale(2, BigDecimal.ROUND_HALF_UP);
+			BigDecimal sumProfitLoc = sumLocDr.subtract(sumLocCr).setScale(2, BigDecimal.ROUND_HALF_UP);
+
+			BigDecimal profitRate = new BigDecimal(BigInteger.ZERO);
+			if (sumLocDr.compareTo(BigDecimal.ZERO) == 1) {
+				profitRate = sumProfitLoc.divide(sumLocDr, 4, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP);
+			}
+
+			String profitStatus = "F";
+			if (!ps_ps.isEmpty()) {
+				profitStatus = "U";
+			}
+			if (sumProfitLoc.compareTo(BigDecimal.ZERO) == 0) {
+				profitStatus = "Z";
+			} else if (sumProfitLoc.compareTo(BigDecimal.ZERO) < 0) {
+				profitStatus = "M";
+			} else if (sumLocDr.compareTo(BigDecimal.ZERO) > 0) {
+				if (profitRate.compareTo(new BigDecimal("0.4")) >= 0) {
+					profitStatus = "H";
+				} else if (profitRate.compareTo(new BigDecimal("0.02")) < 0) {
+					profitStatus = "U".equals(profitStatus) ? "D" : "L";
+				}
+			}
+
+			item.setProfitStatus(profitStatus);
+			switch (profitStatus) {
+				case "Z":
+					item.setProfitStatusText("利润为零");
+					item.setProfitStatusEnText("Profit was zero!");
+					break;
+				case "D":
+					item.setProfitStatusText("利润不成比例且过低");
+					item.setProfitStatusEnText("Profit was unfair and low!");
+					break;
+				case "H":
+					item.setProfitStatusText("利润过高");
+					item.setProfitStatusEnText("Profit was high!");
+					break;
+				case "L":
+					item.setProfitStatusText("利润过低");
+					item.setProfitStatusEnText("Profit was low!");
+					break;
+				case "F":
+					item.setProfitStatusText("利润正常");
+					item.setProfitStatusEnText("");
+					break;
+				case "M":
+					item.setProfitStatusText("利润为负");
+					item.setProfitStatusEnText("Profit was minus!");
+					break;
+				case "U":
+					item.setProfitStatusText("不成比例");
+					item.setProfitStatusEnText("P/S was unfair!");
+					break;
+				default:
+					item.setProfitStatusText("");
+					item.setProfitStatusEnText("");
+			}
+		}
+//						'F':aAuditItem.RefNo2:='正常';
+//						'M':aAuditItem.RefNo2:='为负';
+//						'H':aAuditItem.RefNo2:='过高';
+//						'L':aAuditItem.RefNo2:='过低';
+//						'U':aAuditItem.RefNo2:='不成比例';
+//						'D':aAuditItem.RefNo2:='不成比例且过低';
+*/
 		return null;
 	}
+
+	public Map<String,Object> profitStatus_HY(Long id, String businessType, List<FeeCenter> feeCenterList) {
+
+		return null;
+	}
+
 }