张延森 4 years ago
parent
commit
3a1b6d3b81

+ 30
- 19
src/main/java/com/shigongli/controller/TaMetaImageTagController.java View File

@@ -87,7 +87,7 @@ public class TaMetaImageTagController extends BaseController {
87 87
         }
88 88
 
89 89
         // 先清除所有数据
90
-        iTaMetaImageTagService.removeAllBy(tagIds);
90
+//        iTaMetaImageTagService.removeAllBy(tagIds);
91 91
 
92 92
         // 再保存所有
93 93
         iTaMetaImageTagService.saveBatch(taMetaImageTags);
@@ -108,24 +108,35 @@ public class TaMetaImageTagController extends BaseController {
108 108
             return ResponseBean.error("删除失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
109 109
         }
110 110
     }
111
-//
112
-//    /**
113
-//     * 修改对象
114
-//     * @param id  实体ID
115
-//     * @param taMetaImageTag 实体对象
116
-//     * @return
117
-//     */
118
-//    @RequestMapping(value="/taMetaImageTag/{id}",method= RequestMethod.PUT)
119
-//    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
120
-//    public ResponseBean taMetaImageTagUpdate(@ApiParam("对象ID") @PathVariable Integer id,
121
-//                                        @ApiParam("更新内容") @RequestBody TaMetaImageTag taMetaImageTag) throws Exception{
122
-//
123
-//        if (iTaMetaImageTagService.updateById(taMetaImageTag)){
124
-//            return ResponseBean.success(iTaMetaImageTagService.getById(id));
125
-//        }else {
126
-//            return ResponseBean.error("修改失败, 请重试", ResponseBean.ERROR_UNAVAILABLE);
127
-//        }
128
-//    }
111
+
112
+    /**
113
+     * 修改对象
114
+     * @param id  实体ID
115
+     * @param taMetaImageTag 实体对象
116
+     * @return
117
+     */
118
+    @RequestMapping(value="/taMetaImageTag",method= RequestMethod.PUT)
119
+    @ApiOperation(value="更新", notes = "更新", httpMethod = "PUT", response = ResponseBean.class)
120
+    public ResponseBean taMetaImageTagUpdate(@ApiParam("更新内容") @RequestBody Map<String, Object> params) throws Exception{
121
+        String[] originTags = (String[]) params.get("originTags");
122
+        String[] newTags = (String[]) params.get("newTags");
123
+        String originImage = params.get("originImage").toString();
124
+        String newImage = params.get("newImage").toString();
125
+
126
+        // 先删除旧的映射关系
127
+        iTaMetaImageTagService.removeAllBy(originTags, originImage);
128
+        // 再组装新的
129
+        List<TaMetaImageTag> list = new ArrayList<>();
130
+        for (String tagId: newTags) {
131
+            TaMetaImageTag item = new TaMetaImageTag();
132
+            item.setTagId(tagId);
133
+            item.setImageId(newImage);
134
+            list.add(item);
135
+        }
136
+
137
+        iTaMetaImageTagService.saveBatch(list);
138
+        return ResponseBean.success("success");
139
+    }
129 140
 //
130 141
 //    /**
131 142
 //     * 根据id查询对象

+ 2
- 0
src/main/java/com/shigongli/mapper/TaMetaImageTagMapper.java View File

@@ -22,4 +22,6 @@ public interface TaMetaImageTagMapper extends BaseMapper<TaMetaImageTag> {
22 22
     int removeAllBy(@Param("tagIds") List<String> tagIds);
23 23
 
24 24
     IPage<TaMetaImageTag> pagedBy(IPage<TaMetaImageTag> pg, @Param("tagIds") String[] tagIds);
25
+
26
+    int removeAllByTagAndImage(@Param("tagIds") String[] originTags, @Param("imageId") String originImage);
25 27
 }

+ 2
- 0
src/main/java/com/shigongli/service/ITaMetaImageTagService.java View File

@@ -19,4 +19,6 @@ public interface ITaMetaImageTagService extends IService<TaMetaImageTag> {
19 19
     void removeAllBy(List<String> tagIds);
20 20
 
21 21
     IPage<TaMetaImageTag> pagedBy(IPage<TaMetaImageTag> pg, String tagIds);
22
+
23
+    void removeAllBy(String[] originTags, String originImage);
22 24
 }

+ 13
- 0
src/main/java/com/shigongli/service/impl/TaMetaImageTagServiceImpl.java View File

@@ -39,4 +39,17 @@ public class TaMetaImageTagServiceImpl extends ServiceImpl<TaMetaImageTagMapper,
39 39
         String[] tagIdList = StringUtils.isEmpty(tagIds) ? null : tagIds.split(",");
40 40
         return taMetaImageTagMapper.pagedBy(pg, tagIdList);
41 41
     }
42
+
43
+    @Override
44
+    public void removeAllBy(String[] originTags, String originImage) {
45
+        if (originTags == null || originTags.length < 1) {
46
+            return;
47
+        }
48
+
49
+        if (StringUtils.isEmpty(originImage)) {
50
+            return;
51
+        }
52
+
53
+        taMetaImageTagMapper.removeAllByTagAndImage(originTags, originImage);
54
+    }
42 55
 }

+ 9
- 0
src/main/resources/mapper/TaMetaImageTagMapper.xml View File

@@ -9,6 +9,15 @@
9 9
             #{id}
10 10
         </foreach>
11 11
     </delete>
12
+    <delete id="removeAllByTagAndImage">
13
+        delete from ta_meta_image_tag
14
+        where tag_id in
15
+        <foreach collection="tagIds" item="id" index="index" open="(" close=")" separator=",">
16
+            #{id}
17
+        </foreach>
18
+        And image_id = #{imageId}
19
+
20
+    </delete>
12 21
     <select id="pagedBy" resultType="com.shigongli.entity.TaMetaImageTag">
13 22
         SELECT
14 23
             t.`name` AS tag_name,