|
|
@@ -1,42 +1,184 @@
|
|
|
package com.dk.oauth.service.integral;
|
|
|
|
|
|
+import com.dk.common.exception.BaseBusinessException;
|
|
|
import com.dk.common.infrastructure.annotaiton.Pagination;
|
|
|
+import com.dk.common.infrastructure.constant.Constant;
|
|
|
+import com.dk.common.infrastructure.enums.ErrorCodeEnum;
|
|
|
import com.dk.common.model.pojo.PageList;
|
|
|
+import com.dk.common.response.ResponseCodeEnum;
|
|
|
import com.dk.common.response.ResponseResultUtil;
|
|
|
import com.dk.common.response.ResponseResultVO;
|
|
|
+import com.dk.oauth.mapper.integral.IntegralItemMapper;
|
|
|
+import com.dk.oauth.mapper.integral.IntegralMapper;
|
|
|
+import com.dk.oauth.mapper.integral.IntegralTacticMapper;
|
|
|
+import com.dk.oauth.model.VO.integral.CouponSendVO;
|
|
|
+import com.dk.oauth.model.VO.integral.SignRecordVO;
|
|
|
+import com.dk.oauth.model.pojo.integral.Integral;
|
|
|
+import com.dk.oauth.model.pojo.integral.IntegralItem;
|
|
|
+import com.dk.oauth.model.pojo.integral.IntegralTactic;
|
|
|
import com.dk.oauth.model.pojo.integral.SignRecord;
|
|
|
import com.dk.oauth.mapper.integral.SignRecordMapper;
|
|
|
import com.dk.common.service.BaseService;
|
|
|
import com.dk.common.mapper.BaseMapper;
|
|
|
import com.dk.oauth.model.query.integral.IntegralItemQuery;
|
|
|
+import com.dk.oauth.model.query.integral.IntegralTacticQuery;
|
|
|
import com.dk.oauth.model.query.integral.SignRecordQuery;
|
|
|
import com.dk.oauth.model.response.integral.IntegralItemResponse;
|
|
|
+import com.dk.oauth.model.response.integral.IntegralTacticResponse;
|
|
|
import com.dk.oauth.model.response.integral.SignRecordResponse;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class SignRecordService extends BaseService<SignRecord> {
|
|
|
|
|
|
- @Override
|
|
|
- public BaseMapper<SignRecord> getRepository() {
|
|
|
- return signRecordMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private SignRecordMapper signRecordMapper;
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 条件查询
|
|
|
- * @date : 2024/7/26 9:00
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<SignRecordResponse>> selectByCond(SignRecordQuery signRecordQuery) {
|
|
|
- return super.mergeListWithCount(signRecordQuery, signRecordMapper.selectByCond(signRecordQuery),
|
|
|
- signRecordMapper.countByCond(signRecordQuery));
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public BaseMapper<SignRecord> getRepository() {
|
|
|
+ return signRecordMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SignRecordMapper signRecordMapper;
|
|
|
+ @Autowired
|
|
|
+ private IntegralTacticMapper integralTacticMapper;
|
|
|
+ @Autowired
|
|
|
+ private IntegralMapper integralMapper;
|
|
|
+ @Autowired
|
|
|
+ private IntegralItemMapper integralItemMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 条件查询
|
|
|
+ * @date : 2024/7/26 9:00
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<PageList<SignRecordResponse>> selectByCond(SignRecordQuery signRecordQuery) {
|
|
|
+ return super.mergeListWithCount(signRecordQuery, signRecordMapper.selectByCond(signRecordQuery),
|
|
|
+ signRecordMapper.countByCond(signRecordQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建
|
|
|
+ * @date : 2024/7/25 13:07
|
|
|
+ * @author : jyh
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public ResponseResultVO<?> insert(SignRecordVO signRecordVO) {
|
|
|
+ // 积分策略
|
|
|
+ List<IntegralTacticResponse> integralTacticResponses = integralTacticMapper.selectByCond(new IntegralTacticQuery());
|
|
|
+ if (integralTacticResponses == null || integralTacticResponses.size() == 0) {
|
|
|
+ throw new BaseBusinessException(ResponseCodeEnum.INTEGRAL_TACTIC_EXIST.getCode(),
|
|
|
+ ErrorCodeEnum.INTEGRAL_TACTIC_EXIST.getMessage());
|
|
|
+ }
|
|
|
+ IntegralTacticResponse integralTactic = integralTacticResponses.get(0);
|
|
|
+ // 更新签到表
|
|
|
+ SignRecordQuery signRecordQuery = new SignRecordQuery();
|
|
|
+ signRecordQuery.setUserId(signRecordVO.getUserId());
|
|
|
+ signRecordQuery.setFlgValid(true);
|
|
|
+ List<SignRecordResponse> signRecordResponses = signRecordMapper.selectByCond(signRecordQuery);
|
|
|
+ // 是否包含当天的签到数据
|
|
|
+ if (signRecordResponses == null || signRecordResponses.size() == 0) {
|
|
|
+ //签到数据插入
|
|
|
+ SignRecord signRecord = new SignRecord();
|
|
|
+ signRecord.setCpId(signRecordVO.getCpId());
|
|
|
+ signRecord.setUserId(signRecordVO.getUserId());
|
|
|
+ signRecord.setSignDays(1);
|
|
|
+ signRecord.setLastDate(LocalDate.now());
|
|
|
+ signRecordMapper.insert(signRecord);
|
|
|
+ // 积分数据
|
|
|
+ this.insertIntegralData(integralTactic,signRecordVO,false);
|
|
|
+ } else {
|
|
|
+ // 签到表 包含数据
|
|
|
+ SignRecordResponse signRecordResponse = signRecordResponses.get(0);
|
|
|
+// int year = signRecordResponse.getLastDate().getYear();
|
|
|
+ // 当天已经签到了
|
|
|
+ if (LocalDate.now().compareTo(signRecordResponse.getLastDate()) == 0) {
|
|
|
+ return ResponseResultUtil.success(signRecordResponse.getLastDate());
|
|
|
+ }
|
|
|
+ // 连续昨天的
|
|
|
+ if (signRecordResponse.getLastDate().plusDays(1) == LocalDate.now()) {
|
|
|
+ //判断是否超过15天
|
|
|
+ //签到数据更新
|
|
|
+ SignRecord signRecord = new SignRecord();
|
|
|
+ signRecord.setRecordId(signRecordResponse.getRecordId());
|
|
|
+ if(signRecordResponse.getSignDays() == 15){
|
|
|
+ signRecord.setSignDays(1);
|
|
|
+ }else{
|
|
|
+ signRecord.setSignDays(1 + signRecordResponse.getSignDays());
|
|
|
+ }
|
|
|
+ signRecord.setLastDate(LocalDate.now());
|
|
|
+ signRecordMapper.updateById(signRecord);
|
|
|
+ // 积分数据--连续15天签到积分
|
|
|
+ if(signRecordResponse.getSignDays() + 1 == 15) {
|
|
|
+ this.insertIntegralData(integralTactic, signRecordVO, true);
|
|
|
+ }else{
|
|
|
+ this.insertIntegralData(integralTactic, signRecordVO, true);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //不连续 日期
|
|
|
+ //签到数据更新
|
|
|
+ SignRecord signRecord = new SignRecord();
|
|
|
+ signRecord.setRecordId(signRecordResponse.getRecordId());
|
|
|
+ signRecord.setSignDays(1);
|
|
|
+ signRecord.setLastDate(LocalDate.now());
|
|
|
+ signRecordMapper.updateById(signRecord);
|
|
|
+ // 积分数据
|
|
|
+ this.insertIntegralData(integralTactic,signRecordVO,false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResponseResultUtil.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 积分数据
|
|
|
+ * @author : 姜永辉
|
|
|
+ * @date : 2024/07/29 11:01
|
|
|
+ */
|
|
|
+ private void insertIntegralData(IntegralTacticResponse integralTactic, SignRecordVO signRecordVO, boolean sign) {
|
|
|
+ // 积分明细 -签到
|
|
|
+ IntegralItem integralItem = new IntegralItem();
|
|
|
+ // 积分类型-签到
|
|
|
+ integralItem.setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_SIGN.getName());
|
|
|
+ // 是否签到积分 15天签到积分
|
|
|
+ if (!sign) {
|
|
|
+ integralItem.setIntegral(integralTactic.getSignIntegral());
|
|
|
+ } else {
|
|
|
+ integralItem.setIntegral(integralTactic.getFifteenIntegral());
|
|
|
+ }
|
|
|
+ integralItem.setCpId(signRecordVO.getCpId());
|
|
|
+ integralItem.setAccDate(LocalDateTime.now());
|
|
|
+ integralItem.setUserId(signRecordVO.getUserId());
|
|
|
+ integralItemMapper.insert(integralItem);
|
|
|
+ // 更新或插入总积分的数据
|
|
|
+ // 积分 新公司的
|
|
|
+ Integral integral = new Integral();
|
|
|
+ integral.setCpId(signRecordVO.getCpId());
|
|
|
+ integral.setFlgValid(true);
|
|
|
+ List<Integral> integrals = integralMapper.selectByCond(integral);
|
|
|
+ if (integrals != null && integrals.size() > 0) {
|
|
|
+ // 是否签到积分 15天签到积分
|
|
|
+ if (!sign) {
|
|
|
+ integral.setIntegral(integralTactic.getSignIntegral() + integrals.get(0).getIntegral());
|
|
|
+ } else {
|
|
|
+ integral.setIntegral(integralTactic.getFifteenIntegral() + integrals.get(0).getIntegral());
|
|
|
+ }
|
|
|
+ integralMapper.updateById(integral);
|
|
|
+ } else {
|
|
|
+ // 是否签到积分 15天签到积分
|
|
|
+ if (!sign) {
|
|
|
+ integral.setIntegral(integralTactic.getSignIntegral());
|
|
|
+ } else {
|
|
|
+ integral.setIntegral(integralTactic.getFifteenIntegral());
|
|
|
+ }
|
|
|
+ integralMapper.insert(integral);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|