appId支持多个
Showing
1 changed file
with
23 additions
and
14 deletions
... | @@ -10,9 +10,11 @@ import org.springframework.stereotype.Component; | ... | @@ -10,9 +10,11 @@ import org.springframework.stereotype.Component; |
10 | import org.springframework.transaction.annotation.Transactional; | 10 | import org.springframework.transaction.annotation.Transactional; |
11 | 11 | ||
12 | import java.sql.Connection; | 12 | import java.sql.Connection; |
13 | import java.util.Arrays; | ||
13 | import java.util.HashMap; | 14 | import java.util.HashMap; |
14 | import java.util.List; | 15 | import java.util.List; |
15 | import java.util.Map; | 16 | import java.util.Map; |
17 | import java.util.stream.Collectors; | ||
16 | 18 | ||
17 | @Component | 19 | @Component |
18 | @Slf4j | 20 | @Slf4j |
... | @@ -21,28 +23,35 @@ public class AutoBindAppProcessor { | ... | @@ -21,28 +23,35 @@ public class AutoBindAppProcessor { |
21 | DbUtil dbUtil; | 23 | DbUtil dbUtil; |
22 | 24 | ||
23 | @Value("${entity.appId}") | 25 | @Value("${entity.appId}") |
24 | private Long APP_ID; | 26 | private String APP_ID; |
25 | 27 | ||
26 | public void execute() { | 28 | public void execute() { |
27 | Connection connection = null; | 29 | Connection connection = null; |
28 | try { | 30 | try { |
29 | connection = dbUtil.getConnection(); | 31 | connection = dbUtil.getConnection(); |
30 | // 查询未绑定 | 32 | List<Long> appIds = Arrays.stream(APP_ID.split(",")).map(Long::parseLong).collect(Collectors.toList()); |
31 | String sql = StrUtil.format(" select xm.id,xm.name from x_media xm LEFT JOIN x_media__app xma on xm.id = xma.media_id and xma.app_id = {} where xma.id is null limit 100 ", APP_ID); | 33 | for (Long appId : appIds) { |
32 | List<Map<String, Object>> list = dbUtil.queryList(connection, sql); | 34 | // 查询未绑定 |
35 | String sql = StrUtil.format(" select xm.id,xm.name from x_media xm LEFT JOIN x_media__app xma on xm.id = xma.media_id and xma.app_id = {} where xma.id is null limit 100 ", appId); | ||
36 | List<Map<String, Object>> list = dbUtil.queryList(connection, sql); | ||
33 | // 开启事务 | 37 | // 开启事务 |
34 | dbUtil.beginTransaction(connection); | 38 | dbUtil.beginTransaction(connection); |
35 | for (Map<String, Object> map : list) { | 39 | |
36 | var mediaId = (Long) map.get("id"); | 40 | |
37 | var mapData = new HashMap<String, Object>(); | 41 | for (Map<String, Object> map : list) { |
38 | mapData.put("media_id", mediaId); | 42 | var mediaId = (Long) map.get("id"); |
39 | mapData.put("app_id", APP_ID); | 43 | var mapData = new HashMap<String, Object>(); |
40 | String objectName = "x_media__app"; | 44 | mapData.put("media_id", mediaId); |
45 | mapData.put("app_id", appId); | ||
46 | String objectName = "x_media__app"; | ||
41 | // 添加关联关系 | 47 | // 添加关联关系 |
42 | dbUtil.save(connection, mapData, objectName); | 48 | dbUtil.save(connection, mapData, objectName); |
43 | } | 49 | } |
50 | |||
44 | // 提交事务 | 51 | // 提交事务 |
45 | dbUtil.commitTransaction(connection); | 52 | dbUtil.commitTransaction(connection); |
53 | } | ||
54 | |||
46 | 55 | ||
47 | } catch (Exception ex) { | 56 | } catch (Exception ex) { |
48 | ex.printStackTrace(); | 57 | ex.printStackTrace(); | ... | ... |
-
Please register or sign in to post a comment