1.优化
Showing
1 changed file
with
105 additions
and
73 deletions
1 | package com.topdraw.business.process.service.impl; | 1 | package com.topdraw.business.process.service.impl; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSON; | ||
3 | import com.alibaba.fastjson.JSONArray; | 4 | import com.alibaba.fastjson.JSONArray; |
4 | import com.alibaba.fastjson.JSONObject; | 5 | import com.alibaba.fastjson.JSONObject; |
6 | import com.google.gson.JsonObject; | ||
5 | import com.topdraw.business.module.coupon.service.CouponService; | 7 | import com.topdraw.business.module.coupon.service.CouponService; |
6 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; | 8 | import com.topdraw.business.module.coupon.service.dto.CouponDTO; |
7 | import com.topdraw.business.module.member.group.service.MemberGroupService; | 9 | import com.topdraw.business.module.member.group.service.MemberGroupService; |
... | @@ -111,14 +113,14 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -111,14 +113,14 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
111 | } | 113 | } |
112 | 114 | ||
113 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 | 115 | // 1.通过任务标识获取任务模板,通过模板参数获取具体的模板 |
114 | TaskTemplate taskTemplate = this.getTaskTemplate(event,dataSyncMsg); | 116 | TaskTemplate taskTemplate = this.getTaskTemplate(event, dataSyncMsg); |
115 | // 2.通过任务模板获取对应的任务列表 | 117 | // 2.通过任务模板获取对应的任务列表 |
116 | List<Task> taskList = this.loadListTaskByTaskTemplate(taskTemplate,dataSyncMsg); | 118 | List<Task> taskList = this.loadListTaskByTaskTemplate(taskTemplate, dataSyncMsg); |
117 | // 4.判断当前用户是否满足任务完成条件 | 119 | // 4.判断当前用户是否满足任务完成条件 |
118 | boolean checkResult = this.checkTaskCompletion(memberId,taskList); | 120 | boolean checkResult = this.checkTaskCompletion(memberId, taskList, event, msgData); |
119 | if (checkResult) { | 121 | if (checkResult) { |
120 | // 5.权益区分(积分、权益、成长值) | 122 | // 5.权益区分(积分、权益、成长值) |
121 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId,taskList,msgData); | 123 | Map<RightType,Object> tempRightsMap = this.distinguishRight(memberId, taskList, msgData); |
122 | 124 | ||
123 | // 6.风控检查 | 125 | // 6.风控检查 |
124 | boolean result = this.checkRiskManagement(memberId,tempRightsMap); | 126 | boolean result = this.checkRiskManagement(memberId,tempRightsMap); |
... | @@ -532,7 +534,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -532,7 +534,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
532 | * @return boolean true:success false:fail | 534 | * @return boolean true:success false:fail |
533 | */ | 535 | */ |
534 | //<taskId,boolean> | 536 | //<taskId,boolean> |
535 | private boolean checkTaskCompletion(Long memberId , List<Task> taskList) { | 537 | private boolean checkTaskCompletion(Long memberId , List<Task> taskList, Integer event, DataSyncMsg.MsgData msgData) { |
536 | if (!CollectionUtils.isEmpty(taskList)) { | 538 | if (!CollectionUtils.isEmpty(taskList)) { |
537 | // 会员信息 | 539 | // 会员信息 |
538 | MemberDTO memberDTO = this.memberService.findById(memberId); | 540 | MemberDTO memberDTO = this.memberService.findById(memberId); |
... | @@ -557,7 +559,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -557,7 +559,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
557 | return false; | 559 | return false; |
558 | 560 | ||
559 | // 获取当前任务的完成情况 | 561 | // 获取当前任务的完成情况 |
560 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList); | 562 | boolean result = this.checkAndRefreshTaskCompletion(memberId,taskList,event,msgData); |
561 | 563 | ||
562 | return result; | 564 | return result; |
563 | 565 | ||
... | @@ -673,7 +675,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -673,7 +675,7 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
673 | * @param taskStream | 675 | * @param taskStream |
674 | * @return boolean false:失败 true:成功 | 676 | * @return boolean false:失败 true:成功 |
675 | */ | 677 | */ |
676 | private boolean checkAndRefreshTaskCompletion(Long memberId , List<Task> taskStream) { | 678 | private boolean checkAndRefreshTaskCompletion(Long memberId , List<Task> taskStream, Integer event, DataSyncMsg.MsgData msgData) { |
677 | String time1 = LocalDateTimeUtil.todayStart(); | 679 | String time1 = LocalDateTimeUtil.todayStart(); |
678 | for (Task task : taskStream) { | 680 | for (Task task : taskStream) { |
679 | 681 | ||
... | @@ -690,85 +692,115 @@ public class TaskOperationServiceImpl implements TaskOperationService { | ... | @@ -690,85 +692,115 @@ public class TaskOperationServiceImpl implements TaskOperationService { |
690 | // 行为量(完成此任务需要多少次相同行为的触发) | 692 | // 行为量(完成此任务需要多少次相同行为的触发) |
691 | Integer actionAmount = task.getActionAmount(); | 693 | Integer actionAmount = task.getActionAmount(); |
692 | 694 | ||
693 | // 行为量 1 | 695 | switch (event) { |
694 | if (actionAmount == 1) { | 696 | // 播放记录 |
697 | case 8: | ||
698 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
699 | TrTaskProgressDTO trTaskProgressDTO_0 = trTaskProgressDTOS.get(0); | ||
700 | Integer status_0 = trTaskProgressDTO_0.getStatus(); | ||
701 | Integer currentActionAmount_0 = trTaskProgressDTO_0.getCurrentActionAmount(); | ||
702 | Timestamp completionTime_0 = trTaskProgressDTO_0.getCompletionTime(); | ||
703 | if (status_0 == 1 && currentActionAmount_0 != null && Objects.nonNull(completionTime_0)) { | ||
704 | return false; | ||
705 | } | ||
706 | } | ||
707 | String param = msgData.getParam(); | ||
708 | JSONObject jsonObject = JSON.parseObject(param); | ||
709 | Integer value = Integer.valueOf(jsonObject.get("playDuration").toString()); | ||
710 | if (value >= actionAmount) { | ||
711 | currentActionAmount = actionAmount; | ||
712 | completionTime = TimestampUtil.now(); | ||
713 | status = TASK_FINISH_STATUS; | ||
714 | } | ||
695 | 715 | ||
696 | if (CollectionUtils.isEmpty(trTaskProgressDTOS)) { | 716 | break; |
697 | currentActionAmount = 1; | ||
698 | completionTime = TimestampUtil.now(); | ||
699 | status = TASK_FINISH_STATUS; | ||
700 | } | ||
701 | 717 | ||
702 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | 718 | default: |
703 | // 此任务做过,但未完成 | 719 | // 行为量 1 |
704 | TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0); | 720 | if (actionAmount == 1) { |
705 | Long id_ = trTaskProgressDTO.getId(); | ||
706 | Integer status_ = trTaskProgressDTO.getStatus(); | ||
707 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | ||
708 | Timestamp completionTime1 = trTaskProgressDTO.getCompletionTime(); | ||
709 | |||
710 | // 任务已做,不成功 | ||
711 | if (Objects.nonNull(status_) && status_ == 1 && | ||
712 | Objects.nonNull(currentActionAmount_) && currentActionAmount_ == 1 && | ||
713 | Objects.nonNull(completionTime1) && | ||
714 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { | ||
715 | |||
716 | // 任务重复类型 | ||
717 | Integer taskDailyReset = task.getTaskDailyReset(); | ||
718 | if (taskDailyReset == -1) { | ||
719 | return true; | ||
720 | } else if (currentActionAmount_ < taskDailyReset){ | ||
721 | return true; | ||
722 | } | ||
723 | 721 | ||
722 | if (CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
723 | currentActionAmount = 1; | ||
724 | completionTime = TimestampUtil.now(); | ||
725 | status = TASK_FINISH_STATUS; | ||
726 | } | ||
724 | 727 | ||
725 | return false; | 728 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { |
729 | // 此任务做过,但未完成 | ||
730 | TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0); | ||
731 | Long id_ = trTaskProgressDTO.getId(); | ||
732 | Integer status_ = trTaskProgressDTO.getStatus(); | ||
733 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | ||
734 | Timestamp completionTime1 = trTaskProgressDTO.getCompletionTime(); | ||
735 | |||
736 | // 任务已做,不成功 | ||
737 | if (Objects.nonNull(status_) && status_ == 1 && | ||
738 | Objects.nonNull(currentActionAmount_) && currentActionAmount_ == 1 && | ||
739 | Objects.nonNull(completionTime1) && | ||
740 | completionTime1.toLocalDateTime().toLocalDate().compareTo(LocalDate.now()) == 0) { | ||
741 | |||
742 | // 任务重复类型 | ||
743 | Integer taskDailyReset = task.getTaskDailyReset(); | ||
744 | if (taskDailyReset == -1) { | ||
745 | return true; | ||
746 | } else if (currentActionAmount_ < taskDailyReset){ | ||
747 | return true; | ||
748 | } | ||
749 | |||
750 | |||
751 | return false; | ||
752 | |||
753 | // 未做,成功 | ||
754 | } else { | ||
755 | id = id_; | ||
756 | currentActionAmount = 1; | ||
757 | completionTime = TimestampUtil.now(); | ||
758 | status = TASK_FINISH_STATUS; | ||
759 | } | ||
726 | 760 | ||
727 | // 未做,成功 | 761 | } |
728 | } else { | ||
729 | id = id_; | ||
730 | currentActionAmount = 1; | ||
731 | completionTime = TimestampUtil.now(); | ||
732 | status = TASK_FINISH_STATUS; | ||
733 | } | 762 | } |
734 | 763 | ||
735 | } | 764 | // 行为量非1 |
736 | } | 765 | if (actionAmount != 1) { |
766 | |||
767 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
768 | // 此任务做过,但未完成 | ||
769 | TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0); | ||
770 | |||
771 | Long id_ = trTaskProgressDTO.getId(); | ||
772 | // 状态 0:未完成;1:已完成 | ||
773 | Integer status_ = trTaskProgressDTO.getStatus(); | ||
774 | Timestamp completionTime_ = trTaskProgressDTO.getCompletionTime(); | ||
775 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | ||
776 | // 行为量达到,完成 | ||
777 | if (status_ != 1 && Objects.isNull(completionTime_) && actionAmount == currentActionAmount_+1) { | ||
778 | id = id_; | ||
779 | currentActionAmount = actionAmount; | ||
780 | completionTime = TimestampUtil.now(); | ||
781 | status = TASK_FINISH_STATUS; | ||
782 | } else { | ||
783 | // 行为量未达到,未完成 | ||
784 | id = id_; | ||
785 | currentActionAmount = currentActionAmount_+1; | ||
786 | } | ||
737 | 787 | ||
738 | // 行为量非1 | 788 | } |
739 | if (actionAmount != 1) { | ||
740 | |||
741 | if (!CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
742 | // 此任务做过,但未完成 | ||
743 | TrTaskProgressDTO trTaskProgressDTO = trTaskProgressDTOS.get(0); | ||
744 | |||
745 | Long id_ = trTaskProgressDTO.getId(); | ||
746 | // 状态 0:未完成;1:已完成 | ||
747 | Integer status_ = trTaskProgressDTO.getStatus(); | ||
748 | Timestamp completionTime_ = trTaskProgressDTO.getCompletionTime(); | ||
749 | Integer currentActionAmount_ = trTaskProgressDTO.getCurrentActionAmount(); | ||
750 | // 行为量达到,完成 | ||
751 | if (status_ != 1 && Objects.isNull(completionTime_) && actionAmount == currentActionAmount_+1) { | ||
752 | id = id_; | ||
753 | currentActionAmount = actionAmount; | ||
754 | completionTime = TimestampUtil.now(); | ||
755 | status = TASK_FINISH_STATUS; | ||
756 | } else { | ||
757 | // 行为量未达到,未完成 | ||
758 | id = id_; | ||
759 | currentActionAmount = currentActionAmount_+1; | ||
760 | } | ||
761 | 789 | ||
762 | } | 790 | // 未达到行为量,未完成 |
791 | if (CollectionUtils.isEmpty(trTaskProgressDTOS)) { | ||
792 | currentActionAmount = 1; | ||
793 | status = TASK_UNFINISH_STATUS; | ||
794 | } | ||
763 | 795 | ||
764 | // 未达到行为量,未完成 | 796 | } |
765 | if (CollectionUtils.isEmpty(trTaskProgressDTOS)) { | 797 | |
766 | currentActionAmount = 1; | 798 | break; |
767 | status = TASK_UNFINISH_STATUS; | ||
768 | } | ||
769 | 799 | ||
770 | } | 800 | } |
771 | 801 | ||
802 | |||
803 | |||
772 | TrTaskProgress trTaskProgress = new TrTaskProgress(); | 804 | TrTaskProgress trTaskProgress = new TrTaskProgress(); |
773 | trTaskProgress.setId(id); | 805 | trTaskProgress.setId(id); |
774 | trTaskProgress.setCurrentActionAmount(currentActionAmount); | 806 | trTaskProgress.setCurrentActionAmount(currentActionAmount); | ... | ... |
-
Please register or sign in to post a comment