|
|
@@ -28,147 +28,165 @@ import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class CouponSendService extends BaseService<CouponSend> {
|
|
|
|
|
|
- @Override
|
|
|
- public BaseMapper<CouponSend> getRepository() {
|
|
|
- return couponSendMapper;
|
|
|
- }
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private CouponSendMapper couponSendMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- //优惠券发出实体转换
|
|
|
- private CouponSendConvert couponSendConvert;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- //优惠券获取
|
|
|
- private CouponReceiveMapper couponReceiveMapper;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- //优惠券
|
|
|
- private CouponMapper couponMapper;
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 条件查询
|
|
|
- * @date : 2024/7/25 10:22
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<CouponSendResponse>> selectByCond(CouponSendQuery couponSendQuery) {
|
|
|
- return super.mergeListWithCount(couponSendQuery, couponSendMapper.selectByCond(couponSendQuery),
|
|
|
- couponSendMapper.countByCond(couponSendQuery));
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 条件查询-历史查询
|
|
|
- * @date : 2024/7/25 10:22
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Pagination
|
|
|
- public ResponseResultVO<PageList<CouponSendResponse>> selectByCondHistory(CouponSendQuery couponSendQuery) {
|
|
|
- return super.mergeListWithCount(couponSendQuery, couponSendMapper.selectByCondHistory(couponSendQuery),
|
|
|
- couponSendMapper.countByCond(couponSendQuery));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 新建
|
|
|
- * @date : 2024/7/25 13:07
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- public ResponseResultVO<?> insert(CouponSendVO couponSendVO) {
|
|
|
- //region 根据id查询数据
|
|
|
- CouponSendResponse couponSendResponse = couponSendMapper.selectById(couponSendVO.getCouponId());
|
|
|
- if(couponSendResponse!=null){
|
|
|
- //region 查询已助力人数
|
|
|
- List<CouponReceiveResponse> couponReceiveResponses = couponReceiveMapper.selectByCond(new CouponReceiveQuery().setCouponId(couponSendResponse.getCouponId()));
|
|
|
- int userNum = couponReceiveResponses.size();
|
|
|
-// if(couponReceiveResponses.size()>couponSendResponse.getUserNum()){
|
|
|
-// //所需助力人数已满
|
|
|
-// throw new BaseBusinessException(ErrorCodeEnum.THE_REQUIRED_NUMBER_OF_HELPERS_IS_FULL.getCode(),ErrorCodeEnum.THE_REQUIRED_NUMBER_OF_HELPERS_IS_FULL.getMessage());
|
|
|
-// }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 校验单据时间
|
|
|
- LocalDateTime endTime = couponSendMapper.selectEndTime( new CouponSendQuery()
|
|
|
- .setCouponId(couponSendVO.getCouponId()) )
|
|
|
- .getEndDate();
|
|
|
- //原时间戳
|
|
|
- long primaryTime = endTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
- //本次时间戳
|
|
|
- long thisTime = couponSendVO.getEndDate().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
- //本次发出时间大于截止日期
|
|
|
- if ( (thisTime / 1000) > (primaryTime / 1000)) {
|
|
|
-
|
|
|
- //region 新建
|
|
|
- this.insertCouponSend(couponSendVO);
|
|
|
- //endregion
|
|
|
-
|
|
|
- }
|
|
|
- //本次发出时间小于等于截止日期 并且助力人数未够 直接返回
|
|
|
- if ( (thisTime / 1000) <= (primaryTime / 1000) && userNum < couponSendResponse.getUserNum() ) {
|
|
|
- return ResponseResultUtil.success();
|
|
|
- }
|
|
|
- //本次发出时间小于等于截止日期 并且助力已满足 新建
|
|
|
- if ( (thisTime / 1000) <= (primaryTime / 1000) && userNum == couponSendResponse.getUserNum() ) {
|
|
|
-
|
|
|
- //region 新建
|
|
|
- this.insertCouponSend(couponSendVO);
|
|
|
- //endregion
|
|
|
- // 返回请求数据时系统的当前时间
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- couponSendVO.setNowTime(now.format(formatter));
|
|
|
- return ResponseResultUtil.success(couponSendVO);
|
|
|
- }
|
|
|
- //endregion
|
|
|
- }
|
|
|
- //endregion
|
|
|
-
|
|
|
- //region 不存在 新建
|
|
|
- else {
|
|
|
- //region 新建
|
|
|
- this.insertCouponSend(couponSendVO);
|
|
|
- //endregion
|
|
|
- }
|
|
|
- //endregion
|
|
|
- // 返回请求数据时系统的当前时间
|
|
|
- LocalDateTime now = LocalDateTime.now();
|
|
|
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
- couponSendVO.setNowTime(now.format(formatter));
|
|
|
- return ResponseResultUtil.success(couponSendVO);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 新建优惠券获取
|
|
|
- * @date : 2024/7/26 10:58
|
|
|
- * @author : 寇珊珊
|
|
|
- */
|
|
|
- @Transactional(rollbackFor = {Exception.class})
|
|
|
- public void insertCouponSend(CouponSendVO couponSendVO) {
|
|
|
- //查询优惠券
|
|
|
- List<CouponResponse> couponResponses = couponMapper.selectByCond(new CouponQuery());
|
|
|
- //发出时间
|
|
|
- couponSendVO.setSendDate(LocalDateTime.now());
|
|
|
- //截止时间
|
|
|
- Integer linkValidTimes = couponResponses.get(0).getLinkValidTimes();
|
|
|
- couponSendVO.setEndDate(couponSendVO.getSendDate().plusHours(linkValidTimes));
|
|
|
- CouponSend couponSend = couponSendConvert.convertToPo(couponSendVO);
|
|
|
- couponSendMapper.insert(couponSend);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @desc : 获取助力明细
|
|
|
- * @date : 2024/7/25 13:06
|
|
|
- * @author : 刘尧
|
|
|
- * */
|
|
|
- public ResponseResultVO<?> getCouponSendItem(CouponSendVO couponSendVO) {
|
|
|
- return ResponseResultUtil.success(couponSendMapper.selectCouponSendItem(couponSendVO));
|
|
|
- }
|
|
|
+ @Override
|
|
|
+ public BaseMapper<CouponSend> getRepository() {
|
|
|
+ return couponSendMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CouponSendMapper couponSendMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ //优惠券发出实体转换
|
|
|
+ private CouponSendConvert couponSendConvert;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ //优惠券获取
|
|
|
+ private CouponReceiveMapper couponReceiveMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ //优惠券
|
|
|
+ private CouponMapper couponMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 条件查询
|
|
|
+ * @date : 2024/7/25 10:22
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<PageList<CouponSendResponse>> selectByCond(CouponSendQuery couponSendQuery) {
|
|
|
+ return super.mergeListWithCount(couponSendQuery, couponSendMapper.selectByCond(couponSendQuery),
|
|
|
+ couponSendMapper.countByCond(couponSendQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 条件查询-历史查询
|
|
|
+ * @date : 2024/7/25 10:22
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Pagination
|
|
|
+ public ResponseResultVO<PageList<CouponSendResponse>> selectByCondHistory(CouponSendQuery couponSendQuery) {
|
|
|
+ return super.mergeListWithCount(couponSendQuery, couponSendMapper.selectByCondHistory(couponSendQuery),
|
|
|
+ couponSendMapper.countByCond(couponSendQuery));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建
|
|
|
+ * @date : 2024/7/25 13:07
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public ResponseResultVO<?> insert(CouponSendVO couponSendVO) {
|
|
|
+
|
|
|
+// 20240801 判断是否当前用户 有未过期的 发出id
|
|
|
+ Map<String, Object> map = couponSendMapper.selectCouponSendItem(couponSendVO);
|
|
|
+ if (map != null) {
|
|
|
+ return ResponseResultUtil.success(map);
|
|
|
+ } else {
|
|
|
+ //region 新建
|
|
|
+ this.insertCouponSend(couponSendVO);
|
|
|
+ //endregion
|
|
|
+ // 返回请求数据时系统的当前时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ couponSendVO.setNowTime(now.format(formatter));
|
|
|
+ return ResponseResultUtil.success(couponSendVO);
|
|
|
+ }
|
|
|
+
|
|
|
+// 20240801
|
|
|
+// //region 根据id查询数据
|
|
|
+// CouponSendResponse couponSendResponse = couponSendMapper.selectById(couponSendVO.getCouponId());
|
|
|
+// if (couponSendResponse != null) {
|
|
|
+// //region 查询已助力人数
|
|
|
+// List<CouponReceiveResponse> couponReceiveResponses = couponReceiveMapper.selectByCond(new CouponReceiveQuery().setCouponId(couponSendResponse.getCouponId()));
|
|
|
+// int userNum = couponReceiveResponses.size();
|
|
|
+//// if(couponReceiveResponses.size()>couponSendResponse.getUserNum()){
|
|
|
+//// //所需助力人数已满
|
|
|
+//// throw new BaseBusinessException(ErrorCodeEnum.THE_REQUIRED_NUMBER_OF_HELPERS_IS_FULL.getCode(),ErrorCodeEnum.THE_REQUIRED_NUMBER_OF_HELPERS_IS_FULL.getMessage());
|
|
|
+//// }
|
|
|
+// //endregion
|
|
|
+//
|
|
|
+// //region 校验单据时间
|
|
|
+// LocalDateTime endTime = couponSendMapper.selectEndTime(new CouponSendQuery()
|
|
|
+// .setCouponId(couponSendVO.getCouponId()))
|
|
|
+// .getEndDate();
|
|
|
+// //原时间戳
|
|
|
+// long primaryTime = endTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
+// //本次时间戳
|
|
|
+// long thisTime = couponSendVO.getEndDate().toInstant(ZoneOffset.of("+8")).toEpochMilli();
|
|
|
+// //本次发出时间大于截止日期
|
|
|
+// if ((thisTime / 1000) > (primaryTime / 1000)) {
|
|
|
+//
|
|
|
+// //region 新建
|
|
|
+// this.insertCouponSend(couponSendVO);
|
|
|
+// //endregion
|
|
|
+//
|
|
|
+// }
|
|
|
+// //本次发出时间小于等于截止日期 并且助力人数未够 直接返回
|
|
|
+// if ((thisTime / 1000) <= (primaryTime / 1000) && userNum < couponSendResponse.getUserNum()) {
|
|
|
+// return ResponseResultUtil.success();
|
|
|
+// }
|
|
|
+// //本次发出时间小于等于截止日期 并且助力已满足 新建
|
|
|
+// if ((thisTime / 1000) <= (primaryTime / 1000) && userNum == couponSendResponse.getUserNum()) {
|
|
|
+//
|
|
|
+// //region 新建
|
|
|
+// this.insertCouponSend(couponSendVO);
|
|
|
+// //endregion
|
|
|
+// // 返回请求数据时系统的当前时间
|
|
|
+// LocalDateTime now = LocalDateTime.now();
|
|
|
+// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+// couponSendVO.setNowTime(now.format(formatter));
|
|
|
+// return ResponseResultUtil.success(couponSendVO);
|
|
|
+// }
|
|
|
+// //endregion
|
|
|
+// }
|
|
|
+// //endregion
|
|
|
+//
|
|
|
+// //region 不存在 新建
|
|
|
+// else {
|
|
|
+// //region 新建
|
|
|
+// this.insertCouponSend(couponSendVO);
|
|
|
+// //endregion
|
|
|
+// }
|
|
|
+// //endregion
|
|
|
+// // 返回请求数据时系统的当前时间
|
|
|
+// LocalDateTime now = LocalDateTime.now();
|
|
|
+// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+// couponSendVO.setNowTime(now.format(formatter));
|
|
|
+// return ResponseResultUtil.success(couponSendVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 新建优惠券获取
|
|
|
+ * @date : 2024/7/26 10:58
|
|
|
+ * @author : 寇珊珊
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = {Exception.class})
|
|
|
+ public void insertCouponSend(CouponSendVO couponSendVO) {
|
|
|
+ //查询优惠券
|
|
|
+ List<CouponResponse> couponResponses = couponMapper.selectByCond(new CouponQuery());
|
|
|
+ //发出时间
|
|
|
+ couponSendVO.setSendDate(LocalDateTime.now());
|
|
|
+ //截止时间
|
|
|
+ Integer linkValidTimes = couponResponses.get(0).getLinkValidTimes();
|
|
|
+ couponSendVO.setEndDate(couponSendVO.getSendDate().plusHours(linkValidTimes));
|
|
|
+ CouponSend couponSend = couponSendConvert.convertToPo(couponSendVO);
|
|
|
+ couponSendMapper.insert(couponSend);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @desc : 获取助力明细
|
|
|
+ * @date : 2024/7/25 13:06
|
|
|
+ * @author : 刘尧
|
|
|
+ */
|
|
|
+ public ResponseResultVO<?> getCouponSendItem(CouponSendVO couponSendVO) {
|
|
|
+ return ResponseResultUtil.success(couponSendMapper.selectCouponSendItem(couponSendVO));
|
|
|
+ }
|
|
|
}
|