yufeng před 3 roky
rodič
revize
1662a85ac6

+ 14 - 2
src/main/java/com/ylcm/sys/controller/AdMediaController.java

@@ -142,7 +142,12 @@ public class AdMediaController extends BaseController{
142 142
 		JSONObject result = new JSONObject();
143 143
         result.put("code", Constants.CODE_SUCCESS);
144 144
         result.put("msg", "服务器异常");
145
-        adMediaService.removeById(id);
145
+
146
+        String error = adMediaService.deleteById(id);
147
+        if (error != null) {
148
+			result.put("code", Constants.CODE_FAIL);
149
+			result.put("msg", error);
150
+		}
146 151
         
147 152
         returnResult(request, response, result);
148 153
     }
@@ -155,7 +160,14 @@ public class AdMediaController extends BaseController{
155 160
         result.put("msg", "服务器异常");
156 161
         String[] idArray = ids.split(",");
157 162
         for (String id : idArray) {
158
-            adMediaService.removeById(id);
163
+			String error = adMediaService.deleteById(Integer.parseInt(id));
164
+			if (error != null) {
165
+				result.put("code", Constants.CODE_FAIL);
166
+				result.put("msg", error);
167
+
168
+				returnResult(request, response, result);
169
+				return;
170
+			}
159 171
 		}
160 172
         
161 173
         returnResult(request, response, result);

+ 2 - 0
src/main/java/com/ylcm/sys/service/AdMediaService.java

@@ -21,4 +21,6 @@ public interface AdMediaService extends IService<AdMedia> {
21 21
 	String importBatch(List<AdMediaImportDTO> importDTOs);
22 22
 	
23 23
 	Integer getTotalByName(String name);
24
+
25
+	String deleteById(Integer id);
24 26
 }

+ 30 - 0
src/main/java/com/ylcm/sys/service/impl/AdMediaServiceImpl.java

@@ -1,9 +1,13 @@
1 1
 package com.ylcm.sys.service.impl;
2 2
 
3 3
 import com.ylcm.sys.domain.AdMedia;
4
+import com.ylcm.sys.domain.AdSpecial;
5
+import com.ylcm.sys.domain.AdTheatre;
4 6
 import com.ylcm.sys.excel.model.AdMediaImportDTO;
5 7
 import com.ylcm.sys.exception.BaseException;
6 8
 import com.ylcm.sys.mapper.AdMediaMapper;
9
+import com.ylcm.sys.mapper.AdSpecialMapper;
10
+import com.ylcm.sys.mapper.AdTheatreMapper;
7 11
 import com.ylcm.sys.service.AdMediaService;
8 12
 
9 13
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -15,6 +19,8 @@ import org.apache.commons.lang.StringUtils;
15 19
 import org.springframework.stereotype.Service;
16 20
 import org.springframework.transaction.annotation.Transactional;
17 21
 
22
+import javax.annotation.Resource;
23
+
18 24
 /**
19 25
  * <p>
20 26
  * 媒体管理表 服务实现类
@@ -26,6 +32,12 @@ import org.springframework.transaction.annotation.Transactional;
26 32
 @Service
27 33
 public class AdMediaServiceImpl extends ServiceImpl<AdMediaMapper, AdMedia> implements AdMediaService {
28 34
 
35
+	@Resource
36
+	private AdSpecialMapper adSpecialMapper;
37
+
38
+	@Resource
39
+	private AdTheatreMapper adTheatreMapper;
40
+
29 41
 	@Override
30 42
 	public AdMedia getByName(String name) {
31 43
 		LambdaQueryWrapper<AdMedia> queryWrapper = new LambdaQueryWrapper<AdMedia>().eq(AdMedia::getName, name);
@@ -55,4 +67,22 @@ public class AdMediaServiceImpl extends ServiceImpl<AdMediaMapper, AdMedia> impl
55 67
 		}
56 68
 		return baseMapper.selectCount(queryWrapper);
57 69
 	}
70
+
71
+	@Override
72
+	public String deleteById(Integer id) {
73
+		AdMedia adMedia = baseMapper.selectById(id);
74
+
75
+		AdSpecial adSpecial = adSpecialMapper.selectOne(
76
+				new LambdaQueryWrapper<AdSpecial>().eq(AdSpecial::getMediaName, adMedia.getName()).last("limit 1"));
77
+		if (adSpecial == null) {
78
+			return "该媒体在专题中使用不能删除";
79
+		}
80
+		AdTheatre adTheatre = adTheatreMapper.selectOne(
81
+				new LambdaQueryWrapper<AdTheatre>().eq(AdTheatre::getMediaName, adMedia.getName()).last("limit 1"));
82
+		if (adTheatre != null) {
83
+			return "该媒体在剧场中使用不能删除";
84
+		}
85
+		baseMapper.deleteById(id);
86
+		return null;
87
+	}
58 88
 }