Commit 455a0a0c by 张富康

fix(service): 修复SQL查询参数设置及逻辑错误

- 修正staff_uuid参数传递,使用占位符批量设置参数,避免拼接风险
- 修改director_type参数处理逻辑,动态替换字符串后再准备语句并设置参数
- 修正判空逻辑,将merchantIds为空时返回空集合条件调整正确
- 优化员工手机号查询SQL,连接platform_merchant表过滤已删除记录
- 添加SQL日志打印,便于调试和追踪查询参数
1 parent 4c6aca53
...@@ -1437,12 +1437,17 @@ public class TalentAnalysisService { ...@@ -1437,12 +1437,17 @@ public class TalentAnalysisService {
String sellerUserIdsStr = StrUtil.join(",", sellerUserIds.stream() String sellerUserIdsStr = StrUtil.join(",", sellerUserIds.stream()
.map(key -> "'" + key + "'") // 为每个键添加单引号 .map(key -> "'" + key + "'") // 为每个键添加单引号
.collect(Collectors.toList())); .collect(Collectors.toList()));
String placeholders = String.join(",", Collections.nCopies(sellerUserIds.size(), "?"));
String staffPhoneSql = "select DISTINCT staff_phone\n" + String staffPhoneSql = "select DISTINCT staff_phone\n" +
"from scrm_account.platform_merchant_staff\n" + "from scrm_account.platform_merchant_staff\n" +
"where staff_uuid in (?)\n" + "where staff_uuid in (" + placeholders + ")\n" +
" and del_flag = 0 group by staff_uuid, staff_phone"; " and del_flag = 0 group by staff_uuid, staff_phone";
staffPhoneSt = connQuery02.prepareStatement(staffPhoneSql); staffPhoneSt = connQuery02.prepareStatement(staffPhoneSql);
staffPhoneSt.setString(1, sellerUserIdsStr); int parameterIndex = 0;
for (String item : sellerUserIds) {
parameterIndex = parameterIndex + 1;
staffPhoneSt.setString(parameterIndex, item);
}
// 打印sql日志 // 打印sql日志
log.info("staffPhoneSql:{}", staffPhoneSql); log.info("staffPhoneSql:{}", staffPhoneSql);
log.info("staff_uuid:{}", sellerUserIdsStr); log.info("staff_uuid:{}", sellerUserIdsStr);
...@@ -1603,7 +1608,7 @@ public class TalentAnalysisService { ...@@ -1603,7 +1608,7 @@ public class TalentAnalysisService {
" SELECT merchant_id " + " SELECT merchant_id " +
" FROM dj_car_life_shop_merchant_director_config " + " FROM dj_car_life_shop_merchant_director_config " +
" WHERE director_user_id = ? " + " WHERE director_user_id = ? " +
" AND director_type IN (?) " + " AND director_type IN (director_typexxxxxx) " +
" AND deleted_flag = 'N' " + " AND deleted_flag = 'N' " +
") " + ") " +
" AND sub_merchant_type IN (6, 8) " + " AND sub_merchant_type IN (6, 8) " +
...@@ -1611,11 +1616,9 @@ public class TalentAnalysisService { ...@@ -1611,11 +1616,9 @@ public class TalentAnalysisService {
"GROUP BY sub_merchant_id"; "GROUP BY sub_merchant_id";
// 创建预编译语句(不拼接任何用户输入) // 创建预编译语句(不拼接任何用户输入)
yqMerchantIdSt = connInsert.prepareStatement(yqMerchantIdSql);
// 安全设置参数(staffId会自动转义) // 安全设置参数(staffId会自动转义)
// 判断 (1:精品升级业务负责人,2:精品升级业务服务商负责人,3:会员权益业务负责人,4:会员权益业务服务商负责人,5:1.1线上运营(原盯防负责人), // 判断 (1:精品升级业务负责人,2:精品升级业务服务商负责人,3:会员权益业务负责人,4:会员权益业务服务商负责人,5:1.1线上运营(原盯防负责人),
// 6:飞行督导,7:2.1线上运营,8:1.1区域运营,9:2.1区域运营) // 6:飞行督导,7:2.1线上运营,8:1.1区域运营,9:2.1区域运营)
yqMerchantIdSt.setString(1, staffId); // 假设staffId是字符串类型
String directorType; String directorType;
if (ObjectUtil.equals(role, 3)) { if (ObjectUtil.equals(role, 3)) {
// 角色权限为3-区域运营 => 8:1.1区域运营,9:2.1区域运营 // 角色权限为3-区域运营 => 8:1.1区域运营,9:2.1区域运营
...@@ -1627,7 +1630,9 @@ public class TalentAnalysisService { ...@@ -1627,7 +1630,9 @@ public class TalentAnalysisService {
// 角色权限为6-线上运营 => 5:1.1线上运营(原盯防负责人),7:2.1线上运营 // 角色权限为6-线上运营 => 5:1.1线上运营(原盯防负责人),7:2.1线上运营
directorType = "5,7"; directorType = "5,7";
} }
yqMerchantIdSt.setString(2, directorType); yqMerchantIdSql = yqMerchantIdSql.replace("director_typexxxxxx", directorType);
yqMerchantIdSt = connInsert.prepareStatement(yqMerchantIdSql);
yqMerchantIdSt.setString(1, staffId); // 假设staffId是字符串类型
// 打印sql日志 // 打印sql日志
log.info("yqMerchantIdSql:{}", yqMerchantIdSql); log.info("yqMerchantIdSql:{}", yqMerchantIdSql);
log.info("director_user_id:{},director_type:{}", staffId, directorType); log.info("director_user_id:{},director_type:{}", staffId, directorType);
...@@ -1639,20 +1644,23 @@ public class TalentAnalysisService { ...@@ -1639,20 +1644,23 @@ public class TalentAnalysisService {
} }
log.info("merchantIds:{}", JSONUtil.toJsonStr(merchantIds)); log.info("merchantIds:{}", JSONUtil.toJsonStr(merchantIds));
// 如果staffIds为空,则返回空结果 // 如果staffIds为空,则返回空结果
if (ObjectUtil.isNotEmpty(merchantIds)) { if (ObjectUtil.isEmpty(merchantIds)) {
return Collections.emptyList(); return Collections.emptyList();
} }
String merchantIdsStr = StrUtil.join(",", merchantIds); String merchantIdsStr = StrUtil.join(",", merchantIds);
// 通过园区店ids查询账户中心 // 通过园区店ids查询账户中心
String staffPhoneSql = "select staff_uuid, staff_phone\n" + String staffPhoneSql = "select st.staff_uuid,\n" +
"from scrm_account.platform_merchant_staff\n" + " st.staff_phone\n" +
"where merchant_id in (?)\n" + "from platform_merchant_staff st\n" +
" and del_flag = 0 group by staff_uuid, staff_phone"; " left join platform_merchant pm on st.merchant_id = pm.id and pm.del_flag = 0\n" +
"where st.del_flag = 0\n" +
" and pm.merchantNo in (merchantIdxxxxxx)\n" +
"group by staff_uuid, staff_phone";
// 打印sql日志 // 打印sql日志
log.info("staffPhoneSql:{}", staffPhoneSql); log.info("staffPhoneSql:{}", staffPhoneSql);
log.info("merchant_id:{}", merchantIdsStr); log.info("merchant_id:{}", merchantIdsStr);
staffPhoneSql = staffPhoneSql.replace("merchantIdxxxxxx", merchantIdsStr);
staffPhoneSt = connQuery02.prepareStatement(staffPhoneSql); staffPhoneSt = connQuery02.prepareStatement(staffPhoneSql);
staffPhoneSt.setString(1, merchantIdsStr);
staffPhoneRs = staffPhoneSt.executeQuery(); staffPhoneRs = staffPhoneSt.executeQuery();
while (staffPhoneRs.next()) { while (staffPhoneRs.next()) {
// 保存员工信息进入map // 保存员工信息进入map
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!