Commit 1e1e9c13 authored by shiyu's avatar shiyu

专场进行中通知

parent fefc3f0a
package com.wwdz.ch.core.consts;
public class SpecialPerformanceEnum {
public enum TypeEnum {
AUCTION(1, "拍卖专场"),
;
private int code;
private String des;
TypeEnum(int code, String des) {
this.code = code;
this.des = des;
}
public static String getNameByCode(int code) {
for (SpecialPerformanceEnum.TypeEnum typeEnum : SpecialPerformanceEnum.TypeEnum.values()) {
if (code == typeEnum.getCode()) {
return typeEnum.getDes();
}
}
return null;
}
public int getCode() {
return code;
}
public String getDes() {
return des;
}
}
}
......@@ -44,12 +44,13 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
"/wx/consignSale/**", "/wx/item/**",
"/wx/returnOrder/**", "/wx/distributionOrder/confirmSigned", "/wx/distributionOrder/delivery", "/wx/distributionOrder/cancel",
"/wx/distributionOrder/refund",
"/wx/supplierItem/findItemsOfCurrentDistributor", "/wx/selfPage/updateSwitch", "/wx/supplierItem/findHomePage"
"/wx/supplierItem/findItemsOfCurrentDistributor", "/wx/selfPage/updateSwitch", "/wx/supplierItem/findHomePage",
"/wx/specialPerformance/sendMsg"
//下列路径上线注释
,"/wx/specialPerformance/**"
/*,"/wx/specialPerformance/**"
, "/wx/supplierItem/**", "/wx/shareRecord/**", "/wx/distributionOrder/**", "/wx/selfPage/**", "/wx/auctionRecord/**",
"/wx/shareRecord/**","/wx/collectionBook/**", "/wx/collectedRecord/**", "/wx/collectionItemsRelation/**","/wx/collectionShareRecord/**"
,"/wx/logistics/**","/wx/follow/**","/wx/user/findById","/wx/user/updateQrCode"
,"/wx/logistics/**","/wx/follow/**","/wx/user/findById","/wx/user/updateQrCode"*/
// , "/wx/supplierItem/**", "/wx/shareRecord/**", "/wx/distributionOrder/**", "/wx/selfPage/**", "/wx/auctionRecord/**"
/* "/wx/officialAccount/**",
......
package com.wwdz.ch.wx.impl.distribution;
import com.github.pagehelper.PageInfo;
import com.wwdz.ch.core.api.WxAppletApi;
import com.wwdz.ch.core.consts.DistributionEnum;
import com.wwdz.ch.core.consts.SpecialPerformanceEnum;
import com.wwdz.ch.core.entity.SupplierItemVo;
import com.wwdz.ch.core.notify.AliSmsSender;
import com.wwdz.ch.core.type.PageSearchResult;
import com.wwdz.ch.core.type.Result;
import com.wwdz.ch.core.util.MediaUtil;
import com.wwdz.ch.core.util.PriceUtil;
import com.wwdz.ch.core.util.RedisUtils;
import com.wwdz.ch.db.dao.UserDao;
import com.wwdz.ch.db.dao.distribution.*;
import com.wwdz.ch.db.domain.User;
import com.wwdz.ch.db.domain.distribution.*;
import com.wwdz.ch.db.dto.request.UserRequestDto;
import com.wwdz.ch.db.dto.request.distribution.AuctionRecordRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceConfigRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SupplierItemRequestDto;
import com.wwdz.ch.wx.entity.vo.distribution.SpecialPerformanceVo;
import com.wwdz.ch.wx.service.distribution.SpecialPerformanceService;
import com.xxdxxs.utils.DateUtils;
import com.xxdxxs.utils.EntityMapper;
import com.xxdxxs.utils.StringUtils;
import org.redisson.api.RLock;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -48,6 +58,23 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
@Autowired
AuctionConfigDao auctionConfigDao;
@Autowired
AliSmsSender aliSmsSender;
@Autowired
WxAppletApi wxAppletApi;
@Autowired
UserDao userDao;
@Autowired
RedisUtils redisUtils;
private final static String SPECIAL_PERFORMANCE_URL = "/pages/saleSpecialList/index";
private final static String SPECIAL_PERFORMANCE_PROGRESS_SEND_MSG_KEY = "SPECIAL_PERFORMANCE_PROGRESS_SEND_MSG_KEY:";
@Override
public Result findInfo(SpecialPerformanceRequestDto dto) {
try {
......@@ -220,4 +247,55 @@ public class SpecialPerformanceServiceImpl implements SpecialPerformanceService
}
return Result.failed();
}
@Override
public Result sendMsg() {
try {
SpecialPerformance specialPerformance = specialPerformanceDao.findByType(SpecialPerformanceEnum.TypeEnum.AUCTION.getCode());
if (specialPerformance == null) {
return Result.failed("专场信息为空");
}
logger.info("当前进行的专场id:{}, 名称为 {} ", specialPerformance.getId(), specialPerformance.getTitle());
String progressKey = SPECIAL_PERFORMANCE_PROGRESS_SEND_MSG_KEY + specialPerformance.getId();
if (!redisUtils.hasKey(progressKey)) {
//发送短信通知
String url = wxAppletApi.getUrlLink(SPECIAL_PERFORMANCE_URL, "specialId=" + specialPerformance.getId());
String msg = specialPerformance.getTitle() + "正在火热进行中,请前往" + url + "查看";
boolean hasNextPage = true;
int page = 1;
UserRequestDto userRequestDto = new UserRequestDto();
while (hasNextPage) {
List<User> userList = userDao.findList(userRequestDto);
PageInfo pageInfo = new PageInfo(userList);
for (User user : userList) {
String phone = user.getMobile();
if (StringUtils.hasLength(phone)) {
aliSmsSender.sendSms(phone, msg);
}
}
if (pageInfo.isHasNextPage()) {
page = page + 1;
userRequestDto.setPage(page);
logger.info("专场进行中要发送短信通知的用户数据总页数为 : {}, 当前为 : {}", pageInfo.getPages(), page);
} else {
hasNextPage = false;
logger.info("============= 发送专场进行中短信循环结束 =============");
}
if (page > 500) {
hasNextPage = false;
logger.info("============= 发送专场进行中短信超出上限,停止发送 =============");
}
}
logger.info("================专场id: {}, 进行中通知任务,提醒短信发送成功 ==============", specialPerformance.getId());
redisUtils.set(progressKey, specialPerformance.getId(), 3600 * 24);
} else {
return Result.failed("24小时内只能执行一次专场进行中通知任务");
}
return Result.success("专场进行中通知任务执行成功");
} catch (Exception e) {
logger.error("专场进行中通知任务 error {}", e);
}
return Result.failed();
}
}
......@@ -17,4 +17,10 @@ public interface SpecialPerformanceService {
* @return
*/
Result findItemList(SpecialPerformanceRequestDto dto);
/**
* 手动发送专场进行中短信给用户
* @return
*/
Result sendMsg();
}
......@@ -8,14 +8,12 @@ import com.wwdz.ch.db.dto.request.distribution.SpecialPerformanceRequestDto;
import com.wwdz.ch.db.dto.request.distribution.SupplierItemRequestDto;
import com.wwdz.ch.wx.service.distribution.DistributorShareRecordService;
import com.wwdz.ch.wx.service.distribution.SpecialPerformanceService;
import com.xxdxxs.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/wx/specialPerformance")
......@@ -23,6 +21,8 @@ public class SpecialPerformanceController {
private static final Logger logger = LoggerFactory.getLogger(SpecialPerformanceController.class);
private static final String SECRET = "018ff5941f36a8111519c8ebb9697d51";
@Autowired
SpecialPerformanceService specialPerformanceService;
......@@ -63,4 +63,17 @@ public class SpecialPerformanceController {
}
@ApiOperation(value = "发送专场进行中短信给用户")
@GetMapping("/sendMsg")
public Result sendMsg(@RequestParam("key") String key) {
logger.info(">>>>>>>>>>> 发送专场进行中短信给用户 <<<<<<<<<<<<<");
if (StringUtils.isEmpty(key) || !SECRET.equals(key)) {
return Result.failed(ResultCode.PARAM_ERROR);
}
return specialPerformanceService.sendMsg();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment