From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java | 1557 +++++++++++++++++++++++++++++++---------------------------- 1 files changed, 817 insertions(+), 740 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java index 8db309c..36b6751 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java @@ -1,740 +1,817 @@ -package com.yeshi.fanli.service.impl.homemodule; - -import java.io.InputStream; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.UUID; - -import javax.annotation.Resource; - -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; -import org.yeshi.utils.JsonUtil; -import org.yeshi.utils.tencentcloud.COSManager; - -import com.yeshi.fanli.dao.mybatis.homemodule.SpecialMapper; -import com.yeshi.fanli.dto.common.CommonContentTypeEnum; -import com.yeshi.fanli.entity.AppVersionInfo; -import com.yeshi.fanli.entity.accept.AcceptData; -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.common.JumpDetailV2; -import com.yeshi.fanli.entity.system.ConfigKeyEnum; -import com.yeshi.fanli.exception.banner.SwiperPictureException; -import com.yeshi.fanli.exception.homemodule.SpecialException; -import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; -import com.yeshi.fanli.service.inter.config.AppVersionService; -import com.yeshi.fanli.service.inter.config.ConfigService; -import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService; -import com.yeshi.fanli.service.inter.homemodule.SpecialCardService; -import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService; -import com.yeshi.fanli.service.inter.homemodule.SpecialService; -import com.yeshi.fanli.util.Constant; -import com.yeshi.fanli.util.FilePathEnum; -import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.VersionUtil; - -import net.sf.json.JSONObject; - -@Service -public class SpecialServiceImpl implements SpecialService { - - @Resource - private SpecialMapper specialMapper; - - @Resource - private SpecialPlaceService specialPlaceService; - - @Resource - private SpecialCardService specialCardService; - - @Resource - private JumpDetailV2Service jumpDetailV2Service; - - @Resource - private ConfigService configService; - - @Resource - private AppVersionService appVersionService; - - @Resource - private AdActivityVersionControlService adActivityVersionControlService; - - @Override - public Special selectByPrimaryKey(Long id) { - return specialMapper.selectByPrimaryKey(id); - } - - @Override - public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record, - String jumpType) throws SpecialException, Exception { - - Long cardId = record.getCardId(); - if (cardId == null) { - throw new SpecialException(1, "绠$悊ID涓嶈兘涓虹┖"); - } - - String name = record.getName(); - if (name == null || name.trim().length() == 0) { - throw new SpecialException(1, "涓撻鍚嶇О涓嶈兘涓虹┖"); - } - - Integer sex = record.getSex(); - if (sex == null) { - throw new SpecialException(1, "鎬у埆涓嶈兘涓虹┖"); - } - - String params = record.getParams(); - if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) { - record.setParams(null); - } else if (!StringUtil.isJson(params)) { - throw new SpecialException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡"); - } else { - record.setParams(params.trim()); - } - - if (!StringUtil.isNullOrEmpty(jumpType)) { - List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType); - if (listByType != null && listByType.size() > 0) { - record.setJumpDetail(listByType.get(0)); - } - } - - // 鏃堕棿杞崲 - handleTime(record); - - Long state = record.getState(); - if (state == null) { - record.setState(0L); - } - - // 鍥剧墖涓婁紶 - String picture = null; - if (file != null) { - picture = uploadPicture(file); - } - - // 鍥剧墖涓婁紶 - String subPicture = null; - if (file2 != null) { - subPicture = uploadPicture(file2); - } - - // 鍥剧墖涓婁紶 - String icon = null; - if (file3 != null) { - icon = uploadPicture(file3); - } - - Long id = record.getId(); - if (id == null) { - record.setIcon(icon); - record.setPicture(picture); - record.setSubPicture(subPicture); - - // 鎺掑簭 - record.setOrderby(specialMapper.getDefaultMaxOrder(cardId) + 1); - record.setOrderMan(specialMapper.getManMaxOrder(cardId) + 1); - record.setOrderWoman(specialMapper.getWomanMaxOrder(cardId) + 1); - - record.setCreatetime(new Date()); - record.setUpdatetime(new Date()); - specialMapper.insert(record); - - Special s = new Special(); - s.setId(record.getId()); - s.setOrderby(Integer.parseInt(s.getId() + "")); - s.setOrderMan(Integer.parseInt(s.getId() + "")); - s.setOrderWoman(Integer.parseInt(s.getId() + "")); - specialMapper.updateByPrimaryKeySelective(s); - } else { - // 淇敼 - Special resultObj = specialMapper.selectByPrimaryKey(id); - if (resultObj == null) { - throw new SpecialException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); - } - - // 鍒犻櫎鍥剧墖 - Boolean delIcon = record.getDelIcon(); - if (delIcon != null && delIcon) { - removePicture(resultObj.getIcon()); - resultObj.setIcon(null); - } - Boolean delPicture = record.getDelPicture(); - if (delPicture != null && delPicture) { - removePicture(resultObj.getPicture()); - resultObj.setPicture(null); - } - Boolean delSubPicture = record.getDelSubPicture(); - if (delSubPicture != null && delSubPicture) { - removePicture(resultObj.getSubPicture()); - resultObj.setSubPicture(null); - } - - if (picture != null && picture.trim().length() > 0) { - // 鍒犻櫎鑰佸浘 - removePicture(resultObj.getPicture()); - // 瀛樺偍鏂板浘 - record.setPicture(picture); - } else { - record.setPicture(resultObj.getPicture()); - } - - if (subPicture != null && subPicture.trim().length() > 0) { - // 鍒犻櫎鑰佸浘 - removePicture(resultObj.getSubPicture()); - // 瀛樺偍鏂板浘 - record.setSubPicture(subPicture); - } else { - record.setSubPicture(resultObj.getSubPicture()); - } - - if (icon != null && icon.trim().length() > 0) { - // 鍒犻櫎鑰佸浘 - removePicture(resultObj.getIcon()); - // 瀛樺偍鏂板浘 - record.setIcon(icon); - } else { - record.setIcon(resultObj.getIcon()); - } - - record.setOrderby(resultObj.getOrderby()); - record.setOrderMan(resultObj.getOrderMan()); - record.setOrderWoman(resultObj.getOrderWoman()); - record.setCreatetime(resultObj.getCreatetime()); - - record.setUpdatetime(new Date()); - specialMapper.updateByPrimaryKey(record); - } - } - - /** - * web娈垫椂闂磋浆鎹� - * - * @param record - */ - private void handleTime(Special record) throws SpecialException, Exception { - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); - - String startTime_str = record.getStartTime_str(); - if (!StringUtil.isNullOrEmpty(startTime_str)) { - startTime_str = startTime_str.replaceAll("T", " "); - record.setStartTime(format.parse(startTime_str)); - } - - String endTime_str = record.getEndTime_str(); - if (!StringUtil.isNullOrEmpty(endTime_str)) { - endTime_str = endTime_str.replaceAll("T", " "); - record.setEndTime(format.parse(endTime_str)); - } - - if (record.getEndTime() != null && record.getStartTime() != null - && record.getStartTime().getTime() > record.getEndTime().getTime()) { - throw new SpecialException(1, "璧峰鏃堕棿涓嶈兘灏忎簬缁撴潫鏃堕棿"); - } - } - - /** - * 涓婁紶鍥剧墖 - * - * @param file - * @return - * @throws Exception - */ - public String uploadPicture(MultipartFile file) throws Exception { - - // 鏂囦欢瑙f瀽 - InputStream inputStream = file.getInputStream(); - String contentType = file.getContentType(); - String type = contentType.substring(contentType.indexOf("/") + 1); - - // 鏂囦欢璺緞 - String filePath = FilePathEnum.special.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type; - // 鎵ц涓婁紶 - String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); - - return fileLink; - } - - /** - * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱 - * - * @param record - * @throws Exception - */ - public void removePicture(String picture) throws Exception { - if (picture != null && picture.trim().length() > 0) { - COSManager.getInstance().deleteFile(picture); - } - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void updateOrder(Long id, Integer moveType, Integer sex) throws SpecialException { - - if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1)) || sex == null) { - throw new SpecialException(1, "璇蜂紶閫掓纭弬鏁�"); - } - - Special resultObj = specialMapper.selectByPrimaryKey(id); - if (resultObj == null) { - throw new SpecialException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); - } - - Long cardId = resultObj.getCardId(); - // 鑾峰彇浜ゆ崲瀵硅薄 - Special exchangeObject = null; - if (Special.SEX_ALL == sex || Special.SEX_DEFAULT == sex) { - Integer orderby = resultObj.getOrderby(); - exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderby, sex); - if (exchangeObject == null) { - throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆"); - } - - resultObj.setOrderby(exchangeObject.getOrderby()); - exchangeObject.setOrderby(orderby); - } else if (Special.SEX_MAN == sex) { - Integer orderMan = resultObj.getOrderMan(); - exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderMan, sex); - if (exchangeObject == null) { - throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆"); - } - - resultObj.setOrderMan(exchangeObject.getOrderMan()); - exchangeObject.setOrderMan(orderMan); - } else if (Special.SEX_WOMAN == sex) { - Integer orderWoman = resultObj.getOrderWoman(); - exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderWoman, sex); - - if (exchangeObject == null) { - throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆"); - } - - resultObj.setOrderWoman(exchangeObject.getOrderWoman()); - exchangeObject.setOrderWoman(orderWoman); - } else { - throw new SpecialException(1, "sex鍙傛暟涓嶆纭�"); - } - - specialMapper.updateByPrimaryKey(resultObj); - specialMapper.updateByPrimaryKey(exchangeObject); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public int deleteBatchByPrimaryKey(List<Long> list) throws Exception { - List<Special> listSpecial = specialMapper.queryByListPrimaryKey(list); - for (Special special : listSpecial) { - String src = special.getPicture(); - if (!StringUtil.isNullOrEmpty(src)) { - COSManager.getInstance().deleteFile(src); - } - - String subPicture = special.getSubPicture(); - if (!StringUtil.isNullOrEmpty(subPicture)) { - COSManager.getInstance().deleteFile(subPicture); - } - } - - if (listSpecial != null) - for (Special special : listSpecial) { - List<AdActivityVersionControl> versionList = adActivityVersionControlService - .listByTypeAndSourceId(AdActivityType.special, special.getId()); - if (versionList != null) - for (AdActivityVersionControl control : versionList) - adActivityVersionControlService.deleteByPrimaryKey(control.getId()); - } - return specialMapper.deleteBatchByPrimaryKey(list); - } - - @Override - public int deleteBatchByCardID(List<Long> list) throws Exception { - List<Special> listSpecial = specialMapper.queryByListCardID(list); - for (Special special : listSpecial) { - String src = special.getPicture(); - if (!StringUtil.isNullOrEmpty(src)) { - COSManager.getInstance().deleteFile(src); - } - - String subPicture = special.getSubPicture(); - if (!StringUtil.isNullOrEmpty(subPicture)) { - COSManager.getInstance().deleteFile(subPicture); - } - } - - return specialMapper.deleteBatchByCardID(list); - } - - @Override - public List<Special> listQueryByCard(long start, int count, Long card, String key, Integer sex) { - - List<Special> list = specialMapper.listQueryByCard(start, count, card, key, sex); - if (list == null || list.size() == 0) { - return list; - } - - // 璺宠浆閾炬帴 - for (Special special : list) { - if (special.getState() != null && special.getState().longValue() == 0) { - special.setState(1L); - } else { - special.setState(0L); - } - - Date startTime = special.getStartTime(); - Date endTime = special.getEndTime(); - if (startTime == null && endTime == null) { - special.setStartTime_str(""); - special.setEndTime_str(""); - } else { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); - if (startTime == null) { - special.setStartTime_str(""); - } else { - special.setStartTime_str(sdf.format(startTime)); - } - - if (endTime == null) { - special.setEndTime_str(""); - } else { - special.setEndTime_str(sdf.format(endTime)); - } - } - - String params = special.getParams(); - if (StringUtil.isNullOrEmpty(params)) { - special.setParams(""); - } - - String remark = special.getRemark(); - if (StringUtil.isNullOrEmpty(remark)) { - special.setRemark(""); - } - - JumpDetailV2 jumpDetail = special.getJumpDetail(); - if (jumpDetail == null) { - // 榛樿鏈�夋嫨 - JumpDetailV2 jumpDetailV2 = new JumpDetailV2(); - jumpDetailV2.setName("-鏈�夋嫨-"); - jumpDetailV2.setType("default"); - special.setJumpDetail(jumpDetailV2); - } - } - return list; - } - - @Override - public long countlistQueryByCard(Long card, String key, Integer sex) { - return specialMapper.countlistQueryByCard(card, key, sex); - } - - @Override - @Cacheable(value = "specialCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId") - public List<Special> listBySystemAndCard(String card, Long systemId) { - return specialMapper.listBySystemAndCard(card, systemId); - } - - @Override - @Cacheable(value = "specialCache", key = "'listPageBySystemAndCard-'+#start+'-'+#count+'-'+#card+'-'+#systemId") - public List<Special> listPageBySystemAndCard(long start, int count, String card, Long systemId) { - return specialMapper.listPageBySystemAndCard(start, count, card, systemId); - } - - @Override - @Cacheable(value = "specialCache", key = "'listByVersion-'+#start+'-'+#count+'-'+#card+'-'+#platform+'-'+#versionCode") - public List<Special> listByVersion(long start, int count, String card, String platform, Integer versionCode) { - List<Special> specialList = specialMapper.listByPlaceKey(card, null, null, null); - filterSpecial(specialList, platform, versionCode); - return specialList; - } - - /** - * 涓撻鐗堟湰杩囨护 - * - * @param list - * @param platform - * @param versionCode - */ - private void filterSpecial(List<Special> list, String platform, int versionCode) { - if (list == null || list.size() == 0) - return; - AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode); - if (app == null) { - list.clear(); - return; - } - List<Long> versionIdList = new ArrayList<>(); - versionIdList.add(app.getId()); - List<Long> sourceIdList = new ArrayList<>(); - for (Special special : list) { - sourceIdList.add(special.getId()); - } - - Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList, - AdActivityType.special, versionIdList); - for (int i = 0; i < list.size(); i++) { - if (!sourceIds.contains(list.get(i).getId())) { - list.remove(i--); - } - } - } - - @Override - @Cacheable(value = "specialCache", key = "'listCacheSpecialToIndex'+#acceptData.platform+'-'+#acceptData.version+'-'+#sex") - public JSONObject listCacheSpecialToIndex(AcceptData acceptData, Integer sex) throws Exception { - - // 棣栭〉-5鍦嗗舰2鎺掑尯鍩� - JSONObject arcMap = new JSONObject(); - - String indexArc = "index_arc"; - if (VersionUtil.greaterThan_1_6_5(acceptData.getPlatform(), acceptData.getVersion())) - indexArc = "index_arc_1.6.5"; - else if (VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) - indexArc = "index_arc_1.6.0"; - else if (VersionUtil.greaterThan_1_5_70(acceptData.getPlatform(), acceptData.getVersion())) - indexArc = "index_arc_1.5.7"; - else if (VersionUtil.greaterThan_1_5_60(acceptData.getPlatform(), acceptData.getVersion())) - indexArc = "index_arc_1.5.6"; - - String platform = acceptData.getPlatform(); - int platformCode = Constant.getPlatformCode(platform); - int version = Integer.parseInt(acceptData.getVersion()); - - List<Special> listArc = specialMapper.listByPlaceKey(indexArc, sex, platformCode, version); - filterSpecial(listArc, platform, version); - if (listArc == null) { - listArc = new ArrayList<Special>(); - } else if (listArc.size() > 0) { - Special special = listArc.get(0); - if (special != null) { - // 鑳屾櫙鍥剧墖 - arcMap.put("bottomPicture", special.getBottomPicture()); - } - } - - int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); - - // 澶勭悊9.9鍖呴偖 - if (listArc != null && VersionUtil.greaterThan_1_5_50(acceptData.getPlatform(), acceptData.getVersion())) - for (Special s : listArc) { - if (s.getName().contains("9.9")) {// 9鍧�9 - s.setJumpDetail(jumpDetailV2Service.getByTypeCache("common_template")); - JSONObject params = new JSONObject(); - params.put("key", CommonContentTypeEnum._9k9.name()); - params.put("title", CommonContentTypeEnum._9k9.getDesc()); - s.setParams(params.toString()); - } else if (s.getName().contains("鑷喘绔嬪噺")) { - if (hour < 6) {// 0-6鐐逛箣闂翠笉杩涘叆鑷喘绔嬪噺鐨勯〉闈� - s.setJumpDetail(jumpDetailV2Service.getByTypeCache("web")); - JSONObject params = new JSONObject(); - params.put("url", configService.get(ConfigKeyEnum.tljOwnBuyNogoods.getKey())); - s.setParams(params.toString()); - } else { - // 鏌ヨ涓撻璇︽儏 - Special special = specialMapper.selectByPrimaryKey(s.getId()); - s.setJumpDetail(special.getJumpDetail()); - s.setParams(special.getParams()); - } - } - - if (s.getJumpDetail() != null) { - s.getJumpDetail().setNeedLogin(s.isJumpLogin() - | (s.getJumpDetail().getNeedLogin() != null && s.getJumpDetail().getNeedLogin())); - } - - } - - // 鏁版嵁澶勭悊 -// handlelist(listArc); - arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc)); - - // 棣栭〉-娲诲姩鍖哄煙锛堝コ鐜嬭妭锛� - JSONObject activityMap = new JSONObject(); - List<Special> listActivity = null; - if ("ios".equalsIgnoreCase(acceptData.getPlatform()) - && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) { - // 濡傛灉IOS褰撳墠鐗堟湰澶勪簬瀹℃牳鐘舵�佸氨涓嶈繑鍥� - } else { - listActivity = specialMapper.listByPlaceKey("index_activity", null, platformCode, version); - } - - filterSpecial(listActivity, platform, version); - - if (listActivity == null) { - listActivity = new ArrayList<Special>(); - } else if (listActivity.size() > 0) { - Special special = listActivity.get(0); - if (special != null) { - // 鑳屾櫙鍥剧墖 - activityMap.put("bottomPicture", special.getBottomPicture()); - } - } - - handlelist(listActivity); - - activityMap.put("list", JsonUtil.getApiCommonGson().toJson(listActivity)); - - // 棣栭〉-鏂瑰舰涓撻锛堝搧鐗屽埜銆佹瘝濠�...锛� - String indexBlock = "index_block"; - if (VersionUtil.greaterThan_1_5_60(acceptData.getPlatform(), acceptData.getVersion())) - indexBlock = "index_block_1.5.6"; - - JSONObject blockJsonMap = new JSONObject(); - List<Special> listBlock = specialMapper.listByPlaceKey(indexBlock, sex, platformCode, version); - filterSpecial(listBlock, platform, version); - if (listBlock == null) { - listBlock = new ArrayList<Special>(); - } else if (listBlock.size() > 0) { - Special special = listBlock.get(0); - if (special != null) { - // 鑳屾櫙鍥剧墖 - blockJsonMap.put("bottomPicture", special.getBottomPicture()); - } - } - - // 鍝佺墝鍒� - // >=1.5.40鍚庣殑鐗堟湰鍙互鐢� - if (("android".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 39) - || "ios".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 48) - if (listBlock != null) - for (int i = 0; i < listBlock.size(); i++) { - if ("鍝佺墝鍒�".equalsIgnoreCase(listBlock.get(i).getName())) { - listBlock.get(i).setJumpDetail(jumpDetailV2Service.getByTypeCache("hot_cakes")); - } - } - - // 鏁版嵁澶勭悊 - handlelist(listBlock); - blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(listBlock)); - - JSONObject root = new JSONObject(); - root.put("arcArea", arcMap); - root.put("activityArea", activityMap); - root.put("blockArea", blockJsonMap); - return root; - } - - @Override - public List<Special> listByPlaceKey(String placeKey, Integer platform, Integer versionCode) { - return specialMapper.listByPlaceKey(placeKey, null, platform, versionCode); - } - - @Override - public List<Special> listByPlaceKeyList(long start, int count, List<String> list, Integer platform, - Integer versionCode) { - return specialMapper.listByPlaceKeyList(start, count, list, null, platform, versionCode); - } - - @Override - public long countByPlaceKeyList(List<String> list, Integer platform, Integer versionCode) { - return specialMapper.countByPlaceKeyList(list, null, platform, versionCode); - } - - @Override - @Cacheable(value = "specialCache", key = "'listByPlaceKeyHasLabel'+#start+'-'+#platform+'-'+#versionCode+'-'+#list") - public List<Special> listByPlaceKeyHasLabel(long start, int count, List<String> list, Integer platform, - Integer versionCode) { - return specialMapper.listByPlaceKeyHasLabel(start, count, list, null, platform, versionCode); - } - - /** - * 澶勭悊 鏁版嵁 - * - * @param list - */ - public void handlelist(List<Special> list) { - if (list != null && list.size() > 0) { - for (Special special : list) { - boolean needLogin = special.isJumpLogin(); - JumpDetailV2 jumpDetail = special.getJumpDetail(); - if (jumpDetail != null) { - jumpDetail.setNeedLogin(needLogin); - special.setJumpDetail(jumpDetail); - } - } - } - } - - @Transactional(rollbackFor = Exception.class) - @Override - public void setVersions(Long specialId, List<Long> versions) throws Exception { - Special special = selectByPrimaryKey(specialId); - if (special == null) { - throw new Exception("涓撻涓嶅瓨鍦�"); - } - - Set<Long> oldSet = new HashSet<>(); - - List<AdActivityVersionControl> versionList = adActivityVersionControlService - .listByTypeAndSourceId(AdActivityType.special, specialId); - if (versionList != null) { - for (AdActivityVersionControl control : versionList) - oldSet.add(control.getVersion().getId()); - } - - Set<Long> newSet = new HashSet<>(); - - for (Long version : versions) { - newSet.add(version); - } - - Set<Long> delSet = new HashSet<>(); - delSet.addAll(oldSet); - delSet.removeAll(newSet); - for (Long versionId : delSet) { - adActivityVersionControlService.deleteBySourceAndVersion(specialId, AdActivityType.special, versionId); - } - - Set<Long> addSet = new HashSet<>(); - addSet.addAll(newSet); - addSet.removeAll(oldSet); - - // 娣诲姞鏄犲皠 - for (Long versionId : addSet) { - AdActivityVersionControl control = new AdActivityVersionControl(); - control.setCreateTime(new Date()); - control.setSourceId(special.getId()); - control.setType(AdActivityType.special); - control.setVersion(new AppVersionInfo(versionId)); - try { - adActivityVersionControlService.addVersionControl(control); - } catch (Exception e) { - throw new SwiperPictureException(2, e.getMessage()); - } - } - } - - @Override - public void switchState(Long id) throws SpecialException { - if (id == null) { - throw new SpecialException(1, "璇蜂紶閫掓纭弬鏁�"); - } - - Special resultObj = specialMapper.selectByPrimaryKey(id); - if (resultObj == null) { - throw new SpecialException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); - } - - Long state = resultObj.getState(); - if (state == null || state == 0) { - state = 1L; - } else { - state = 0L; - } - - Special updateObj = new Special(); - updateObj.setId(id); - updateObj.setState(state); - updateObj.setJumpLogin(resultObj.isJumpLogin()); - specialMapper.updateByPrimaryKeySelective(updateObj); - } - -} +package com.yeshi.fanli.service.impl.homemodule; + +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.SystemEnum; +import com.yeshi.fanli.util.*; +import org.apache.commons.beanutils.PropertyUtils; +import org.omg.PortableInterceptor.SYSTEM_EXCEPTION; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; +import org.yeshi.utils.JsonUtil; +import org.yeshi.utils.tencentcloud.COSManager; + +import com.yeshi.fanli.dao.mybatis.homemodule.SpecialMapper; +import com.yeshi.fanli.dto.common.CommonContentTypeEnum; +import com.yeshi.fanli.entity.AppVersionInfo; +import com.yeshi.fanli.entity.accept.AcceptData; +import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl; +import com.yeshi.fanli.entity.bus.homemodule.AdActivityVersionControl.AdActivityType; +import com.yeshi.fanli.entity.bus.homemodule.CommonShareInfo; +import com.yeshi.fanli.entity.bus.homemodule.CommonShareInfo.CommonShareInfoEnum; +import com.yeshi.fanli.entity.bus.homemodule.Special; +import com.yeshi.fanli.entity.common.JumpDetailV2; +import com.yeshi.fanli.entity.system.ConfigKeyEnum; +import com.yeshi.fanli.exception.banner.SwiperPictureException; +import com.yeshi.fanli.exception.homemodule.SpecialException; +import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; +import com.yeshi.fanli.service.inter.config.AppVersionService; +import com.yeshi.fanli.service.inter.config.ConfigService; +import com.yeshi.fanli.service.inter.homemodule.AdActivityVersionControlService; +import com.yeshi.fanli.service.inter.homemodule.CommonShareInfoService; +import com.yeshi.fanli.service.inter.homemodule.SpecialCardService; +import com.yeshi.fanli.service.inter.homemodule.SpecialPlaceService; +import com.yeshi.fanli.service.inter.homemodule.SpecialService; +import com.yeshi.fanli.service.manger.goods.ConvertLinkManager; +import com.yeshi.fanli.vo.homemodule.SpecialVO; + +import net.sf.json.JSONObject; + +@Service +public class SpecialServiceImpl implements SpecialService { + + @Resource + private SpecialMapper specialMapper; + + @Resource + private CommonShareInfoService commonShareInfoService; + + @Resource + private JumpDetailV2Service jumpDetailV2Service; + + @Resource + private ConfigService configService; + + @Resource + private AppVersionService appVersionService; + + @Resource + private ConvertLinkManager convertLinkManager; + + @Resource + private AdActivityVersionControlService adActivityVersionControlService; + + @Override + public Special selectByPrimaryKey(Long id) { + return specialMapper.selectByPrimaryKey(id); + } + + @Override + public void saveObject(MultipartFile file, MultipartFile file2, MultipartFile file3, Special record, + String jumpType, CommonShareInfo shareInfo,SystemEnum system) throws SpecialException, Exception { + + Long cardId = record.getCardId(); + if (cardId == null) { + throw new SpecialException(1, "绠$悊ID涓嶈兘涓虹┖"); + } + + String name = record.getName(); + if (name == null || name.trim().length() == 0) { + throw new SpecialException(1, "涓撻鍚嶇О涓嶈兘涓虹┖"); + } + + Integer sex = record.getSex(); + if (sex == null) { + throw new SpecialException(1, "鎬у埆涓嶈兘涓虹┖"); + } + + String params = record.getParams(); + if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) { + record.setParams(null); + } else if (!StringUtil.isJson(params)) { + throw new SpecialException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡"); + } else { + record.setParams(params.trim()); + } + + if (!StringUtil.isNullOrEmpty(jumpType)) { + List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType,system); + if (listByType != null && listByType.size() > 0) { + record.setJumpDetail(listByType.get(0)); + } + } + + // 鏃堕棿杞崲 + handleTime(record); + + Long state = record.getState(); + if (state == null) { + record.setState(0L); + } + + // 鍥剧墖涓婁紶 + String picture = null; + if (file != null) { + picture = uploadPicture(file); + } + + // 鍥剧墖涓婁紶 + String subPicture = null; + if (file2 != null) { + subPicture = uploadPicture(file2); + } + + // 鍥剧墖涓婁紶 + String icon = null; + if (file3 != null) { + icon = uploadPicture(file3); + } + + Long id = record.getId(); + if (id == null) { + record.setIcon(icon); + record.setPicture(picture); + record.setSubPicture(subPicture); + + // 鎺掑簭 + record.setOrderby(specialMapper.getDefaultMaxOrder(cardId) + 1); + record.setOrderMan(specialMapper.getManMaxOrder(cardId) + 1); + record.setOrderWoman(specialMapper.getWomanMaxOrder(cardId) + 1); + + record.setCreatetime(new Date()); + record.setUpdatetime(new Date()); + specialMapper.insert(record); + + shareInfo.setPid(record.getId()); + + Special s = new Special(); + s.setId(record.getId()); + s.setOrderby(Integer.parseInt(s.getId() + "")); + s.setOrderMan(Integer.parseInt(s.getId() + "")); + s.setOrderWoman(Integer.parseInt(s.getId() + "")); + specialMapper.updateByPrimaryKeySelective(s); + } else { + // 淇敼 + Special resultObj = specialMapper.selectByPrimaryKey(id); + if (resultObj == null) { + throw new SpecialException(1, "淇敼鍐呭宸蹭笉瀛樺湪"); + } + + // 鍒犻櫎鍥剧墖 + Boolean delIcon = record.getDelIcon(); + if (delIcon != null && delIcon) { + removePicture(resultObj.getIcon()); + resultObj.setIcon(null); + } + Boolean delPicture = record.getDelPicture(); + if (delPicture != null && delPicture) { + removePicture(resultObj.getPicture()); + resultObj.setPicture(null); + } + Boolean delSubPicture = record.getDelSubPicture(); + if (delSubPicture != null && delSubPicture) { + removePicture(resultObj.getSubPicture()); + resultObj.setSubPicture(null); + } + + if (picture != null && picture.trim().length() > 0) { + // 鍒犻櫎鑰佸浘 + removePicture(resultObj.getPicture()); + // 瀛樺偍鏂板浘 + record.setPicture(picture); + } else { + record.setPicture(resultObj.getPicture()); + } + + if (subPicture != null && subPicture.trim().length() > 0) { + // 鍒犻櫎鑰佸浘 + removePicture(resultObj.getSubPicture()); + // 瀛樺偍鏂板浘 + record.setSubPicture(subPicture); + } else { + record.setSubPicture(resultObj.getSubPicture()); + } + + if (icon != null && icon.trim().length() > 0) { + // 鍒犻櫎鑰佸浘 + removePicture(resultObj.getIcon()); + // 瀛樺偍鏂板浘 + record.setIcon(icon); + } else { + record.setIcon(resultObj.getIcon()); + } + + record.setOrderby(resultObj.getOrderby()); + record.setOrderMan(resultObj.getOrderMan()); + record.setOrderWoman(resultObj.getOrderWoman()); + record.setCreatetime(resultObj.getCreatetime()); + + record.setUpdatetime(new Date()); + specialMapper.updateByPrimaryKey(record); + + shareInfo.setPid(record.getId()); + } + + // 娣诲姞琛ュ厖淇℃伅 + shareInfo.setType(CommonShareInfoEnum.special); + commonShareInfoService.save(shareInfo); + } + + /** + * web娈垫椂闂磋浆鎹� + * + * @param record + */ + private void handleTime(Special record) throws SpecialException, Exception { + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + + String startTime_str = record.getStartTime_str(); + if (!StringUtil.isNullOrEmpty(startTime_str)) { + startTime_str = startTime_str.replaceAll("T", " "); + record.setStartTime(format.parse(startTime_str)); + } + + String endTime_str = record.getEndTime_str(); + if (!StringUtil.isNullOrEmpty(endTime_str)) { + endTime_str = endTime_str.replaceAll("T", " "); + record.setEndTime(format.parse(endTime_str)); + } + + if (record.getEndTime() != null && record.getStartTime() != null + && record.getStartTime().getTime() > record.getEndTime().getTime()) { + throw new SpecialException(1, "璧峰鏃堕棿涓嶈兘灏忎簬缁撴潫鏃堕棿"); + } + } + + /** + * 涓婁紶鍥剧墖 + * + * @param file + * @return + * @throws Exception + */ + public String uploadPicture(MultipartFile file) throws Exception { + + // 鏂囦欢瑙f瀽 + InputStream inputStream = file.getInputStream(); + String contentType = file.getContentType(); + String type = contentType.substring(contentType.indexOf("/") + 1); + + // 鏂囦欢璺緞 + String filePath = FilePathEnum.special.getPath() + UUID.randomUUID().toString().replace("-", "") + "." + type; + // 鎵ц涓婁紶 + String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + + return fileLink; + } + + /** + * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱 + * @param picture + * @throws Exception + */ + public void removePicture(String picture) throws Exception { + if (picture != null && picture.trim().length() > 0) { + COSManager.getInstance().deleteFile(picture); + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void updateOrder(Long id, Integer moveType, Integer sex) throws SpecialException { + + if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1)) || sex == null) { + throw new SpecialException(1, "璇蜂紶閫掓纭弬鏁�"); + } + + Special resultObj = specialMapper.selectByPrimaryKey(id); + if (resultObj == null) { + throw new SpecialException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); + } + + Long cardId = resultObj.getCardId(); + // 鑾峰彇浜ゆ崲瀵硅薄 + Special exchangeObject = null; + if (Special.SEX_ALL == sex || Special.SEX_DEFAULT == sex) { + Integer orderby = resultObj.getOrderby(); + exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderby, sex); + if (exchangeObject == null) { + throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆"); + } + + resultObj.setOrderby(exchangeObject.getOrderby()); + exchangeObject.setOrderby(orderby); + } else if (Special.SEX_MAN == sex) { + Integer orderMan = resultObj.getOrderMan(); + exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderMan, sex); + if (exchangeObject == null) { + throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆"); + } + + resultObj.setOrderMan(exchangeObject.getOrderMan()); + exchangeObject.setOrderMan(orderMan); + } else if (Special.SEX_WOMAN == sex) { + Integer orderWoman = resultObj.getOrderWoman(); + exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, orderWoman, sex); + + if (exchangeObject == null) { + throw new SpecialException(1, "娌℃湁鎵惧埌鍙氦鎹㈢殑浣嶇疆"); + } + + resultObj.setOrderWoman(exchangeObject.getOrderWoman()); + exchangeObject.setOrderWoman(orderWoman); + } else { + throw new SpecialException(1, "sex鍙傛暟涓嶆纭�"); + } + + specialMapper.updateByPrimaryKey(resultObj); + specialMapper.updateByPrimaryKey(exchangeObject); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public int deleteBatchByPrimaryKey(List<Long> list) throws Exception { + List<Special> listSpecial = specialMapper.queryByListPrimaryKey(list); + for (Special special : listSpecial) { + String src = special.getPicture(); + if (!StringUtil.isNullOrEmpty(src)) { + COSManager.getInstance().deleteFile(src); + } + + String subPicture = special.getSubPicture(); + if (!StringUtil.isNullOrEmpty(subPicture)) { + COSManager.getInstance().deleteFile(subPicture); + } + + commonShareInfoService.deleteByPidAndType(special.getId(), CommonShareInfoEnum.special.name()); + } + + if (listSpecial != null) + for (Special special : listSpecial) { + List<AdActivityVersionControl> versionList = adActivityVersionControlService + .listByTypeAndSourceId(AdActivityType.special, special.getId()); + if (versionList != null) + for (AdActivityVersionControl control : versionList) + adActivityVersionControlService.deleteByPrimaryKey(control.getId()); + } + return specialMapper.deleteBatchByPrimaryKey(list); + } + + @Override + public int deleteBatchByCardID(List<Long> list) throws Exception { + List<Special> listSpecial = specialMapper.queryByListCardID(list); + for (Special special : listSpecial) { + String src = special.getPicture(); + if (!StringUtil.isNullOrEmpty(src)) { + COSManager.getInstance().deleteFile(src); + } + + String subPicture = special.getSubPicture(); + if (!StringUtil.isNullOrEmpty(subPicture)) { + COSManager.getInstance().deleteFile(subPicture); + } + + commonShareInfoService.deleteByPidAndType(special.getId(), CommonShareInfoEnum.special.name()); + } + + return specialMapper.deleteBatchByCardID(list); + } + + @Override + public List<SpecialVO> listQueryByCard(long start, int count, Long card, String key, Integer sex) { + List<Special> list = specialMapper.listQueryByCard(start, count, card, key, sex); + if (list == null) { + return null; + } + + List<SpecialVO> listvo = new ArrayList<SpecialVO>(); + for (Special special : list) { + SpecialVO specialVO = new SpecialVO(); + try { + PropertyUtils.copyProperties(specialVO, special); + } catch (Exception e) { + e.printStackTrace(); + continue; + } + + if (specialVO.getState() != null && specialVO.getState().longValue() == 0) { + specialVO.setState(1L); + } else { + specialVO.setState(0L); + } + + Date startTime = specialVO.getStartTime(); + Date endTime = specialVO.getEndTime(); + if (startTime == null && endTime == null) { + specialVO.setStartTime_str(""); + specialVO.setEndTime_str(""); + } else { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); + if (startTime == null) { + specialVO.setStartTime_str(""); + } else { + specialVO.setStartTime_str(sdf.format(startTime)); + } + + if (endTime == null) { + specialVO.setEndTime_str(""); + } else { + specialVO.setEndTime_str(sdf.format(endTime)); + } + } + + String params = specialVO.getParams(); + if (StringUtil.isNullOrEmpty(params)) { + specialVO.setParams(""); + } + + String remark = specialVO.getRemark(); + if (StringUtil.isNullOrEmpty(remark)) { + specialVO.setRemark(""); + } + + JumpDetailV2 jumpDetail = specialVO.getJumpDetail(); + if (jumpDetail == null) { + // 榛樿鏈�夋嫨 + JumpDetailV2 jumpDetailV2 = new JumpDetailV2(); + jumpDetailV2.setName("-鏈�夋嫨-"); + jumpDetailV2.setType("default"); + specialVO.setJumpDetail(jumpDetailV2); + } + + // 鍒嗕韩琛ュ厖淇℃伅 + CommonShareInfo info = commonShareInfoService.getByPidAndType(specialVO.getId(), + CommonShareInfoEnum.special.name()); + if (info == null) { + specialVO.setNeedSpin(false); + specialVO.setComment(""); + } else { + specialVO.setNeedSpin(info.getNeedSpin()); + if (StringUtil.isNullOrEmpty(info.getComment())) { + specialVO.setComment(""); + } else { + specialVO.setComment(info.getComment()); + } + } + listvo.add(specialVO); + } + return listvo; + } + + @Override + public long countlistQueryByCard(Long card, String key, Integer sex) { + return specialMapper.countlistQueryByCard(card, key, sex); + } + + @Override + @Cacheable(value = "specialCache", key = "'listByVersion-'+#start+'-'+#count+'-'+#card+'-'+#platform+'-'+#versionCode+'-'+#system") + public List<SpecialVO> listByVersion(long start, int count, String card, String platform, Integer versionCode,SystemEnum system) { + List<Special> specialList = specialMapper.listByPlaceKey(card, null, null, null, system); + filterSpecial(specialList, platform, versionCode,system); + return transformVO(specialList,system); + } + + /** + * 涓撻鐗堟湰杩囨护 + * + * @param list + * @param platform + * @param versionCode + */ + private void filterSpecial(List<Special> list, String platform, int versionCode,SystemEnum system) { + if (list == null || list.size() == 0) + return; + AppVersionInfo app = appVersionService.getClientVersion(platform, versionCode,system); + if (app == null) { + list.clear(); + return; + } + List<Long> versionIdList = new ArrayList<>(); + versionIdList.add(app.getId()); + List<Long> sourceIdList = new ArrayList<>(); + for (Special special : list) { + sourceIdList.add(special.getId()); + } + + Set<Long> sourceIds = adActivityVersionControlService.filterSourceIdByVersion(sourceIdList, + AdActivityType.special, versionIdList); + for (int i = 0; i < list.size(); i++) { + if (!sourceIds.contains(list.get(i).getId())) { + list.remove(i--); + } + } + } + + @Override + @Cacheable(value = "specialCache", key = "'listCacheSpecialToIndex'+#acceptData.platform+'-'+#acceptData.version+'-'+#sex+'-'+#system") + public JSONObject listCacheSpecialToIndex(AcceptData acceptData, Integer sex,SystemEnum system) throws Exception { + + // 棣栭〉-5鍦嗗舰2鎺掑尯鍩� + JSONObject arcMap = new JSONObject(); + + String indexArc = "index_arc"; + if (VersionUtil.greaterThan_1_6_5(acceptData.getPlatform(), acceptData.getVersion())) + indexArc = "index_arc_1.6.5"; + else if (VersionUtil.greaterThan_1_6_0(acceptData.getPlatform(), acceptData.getVersion())) + indexArc = "index_arc_1.6.0"; + else if (VersionUtil.greaterThan_1_5_70(acceptData.getPlatform(), acceptData.getVersion())) + indexArc = "index_arc_1.5.7"; + else if (VersionUtil.greaterThan_1_5_60(acceptData.getPlatform(), acceptData.getVersion())) + indexArc = "index_arc_1.5.6"; + + String platform = acceptData.getPlatform(); + int platformCode = Constant.getPlatformCode(platform); + int version = Integer.parseInt(acceptData.getVersion()); + + List<Special> listArc = specialMapper.listByPlaceKey(indexArc, sex, platformCode, version,system); + filterSpecial(listArc, platform, version,system); + if (listArc == null) { + listArc = new ArrayList<Special>(); + } else if (listArc.size() > 0) { + Special special = listArc.get(0); + if (special != null) { + // 鑳屾櫙鍥剧墖 + arcMap.put("bottomPicture", special.getBottomPicture()); + } + } + + int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY); + + // 澶勭悊9.9鍖呴偖 + if (listArc != null && VersionUtil.greaterThan_1_5_50(acceptData.getPlatform(), acceptData.getVersion())) + for (Special s : listArc) { + if (s.getName().contains("9.9")) {// 9鍧�9 + s.setJumpDetail(jumpDetailV2Service.getByTypeCache("common_template",system)); + JSONObject params = new JSONObject(); + params.put("key", CommonContentTypeEnum._9k9.name()); + params.put("title", CommonContentTypeEnum._9k9.getDesc()); + s.setParams(params.toString()); + } else if (s.getName().contains("鑷喘绔嬪噺")) { + if (hour < 6) {// 0-6鐐逛箣闂翠笉杩涘叆鑷喘绔嬪噺鐨勯〉闈� + s.setJumpDetail(jumpDetailV2Service.getByTypeCache("web",system)); + JSONObject params = new JSONObject(); + params.put("url", configService.getValue(ConfigKeyEnum.tljOwnBuyNogoods.getKey(), SystemInfoUtil.getSystem(acceptData))); + s.setParams(params.toString()); + } else { + // 鏌ヨ涓撻璇︽儏 + Special special = specialMapper.selectByPrimaryKey(s.getId()); + s.setJumpDetail(special.getJumpDetail()); + s.setParams(special.getParams()); + } + } + + if (s.getJumpDetail() != null) { + s.getJumpDetail().setNeedLogin(s.isJumpLogin() + | (s.getJumpDetail().getNeedLogin() != null && s.getJumpDetail().getNeedLogin())); + } + + } + + // 鏁版嵁澶勭悊 +// handlelist(listArc); + arcMap.put("list", JsonUtil.getApiCommonGson().toJson(transformVO(listArc,SystemInfoUtil.getSystem(acceptData)))); + + // 棣栭〉-娲诲姩鍖哄煙锛堝コ鐜嬭妭锛� + JSONObject activityMap = new JSONObject(); + List<Special> listActivity = null; + if ("ios".equalsIgnoreCase(acceptData.getPlatform()) + && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()), SystemInfoUtil.getSystem(acceptData))) { + // 濡傛灉IOS褰撳墠鐗堟湰澶勪簬瀹℃牳鐘舵�佸氨涓嶈繑鍥� + } else { + listActivity = specialMapper.listByPlaceKey("index_activity", null, platformCode, version,system); + } + + filterSpecial(listActivity, platform, version,system); + + if (listActivity == null) { + listActivity = new ArrayList<Special>(); + } else if (listActivity.size() > 0) { + Special special = listActivity.get(0); + if (special != null) { + // 鑳屾櫙鍥剧墖 + activityMap.put("bottomPicture", special.getBottomPicture()); + } + } + + handlelist(listActivity); + + activityMap.put("list", JsonUtil.getApiCommonGson().toJson(transformVO(listActivity,system))); + + // 棣栭〉-鏂瑰舰涓撻锛堝搧鐗屽埜銆佹瘝濠�...锛� + String indexBlock = "index_block"; + if (VersionUtil.greaterThan_1_5_60(acceptData.getPlatform(), acceptData.getVersion())) + indexBlock = "index_block_1.5.6"; + + JSONObject blockJsonMap = new JSONObject(); + List<Special> listBlock = specialMapper.listByPlaceKey(indexBlock, sex, platformCode, version,system); + filterSpecial(listBlock, platform, version,system); + if (listBlock == null) { + listBlock = new ArrayList<Special>(); + } else if (listBlock.size() > 0) { + Special special = listBlock.get(0); + if (special != null) { + // 鑳屾櫙鍥剧墖 + blockJsonMap.put("bottomPicture", special.getBottomPicture()); + } + } + + // 鍝佺墝鍒� + // >=1.5.40鍚庣殑鐗堟湰鍙互鐢� + if (("android".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 39) + || "ios".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 48) + if (listBlock != null) + for (int i = 0; i < listBlock.size(); i++) { + if ("鍝佺墝鍒�".equalsIgnoreCase(listBlock.get(i).getName())) { + listBlock.get(i).setJumpDetail(jumpDetailV2Service.getByTypeCache("hot_cakes",system)); + } + } + + // 鏁版嵁澶勭悊 + handlelist(listBlock); + blockJsonMap.put("list", JsonUtil.getApiCommonGson().toJson(transformVO(listBlock,system))); + + JSONObject root = new JSONObject(); + root.put("arcArea", arcMap); + root.put("activityArea", activityMap); + root.put("blockArea", blockJsonMap); + return root; + } + + @Override + public List<Special> listByPlaceKey(String placeKey, Integer platform, Integer versionCode,SystemEnum system) { + return specialMapper.listByPlaceKey(placeKey, null, platform, versionCode,system); + } + + @Override + public List<Special> listByPlaceKeyList(long start, int count, List<String> list, Integer platform, + Integer versionCode,SystemEnum system) { + return specialMapper.listByPlaceKeyList(start, count, list, null, platform, versionCode,system); + } + + @Override + public long countByPlaceKeyList(List<String> list, Integer platform, Integer versionCode,SystemEnum system) { + return specialMapper.countByPlaceKeyList(list, null, platform, versionCode,system); + } + + @Override + @Cacheable(value = "specialCache", key = "'listByPlaceKeyHasLabel'+#start+'-'+#platform+'-'+#versionCode+'-'+#list") + public List<SpecialVO> listByPlaceKeyHasLabel(long start, int count, List<String> list, Integer platform, + Integer versionCode,SystemEnum system) { + List<Special> listSpecial = specialMapper.listByPlaceKeyHasLabel(start, count, list, null, + platform, versionCode,system); + return transformVO(listSpecial,system); + } + + + /** + * 杞崲VO + * @param list + * @return + */ + private List<SpecialVO> transformVO(List<Special> list, SystemEnum system) { + List<SpecialVO> listVo = new ArrayList<SpecialVO>(); + if (list != null && list.size() > 0) { + for (Special special: list) { + SpecialVO specialVO = new SpecialVO(); + try { + PropertyUtils.copyProperties(specialVO, special); + } catch (Exception e) { + e.printStackTrace(); + continue; + } + + // 璺宠浆娲诲姩杩囨浮椤� + CommonShareInfo info = commonShareInfoService.getByPidAndType(specialVO.getId(), + CommonShareInfoEnum.special.name()); + if (info != null && !StringUtil.isNullOrEmpty(info.getComment())) { + String link = configService.getValue(ConfigKeyEnum.activityDetailLink.getKey(),system) + "?type=%s&id=%s"; + link = String.format(link, CommonShareInfoEnum.special.name(),specialVO.getId()); + + // 璺宠浆閾炬帴 + JSONObject params = new JSONObject(); + params.put("url", link); + + // 鏇挎崲娣樺疂瀹樻柟娲诲姩 + String comment = info.getComment(); + List<String> activityIdList = convertLinkManager.getTaoBaoOfficialActivityId(comment); + for (String st : activityIdList) + comment = comment.replace(st, ""); + + specialVO.setComment(comment); + specialVO.setParams(params.toString()); + specialVO.setJumpDetail(jumpDetailV2Service.getByTypeCache("web",system)); + } + listVo.add(specialVO); + } + } + return listVo; + } + + + + + /** + * 澶勭悊 鏁版嵁 + * + * @param list + */ + public void handlelist(List<Special> list) { + if (list != null && list.size() > 0) { + for (Special special : list) { + boolean needLogin = special.isJumpLogin(); + JumpDetailV2 jumpDetail = special.getJumpDetail(); + if (jumpDetail != null) { + jumpDetail.setNeedLogin(needLogin); + special.setJumpDetail(jumpDetail); + } + } + } + } + + @Transactional(rollbackFor = Exception.class) + @Override + public void setVersions(Long specialId, List<Long> versions) throws Exception { + Special special = selectByPrimaryKey(specialId); + if (special == null) { + throw new Exception("涓撻涓嶅瓨鍦�"); + } + + Set<Long> oldSet = new HashSet<>(); + + List<AdActivityVersionControl> versionList = adActivityVersionControlService + .listByTypeAndSourceId(AdActivityType.special, specialId); + if (versionList != null) { + for (AdActivityVersionControl control : versionList) + oldSet.add(control.getVersion().getId()); + } + + Set<Long> newSet = new HashSet<>(); + + for (Long version : versions) { + newSet.add(version); + } + + Set<Long> delSet = new HashSet<>(); + delSet.addAll(oldSet); + delSet.removeAll(newSet); + for (Long versionId : delSet) { + adActivityVersionControlService.deleteBySourceAndVersion(specialId, AdActivityType.special, versionId); + } + + Set<Long> addSet = new HashSet<>(); + addSet.addAll(newSet); + addSet.removeAll(oldSet); + + // 娣诲姞鏄犲皠 + for (Long versionId : addSet) { + AdActivityVersionControl control = new AdActivityVersionControl(); + control.setCreateTime(new Date()); + control.setSourceId(special.getId()); + control.setType(AdActivityType.special); + control.setVersion(new AppVersionInfo(versionId)); + try { + adActivityVersionControlService.addVersionControl(control); + } catch (Exception e) { + throw new SwiperPictureException(2, e.getMessage()); + } + } + } + + @Override + public void switchState(Long id) throws SpecialException { + if (id == null) { + throw new SpecialException(1, "璇蜂紶閫掓纭弬鏁�"); + } + + Special resultObj = specialMapper.selectByPrimaryKey(id); + if (resultObj == null) { + throw new SpecialException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); + } + + Long state = resultObj.getState(); + if (state == null || state == 0) { + state = 1L; + } else { + state = 0L; + } + + Special updateObj = new Special(); + updateObj.setId(id); + updateObj.setState(state); + updateObj.setJumpLogin(resultObj.isJumpLogin()); + specialMapper.updateByPrimaryKeySelective(updateObj); + } + +} -- Gitblit v1.8.0