From 573c491b4a1ba60e12a5678a01c1546c0077c1ee Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 30 七月 2019 09:07:42 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialServiceImpl.java | 287 ++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 174 insertions(+), 113 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 907b97d..3e61581 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 @@ -7,18 +7,18 @@ import java.util.UUID; import javax.annotation.Resource; -import javax.transaction.Transactional; 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.accept.AcceptData; import com.yeshi.fanli.entity.bus.homemodule.Special; -import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture; import com.yeshi.fanli.entity.common.JumpDetailV2; import com.yeshi.fanli.exception.homemodule.SpecialException; import com.yeshi.fanli.service.inter.common.JumpDetailV2Service; @@ -26,106 +26,119 @@ 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.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; - @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{ - + 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) ) { + if (params == null || params.trim().length() == 0 || "null".equalsIgnoreCase(params)) { record.setParams(null); } else if (!StringUtil.isJson(params)) { throw new SpecialException(1, "璺宠浆鍙傛暟闈濲SON鏍煎紡"); } - + if (!StringUtil.isNullOrEmpty(jumpType)) { List<JumpDetailV2> listByType = jumpDetailV2Service.listByType(jumpType); - if (listByType !=null && listByType.size() > 0) { + if (listByType != null && listByType.size() > 0) { record.setJumpDetail(listByType.get(0)); - } + } } - + 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); - - int maxOrder = specialMapper.getMaxOrderByCard(cardId); - record.setOrderby(maxOrder + 1); - + + // 鎺掑簭 + 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) { @@ -142,9 +155,7 @@ removePicture(resultObj.getSubPicture()); resultObj.setSubPicture(null); } - - - + if (picture != null && picture.trim().length() > 0) { // 鍒犻櫎鑰佸浘 removePicture(resultObj.getPicture()); @@ -153,7 +164,7 @@ } else { record.setPicture(resultObj.getPicture()); } - + if (subPicture != null && subPicture.trim().length() > 0) { // 鍒犻櫎鑰佸浘 removePicture(resultObj.getSubPicture()); @@ -162,8 +173,7 @@ } else { record.setSubPicture(resultObj.getSubPicture()); } - - + if (icon != null && icon.trim().length() > 0) { // 鍒犻櫎鑰佸浘 removePicture(resultObj.getIcon()); @@ -172,38 +182,42 @@ } 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); } } - /** * 涓婁紶鍥剧墖 + * * @param file * @return * @throws Exception */ public String uploadPicture(MultipartFile file) throws Exception { - - // 鏂囦欢瑙f瀽 + + // 鏂囦欢瑙f瀽 InputStream inputStream = file.getInputStream(); String contentType = file.getContentType(); String type = contentType.substring(contentType.indexOf("/") + 1); - + // 鏂囦欢璺緞 - String filePath="/img/special/"+UUID.randomUUID().toString().replace("-", "") + "." + type; + String filePath = "/img/special/" + UUID.randomUUID().toString().replace("-", "") + "." + type; // 鎵ц涓婁紶 - String fileLink= COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); - + String fileLink = COSManager.getInstance().uploadFile(inputStream, filePath).getUrl(); + return fileLink; } /** * 鍒犻櫎鍥剧墖-涓嶆洿鏂版暟鎹簱 + * * @param record * @throws Exception */ @@ -212,52 +226,69 @@ COSManager.getInstance().deleteFile(picture); } } - - + @Override @Transactional - public void updateOrder(Long id, Integer moveType) throws SpecialException { - - if (id == null || moveType == null || (!moveType.equals(1) && !moveType.equals(-1))) { + 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, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); } - - Integer order = resultObj.getOrderby(); + Long cardId = resultObj.getCardId(); - // 鑾峰彇浜ゆ崲瀵硅薄 - Special exchangeObject = specialMapper.getOrderByCardID(cardId, moveType, order); - if (exchangeObject == null) { - if (moveType == 1) { - throw new SpecialException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶浣庝簡"); - } else { - throw new SpecialException(1, "鍦ㄧ浉鍚屼娇鐢ㄥ湴鏂逛腑浼樺厛绾у凡缁忔渶楂樹簡"); + 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鍙傛暟涓嶆纭�"); } - - resultObj.setOrderby(exchangeObject.getOrderby()); - exchangeObject.setOrderby(order); - + specialMapper.updateByPrimaryKey(resultObj); specialMapper.updateByPrimaryKey(exchangeObject); } - - + @Override @Transactional - public int deleteBatchByPrimaryKey(List<Long> list) throws Exception{ + public int deleteBatchByPrimaryKey(List<Long> list) throws Exception { List<Special> listSpecial = specialMapper.queryByListPrimaryKey(list); - for (Special special: listSpecial) { + 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); @@ -265,46 +296,45 @@ } return specialMapper.deleteBatchByPrimaryKey(list); } - + @Override - public int deleteBatchByCardID(List<Long> list) throws Exception{ + public int deleteBatchByCardID(List<Long> list) throws Exception { List<Special> listSpecial = specialMapper.queryByListCardID(list); - for (Special special: listSpecial) { + 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){ - - List<Special> list = specialMapper.listQueryByCard(start, count, card, key); + 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) { + for (Special special : list) { 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) { // 榛樿鏈�夋嫨 @@ -316,49 +346,65 @@ } return list; } - - + @Override - public long countlistQueryByCard(Long card, String key) { - return specialMapper.countlistQueryByCard(card, key); + public long countlistQueryByCard(Long card, String key, Integer sex) { + return specialMapper.countlistQueryByCard(card, key, sex); } - - + @Override - @Cacheable(value = "configCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId") + @Cacheable(value = "specialCache", key = "'listBySystemAndCard-'+#card+'-'+#systemId") public List<Special> listBySystemAndCard(String card, Long systemId) { return specialMapper.listBySystemAndCard(card, systemId); } - @Override - @Cacheable(value = "configCache", key = "'listPageBySystemAndCard-'+#start+'-'+#count+'-'+#card+'-'+#systemId") + @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 = "configCache", key = "'listCacheSpecialToIndex'") - public JSONObject listCacheSpecialToIndex(AcceptData acceptData) throws Exception{ - + @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(); - List<Special> listArc = specialMapper.listByPlaceKey("index_arc"); + + String indexArc = "index_arc"; + 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"; + + List<Special> listArc = specialMapper.listByPlaceKey(indexArc, sex); if (listArc == null) { listArc = new ArrayList<Special>(); - } else if(listArc.size() > 0){ + } else if (listArc.size() > 0) { Special special = listArc.get(0); if (special != null) { // 鑳屾櫙鍥剧墖 arcMap.put("bottomPicture", special.getBottomPicture()); } } + + // 澶勭悊9.9鍖呴偖 + if (listArc != null && VersionUtil.greaterThan_1_5_50(acceptData.getPlatform(), acceptData.getVersion()) + && !Constant.IS_TEST) + 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()); + } + } + // 鏁版嵁澶勭悊 handlelist(listArc); arcMap.put("list", JsonUtil.getApiCommonGson().toJson(listArc)); - - + // 棣栭〉-娲诲姩鍖哄煙锛堝コ鐜嬭妭锛� JSONObject activityMap = new JSONObject(); List<Special> listActivity = null; @@ -366,60 +412,75 @@ && configService.iosOnLining(Integer.parseInt(acceptData.getVersion()))) { // 濡傛灉IOS褰撳墠鐗堟湰澶勪簬瀹℃牳鐘舵�佸氨涓嶈繑鍥� } else { - listActivity = specialMapper.listByPlaceKey("index_activity"); + listActivity = specialMapper.listByPlaceKey("index_activity", null); } - + if (listActivity == null) { listActivity = new ArrayList<Special>(); - } else if(listActivity.size() > 0){ + } 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("index_block"); + List<Special> listBlock = specialMapper.listByPlaceKey(indexBlock, sex); if (listBlock == null) { listBlock = new ArrayList<Special>(); - } else if(listBlock.size() > 0){ + } 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) { - return specialMapper.listByPlaceKey(placeKey); + return specialMapper.listByPlaceKey(placeKey, null); } - - + /** * 澶勭悊 鏁版嵁 + * * @param list */ public void handlelist(List<Special> list) { if (list != null && list.size() > 0) { - for (Special special: list) { + for (Special special : list) { boolean needLogin = special.isJumpLogin(); JumpDetailV2 jumpDetail = special.getJumpDetail(); if (jumpDetail != null) { -- Gitblit v1.8.0