| | |
| | | package com.ks.daylucky.controller.api.client; |
| | | |
| | | import com.ks.daylucky.pojo.DO.ActivityTag; |
| | | import com.ks.daylucky.pojo.DO.UserInfo; |
| | | import com.ks.daylucky.pojo.DO.ActivityScanRecord; |
| | | import com.ks.daylucky.pojo.DO.AppConfig; |
| | | import com.ks.daylucky.pojo.VO.ActivityShareInfoVO; |
| | | import com.ks.daylucky.pojo.DTO.AssistJoinInfoDTO; |
| | | import com.ks.daylucky.pojo.DTO.ConfigKeyEnum; |
| | | import com.ks.daylucky.pojo.VO.AcceptData; |
| | | import com.ks.daylucky.pojo.VO.ActivityDetailInfoVO; |
| | | import com.ks.daylucky.pojo.VO.SimpleUser; |
| | | import com.ks.daylucky.service.ActivityTagService; |
| | | import com.ks.daylucky.service.UserInfoService; |
| | | import com.ks.daylucky.pojo.DTO.ActivityDetailInfoDTO; |
| | | import com.ks.daylucky.pojo.VO.ActivityDetailVO; |
| | | import com.ks.daylucky.service.*; |
| | | import com.ks.daylucky.util.Constant; |
| | | import com.ks.daylucky.util.UserInfoUtil; |
| | | import com.ks.daylucky.util.RSAUtil; |
| | | 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.lucky.pojo.DO.LuckyActivity; |
| | | import com.ks.lucky.pojo.DO.LuckyActivityJoinRecord; |
| | | import com.ks.lucky.pojo.DTO.ActivitySimpleUser; |
| | | import com.ks.lucky.remote.service.LuckyActivityJoinService; |
| | | 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 org.yeshi.utils.encrypt.AESUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.security.AccessControlContext; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/client/activity") |
| | | public class ActivityController { |
| | | |
| | | @Resource |
| | | @Reference(version = "1.0.0") |
| | | private LuckyActivityService luckyActivityService; |
| | | |
| | | @Resource |
| | | private ActivityTagService activityTagService; |
| | | @Reference(version = "1.0.0") |
| | | private LuckyActivityJoinAssistService luckyActivityJoinAssistService; |
| | | |
| | | @Resource |
| | | private LuckyActivityJoinService luckyActivityJoinService; |
| | | private ActivityScanRecordService activityScanRecordService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | private ActivityService activityService; |
| | | |
| | | @Resource |
| | | private AppConfigService appConfigService; |
| | | |
| | | |
| | | /** |
| | | * 获取活动详情 |
| | | * |
| | | * @param acceptData |
| | | * @param activityId |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("getActivityDetail") |
| | | public String getActivityDetail(AcceptData acceptData, Long activityId) { |
| | | ActivityDetailInfoDTO dto = activityService.getActivityDetail(activityId, acceptData.getApp().getId(), acceptData.getUid(), true, 20, false); |
| | | if (dto == null) { |
| | | return JsonUtil.loadFalseResult("活动不存在"); |
| | | } |
| | | |
| | | ActivityDetailInfoVO vo = new ActivityDetailInfoVO(); |
| | | AppConfig help = appConfigService.getConfigCache(acceptData.getApp().getId(), ConfigKeyEnum.activityDetailHelp, acceptData.getVersion()); |
| | | |
| | | LuckyActivity actiivty = luckyActivityService.getActivityDetail(activityId); |
| | | //获取tag |
| | | List<ActivityTag> tagList = activityTagService.getTagList(activityId); |
| | | Integer assistCount = null; |
| | | if (dto.getJoin()) { |
| | | long count = luckyActivityJoinAssistService.countAssistRecord(activityId, acceptData.getApp().getId(), acceptData.getUid() + ""); |
| | | assistCount = (int) count; |
| | | } |
| | | |
| | | //获取参与者数量 |
| | | long count = luckyActivityJoinService.countWeightRank(activityId); |
| | | //查询赞助商已经开始的活动数量 |
| | | |
| | | //获取最近的参与者列表 |
| | | List<SimpleUser> userList = new ArrayList<>(); |
| | | luckyActivityJoinService.getJoinerList(activityId, 1, 20); |
| | | List<ActivitySimpleUser> list = luckyActivityJoinService.getJoinerList(activityId, 1, Constant.PAGE_SIZE); |
| | | 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); |
| | | |
| | | //分享信息 |
| | | |
| | | ActivityShareInfoVO shareInfoDTO = new ActivityShareInfoVO(); |
| | | shareInfoDTO.setPath(String.format("/pages/activity-detail/activity-detail?id=%s&joinInfo=%s", activityId, ActivityUtil.getShareJoinInfo(acceptData.getUid(), activityId))); |
| | | shareInfoDTO.setTitle("测试标题"); |
| | | shareInfoDTO.setDesc("测试简介"); |
| | | // shareInfoDTO.setBgImgUrl(); |
| | | vo.setShareInfo(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<LuckyActivity> list = luckyActivityService.getRecommendActivity(acceptData.getApp().getId(), acceptData.getUid() + "", page, Constant.PAGE_SIZE); |
| | | long count = luckyActivityService.getRecommendActivityCount(acceptData.getApp().getId(), acceptData.getUid() + ""); |
| | | |
| | | List<Long> activityIds = new ArrayList<>(); |
| | | if (list != null && list.size() > 0) { |
| | | Map<Long, UserInfo> userInfoMap = userInfoService.listUserInfoAsMap(UserInfoUtil.getBaseUserList(list)); |
| | | for (ActivitySimpleUser info : list) { |
| | | UserInfo user = userInfoMap.get(info.getUid()); |
| | | if (user != null) { |
| | | userList.add(new SimpleUser(user.getId(), user.getNickName(), user.getPortrait())); |
| | | } |
| | | for (LuckyActivity activity : list) { |
| | | activityIds.add(activity.getId()); |
| | | } |
| | | } |
| | | List<ActivityDetailInfoDTO> dtoList = activityService.getActivityDetail(activityIds, acceptData.getApp().getId(), acceptData.getUid(), false); |
| | | |
| | | //获取是否参加 |
| | | LuckyActivityJoinRecord record = luckyActivityJoinService.getJoinInfo(activityId, acceptData.getApp().getId(), acceptData.getUid() + ""); |
| | | |
| | | boolean join = false; |
| | | if (record != null) { |
| | | join = true; |
| | | //TODO 测试 |
| | | for (int i = 0; i < 20; i++) { |
| | | dtoList.add(dtoList.get(0)); |
| | | } |
| | | |
| | | vo.setActivity(actiivty); |
| | | vo.setJoin(join); |
| | | vo.setJoinerList(userList); |
| | | vo.setTagList(tagList); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("data", JsonUtil.getSimpleGson().toJson(ActivityListItemInfoVOFactory.create(dtoList))); |
| | | data.put("count", count); |
| | | return JsonUtil.loadTrueResult(data); |
| | | } |
| | | |
| | | return JsonUtil.loadTrueResult(vo); |
| | | |
| | | /** |
| | | * 获取赞助商的活动 |
| | | * |
| | | * @param acceptData |
| | | * @param page |
| | | * @return |
| | | */ |
| | | @ResponseBody |
| | | @RequestMapping("getSponsorActivity") |
| | | public String getSponsorActivity(AcceptData acceptData, Long sponsorId, int page) { |
| | | |
| | | List<LuckyActivity> list = luckyActivityService.getActivityList(acceptData.getApp().getId(), sponsorId, getCanShowStateList(), null, page, Constant.CLIENT_ACTIVITY_LIST_PAGE_SIZE); |
| | | long count = luckyActivityService.countActivity(acceptData.getApp().getId(), sponsorId, getCanShowStateList(), null); |
| | | |
| | | List<Long> activityIds = new ArrayList<>(); |
| | | if (list != null && list.size() > 0) { |
| | | for (LuckyActivity activity : list) { |
| | | activityIds.add(activity.getId()); |
| | | } |
| | | } |
| | | List<ActivityDetailInfoDTO> 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<ActivityScanRecord> list = activityScanRecordService.getRecordList(acceptData.getUid(), page, Constant.CLIENT_ACTIVITY_LIST_PAGE_SIZE); |
| | | long count = activityScanRecordService.countRecord(acceptData.getUid()); |
| | | |
| | | List<Long> activityIds = new ArrayList<>(); |
| | | if (list != null && list.size() > 0) { |
| | | for (ActivityScanRecord record : list) { |
| | | activityIds.add(record.getActivityId()); |
| | | } |
| | | } |
| | | List<ActivityDetailInfoDTO> 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<Integer> getCanShowStateList() { |
| | | List<Integer> list = new ArrayList<>(); |
| | | list.add(LuckyActivity.STATE_OPENED); |
| | | list.add(LuckyActivity.STATE_STARTED); |
| | | list.add(LuckyActivity.STATE_FINISH); |
| | | return list; |
| | | } |
| | | |
| | | |