|
|
@@ -1015,29 +1015,136 @@ public class contractApproveController {
|
|
|
return ResponseObject.newOkResponse();
|
|
|
}
|
|
|
|
|
|
- @Mapping(value = "com.awspaas.user.apps.donenow_ctt.insertCommissionPeriods")
|
|
|
- public ResponseObject insertCommissionPeriods(UserContext uc,
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.updateCommissionPeriodEndDate")
|
|
|
+ public ResponseObject updateCommissionPeriodEndDate(UserContext uc, String id, String periodEndDate) {
|
|
|
+ // 1. 参数校验
|
|
|
+ if (StringUtils.isBlank(id)) {
|
|
|
+ return ResponseObject.newErrResponse("id 不能为空");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(periodEndDate)) {
|
|
|
+ return ResponseObject.newErrResponse("PERIOD_END_DATE 不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+
|
|
|
+ // 3. 构建更新 SQL
|
|
|
+ String updateSql = "UPDATE BO_EU_DNCTT_COMMISSION SET PERIOD_END_DATE = ? WHERE ID = ?";
|
|
|
+
|
|
|
+ // 4. 执行更新操作
|
|
|
+ int rows = DBSql.update(updateSql, new Object[]{periodEndDate, id});
|
|
|
+
|
|
|
+ // 5. 构造返回结果
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("id", id);
|
|
|
+ result.put("periodEndDate", periodEndDate);
|
|
|
+ result.put("updatedRows", rows);
|
|
|
+
|
|
|
+ ResponseObject responseObject = ResponseObject.newOkResponse();
|
|
|
+ responseObject.setData(result);
|
|
|
+
|
|
|
+ return responseObject;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseObject.newErrResponse("更新失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按月补贴:周期增量=1个月
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.insertMonthlyCommission")
|
|
|
+ public ResponseObject insertMonthlyCommission(UserContext uc,
|
|
|
String bindid,
|
|
|
String startDate,
|
|
|
String endDate,
|
|
|
String amount) {
|
|
|
+ return insertCommissionByPeriod(uc, bindid, startDate, endDate, amount, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按季度补贴:周期增量=3个月
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.insertQuarterlyCommission")
|
|
|
+ public ResponseObject insertQuarterlyCommission(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount) {
|
|
|
+ return insertCommissionByPeriod(uc, bindid, startDate, endDate, amount, 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按年补贴:周期增量=12个月
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.insertYearlyCommission")
|
|
|
+ public ResponseObject insertYearlyCommission(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount) {
|
|
|
+ return insertCommissionByPeriod(uc, bindid, startDate, endDate, amount, 12);
|
|
|
+ }
|
|
|
|
|
|
+ // 一次性补贴:只生成一个周期(开始日期到结束日期)
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.insertOneTimeCommission")
|
|
|
+ public ResponseObject insertOneTimeCommission(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount) {
|
|
|
// 1. 参数校验
|
|
|
- if (StringUtils.isBlank(bindid)) {
|
|
|
- return ResponseObject.newErrResponse("bindid不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(startDate)) {
|
|
|
- return ResponseObject.newErrResponse("开始日期不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(endDate)) {
|
|
|
- return ResponseObject.newErrResponse("结束日期不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(amount)) {
|
|
|
- return ResponseObject.newErrResponse("金额不能为空");
|
|
|
+ if (StringUtils.isBlank(bindid)) return ResponseObject.newErrResponse("bindid不能为空");
|
|
|
+ if (StringUtils.isBlank(startDate)) return ResponseObject.newErrResponse("开始日期不能为空");
|
|
|
+ if (StringUtils.isBlank(endDate)) return ResponseObject.newErrResponse("结束日期不能为空");
|
|
|
+ if (StringUtils.isBlank(amount)) return ResponseObject.newErrResponse("金额不能为空");
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ // 校验开始日期是否早于结束日期
|
|
|
+ Date start = sdf.parse(startDate);
|
|
|
+ Date end = sdf.parse(endDate);
|
|
|
+ if (start.after(end)) {
|
|
|
+ return ResponseObject.newErrResponse("开始日期不能晚于结束日期");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 插入SQL(仅插入一条记录)
|
|
|
+ String insertSql = "INSERT INTO BO_EU_DNCTT_COMMISSION_PERIOD " +
|
|
|
+ "(ID, ORGID, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, " +
|
|
|
+ "COMMISSION_DOLLARS, PERIOD_ADJUSTED_PRICE) " +
|
|
|
+ "VALUES (UUID(), ?, ?, ?, ?, ?, ?)";
|
|
|
+
|
|
|
+ // 3. 执行插入(仅一次,不循环)
|
|
|
+ int rows = DBSql.update(insertSql, new Object[]{
|
|
|
+ uc.getCompanyModel().getId(),
|
|
|
+ bindid,
|
|
|
+ startDate, // 直接用用户输入的开始日期
|
|
|
+ endDate, // 直接用用户输入的结束日期
|
|
|
+ amount,
|
|
|
+ amount
|
|
|
+ });
|
|
|
+
|
|
|
+ // 4. 返回结果
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("bindid", bindid);
|
|
|
+ result.put("rows", rows); // 应为1(成功插入1条)
|
|
|
+ ResponseObject responseObject = ResponseObject.newOkResponse();
|
|
|
+ responseObject.setData(result);
|
|
|
+
|
|
|
+ return responseObject;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseObject.newErrResponse("插入失败:" + e.getMessage());
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ // 通用方法:按周期增量(1/3/12个月)生成多个周期
|
|
|
+ private ResponseObject insertCommissionByPeriod(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount,
|
|
|
+ int periodIncrement) {
|
|
|
+ // 参数校验(同上,略)
|
|
|
+ if (StringUtils.isBlank(bindid)) return ResponseObject.newErrResponse("bindid不能为空");
|
|
|
+ // ... 其他校验
|
|
|
|
|
|
try {
|
|
|
- // 2. 日期处理
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(sdf.parse(startDate));
|
|
|
@@ -1046,28 +1153,26 @@ public class contractApproveController {
|
|
|
Calendar endCal = Calendar.getInstance();
|
|
|
endCal.setTime(sdf.parse(endDate));
|
|
|
|
|
|
- // 3. 插入 SQL
|
|
|
String insertSql = "INSERT INTO BO_EU_DNCTT_COMMISSION_PERIOD " +
|
|
|
- "(ID,ORGID, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, COMMISSION_DOLLARS,PERIOD_ADJUSTED_PRICE) " +
|
|
|
- "VALUES (UUID(),?, ?, ?, ?, ?,?)";
|
|
|
+ "(ID, ORGID, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, " +
|
|
|
+ "COMMISSION_DOLLARS, PERIOD_ADJUSTED_PRICE) " +
|
|
|
+ "VALUES (UUID(), ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
|
int rows = 0;
|
|
|
-
|
|
|
Calendar currentCal = Calendar.getInstance();
|
|
|
currentCal.setTime(sdf.parse(startDate));
|
|
|
|
|
|
- // 4. 循环生成 12 个周期
|
|
|
- for (int i = 0; i < 12; i++) {
|
|
|
+ // 循环生成周期(按传入的增量:1/3/12个月)
|
|
|
+ while (true) {
|
|
|
Date periodStart = currentCal.getTime();
|
|
|
+ if (periodStart.after(endCal.getTime())) break;
|
|
|
|
|
|
- currentCal.add(Calendar.MONTH, 1);
|
|
|
+ currentCal.add(Calendar.MONTH, periodIncrement);
|
|
|
currentCal.set(Calendar.DATE, settleDay);
|
|
|
currentCal.add(Calendar.DATE, -1);
|
|
|
Date periodEnd = currentCal.getTime();
|
|
|
|
|
|
- if (periodEnd.after(endCal.getTime())) {
|
|
|
- periodEnd = endCal.getTime();
|
|
|
- }
|
|
|
+ if (periodEnd.after(endCal.getTime())) periodEnd = endCal.getTime();
|
|
|
|
|
|
rows += DBSql.update(insertSql, new Object[]{
|
|
|
uc.getCompanyModel().getId(),
|
|
|
@@ -1080,20 +1185,10 @@ public class contractApproveController {
|
|
|
|
|
|
currentCal.add(Calendar.DATE, 1);
|
|
|
currentCal.set(Calendar.DATE, settleDay);
|
|
|
-
|
|
|
- if (periodStart.after(endCal.getTime())) {
|
|
|
- break;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
- // 5. 构造返回结果
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("bindid", bindid);
|
|
|
- result.put("startDate", startDate);
|
|
|
- result.put("endDate", endDate);
|
|
|
- result.put("amount", amount);
|
|
|
result.put("rows", rows);
|
|
|
-
|
|
|
ResponseObject responseObject = ResponseObject.newOkResponse();
|
|
|
responseObject.setData(result);
|
|
|
|
|
|
@@ -1105,150 +1200,213 @@ public class contractApproveController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Mapping(value = "com.awspaas.user.apps.donenow_ctt.batchInsertAgentPeriods")
|
|
|
- public ResponseObject batchInsertAgentPeriods(UserContext uc,
|
|
|
- String bindid,
|
|
|
- String startDate,
|
|
|
- String endDate,
|
|
|
- String amount) {
|
|
|
+ // 通用查询代理列表(不变)
|
|
|
+ private List<Map<String, Object>> queryAgentList(String bindid) {
|
|
|
+ List<Map<String, Object>> agentList = new ArrayList<>();
|
|
|
+ int offset = 0;
|
|
|
+ while (true) {
|
|
|
+ String querySql = "SELECT AGENT, RATIO FROM BO_EU_DNCTT_COMMISSION_AGENT WHERE bindid = ? LIMIT 1 OFFSET ?";
|
|
|
+ RowMap agentMap = DBSql.getMap(querySql, new Object[]{bindid, offset});
|
|
|
+ if (agentMap == null) break;
|
|
|
+
|
|
|
+ String agent = agentMap.getString("AGENT");
|
|
|
+ BigDecimal ratio = parseRatio(agentMap.get("RATIO"));
|
|
|
+ if (ratio == null) {
|
|
|
+ throw new RuntimeException("代理 " + agent + " 的比例为空");
|
|
|
+ }
|
|
|
|
|
|
- // 1. 参数校验
|
|
|
- if (StringUtils.isBlank(bindid)) {
|
|
|
- return ResponseObject.newErrResponse("bindid不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(startDate)) {
|
|
|
- return ResponseObject.newErrResponse("开始日期不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(endDate)) {
|
|
|
- return ResponseObject.newErrResponse("结束日期不能为空");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(amount)) {
|
|
|
- return ResponseObject.newErrResponse("基础金额不能为空");
|
|
|
+ Map<String, Object> agentInfo = new HashMap<>();
|
|
|
+ agentInfo.put("AGENT", agent);
|
|
|
+ agentInfo.put("RATIO", ratio);
|
|
|
+ agentList.add(agentInfo);
|
|
|
+ offset++;
|
|
|
}
|
|
|
+ return agentList;
|
|
|
+ }
|
|
|
|
|
|
+ // 通用比例解析(不变)
|
|
|
+ private BigDecimal parseRatio(Object ratioObj) {
|
|
|
+ if (ratioObj == null) return null;
|
|
|
try {
|
|
|
- // 2. 分页查询所有代理(同时查 AGENT 和 RATIO)
|
|
|
- List<Map<String, Object>> agentList = new ArrayList<>();
|
|
|
- int offset = 0;
|
|
|
- while (true) {
|
|
|
- String querySql = "SELECT AGENT, RATIO FROM BO_EU_DNCTT_COMMISSION_AGENT WHERE bindid = ? LIMIT 1 OFFSET ?";
|
|
|
- RowMap agentMap = DBSql.getMap(querySql, new Object[]{bindid, offset});
|
|
|
- if (agentMap == null) {
|
|
|
- break; // 没有更多数据
|
|
|
- }
|
|
|
-
|
|
|
- String agent = agentMap.getString("AGENT");
|
|
|
- BigDecimal ratio = null;
|
|
|
-
|
|
|
- Object ratioObj = agentMap.get("RATIO");
|
|
|
- if (ratioObj != null) {
|
|
|
- if (ratioObj instanceof BigDecimal) {
|
|
|
- ratio = (BigDecimal) ratioObj;
|
|
|
- } else if (ratioObj instanceof Double) {
|
|
|
- ratio = BigDecimal.valueOf((Double) ratioObj);
|
|
|
- } else if (ratioObj instanceof Float) {
|
|
|
- ratio = BigDecimal.valueOf(((Float) ratioObj).doubleValue());
|
|
|
- } else if (ratioObj instanceof Integer) {
|
|
|
- ratio = BigDecimal.valueOf(((Integer) ratioObj).longValue());
|
|
|
- } else {
|
|
|
- try {
|
|
|
- ratio = new BigDecimal(ratioObj.toString());
|
|
|
- } catch (Exception e) {
|
|
|
- return ResponseObject.newErrResponse("代理 " + agent + " 的比例格式错误:" + ratioObj);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (ratio == null) {
|
|
|
- return ResponseObject.newErrResponse("代理 " + agent + " 的比例为空");
|
|
|
- }
|
|
|
-
|
|
|
- Map<String, Object> agentInfo = new HashMap<>();
|
|
|
- agentInfo.put("AGENT", agent);
|
|
|
- agentInfo.put("RATIO", ratio);
|
|
|
- agentList.add(agentInfo);
|
|
|
+ if (ratioObj instanceof BigDecimal) return (BigDecimal) ratioObj;
|
|
|
+ if (ratioObj instanceof Double) return BigDecimal.valueOf((Double) ratioObj);
|
|
|
+ if (ratioObj instanceof Float) return BigDecimal.valueOf(((Float) ratioObj).doubleValue());
|
|
|
+ if (ratioObj instanceof Integer) return BigDecimal.valueOf(((Integer) ratioObj).longValue());
|
|
|
+ return new BigDecimal(ratioObj.toString());
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("比例格式错误:" + ratioObj, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- offset++;
|
|
|
+ // 通用周期生成方法(按月/季度/年复用,不变)
|
|
|
+ private ResponseObject batchInsertAgentByPeriod(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount,
|
|
|
+ int periodIncrement) {
|
|
|
+ try {
|
|
|
+ // 参数校验
|
|
|
+ if (StringUtils.isBlank(bindid) || StringUtils.isBlank(startDate) ||
|
|
|
+ StringUtils.isBlank(endDate) || StringUtils.isBlank(amount)) {
|
|
|
+ return ResponseObject.newErrResponse("bindid、日期、金额不能为空");
|
|
|
}
|
|
|
|
|
|
+ // 查询代理列表
|
|
|
+ List<Map<String, Object>> agentList = queryAgentList(bindid);
|
|
|
if (agentList.isEmpty()) {
|
|
|
return ResponseObject.newErrResponse("未找到二级代理数据");
|
|
|
}
|
|
|
|
|
|
- // 3. 日期处理
|
|
|
+ // 日期与金额处理
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(sdf.parse(startDate));
|
|
|
int settleDay = cal.get(Calendar.DATE);
|
|
|
-
|
|
|
Calendar endCal = Calendar.getInstance();
|
|
|
endCal.setTime(sdf.parse(endDate));
|
|
|
+ BigDecimal baseAmount = new BigDecimal(amount);
|
|
|
|
|
|
- // 4. 插入 SQL
|
|
|
+ // 插入SQL
|
|
|
String insertSql = "INSERT INTO BO_EU_DNCTT_COMMISSION_PERIOD_AGENT " +
|
|
|
- "(ID, AGENT,ORGID, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, COMMISSION_DOLLARS,PERIOD_ADJUSTED_PRICE) " +
|
|
|
- "VALUES (UUID(), ?,?, ?, ?, ?, ?,?)";
|
|
|
+ "(ID, AGENT, ORGID, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, " +
|
|
|
+ "COMMISSION_DOLLARS, PERIOD_ADJUSTED_PRICE) " +
|
|
|
+ "VALUES (UUID(), ?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
|
- int rows = 0;
|
|
|
- BigDecimal baseAmount = new BigDecimal(amount);
|
|
|
-
|
|
|
- // 5. 循环每个代理
|
|
|
+ int totalRows = 0;
|
|
|
for (Map<String, Object> agentInfo : agentList) {
|
|
|
String agent = (String) agentInfo.get("AGENT");
|
|
|
BigDecimal ratio = (BigDecimal) agentInfo.get("RATIO");
|
|
|
+ BigDecimal realCommission = baseAmount.multiply(ratio.divide(new BigDecimal("100")));
|
|
|
|
|
|
- // 百分比转小数(20 → 0.2)
|
|
|
- BigDecimal ratioDecimal = ratio.divide(new BigDecimal("100"));
|
|
|
-
|
|
|
- // 计算实际佣金
|
|
|
- BigDecimal realCommission = baseAmount.multiply(ratioDecimal);
|
|
|
-
|
|
|
+ // 按周期增量生成子周期
|
|
|
Calendar currentCal = Calendar.getInstance();
|
|
|
currentCal.setTime(sdf.parse(startDate));
|
|
|
-
|
|
|
- for (int i = 0; i < 12; i++) {
|
|
|
+ while (true) {
|
|
|
Date periodStart = currentCal.getTime();
|
|
|
+ if (periodStart.after(endCal.getTime())) break;
|
|
|
|
|
|
- currentCal.add(Calendar.MONTH, 1);
|
|
|
+ // 计算周期结束日
|
|
|
+ currentCal.add(Calendar.MONTH, periodIncrement);
|
|
|
currentCal.set(Calendar.DATE, settleDay);
|
|
|
currentCal.add(Calendar.DATE, -1);
|
|
|
Date periodEnd = currentCal.getTime();
|
|
|
+ if (periodEnd.after(endCal.getTime())) periodEnd = endCal.getTime();
|
|
|
|
|
|
- if (periodEnd.after(endCal.getTime())) {
|
|
|
- periodEnd = endCal.getTime();
|
|
|
- }
|
|
|
-
|
|
|
- rows += DBSql.update(insertSql, new Object[]{
|
|
|
- agent,
|
|
|
- uc.getCompanyModel().getId(),
|
|
|
- bindid,
|
|
|
- sdf.format(periodStart),
|
|
|
- sdf.format(periodEnd),
|
|
|
- realCommission.toPlainString(),
|
|
|
- realCommission.toPlainString()
|
|
|
+ // 插入记录
|
|
|
+ totalRows += DBSql.update(insertSql, new Object[]{
|
|
|
+ agent, uc.getCompanyModel().getId(), bindid,
|
|
|
+ sdf.format(periodStart), sdf.format(periodEnd),
|
|
|
+ realCommission.toPlainString(), realCommission.toPlainString()
|
|
|
});
|
|
|
|
|
|
+ // 准备下一个周期
|
|
|
currentCal.add(Calendar.DATE, 1);
|
|
|
currentCal.set(Calendar.DATE, settleDay);
|
|
|
-
|
|
|
- if (periodStart.after(endCal.getTime())) {
|
|
|
- break;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 6. 返回结果
|
|
|
+ // 返回结果
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("bindid", bindid);
|
|
|
- result.put("startDate", startDate);
|
|
|
- result.put("endDate", endDate);
|
|
|
- result.put("baseAmount", amount);
|
|
|
- result.put("rows", rows);
|
|
|
+ result.put("rows", totalRows);
|
|
|
result.put("agentCount", agentList.size());
|
|
|
-
|
|
|
ResponseObject responseObject = ResponseObject.newOkResponse();
|
|
|
responseObject.setData(result);
|
|
|
+ return responseObject;
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return ResponseObject.newErrResponse("插入失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 按月生成(周期增量=1个月)
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.batchInsertAgentMonthly")
|
|
|
+ public ResponseObject batchInsertAgentMonthly(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount) {
|
|
|
+ return batchInsertAgentByPeriod(uc, bindid, startDate, endDate, amount, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 按季度生成(周期增量=3个月)
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.batchInsertAgentQuarterly")
|
|
|
+ public ResponseObject batchInsertAgentQuarterly(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount) {
|
|
|
+ return batchInsertAgentByPeriod(uc, bindid, startDate, endDate, amount, 3);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 按年生成(新增,周期增量=12个月)
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.batchInsertAgentYearly")
|
|
|
+ public ResponseObject batchInsertAgentYearly(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount) {
|
|
|
+ return batchInsertAgentByPeriod(uc, bindid, startDate, endDate, amount, 12); // 12个月=1年
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 一次性生成(无周期拆分)
|
|
|
+ @Mapping(value = "com.awspaas.user.apps.donenow_ctt.batchInsertAgentOneTime")
|
|
|
+ public ResponseObject batchInsertAgentOneTime(UserContext uc,
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate,
|
|
|
+ String amount) {
|
|
|
+ try {
|
|
|
+ // 参数校验
|
|
|
+ if (StringUtils.isBlank(bindid) || StringUtils.isBlank(startDate) ||
|
|
|
+ StringUtils.isBlank(endDate) || StringUtils.isBlank(amount)) {
|
|
|
+ return ResponseObject.newErrResponse("bindid、日期、金额不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日期合法性校验
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date start = sdf.parse(startDate);
|
|
|
+ Date end = sdf.parse(endDate);
|
|
|
+ if (start.after(end)) {
|
|
|
+ return ResponseObject.newErrResponse("开始日期不能晚于结束日期");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询代理列表
|
|
|
+ List<Map<String, Object>> agentList = queryAgentList(bindid);
|
|
|
+ if (agentList.isEmpty()) {
|
|
|
+ return ResponseObject.newErrResponse("未找到二级代理数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 插入SQL
|
|
|
+ String insertSql = "INSERT INTO BO_EU_DNCTT_COMMISSION_PERIOD_AGENT " +
|
|
|
+ "(ID, AGENT, ORGID, BINDID, PERIOD_BEGIN_DATE, PERIOD_END_DATE, " +
|
|
|
+ "COMMISSION_DOLLARS, PERIOD_ADJUSTED_PRICE) " +
|
|
|
+ "VALUES (UUID(), ?, ?, ?, ?, ?, ?, ?)";
|
|
|
+
|
|
|
+ int totalRows = 0;
|
|
|
+ BigDecimal baseAmount = new BigDecimal(amount);
|
|
|
+ for (Map<String, Object> agentInfo : agentList) {
|
|
|
+ String agent = (String) agentInfo.get("AGENT");
|
|
|
+ BigDecimal ratio = (BigDecimal) agentInfo.get("RATIO");
|
|
|
+ BigDecimal realCommission = baseAmount.multiply(ratio.divide(new BigDecimal("100")));
|
|
|
|
|
|
+ // 直接插入“开始→结束”的1条记录
|
|
|
+ totalRows += DBSql.update(insertSql, new Object[]{
|
|
|
+ agent, uc.getCompanyModel().getId(), bindid,
|
|
|
+ startDate, endDate,
|
|
|
+ realCommission.toPlainString(), realCommission.toPlainString()
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 返回结果
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("bindid", bindid);
|
|
|
+ result.put("rows", totalRows);
|
|
|
+ result.put("agentCount", agentList.size());
|
|
|
+ ResponseObject responseObject = ResponseObject.newOkResponse();
|
|
|
+ responseObject.setData(result);
|
|
|
return responseObject;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
@@ -1259,15 +1417,19 @@ public class contractApproveController {
|
|
|
|
|
|
@Mapping(value = "com.awspaas.user.apps.donenow_ctt.checkCommissionPeriodExists")
|
|
|
public ResponseObject checkCommissionPeriodExists(UserContext uc,
|
|
|
- String bindid) {
|
|
|
+ String bindid,
|
|
|
+ String startDate,
|
|
|
+ String endDate) {
|
|
|
try {
|
|
|
String checkSql = "SELECT COUNT(1) FROM BO_EU_DNCTT_COMMISSION_PERIOD " +
|
|
|
- "WHERE BINDID = ?";
|
|
|
+ "WHERE BINDID = ? " +
|
|
|
+ "AND PERIOD_BEGIN_DATE <= ? " +
|
|
|
+ "AND PERIOD_END_DATE >= ?";
|
|
|
|
|
|
- int existCount = DBSql.getInt(checkSql, new Object[]{bindid});
|
|
|
+ int existCount = DBSql.getInt(checkSql, new Object[]{bindid, endDate, startDate});
|
|
|
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("exists", existCount > 0); // true 表示已存在
|
|
|
+ result.put("exists", existCount > 0);
|
|
|
|
|
|
ResponseObject responseObject = ResponseObject.newOkResponse();
|
|
|
responseObject.setData(result);
|
|
|
@@ -1303,48 +1465,31 @@ public class contractApproveController {
|
|
|
|
|
|
@Mapping(value = "com.awspaas.user.apps.donenow_ctt.updateAgentCommissionByIds")
|
|
|
public ResponseObject updateAgentCommissionByIds(UserContext uc,
|
|
|
- String ids, // 多个ID逗号分隔
|
|
|
- String agent, // 二级代理(必填)
|
|
|
- String ACCOUNT_PAY_DATE, // 实际付款时间(必填)
|
|
|
- BigDecimal payAmount,// 付款金额(必填)
|
|
|
- String payer, // 付款人(必填)
|
|
|
- String remark, // 备注(可选)
|
|
|
- String invoiceTypeId,// 发票类型(可选)
|
|
|
- String agentInvoiceNo,// 二代发票号(可选)
|
|
|
- String invoiceFile) // 发票附件(可选)
|
|
|
- {
|
|
|
+ String ids,
|
|
|
+ String commissionPayId,
|
|
|
+ String agent,
|
|
|
+ String ACCOUNT_PAY_DATE,
|
|
|
+ BigDecimal payAmount,
|
|
|
+ String payer,
|
|
|
+ String remark,
|
|
|
+ String invoiceTypeId,
|
|
|
+ String agentInvoiceNo,
|
|
|
+ String invoiceFile) {
|
|
|
try {
|
|
|
- // 必填字段校验
|
|
|
if (ids == null || ids.trim().isEmpty()) {
|
|
|
- ResponseObject err = ResponseObject.newErrResponse("ids不能为空");
|
|
|
- return err;
|
|
|
- }
|
|
|
- if (agent == null || agent.trim().isEmpty()) {
|
|
|
- ResponseObject err = ResponseObject.newErrResponse("二级代理不能为空");
|
|
|
- return err;
|
|
|
- }
|
|
|
- if (ACCOUNT_PAY_DATE == null || ACCOUNT_PAY_DATE.trim().isEmpty()) {
|
|
|
- ResponseObject err = ResponseObject.newErrResponse("实际付款时间不能为空");
|
|
|
- return err;
|
|
|
- }
|
|
|
- if (payAmount == null || payAmount.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
- ResponseObject err = ResponseObject.newErrResponse("付款金额无效");
|
|
|
- return err;
|
|
|
+ return ResponseObject.newErrResponse("ids不能为空");
|
|
|
}
|
|
|
- if (payer == null || payer.trim().isEmpty()) {
|
|
|
- ResponseObject err = ResponseObject.newErrResponse("付款人不能为空");
|
|
|
- return err;
|
|
|
+ if (commissionPayId == null || commissionPayId.trim().isEmpty()) {
|
|
|
+ return ResponseObject.newErrResponse("commissionPayId不能为空");
|
|
|
}
|
|
|
|
|
|
- // ID 转数组
|
|
|
String[] idArr = ids.split(",");
|
|
|
|
|
|
- // 动态拼接 SQL
|
|
|
StringBuilder updateSql = new StringBuilder("UPDATE VIEW_EU_DNV_COMMISSION_PERIOD_AGENT SET ");
|
|
|
List<Object> params = new ArrayList<>();
|
|
|
|
|
|
- // 必更新字段
|
|
|
- updateSql.append("AGENT = ?, ACCOUNT_PAY_DATE = ?, PAY_AMOUNT = ?, PAYER = ?, ");
|
|
|
+ updateSql.append("COMMISSION_PAY_ID = ?, AGENT = ?, ACCOUNT_PAY_DATE = ?, PAY_AMOUNT = ?, PAYER = ?, ");
|
|
|
+ params.add(commissionPayId.trim());
|
|
|
params.add(agent);
|
|
|
params.add(ACCOUNT_PAY_DATE);
|
|
|
params.add(payAmount);
|
|
|
@@ -1368,12 +1513,10 @@ public class contractApproveController {
|
|
|
params.add(invoiceFile);
|
|
|
}
|
|
|
|
|
|
- // 去掉最后一个逗号和空格
|
|
|
if (updateSql.charAt(updateSql.length() - 2) == ',') {
|
|
|
updateSql.setLength(updateSql.length() - 2);
|
|
|
}
|
|
|
|
|
|
- // WHERE IN
|
|
|
StringBuilder placeholders = new StringBuilder();
|
|
|
for (int i = 0; i < idArr.length; i++) {
|
|
|
if (i > 0) placeholders.append(",");
|
|
|
@@ -1381,15 +1524,12 @@ public class contractApproveController {
|
|
|
}
|
|
|
updateSql.append(" WHERE ID IN (").append(placeholders.toString()).append(")");
|
|
|
|
|
|
- // 补充ID参数
|
|
|
for (String id : idArr) {
|
|
|
params.add(id.trim());
|
|
|
}
|
|
|
|
|
|
- // 执行更新
|
|
|
int updateCount = DBSql.update(updateSql.toString(), params.toArray());
|
|
|
|
|
|
- // 构造返回结果
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("updateCount", updateCount);
|
|
|
|
|
|
@@ -1399,9 +1539,9 @@ public class contractApproveController {
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- ResponseObject err = ResponseObject.newErrResponse("更新失败:" + e.getMessage());
|
|
|
- return err;
|
|
|
+ return ResponseObject.newErrResponse("更新失败:" + e.getMessage());
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 佣金审批
|
|
|
@@ -1528,4 +1668,7 @@ public class contractApproveController {
|
|
|
}
|
|
|
return ResponseObject.newOkResponse();
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|