|
|
@@ -6,6 +6,8 @@ import java.sql.SQLException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import org.apache.commons.codec.binary.StringUtils;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+
|
|
|
import com.kingdee.bos.BOSException;
|
|
|
import com.kingdee.bos.Context;
|
|
|
import com.kingdee.eas.util.app.DbUtil;
|
|
|
@@ -16,6 +18,7 @@ import com.kingdee.shr.compensation.app.formula.data.Tools;
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 函数二开
|
|
|
* @author coyle
|
|
|
@@ -23,8 +26,8 @@ import com.kingdee.shr.compensation.app.formula.data.Tools;
|
|
|
*/
|
|
|
public class CalFunctionServiceExt extends SalaryCalFunction {
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 水电费取数
|
|
|
* @param type
|
|
|
@@ -36,53 +39,55 @@ public class CalFunctionServiceExt extends SalaryCalFunction {
|
|
|
*/
|
|
|
public double getWaterOrElectPay(String type, Map paramMap, HashMap tempMap, CalSchemeInfo calScheme, String mainTableRowFilter) {
|
|
|
Context ctx = Tools.getInstance().getCtx();
|
|
|
- String key = "getWaterOrElectPay" + calScheme.getNumber() + calScheme.getPeriodYear() + calScheme.getPeriodMonth();
|
|
|
- Map<String, Double> dataMap = new HashMap<String, Double>();
|
|
|
+ String key = "getWaterOrElectPay" + calScheme.getNumber() + calScheme.getPeriodYear() + calScheme.getPeriodMonth()+type;
|
|
|
+ Map<String, Double> dataMap = new HashMap<String, Double>();
|
|
|
String personId = paramMap.get("T_HR_SCMPCALTABLE_FPERSONID") == null ? null : paramMap.get("T_HR_SCMPCALTABLE_FPERSONID").toString();
|
|
|
BigDecimal amt = BigDecimal.ZERO;
|
|
|
if (personId == null) return 0.0;
|
|
|
- if (null == tempMap || null == tempMap.get(key)) {
|
|
|
- String sqlStr = getPerformanceDataSql(personId, mainTableRowFilter, calScheme);
|
|
|
- try {
|
|
|
- IRowSet rowSet = DbUtil.executeQuery(ctx, sqlStr);
|
|
|
- while (rowSet.next()) {
|
|
|
- personId = rowSet.getString("cFPersonId");
|
|
|
- // 处理可能的null值,默认为BigDecimal.ZERO
|
|
|
- BigDecimal wamt = rowSet.getBigDecimal("wamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("wamt");
|
|
|
- BigDecimal spwamt = rowSet.getBigDecimal("spwamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("spwamt");
|
|
|
- BigDecimal eamt = rowSet.getBigDecimal("eamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("eamt");
|
|
|
- BigDecimal speamt = rowSet.getBigDecimal("speamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("speamt");
|
|
|
-
|
|
|
- if (StringUtils.equals("1", type)) {
|
|
|
- amt = wamt.add(spwamt);
|
|
|
- } else if (StringUtils.equals("2", type)) {
|
|
|
- amt = eamt.add(speamt);
|
|
|
- } else {
|
|
|
- amt = wamt.add(spwamt).add(eamt).add(speamt);
|
|
|
- }
|
|
|
-
|
|
|
- // 设置两位小数并四舍五入
|
|
|
- amt = amt.setScale(2, RoundingMode.HALF_UP);
|
|
|
- // 转换为double类型
|
|
|
- double amtDouble = amt.doubleValue();
|
|
|
- dataMap.put(personId + "_" + type, amtDouble);
|
|
|
- }
|
|
|
- } catch (BOSException | SQLException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ if (null == tempMap || ObjectUtils.isEmpty(tempMap.get(key))) {
|
|
|
+ String sqlStr = getPerformanceDataSql(personId, mainTableRowFilter, calScheme);
|
|
|
+ try {
|
|
|
+
|
|
|
+ IRowSet rowSet = DbUtil.executeQuery(ctx, sqlStr);
|
|
|
+ while (rowSet.next()) {
|
|
|
+ String sqlPerson = rowSet.getString("cFPersonId");
|
|
|
+ // 处理可能的null值,默认为BigDecimal.ZERO
|
|
|
+ BigDecimal wamt = rowSet.getBigDecimal("wamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("wamt");
|
|
|
+ BigDecimal spwamt = rowSet.getBigDecimal("spwamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("spwamt");
|
|
|
+ BigDecimal eamt = rowSet.getBigDecimal("eamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("eamt");
|
|
|
+ BigDecimal speamt = rowSet.getBigDecimal("speamt") == null ? BigDecimal.ZERO : rowSet.getBigDecimal("speamt");
|
|
|
+
|
|
|
+ if (StringUtils.equals("1", type)) {
|
|
|
+ amt = wamt.add(spwamt);
|
|
|
+ } else if (StringUtils.equals("2", type)) {
|
|
|
+ amt = eamt.add(speamt);
|
|
|
+ } else {
|
|
|
+ amt = wamt.add(spwamt).add(eamt).add(speamt);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置两位小数并四舍五入
|
|
|
+ amt = amt.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ // 转换为double类型
|
|
|
+ double amtDouble = amt.doubleValue();
|
|
|
+ dataMap.put(sqlPerson + "_" + type, amtDouble);
|
|
|
+ }
|
|
|
+ } catch (BOSException | SQLException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ tempMap.put(key, dataMap);
|
|
|
}
|
|
|
- tempMap.put(key, dataMap);
|
|
|
+
|
|
|
dataMap = ( Map<String, Double>) tempMap.get(key);
|
|
|
return dataMap.get(personId + "_" + type) == null ? 0.00 : dataMap.get(personId + "_" + type);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 取数sql
|
|
|
* @param personId
|
|
|
@@ -95,10 +100,10 @@ public class CalFunctionServiceExt extends SalaryCalFunction {
|
|
|
//and FID in (select * from VTZD0RDVX15O2LMJ0F0TWRZ7UYW8YKVSD8D))
|
|
|
StringBuffer sqlStr = new StringBuffer();
|
|
|
sqlStr.append("SELECT cFPersonId, ");
|
|
|
- sqlStr.append(" SUM(wamt) AS wamt, ");
|
|
|
- sqlStr.append(" SUM(eamt) AS eamt, ");
|
|
|
- sqlStr.append(" SUM(spwamt) AS spwamt, ");
|
|
|
- sqlStr.append(" SUM(speamt) AS speamt ");
|
|
|
+ sqlStr.append(" SUM(wamt) AS wamt, ");
|
|
|
+ sqlStr.append(" SUM(eamt) AS eamt, ");
|
|
|
+ sqlStr.append(" SUM(spwamt) AS spwamt, ");
|
|
|
+ sqlStr.append(" SUM(speamt) AS speamt ");
|
|
|
sqlStr.append("FROM ( ");
|
|
|
|
|
|
// 第一部分:普通表数据(CT_WOE_WaterElectricity)
|
|
|
@@ -110,13 +115,13 @@ public class CalFunctionServiceExt extends SalaryCalFunction {
|
|
|
sqlStr.append(" FROM CT_WOE_WaterElectricity defu ");
|
|
|
sqlStr.append(" WHERE ");
|
|
|
if (null == mainTableRowFilter) {
|
|
|
- sqlStr.append(" defu.cFPersonId = '").append(personId).append("' ");
|
|
|
+ sqlStr.append(" defu.cFPersonId = '").append(personId).append("' ");
|
|
|
} else {
|
|
|
- sqlStr.append(" defu.cFPersonId IN (SELECT FPersonId FROM t_hr_scmpcaltable ");
|
|
|
- sqlStr.append(" WHERE ").append(mainTableRowFilter).append(") ");
|
|
|
+ sqlStr.append(" defu.cFPersonId IN (SELECT FPersonId FROM t_hr_scmpcaltable ");
|
|
|
+ sqlStr.append(" WHERE ").append(mainTableRowFilter).append(") ");
|
|
|
}
|
|
|
- sqlStr.append(" AND defu.CFYearMonth = '").append(calScheme.getPeriodYear()).append("-").append(calScheme.getPeriodMonth()).append("' ");
|
|
|
- sqlStr.append(" AND defu.fbillstate = '3' ");
|
|
|
+ sqlStr.append(" AND defu.CFYearMonth = '").append(calScheme.getPeriodYear()).append("-").append(String.format("%02d", calScheme.getPeriodMonth())).append("' ");
|
|
|
+ sqlStr.append(" AND defu.fbillstate = '0' ");
|
|
|
|
|
|
sqlStr.append(" UNION ALL ");
|
|
|
|
|
|
@@ -129,13 +134,13 @@ public class CalFunctionServiceExt extends SalaryCalFunction {
|
|
|
sqlStr.append(" FROM CT_WOE_WaterElectricitySpecial special ");
|
|
|
sqlStr.append(" WHERE ");
|
|
|
if (null == mainTableRowFilter) {
|
|
|
- sqlStr.append(" special.CFPersonID = '").append(personId).append("' ");
|
|
|
+ sqlStr.append(" special.CFPersonID = '").append(personId).append("' ");
|
|
|
} else {
|
|
|
- sqlStr.append(" special.CFPersonID IN (SELECT FPersonId FROM t_hr_scmpcaltable ");
|
|
|
- sqlStr.append(" WHERE ").append(mainTableRowFilter).append(") ");
|
|
|
+ sqlStr.append(" special.CFPersonID IN (SELECT FPersonId FROM t_hr_scmpcaltable ");
|
|
|
+ sqlStr.append(" WHERE ").append(mainTableRowFilter).append(") ");
|
|
|
}
|
|
|
- sqlStr.append(" AND special.CFYearMonth = '").append(calScheme.getPeriodYear()).append("-").append(calScheme.getPeriodMonth()).append("' ");
|
|
|
- sqlStr.append(" AND special.fbillstate = '3' ");
|
|
|
+ sqlStr.append(" AND special.CFYearMonth = '").append(calScheme.getPeriodYear()).append("-").append(String.format("%02d", calScheme.getPeriodMonth())).append("' ");
|
|
|
+ sqlStr.append(" AND special.fbillstate = '0' ");
|
|
|
|
|
|
sqlStr.append(") combined_data "); // 子查询别名
|
|
|
sqlStr.append("GROUP BY cFPersonId "); // 按人员ID分组汇总
|