|
|
@@ -30,158 +30,194 @@ 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.time.format.DateTimeFormatter;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class IntegralShareService extends BaseService<IntegralShare> {
|
|
|
|
|
|
- @Override
|
|
|
- public BaseMapper<IntegralShare> getRepository() {
|
|
|
- return integralShareMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IntegralShareMapper integralShareMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- //实体转换
|
|
|
- private IntegralShareConvert integralShareConvert;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- //积分策略
|
|
|
- private IntegralTacticMapper integralTacticMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private IntegralMapper integralMapper;
|
|
|
- @Autowired
|
|
|
- private IntegralItemMapper integralItemMapper;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 条件查询
|
|
|
- * @date : 2024/7/24 15:47
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<IntegralShareResponse>> selectByCond(IntegralShareQuery integralShareQuery) {
|
|
|
- return super.mergeListWithCount(integralShareQuery, integralShareMapper.selectByCond(integralShareQuery),
|
|
|
- integralShareMapper.countByCond(integralShareQuery));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 根据id查询
|
|
|
- * @date : 2024/7/26 8:55
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- public ResponseResultVO<?> selectById(Integer id) {
|
|
|
- IntegralShareResponse integralShareResponse = integralShareMapper.selectById(id);
|
|
|
- return ResponseResultUtil.success(integralShareResponse);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 新建
|
|
|
- * @date : 2024/7/30 13:13
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- public ResponseResultVO<?> insert(IntegralShareVO integralShareVO) {
|
|
|
- //region 查询积分策略每日可分享次数
|
|
|
- List<IntegralTacticResponse> integralTacticResponses = integralTacticMapper.selectByCond(new IntegralTacticQuery());
|
|
|
- if(integralTacticResponses==null){
|
|
|
- //积分策略不存在
|
|
|
- throw new BaseBusinessException(ErrorCodeEnum.INTEGRAL_TACTIC_EXIST.getCode(), ErrorCodeEnum.INTEGRAL_TACTIC_EXIST.getMessage());
|
|
|
- }
|
|
|
- IntegralTacticResponse integralTactic = integralTacticResponses.get(0);
|
|
|
- //每日分享次数
|
|
|
- Integer shareDayNum = integralTacticResponses.get(0).getShareDayNum();
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 判断当前是积分分享还是积分邀请
|
|
|
- if(Constant.IntegralType.INTEGRAL_TYPE_INVITE.getName().equals(integralShareVO.getIntegralType())){
|
|
|
- //region 查询积分分享 当日已经分享的次数
|
|
|
- Long shareSize = integralShareMapper.countByCond(new IntegralShareQuery()
|
|
|
- .setCpId(integralShareVO.getCpId())
|
|
|
- .setShareDateFlag(true)
|
|
|
- .setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_INVITE.getName())
|
|
|
- );
|
|
|
-
|
|
|
- //积分策略可每日分享次数 是否等于 当日已经分享的次数
|
|
|
- if(shareSize >0 ){
|
|
|
- //当日已进行过邀请
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
- //endregion
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 分享
|
|
|
- else{
|
|
|
- //region 查询积分分享 当日已经分享的次数
|
|
|
- Long shareSize = integralShareMapper.countByCond(new IntegralShareQuery()
|
|
|
- .setCpId(integralShareVO.getCpId())
|
|
|
- .setShareDateFlag(true)
|
|
|
- .setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_SHARE.getName())
|
|
|
- );
|
|
|
- //积分策略可每日分享次数 是否等于 当日已经分享的次数
|
|
|
- if(Long.valueOf(shareDayNum) == shareSize){
|
|
|
- //当日已无可分享次数
|
|
|
- throw new BaseBusinessException(ErrorCodeEnum.HERE_ARE_NO_MORE_SHAREABLE_TIMES_ON_THAT_DAY.getCode(), ErrorCodeEnum.HERE_ARE_NO_MORE_SHAREABLE_TIMES_ON_THAT_DAY.getMessage());
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
- // 积分明细
|
|
|
- IntegralItem integralItem = new IntegralItem();
|
|
|
- integralItem.setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_REGISTER.getName());
|
|
|
- integralItem.setIntegral(integralTactic.getShareIntegral());
|
|
|
- integralItem.setCpId(integralShareVO.getCpId());
|
|
|
- integralItem.setAccDate(LocalDateTime.now());
|
|
|
- integralItem.setUserId(integralShareVO.getUserId());
|
|
|
- integralItem.setStaffName(integralShareVO.getStaffName());
|
|
|
- integralItemMapper.insert(integralItem);
|
|
|
- // 积分 新公司的
|
|
|
- Integral integral = new Integral();
|
|
|
- integral.setCpId(integralShareVO.getCpId());
|
|
|
- integral.setFlgValid(true);
|
|
|
- IntegralQuery integralQuery = new IntegralQuery();
|
|
|
- integralQuery.setCpId(integralShareVO.getCpId());
|
|
|
- integralQuery.setFlgValid(true);
|
|
|
- List<IntegralResponse> integralResponses = integralMapper.selectByCond(integralQuery);
|
|
|
- if (integralResponses != null && integralResponses.size() > 0) {
|
|
|
- integral.setIntegral(integralTactic.getShareIntegral() );
|
|
|
- integralMapper.updateById(integral);
|
|
|
- }else{
|
|
|
- integral.setIntegral(integralTactic.getShareIntegral());
|
|
|
- integralMapper.insert(integral);
|
|
|
- }
|
|
|
-
|
|
|
- //endregion
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 新建
|
|
|
- //分享时间
|
|
|
- integralShareVO.setShareDate(LocalDateTime.now());
|
|
|
- //截止时间
|
|
|
- integralShareVO.setEndDate(LocalDateTime.now().plusDays(integralTacticResponses.get(0).getShareValidTimes()));
|
|
|
- //实体转换
|
|
|
- IntegralShare integralShare = integralShareConvert.convertToPo(integralShareVO);
|
|
|
- //新建
|
|
|
- integralShareMapper.insert(integralShare);
|
|
|
- //endregion
|
|
|
-
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public BaseMapper<IntegralShare> getRepository() {
|
|
|
+ return integralShareMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IntegralShareMapper integralShareMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ //实体转换
|
|
|
+ private IntegralShareConvert integralShareConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ //积分策略
|
|
|
+ private IntegralTacticMapper integralTacticMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IntegralMapper integralMapper;
|
|
|
+ @Autowired
|
|
|
+ private IntegralItemMapper integralItemMapper;
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 条件查询
|
|
|
+ * @date : 2024/7/24 15:47
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<PageList<IntegralShareResponse>> selectByCond(IntegralShareQuery integralShareQuery) {
|
|
|
+ return super.mergeListWithCount(integralShareQuery, integralShareMapper.selectByCond(integralShareQuery),
|
|
|
+ integralShareMapper.countByCond(integralShareQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 根据id查询
|
|
|
+ * @date : 2024/7/26 8:55
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> selectById(Integer id) {
|
|
|
+ IntegralShareResponse integralShareResponse = integralShareMapper.selectById(id);
|
|
|
+ return ResponseResultUtil.success(integralShareResponse);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建
|
|
|
+ * @date : 2024/7/30 13:13
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public ResponseResultVO<?> insert(IntegralShareVO integralShareVO) {
|
|
|
+ //region 查询积分策略每日可分享次数
|
|
|
+ List<IntegralTacticResponse> integralTacticResponses = integralTacticMapper.selectByCond(new IntegralTacticQuery());
|
|
|
+ if (integralTacticResponses == null) {
|
|
|
+ //积分策略不存在
|
|
|
+ throw new BaseBusinessException(ErrorCodeEnum.INTEGRAL_TACTIC_EXIST.getCode(), ErrorCodeEnum.INTEGRAL_TACTIC_EXIST.getMessage());
|
|
|
+ }
|
|
|
+ IntegralTacticResponse integralTactic = integralTacticResponses.get(0);
|
|
|
+ //每日分享次数
|
|
|
+ Integer shareDayNum = integralTacticResponses.get(0).getShareDayNum();
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 判断当前是积分分享还是积分邀请
|
|
|
+ if (Constant.IntegralType.INTEGRAL_TYPE_INVITE.getName().equals(integralShareVO.getIntegralType())) {
|
|
|
+ IntegralShareQuery integralShareQuery = new IntegralShareQuery()
|
|
|
+ .setCpId(integralShareVO.getCpId())
|
|
|
+ .setUserId(integralShareVO.getUserId())
|
|
|
+ .setShareDateFlag(true)
|
|
|
+ .setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_INVITE.getName());
|
|
|
+ //region 查询积分分享 当日已经分享的次数
|
|
|
+// Long shareSize = integralShareMapper.countByCond(integralShareQuery);
|
|
|
+ List<IntegralShareResponse> integralShareResponses = integralShareMapper.selectByCond(integralShareQuery);
|
|
|
+ //积分策略可每日分享次数 是否等于 当日已经分享的次数
|
|
|
+ if (integralShareResponses!=null && integralShareResponses.size() > 0) {
|
|
|
+ //当日已进行过邀请
|
|
|
+ IntegralShareResponse response = integralShareResponses.get(0);
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ response.setNowDate(now.format(formatter));
|
|
|
+ return ResponseResultUtil.success(response);
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 分享
|
|
|
+ else {
|
|
|
+ //region 查询积分分享 当日已经分享的次数
|
|
|
+ Long shareSize = integralShareMapper.countByCond(new IntegralShareQuery()
|
|
|
+ .setCpId(integralShareVO.getCpId())
|
|
|
+ .setUserId(integralShareVO.getUserId())
|
|
|
+ .setShareDateFlag(true)
|
|
|
+ .setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_SHARE.getName())
|
|
|
+ );
|
|
|
+ //积分策略可每日分享次数 是否等于 当日已经分享的次数
|
|
|
+ if (Long.valueOf(shareDayNum) == shareSize) {
|
|
|
+ //当日已无可分享次数
|
|
|
+ throw new BaseBusinessException(ErrorCodeEnum.HERE_ARE_NO_MORE_SHAREABLE_TIMES_ON_THAT_DAY.getCode(), ErrorCodeEnum.HERE_ARE_NO_MORE_SHAREABLE_TIMES_ON_THAT_DAY.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ // 积分明细
|
|
|
+ IntegralItem integralItem = new IntegralItem();
|
|
|
+ integralItem.setIntegralType(Constant.IntegralType.INTEGRAL_TYPE_SHARE.getName());
|
|
|
+ integralItem.setIntegral(integralTactic.getShareIntegral());
|
|
|
+ integralItem.setCpId(integralShareVO.getCpId());
|
|
|
+ integralItem.setAccDate(LocalDateTime.now());
|
|
|
+ integralItem.setUserId(integralShareVO.getUserId());
|
|
|
+ integralItem.setStaffName(integralShareVO.getStaffName());
|
|
|
+ integralItemMapper.insert(integralItem);
|
|
|
+ // 积分 新公司的
|
|
|
+ Integral integral = new Integral();
|
|
|
+ integral.setCpId(integralShareVO.getCpId());
|
|
|
+ integral.setFlgValid(true);
|
|
|
+ IntegralQuery integralQuery = new IntegralQuery();
|
|
|
+ integralQuery.setCpId(integralShareVO.getCpId());
|
|
|
+ integralQuery.setFlgValid(true);
|
|
|
+ List<IntegralResponse> integralResponses = integralMapper.selectByCond(integralQuery);
|
|
|
+ if (integralResponses != null && integralResponses.size() > 0) {
|
|
|
+ integral.setIntegral(integralTactic.getShareIntegral());
|
|
|
+ integralMapper.updateById(integral);
|
|
|
+ } else {
|
|
|
+ integral.setIntegral(integralTactic.getShareIntegral());
|
|
|
+ integralMapper.insert(integral);
|
|
|
+ }
|
|
|
+
|
|
|
+ //endregion
|
|
|
+ }
|
|
|
+ //endregion
|
|
|
+
|
|
|
+ //region 新建
|
|
|
+ //分享时间
|
|
|
+ integralShareVO.setShareDate(LocalDateTime.now());
|
|
|
+ //截止时间
|
|
|
+ if (Constant.IntegralType.INTEGRAL_TYPE_INVITE.getName().equals(integralShareVO.getIntegralType())) {
|
|
|
+ integralShareVO.setEndDate(LocalDateTime.now().plusHours(integralTacticResponses.get(0).getShareValidTimes()));
|
|
|
+ } else {
|
|
|
+ // 获取当前日期时间
|
|
|
+ LocalDate currentDateTime = LocalDate.now(); // 设置时间为23点59分
|
|
|
+
|
|
|
+ integralShareVO.setEndDate(LocalDateTime.of(currentDateTime.getYear(), currentDateTime.getMonth().getValue(),
|
|
|
+ currentDateTime.getDayOfMonth(), 23, 59, 59));
|
|
|
+ }
|
|
|
+ //实体转换
|
|
|
+ IntegralShare integralShare = integralShareConvert.convertToPo(integralShareVO);
|
|
|
+ //新建
|
|
|
+ integralShareMapper.insert(integralShare);
|
|
|
+ //endregion
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ integralShare.setNowTime(now.format(formatter));
|
|
|
+ return ResponseResultUtil.success(integralShare);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 查询历史记录
|
|
|
+ * @date : 2024/7/24 15:47
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<PageList<IntegralShareResponse>> selectHistoryRecord(IntegralShareQuery integralShareQuery) {
|
|
|
+ return super.mergeListWithCount(integralShareQuery, integralShareMapper.selectHistoryRecordByCond(integralShareQuery),
|
|
|
+ integralShareMapper.countByCond(integralShareQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 当日积分分享数
|
|
|
+ * @date : 2024/8/1 10:13
|
|
|
+ * @author : 刘尧
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> selectShareNumber(IntegralShareQuery integralShareQuery) {
|
|
|
+ return ResponseResultUtil.success(integralShareMapper.selectShareNumber(integralShareQuery));
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
- * @desc : 查询历史记录
|
|
|
- * @date : 2024/7/24 15:47
|
|
|
- * @author : 寇珊珊
|
|
|
+ * @desc : 当日积分邀请明细
|
|
|
+ * @date : 2024/8/1 10:36
|
|
|
+ * @author : 刘尧
|
|
|
*/
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<IntegralShareResponse>> selectHistoryRecord(IntegralShareQuery integralShareQuery) {
|
|
|
- return super.mergeListWithCount(integralShareQuery, integralShareMapper.selectHistoryRecordByCond(integralShareQuery),
|
|
|
- integralShareMapper.countByCond(integralShareQuery));
|
|
|
+ public ResponseResultVO<?> selectShareItem(IntegralShareQuery integralShareQuery) {
|
|
|
+ return ResponseResultUtil.success(integralShareMapper.selectShareItem(integralShareQuery));
|
|
|
}
|
|
|
}
|