package com.ks.daylucky.controller.api.client; import com.google.gson.Gson; import com.ks.daylucky.pojo.DO.ActivityScanRecord; import com.ks.daylucky.pojo.DO.AppConfig; import com.ks.daylucky.pojo.DTO.SimpleShareInfo; import com.ks.daylucky.pojo.VO.AlipayXCXShareInfoVO; import com.ks.daylucky.pojo.DTO.ConfigKeyEnum; import com.ks.daylucky.pojo.VO.AcceptData; import com.ks.daylucky.pojo.DTO.ActivityDetailInfoDTO; import com.ks.daylucky.pojo.VO.ActivityDetailVO; import com.ks.daylucky.pojo.VO.SimpleUser; import com.ks.daylucky.service.*; import com.ks.daylucky.util.Constant; import com.ks.daylucky.util.activity.ActivityUtil; import com.ks.daylucky.util.factory.vo.ActivityDetailVOFactory; import com.ks.daylucky.util.factory.vo.ActivityListItemInfoVOFactory; import com.ks.lib.common.exception.ParamsException; import com.ks.lucky.pojo.DO.LuckyActivity; import com.ks.lucky.remote.service.LuckyActivityJoinAssistService; import com.ks.lucky.remote.service.LuckyActivityService; import net.sf.json.JSONObject; import org.apache.dubbo.config.annotation.Reference; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.yeshi.utils.JsonUtil; import javax.annotation.Resource; import java.net.URLEncoder; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @Controller @RequestMapping("api/client/activity") public class ActivityController { @Reference(version = "1.0.0", check = false) private LuckyActivityService luckyActivityService; @Reference(version = "1.0.0", check = false) private LuckyActivityJoinAssistService luckyActivityJoinAssistService; @Resource private ActivityScanRecordService activityScanRecordService; @Resource private ActivityService activityService; @Resource private AppConfigService appConfigService; @Resource private ActivityExtraInfoService activityExtraInfoService; @Resource private UserActivityExtraInfoService userActivityExtraInfoService; @Resource private UserInfoService userInfoService; /** * 获取活动详情 * * @param acceptData * @param activityId * @return */ @ResponseBody @RequestMapping("getActivityDetail") public String getActivityDetail(AcceptData acceptData, Long activityId) throws ParamsException { ActivityDetailInfoDTO dto = activityService.getActivityDetail(activityId, acceptData.getApp().getId(), acceptData.getUid(), true, 8, false); if (dto == null) { return JsonUtil.loadFalseResult("活动不存在"); } AppConfig help = appConfigService.getConfigCache(acceptData.getApp().getId(), ConfigKeyEnum.activityDetailHelp, acceptData.getVersion()); Integer assistCount = null; if (dto.getJoin()) { long count = luckyActivityJoinAssistService.countAssistRecord(activityId, acceptData.getApp().getId(), acceptData.getUid() + ""); assistCount = (int) count; } //查询赞助商已经开始的活动数量 long count = luckyActivityService.countActivity(acceptData.getApp().getId(), dto.getActivity().getSponsorId(), ActivityUtil.getCanShowAcivityStateList(), null); ActivityDetailVO vo = ActivityDetailVOFactory.create(dto, help != null ? help.getValue() : null, assistCount, (int) count); //分享信息 String activityShareImage = null; try { activityShareImage = activityExtraInfoService.getShareImageLink(activityId, vo.getActivity().getAwardList(), acceptData.getApp().getId()); } catch (Exception e) { e.printStackTrace(); } AppConfig appConfig = appConfigService.getConfigCache(acceptData.getApp().getId(), ConfigKeyEnum.activityShareInfo, acceptData.getVersion()); SimpleShareInfo info = new Gson().fromJson(appConfig.getValue(), SimpleShareInfo.class); AlipayXCXShareInfoVO shareInfoDTO = new AlipayXCXShareInfoVO(); shareInfoDTO.setPath(String.format("/pages/activity-detail/activity-detail?id=%s&joinInfo=%s", activityId, ActivityUtil.getShareJoinInfo(acceptData.getUid(), activityId))); shareInfoDTO.setTitle(info.getTitle()); shareInfoDTO.setDesc(info.getDesc()); shareInfoDTO.setBgImgUrl(activityShareImage); vo.setShareInfo(shareInfoDTO); //已经加入活动就需要返回助力分享图 if (vo.isJoined()) { SimpleUser user = userInfoService.getSimpleUser(acceptData.getUid()); if (user != null) { String assistShareImage = null; try { assistShareImage = userActivityExtraInfoService.getShareImageLink(activityId, user, acceptData.getApp().getId()); } catch (Exception e) { e.printStackTrace(); } shareInfoDTO = new AlipayXCXShareInfoVO(); shareInfoDTO.setPath(String.format("/pages/activity-detail/activity-detail?id=%s&joinInfo=%s", activityId, URLEncoder.encode(ActivityUtil.getShareJoinInfo(acceptData.getUid(), activityId)))); shareInfoDTO.setTitle(info.getTitle()); shareInfoDTO.setDesc(info.getDesc()); shareInfoDTO.setBgImgUrl(assistShareImage); vo.setAssistShareInfo(shareInfoDTO); } } //加入浏览记录 ActivityScanRecord record = new ActivityScanRecord(); record.setActivityId(activityId); record.setUid(acceptData.getUid()); activityScanRecordService.addRecord(record); AppConfig config = appConfigService.getConfigCache(acceptData.getApp().getId(), ConfigKeyEnum.disclaimers, acceptData.getVersion()); if (config != null) { vo.setDisclaimers(config.getValue()); } return JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(vo)); } /** * 获取推荐活动列表 * * @param acceptData * @param page * @return */ @ResponseBody @RequestMapping("getRecommendActivity") public String getRecommendActivity(AcceptData acceptData, int page) { List list = luckyActivityService.getRecommendActivity(acceptData.getApp().getId(), acceptData.getUid() + "", page, Constant.PAGE_SIZE); long count = luckyActivityService.getRecommendActivityCount(acceptData.getApp().getId(), acceptData.getUid() + ""); List activityIds = new ArrayList<>(); if (list != null && list.size() > 0) { for (LuckyActivity activity : list) { activityIds.add(activity.getId()); } } List dtoList = activityService.getActivityDetail(activityIds, acceptData.getApp().getId(), acceptData.getUid(), false); JSONObject data = new JSONObject(); data.put("data", JsonUtil.getSimpleGson().toJson(ActivityListItemInfoVOFactory.create(dtoList))); data.put("count", count); return JsonUtil.loadTrueResult(data); } /** * 获取赞助商的活动 * * @param acceptData * @param page * @return */ @ResponseBody @RequestMapping("getSponsorActivity") public String getSponsorActivity(AcceptData acceptData, Long sponsorId, Long activityId, int page) { List list = luckyActivityService.getActivityList(acceptData.getApp().getId(), sponsorId, getCanShowStateList(), Arrays.asList(new Long[]{activityId}), null, page, Constant.CLIENT_ACTIVITY_LIST_PAGE_SIZE); long count = luckyActivityService.countActivity(acceptData.getApp().getId(), sponsorId, getCanShowStateList(), null, Arrays.asList(new Long[]{activityId})); List activityIds = new ArrayList<>(); if (list != null && list.size() > 0) { for (LuckyActivity activity : list) { activityIds.add(activity.getId()); } } List dtoList = activityService.getActivityDetail(activityIds, acceptData.getApp().getId(), acceptData.getUid(), false); JSONObject data = new JSONObject(); data.put("data", JsonUtil.getSimpleGson().toJson(ActivityListItemInfoVOFactory.create(dtoList))); data.put("count", count); return JsonUtil.loadTrueResult(data); } /** * 获取浏览足迹 * * @param acceptData * @param page * @return */ @ResponseBody @RequestMapping("getScanActivityRecord") public String getScanActivityRecord(AcceptData acceptData, int page) { List list = activityScanRecordService.getRecordList(acceptData.getUid(), page, Constant.CLIENT_ACTIVITY_LIST_PAGE_SIZE); long count = activityScanRecordService.countRecord(acceptData.getUid()); List activityIds = new ArrayList<>(); if (list != null && list.size() > 0) { for (ActivityScanRecord record : list) { activityIds.add(record.getActivityId()); } } List dtoList = activityService.getActivityDetail(activityIds, acceptData.getApp().getId(), acceptData.getUid(), false); JSONObject data = new JSONObject(); data.put("data", JsonUtil.getSimpleGson().toJson(ActivityListItemInfoVOFactory.create(dtoList))); data.put("count", count); return JsonUtil.loadTrueResult(data); } private List getCanShowStateList() { List list = new ArrayList<>(); list.add(LuckyActivity.STATE_OPENED); list.add(LuckyActivity.STATE_STARTED); list.add(LuckyActivity.STATE_FINISH); return list; } }