Browse Source

批量更新 一个事物中去掉stat

yufeng 3 years ago
parent
commit
2efdddc4cb

+ 10 - 8
src/main/java/com/ylcm/sys/controller/AdTheatreController.java

@@ -16,12 +16,7 @@ import com.ylcm.sys.domain.AdTv;
16
 import com.ylcm.sys.excel.listener.BaseExcelListener;
16
 import com.ylcm.sys.excel.listener.BaseExcelListener;
17
 import com.ylcm.sys.excel.model.AdTheatreExcelDTO;
17
 import com.ylcm.sys.excel.model.AdTheatreExcelDTO;
18
 import com.ylcm.sys.form.AdTheatreForm;
18
 import com.ylcm.sys.form.AdTheatreForm;
19
-import com.ylcm.sys.service.AdMediaService;
20
-import com.ylcm.sys.service.AdPlatformService;
21
-import com.ylcm.sys.service.AdProductService;
22
-import com.ylcm.sys.service.AdTheatreService;
23
-import com.ylcm.sys.service.AdTheatreTvService;
24
-import com.ylcm.sys.service.AdTvService;
19
+import com.ylcm.sys.service.*;
25
 import com.ylcm.sys.vo.AdTheatreVO;
20
 import com.ylcm.sys.vo.AdTheatreVO;
26
 import lombok.extern.slf4j.Slf4j;
21
 import lombok.extern.slf4j.Slf4j;
27
 import org.apache.commons.collections.CollectionUtils;
22
 import org.apache.commons.collections.CollectionUtils;
@@ -60,6 +55,8 @@ public class AdTheatreController extends BaseController{
60
 	private AdPlatformService adPlatformService;
55
 	private AdPlatformService adPlatformService;
61
 	@Resource
56
 	@Resource
62
 	private AdMediaService adMediaService;
57
 	private AdMediaService adMediaService;
58
+	@Resource
59
+	private AdTheatreTvStatService adTheatreTvStatService;
63
 
60
 
64
 	/**
61
 	/**
65
 	 * to 列表页面
62
 	 * to 列表页面
@@ -253,9 +250,14 @@ public class AdTheatreController extends BaseController{
253
 				tvList.add(dto.toAdTheatreTv());
250
 				tvList.add(dto.toAdTheatreTv());
254
 			}
251
 			}
255
 			// 入库
252
 			// 入库
256
-			msg = adTheatreService.batchAdd(list, tvList);
253
+			List<AdTheatre> adTheatres = adTheatreService.batchAdd(list, tvList);
254
+
255
+			for (AdTheatre adTheatre:adTheatres) {
256
+				adTheatreTvStatService.saveStatByTheatreTv(adTheatre);
257
+			}
258
+
257
 			// 判断执行结果
259
 			// 判断执行结果
258
-			if ("ok".equals(msg)) {
260
+			if (adTheatres != null) {
259
 				request.setAttribute("repeat", 0);
261
 				request.setAttribute("repeat", 0);
260
 				request.setAttribute("code", Constants.CODE_SUCCESS);
262
 				request.setAttribute("code", Constants.CODE_SUCCESS);
261
 				request.setAttribute("msg", msg);
263
 				request.setAttribute("msg", msg);

+ 1 - 1
src/main/java/com/ylcm/sys/service/AdTheatreService.java

@@ -32,7 +32,7 @@ public interface AdTheatreService extends IService<AdTheatre> {
32
      * @param tvList 电视剧收视数据
32
      * @param tvList 电视剧收视数据
33
      * @return 执行结果:errorMsg or ok
33
      * @return 执行结果:errorMsg or ok
34
      */
34
      */
35
-    String batchAdd(List<AdTheatre> list, List<AdTheatreTv> tvList) throws Exception;
35
+    List<AdTheatre> batchAdd(List<AdTheatre> list, List<AdTheatreTv> tvList) throws Exception;
36
 
36
 
37
     String deleteById(Integer id);
37
     String deleteById(Integer id);
38
 
38
 

+ 7 - 0
src/main/java/com/ylcm/sys/service/AdTheatreTvService.java

@@ -15,6 +15,13 @@ public interface AdTheatreTvService extends IService<AdTheatreTv> {
15
 
15
 
16
     AdTheatreTv getByTheatreId(Integer adTheatreId);
16
     AdTheatreTv getByTheatreId(Integer adTheatreId);
17
 
17
 
18
+    String add1(AdTheatreTv record);
19
+
20
+    /**
21
+     * 带更新stat
22
+     * @param record
23
+     * @return
24
+     */
18
     String add(AdTheatreTv record);
25
     String add(AdTheatreTv record);
19
 
26
 
20
 }
27
 }

+ 4 - 3
src/main/java/com/ylcm/sys/service/impl/AdTheatreServiceImpl.java

@@ -73,7 +73,7 @@ public class AdTheatreServiceImpl extends ServiceImpl<AdTheatreMapper, AdTheatre
73
 
73
 
74
     @Override
74
     @Override
75
     @Transactional(rollbackFor = Exception.class)
75
     @Transactional(rollbackFor = Exception.class)
76
-    public String batchAdd(List<AdTheatre> list, List<AdTheatreTv> tvList) throws Exception {
76
+    public List<AdTheatre> batchAdd(List<AdTheatre> list, List<AdTheatreTv> tvList) throws Exception {
77
         if (list.size() != tvList.size()){
77
         if (list.size() != tvList.size()){
78
             throw new Exception("批量新增error:剧场ListSize != 收视率ListSize");
78
             throw new Exception("批量新增error:剧场ListSize != 收视率ListSize");
79
         }
79
         }
@@ -93,9 +93,10 @@ public class AdTheatreServiceImpl extends ServiceImpl<AdTheatreMapper, AdTheatre
93
              */
93
              */
94
             AdTheatreTv theatreTv = tvList.get(i);
94
             AdTheatreTv theatreTv = tvList.get(i);
95
             theatreTv.setAdTheatreId(record.getId());
95
             theatreTv.setAdTheatreId(record.getId());
96
-            adTheatreTvService.add(theatreTv);
96
+            adTheatreTvService.add1(theatreTv);
97
+
97
         }
98
         }
98
-        return "ok";
99
+        return list;
99
     }
100
     }
100
 
101
 
101
     @Transactional(rollbackFor = Exception.class)
102
     @Transactional(rollbackFor = Exception.class)

+ 18 - 0
src/main/java/com/ylcm/sys/service/impl/AdTheatreTvServiceImpl.java

@@ -43,6 +43,24 @@ public class AdTheatreTvServiceImpl extends ServiceImpl<AdTheatreTvMapper, AdThe
43
 
43
 
44
     @Override
44
     @Override
45
     @Transactional(rollbackFor = Exception.class)
45
     @Transactional(rollbackFor = Exception.class)
46
+    public String add1(AdTheatreTv record) {
47
+        AdTheatreTv old = getByTheatreId(record.getAdTheatreId());
48
+        if (old == null){
49
+            // insert
50
+            baseMapper.insert(record);
51
+        } else {
52
+            // update
53
+            record.setId(old.getId());
54
+            baseMapper.updateById(record);
55
+        }
56
+
57
+//        AdTheatre adTheatre = adTheatreService.getById(record.getAdTheatreId());
58
+//        adTheatreTvStatService.saveStatByTheatreTv(adTheatre);
59
+        return "ok";
60
+    }
61
+
62
+    @Override
63
+    @Transactional(rollbackFor = Exception.class)
46
     public String add(AdTheatreTv record) {
64
     public String add(AdTheatreTv record) {
47
         AdTheatreTv old = getByTheatreId(record.getAdTheatreId());
65
         AdTheatreTv old = getByTheatreId(record.getAdTheatreId());
48
         if (old == null){
66
         if (old == null){