From 0cbdd620aac13ac8b06599294183cf1246626f0e Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 16 十二月 2019 16:05:32 +0800
Subject: [PATCH] 专题版本控制

---
 fanli/src/main/java/com/yeshi/fanli/controller/admin/homemodule/SpecialCardAdminController.java |  105 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 102 insertions(+), 3 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/homemodule/SpecialCardAdminController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/homemodule/SpecialCardAdminController.java
index d22d934..e2d1609 100644
--- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/homemodule/SpecialCardAdminController.java
+++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/homemodule/SpecialCardAdminController.java
@@ -2,7 +2,9 @@
 
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletRequest;
@@ -15,16 +17,22 @@
 import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
+import com.yeshi.fanli.entity.AppVersionInfo;
+import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl;
+import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType;
 import com.yeshi.fanli.entity.bus.homemodule.Special;
 import com.yeshi.fanli.entity.bus.homemodule.SpecialCard;
 import com.yeshi.fanli.exception.homemodule.FloatADException;
 import com.yeshi.fanli.exception.homemodule.SpecialException;
+import com.yeshi.fanli.service.inter.config.AppVersionService;
+import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialCardService;
 import com.yeshi.fanli.service.inter.homemodule.SpecialService;
 import com.yeshi.fanli.tag.PageEntity;
 import com.yeshi.fanli.util.Constant;
 import com.yeshi.fanli.util.StringUtil;
 
+import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 
 @Controller
@@ -36,6 +44,12 @@
 
 	@Resource
 	private SpecialCardService specialCardService;
+
+	@Resource
+	private AppVersionService appVersionService;
+
+	@Resource
+	private AdActivityVersionControlService adActivityVersionControlService;
 
 	/**
 	 * 淇濆瓨淇℃伅
@@ -247,8 +261,8 @@
 	 */
 	@RequestMapping(value = "querySpecial")
 	public void querySpecial(String callback, Integer pageIndex, Integer pageSize, String key, Long cardId, Integer sex,
-			PrintWriter out) {
-
+			String version, String platform, PrintWriter out) {
+		pageSize = 100;
 		if (pageIndex == null || pageIndex < 1) {
 			pageIndex = 1;
 		}
@@ -262,16 +276,65 @@
 			return;
 		}
 
+		List<AppVersionInfo> versionList = null;
+		if (!StringUtil.isNullOrEmpty(version) || !StringUtil.isNullOrEmpty(platform)) {
+			versionList = new ArrayList<>();
+			if (!StringUtil.isNullOrEmpty(version) && !StringUtil.isNullOrEmpty(platform)) {
+				AppVersionInfo appVersion = appVersionService.getByPlatformAndVersion(platform, version);
+				if (appVersion != null)
+					versionList.add(appVersion);
+			} else if (!StringUtil.isNullOrEmpty(version)) {
+				List<AppVersionInfo> appVersionList = appVersionService.listByVersion(version);
+				if (appVersionList != null) {
+					versionList.addAll(appVersionList);
+				}
+			} else {
+				List<AppVersionInfo> appVersionList = appVersionService.getAppVersionInfoListByPlatform(platform);
+				if (appVersionList != null) {
+					versionList.addAll(appVersionList);
+				}
+			}
+		}
+
 		try {
 
 			List<Special> list = specialService.listQueryByCard((pageIndex - 1) * pageSize, pageSize, cardId, key, sex);
+			long count = specialService.countlistQueryByCard(cardId, key, sex);
+			// 鑾峰彇鏈夋晥鐨勪笓棰�
 
 			if (list == null || list.size() == 0) {
 				JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏆傛棤鏁版嵁"));
 				return;
 			}
 
-			long count = specialService.countlistQueryByCard(cardId, key, sex);
+			// 杩囨护
+			if (versionList != null) {
+				if (versionList.size() > 0) {
+					List<Long> sourceIdList = new ArrayList<>();
+					for (Special special : list) {
+						sourceIdList.add(special.getId());
+					}
+					List<Long> versionIdList = new ArrayList<>();
+					for (AppVersionInfo versionInfo : versionList)
+						versionIdList.add(versionInfo.getId());
+					List<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList,
+							AdActivityType.special, versionIdList);
+					Set<Long> sets = new HashSet<>();
+					if (sourceIds != null)
+						for (Long sourceId : sourceIds) {
+							sets.add(sourceId);
+						}
+					for (int i = 0; i < list.size(); i++) {
+						if (!sets.contains(list.get(i).getId())) {
+							list.remove(i--);
+						}
+					}
+					count = list.size();
+				} else {
+					list.clear();
+					count = 0;
+				}
+			}
 
 			int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
 			PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
@@ -290,7 +353,43 @@
 			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎿嶄綔寮傚父"));
 			e.printStackTrace();
 		}
+	}
 
+	/**
+	 * 璁剧疆鐗堟湰
+	 * 
+	 * @param callback
+	 * @param id
+	 * @param moveType
+	 * @param sex
+	 * @param out
+	 */
+	@RequestMapping(value = "setVersions")
+	public void setVersions(String callback, Long id, String versions, PrintWriter out) {
+		JSONArray versionArray = JSONArray.fromObject(versions);
+		List<Long> versionIds = new ArrayList<>();
+		for (int i = 0; i < versionArray.size(); i++) {
+			Long version = versionArray.optLong(i);
+			versionIds.add(version);
+		}
+		try {
+			specialService.setVersions(id, versionIds);
+			JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(""));
+		} catch (Exception e) {
+			JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMessage()));
+		}
+	}
+
+	@RequestMapping(value = "getVersions")
+	public void getVersions(String callback, Long id, PrintWriter out) {
+		List<AdActivityVersionControl> list = adActivityVersionControlService
+				.listByTypeAndSourceId(AdActivityType.special, id);
+
+		List<Long> versionList = new ArrayList<>();
+		if (list != null)
+			for (AdActivityVersionControl control : list)
+				versionList.add(control.getId());
+		JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(versionList));
 	}
 
 }

--
Gitblit v1.8.0