|
@@ -1,20 +1,120 @@
|
|
|
package com.kym.service.admin.impl;
|
|
package com.kym.service.admin.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
|
|
+import com.kym.common.utils.CommUtil;
|
|
|
|
|
+import com.kym.common.utils.IDGenerator;
|
|
|
import com.kym.entity.admin.Activity;
|
|
import com.kym.entity.admin.Activity;
|
|
|
|
|
+import com.kym.entity.admin.ActivityStation;
|
|
|
|
|
+import com.kym.entity.admin.RechargeRights;
|
|
|
|
|
+import com.kym.entity.admin.Station;
|
|
|
|
|
+import com.kym.entity.admin.queryParams.ActivityQueryParam;
|
|
|
|
|
+import com.kym.entity.admin.vo.ActivityVo;
|
|
|
|
|
+import com.kym.entity.common.PageBean;
|
|
|
import com.kym.mapper.admin.ActivityMapper;
|
|
import com.kym.mapper.admin.ActivityMapper;
|
|
|
import com.kym.service.admin.ActivityService;
|
|
import com.kym.service.admin.ActivityService;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
|
|
+import com.kym.service.admin.ActivityStationService;
|
|
|
|
|
+import com.kym.service.admin.RechargeRightsService;
|
|
|
|
|
+import com.kym.service.admin.StationService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+
|
|
|
|
|
+import static com.kym.entity.admin.Activity.APPLY_STATION_部分站点;
|
|
|
|
|
+import static com.kym.entity.admin.Activity.DISCOUNT_TYPE_服务费折扣权益;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* <p>
|
|
* <p>
|
|
|
- * 服务实现类
|
|
|
|
|
|
|
+ * 服务实现类
|
|
|
* </p>
|
|
* </p>
|
|
|
*
|
|
*
|
|
|
* @author skyline
|
|
* @author skyline
|
|
|
* @since 2023-10-18
|
|
* @since 2023-10-18
|
|
|
*/
|
|
*/
|
|
|
@Service
|
|
@Service
|
|
|
|
|
+@DS("db-admin")
|
|
|
|
|
+@Slf4j
|
|
|
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService {
|
|
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService {
|
|
|
|
|
|
|
|
|
|
+ private final ActivityStationService activityStationService;
|
|
|
|
|
+ private final RechargeRightsService rechargeRightsService;
|
|
|
|
|
+ private final StationService stationService;
|
|
|
|
|
+
|
|
|
|
|
+ public ActivityServiceImpl(ActivityStationService activityStationService, RechargeRightsService rechargeRightsService, StationService stationService) {
|
|
|
|
|
+ this.activityStationService = activityStationService;
|
|
|
|
|
+ this.rechargeRightsService = rechargeRightsService;
|
|
|
|
|
+ this.stationService = stationService;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 新增活动
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param activityVo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public ActivityVo createActivity(ActivityVo activityVo) {
|
|
|
|
|
+ // 新增activity
|
|
|
|
|
+ var activity = new Activity();
|
|
|
|
|
+ activity.setId(IDGenerator.INS().nextId());
|
|
|
|
|
+ BeanUtils.copyProperties(activityVo, activity);
|
|
|
|
|
+ save(activity);
|
|
|
|
|
+
|
|
|
|
|
+ // 新增activityStation
|
|
|
|
|
+ if (activityVo.getApplyStation() == APPLY_STATION_部分站点 && !CommUtil.isEmptyOrNull(activityVo.getStationIds())) {
|
|
|
|
|
+ var activityStationList = activityVo.getStationIds().stream().map(stationId -> new ActivityStation().setActivityId(activity.getId()).setStationId(stationId)).toList();
|
|
|
|
|
+ activityStationService.saveBatch(activityStationList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 新增rechargeRights
|
|
|
|
|
+ if (activityVo.getDiscountType().equals(DISCOUNT_TYPE_服务费折扣权益) && !CommUtil.isEmptyOrNull(activityVo.getRechargeRightsList())) {
|
|
|
|
|
+ var rechargeRightsList = activityVo.getRechargeRightsList().stream().peek(rechargeRights -> BeanUtils.copyProperties(activity, rechargeRights)).toList();
|
|
|
|
|
+ rechargeRightsService.saveBatch(rechargeRightsList);
|
|
|
|
|
+ activityVo.setRechargeRightsList(rechargeRightsList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return activityVo;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 主活动列表
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public PageBean<Activity> listActivity(ActivityQueryParam params) {
|
|
|
|
|
+ PageHelper.startPage(params.getPageNum(), params.getPageSize());
|
|
|
|
|
+ var list = lambdaQuery()
|
|
|
|
|
+ .like(CommUtil.isNotEmptyAndNull(params.getName()), Activity::getName, params.getName())
|
|
|
|
|
+ .eq(CommUtil.isNotEmptyAndNull(params.getStatus()), Activity::getStatus, params.getStatus())
|
|
|
|
|
+ .gt(CommUtil.isNotEmptyAndNull(params.getStartTime()), Activity::getStartTime, params.getStartTime())
|
|
|
|
|
+ .lt(CommUtil.isNotEmptyAndNull(params.getEndTime()), Activity::getEndTime, params.getEndTime())
|
|
|
|
|
+ .list();
|
|
|
|
|
+ return new PageBean<>(list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 活动详情
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param params
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HashMap<String, Object> activityDetail(ActivityQueryParam params) {
|
|
|
|
|
+ var res = new HashMap<String, Object>(2);
|
|
|
|
|
+ if (params.getDiscountType().equals(DISCOUNT_TYPE_服务费折扣权益)) {
|
|
|
|
|
+ var rechargeRightsList = rechargeRightsService.lambdaQuery().eq(RechargeRights::getActivityId, params.getId()).list();
|
|
|
|
|
+ res.put("rechargeRightsList", rechargeRightsList);
|
|
|
|
|
+ var activityStationIds = activityStationService.lambdaQuery().eq(ActivityStation::getActivityId, params.getId()).list().stream().map(ActivityStation::getStationId).toList();
|
|
|
|
|
+ var stationList = stationService.lambdaQuery().in(Station::getStationId, activityStationIds).list();
|
|
|
|
|
+ res.put("stationList", stationList);
|
|
|
|
|
+ }
|
|
|
|
|
+ return res;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|