@@ -17,10 +17,10 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.annotation.Resource;
@@ -31,98 +31,108 @@ import java.util.stream.Collectors;
@RequestMapping("/api/couponSend")
@RequestMapping("/api/couponSend")
@Api(description = "商户注券相关接口")
@Api(description = "商户注券相关接口")
public class WxCouponSendController extends BaseController {
public class WxCouponSendController extends BaseController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private WxCouponSendService wxCouponSendService;
@Autowired
private WxCouponActionLogService wxCouponActionLogService;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private WxCouponSendService wxCouponSendService;
@Autowired
private WxCouponActionLogService wxCouponActionLogService;
@Resource
private WxCUserMapper wxCUserMapper;
@Resource
private WxCUserMapper wxCUserMapper;
@ApiOperation("查询商户注券列表")
@GetMapping("/list")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
})
public ResultData list(WxCouponSend wxCouponSend, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::list");
if (Objects.isNull(wxCouponSend.getSendType())) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setMerchantId(getUser().getMerchantId());
if (Objects.nonNull(wxCouponSend.getExpired()) && Objects.equals(wxCouponSend.getExpired(), 0)) {
wxCouponSend.setMerchantLnventory(0);
}
wxCouponSend.setStatus(wxCouponSend.getStatus());
//库存大于0
wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC);
final PageInfo<WxCouponSendVo> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize);
@ApiOperation("查询商户注券列表")
@GetMapping("/list")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
})
public ResultData list(WxCouponSend wxCouponSend, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::list");
if (Objects.isNull(wxCouponSend.getSendType())) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setMerchantId(getUser().getMerchantId());
if (Objects.nonNull(wxCouponSend.getExpired()) && Objects.equals(wxCouponSend.getExpired(), 0)) {
wxCouponSend.setMerchantLnventory(0);
}
wxCouponSend.setStatus(wxCouponSend.getStatus());
//库存大于0
if (Objects.isNull(wxCouponSend.getSortColumn())) {
wxCouponSend.setSortColumns(BaseEntity.SortField.CreateDate_DESC);
}
final PageInfo<WxCouponSendVo> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize);
for (WxCouponSendVo cs : page.getList()) {
cs.setSendCount(wxCouponActionLogService.getCountByChannelId(getTenantId(), cs.getSendType(), cs.getId()));
}
return new ResultData(page);
}
for (WxCouponSendVo cs : page.getList()) {
cs.setSendCount(wxCouponActionLogService.getCountByChannelId(getTenantId(), cs.getSendType(), cs.getId()));
}
return new ResultData(page);
}
@ApiOperation("商户注券")
@PostMapping("/handSel")
@ApiImplicitParams({
@ApiImplicitParam(name = "wxCouponSendIds", value = "CouponSend ID数组", dataType = "string",allowMultiple=true, paramType = "query", required = true),
@ApiImplicitParam(name = "cUserId", value = "用户ID", dataType = "long", paramType = "query", required = true),
})
public ResultData handSel(String[] wxCouponSendIds, Long cUserId ) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::handSel");
WxCUser cu = wxCUserMapper.selectByPrimaryKey(cUserId);
if (Objects.isNull(cu)) {
throw new MallinkException(ErrorCode.USER_IS_EMPTY);
}
if (ArrayUtils.isEmpty(wxCouponSendIds )) {
throw new MallinkException(ErrorCode.COUPON _IS_EMPTY);
}
@ApiOperation("商户注券")
@PostMapping("/handSel")
@ApiImplicitParams({
@ApiImplicitParam(name = "wxCouponSendIds", value = "CouponSend ID数组", dataType = "string", allowMultiple = true, paramType = "query", required = true),
@ApiImplicitParam(name = "cUserId", value = "用户ID", dataType = "long", paramType = "query", required = true),
})
public ResultData handSel(@RequestBody Map<String, Object> params ) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::handSel");
if (CollectionUtils.isEmpty(params)) {
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL);
}
WxCUser cu = wxCUserMapper.selectByPrimaryKey(params.get("cUserId"));
if (Objects.isNull(cu )) {
throw new MallinkException(ErrorCode.USER _IS_EMPTY);
}
WxCouponSend wxCouponSend = new WxCouponSend();
wxCouponSend.setIds(Arrays.stream(wxCouponSendIds).map(Long::parseLong).collect(Collectors.toList()));
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setSendType(EnumCouponSendSendType.MERCHANT.getCode());
wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode());
wxCouponSendService.handSel(wxCouponSend, cu);
return new ResultData();
}
if (!params.containsKey("wxCouponSendIds")) {
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}
@ApiOperation("注券记录")
@GetMapping("/actionLog")
@ApiImplicitParams({
@ApiImplicitParam(name = "channelType", value = "注券类型,商户注券=7", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "beginDate", value = "开始日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "endDate", value = "结束日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
})
public ResultData sendLog(Integer channelType, String beginDate, String endDate, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::actionLog");
Map<String, Object> params = new HashMap<>();
if (Objects.nonNull(beginDate)) {
Date begin = DateUtils.stringToDate(beginDate);
params.put("beginDate", begin);
}
List<String> wxCouponSendIds = (List<String>) params.get("wxCouponSendIds");
if (CollectionUtils.isEmpty(wxCouponSendIds)) {
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}
if (Objects.nonNull(endDate)) {
Date end = DateUtils.stringToDate(endDate);
Calendar cal = Calendar.getInstance();
cal.setTime(end);
cal.add(Calendar.DATE, 1);
params.put("endDate", cal.getTime());
}
params.put("tenantId", getTenantId());
params.put("channelType", channelType);
params.put("merchantId", getUser().getMerchantId());
PageInfo<WxCouponActionLogVo> data = wxCouponActionLogService.getActionLog(params, pageNum, pageSize);
return new ResultData(data);
}
WxCouponSend wxCouponSend = new WxCouponSend();
wxCouponSend.setIds(wxCouponSendIds.stream().map(Long::parseLong).collect(Collectors.toList()));
wxCouponSend.setTenantId(getTenantId());
wxCouponSend.setSendType(EnumCouponSendSendType.MERCHANT.getCode());
wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode());
wxCouponSendService.handSel(wxCouponSend, cu);
return new ResultData();
}
@ApiOperation("注券记录")
@GetMapping("/actionLog")
@ApiImplicitParams({
@ApiImplicitParam(name = "channelType", value = "注券类型,商户注券=7", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "beginDate", value = "开始日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "endDate", value = "结束日期 yyyy-MM-dd", dataType = "string", paramType = "query"),
@ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true),
@ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true),
})
public ResultData sendLog(Integer channelType, String beginDate, String endDate, Integer pageNum, Integer pageSize) {
logger.debug("[" + getIpAddr() + "] WxCouponSendController::actionLog");
Map<String, Object> params = new HashMap<>();
if (Objects.nonNull(beginDate)) {
Date begin = DateUtils.stringToDate(beginDate);
params.put("beginDate", begin);
}
if (Objects.nonNull(endDate)) {
Date end = DateUtils.stringToDate(endDate);
Calendar cal = Calendar.getInstance();
cal.setTime(end);
cal.add(Calendar.DATE, 1);
params.put("endDate", cal.getTime());
}
params.put("tenantId", getTenantId());
params.put("channelType", channelType);
params.put("merchantId", getUser().getMerchantId());
PageInfo<WxCouponActionLogVo> data = wxCouponActionLogService.getActionLog(params, pageNum, pageSize);
return new ResultData(data);
}
}
}