新增功能

This commit is contained in:
2026-02-10 14:56:16 +08:00
parent 743bbc9e34
commit fb0cbea2dc
63 changed files with 5831 additions and 0 deletions

View File

@ -0,0 +1,218 @@
package com.fuint.common.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fuint.repository.model.MtUser;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
/**
* 积分记录实体类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public class RaffleDto implements Serializable {
private Integer id;
private String title;
private String brief;
private String hot;
private String image;
private String raffleType;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getBrief() {
return brief;
}
public void setBrief(String brief) {
this.brief = brief;
}
public String getHot() {
return hot;
}
public void setHot(String hot) {
this.hot = hot;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getRaffleType() {
return raffleType;
}
public void setRaffleType(String raffleType) {
this.raffleType = raffleType;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Integer getClick() {
return click;
}
public void setClick(Integer click) {
this.click = click;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
private String description;
private Integer click;
private Integer sort;
private Date createTime;
private Date updateTime;
private String status;
private String operator;
private Integer nowCnt;
private Integer allCnt;
private Integer rafflePoint;
public Integer getRafflePoint() {
return rafflePoint;
}
public void setRafflePoint(Integer rafflePoint) {
this.rafflePoint = rafflePoint;
}
public Integer getNowCnt() {
return nowCnt;
}
public void setNowCnt(Integer nowCnt) {
this.nowCnt = nowCnt;
}
public Integer getAllCnt() {
return allCnt;
}
public void setAllCnt(Integer allCnt) {
this.allCnt = allCnt;
}
private String extraPrize;
private String extraImage;
private String extraType;
private Integer forwardPoint;
public String getExtraPrize() {
return extraPrize;
}
public void setExtraPrize(String extraPrize) {
this.extraPrize = extraPrize;
}
public String getExtraImage() {
return extraImage;
}
public void setExtraImage(String extraImage) {
this.extraImage = extraImage;
}
public String getExtraType() {
return extraType;
}
public void setExtraType(String extraType) {
this.extraType = extraType;
}
public Integer getForwardPoint() {
return forwardPoint;
}
public void setForwardPoint(Integer forwardPoint) {
this.forwardPoint = forwardPoint;
}
}

View File

@ -0,0 +1,187 @@
package com.fuint.common.dto;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
/**
* 抽奖表
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public class RaffleItemDto {
private Integer id;
private Integer raffleId;
private String title;
private String prize;
private Integer point;
private Integer userId;
private String userNo;
private String name;
private String image;
private Integer win;
private Integer deal;
private String description;
private Date createTime;
private Date updateTime;
private String operator;
private String forwardUserId;
private String prizeType;
public String getForwardUserId() {
return forwardUserId;
}
public void setForwardUserId(String forwardUserId) {
this.forwardUserId = forwardUserId;
}
public String getPrizeType() {
return prizeType;
}
public void setPrizeType(String prizeType) {
this.prizeType = prizeType;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getRaffleId() {
return raffleId;
}
public void setRaffleId(Integer raffleId) {
this.raffleId = raffleId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getPrize() {
return prize;
}
public void setPrize(String prize) {
this.prize = prize;
}
public Integer getPoint() {
return point;
}
public void setPoint(Integer point) {
this.point = point;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getUserNo() {
return userNo;
}
public void setUserNo(String userNo) {
this.userNo = userNo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public Integer getWin() {
return win;
}
public void setWin(Integer win) {
this.win = win;
}
public Integer getDeal() {
return deal;
}
public void setDeal(Integer deal) {
this.deal = deal;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public Date getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
}

View File

@ -0,0 +1,40 @@
package com.fuint.common.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 抽奖类型DTO
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Data
public class RaffleTypeDto implements Serializable {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("商户ID")
private Integer merchantId;
@ApiModelProperty("店铺ID")
private Integer storeId;
@ApiModelProperty("类型编码")
private String code;
@ApiModelProperty("类型名称")
private String name;
@ApiModelProperty("备注")
private String description;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("状态")
private String status;
}

View File

@ -0,0 +1,64 @@
package com.fuint.common.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 任务中心实体
*
* Created by Codex
*/
@Data
public class TaskDto implements Serializable {
@ApiModelProperty("自增ID")
private Integer id;
@ApiModelProperty("所属商户ID")
private Integer merchantId;
@ApiModelProperty("所属店铺ID")
private Integer storeId;
@ApiModelProperty("任务编码")
private String taskCode;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("任务类型")
private String taskType;
@ApiModelProperty("任务描述")
private String taskDesc;
@ApiModelProperty("任务跳转链接")
private String jumpUrl;
@ApiModelProperty("奖励积分")
private Integer rewardPoint;
@ApiModelProperty("每日可领取次数")
private Integer dailyLimit;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("最后操作人")
private String operator;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("创建时间")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("状态A正常D删除")
private String status;
}

View File

@ -0,0 +1,36 @@
package com.fuint.common.enums;
/**
* 订单类型
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public enum PrizeTypeEnum {
NORMAL("NORMAL", "普通奖"),
EXTRA("EXTRA", "额外奖");
private String key;
private String value;
PrizeTypeEnum(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,39 @@
package com.fuint.common.enums;
/**
* 订单类型
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public enum RaffleTypeEnum {
TCG("tcg", "集换式卡牌"),
GK("gk", "手办"),
GAME("game", "主机游戏"),
POPMART("popmart", "泡泡玛特"),
ALL("all", "所有");
private String key;
private String value;
RaffleTypeEnum(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

View File

@ -0,0 +1,20 @@
package com.fuint.common.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 卡券列表请求参数
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Data
public class RaffleParam extends PageParam implements Serializable {
private String dataType;
}

View File

@ -0,0 +1,31 @@
package com.fuint.common.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 抽奖类型分页请求参数
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Data
public class RaffleTypePage extends PageParam implements Serializable {
@ApiModelProperty("所属商户ID")
private Integer merchantId;
@ApiModelProperty("所属店铺ID")
private Integer storeId;
@ApiModelProperty("类型编码")
private String code;
@ApiModelProperty("类型名称")
private String name;
@ApiModelProperty("状态")
private String status;
}

View File

@ -0,0 +1,30 @@
package com.fuint.common.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 任务中心分页请求参数
*
* Created by Codex
*/
@Data
public class TaskPage extends PageParam implements Serializable {
@ApiModelProperty("所属商户ID")
private Integer merchantId;
@ApiModelProperty("所属店铺ID")
private Integer storeId;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("任务类型")
private String taskType;
@ApiModelProperty("状态")
private String status;
}

View File

@ -0,0 +1,26 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.dto.PointDto;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.model.MtGrow;
import com.fuint.repository.model.MtPoint;
/**
* 积分业务接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface GrowService extends IService<MtGrow> {
MtGrow querySignInfo(Integer userId);
boolean doSign(Integer id) throws BusinessCheckException;
boolean doAdv(Integer id) throws BusinessCheckException;
void clearAdvNum() throws BusinessCheckException;
}

View File

@ -0,0 +1,108 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.dto.PointDto;
import com.fuint.common.dto.RaffleDto;
import com.fuint.common.dto.RaffleItemDto;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.param.RaffleParam;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtPoint;
import com.fuint.repository.model.MtRaffle;
import com.fuint.repository.model.MtRaffleItem;
import com.fuint.repository.model.MtUser;
import java.util.List;
/**
* 抽奖业务接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface RaffleService extends IService<MtRaffle> {
/**
* 分页查询抽奖列表
*
* @param paginationRequest
* @return
*/
PaginationResponse<RaffleDto> queryListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException;
/**
* 保存抽奖
*
* @param reqRaffleDto
* @return
*/
int addRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException;
/**
* 保存抽奖明细
*
* @param reqRaffleItemDto
* @return
*/
void addRaffleItem(MtRaffleItem reqRaffleItemDto) throws BusinessCheckException;
/**
* 保存抽奖明细
*
* @param raffleItemDto
* @return
*/
List<MtRaffleItem> queryRaffleItemByRaffleId(RaffleItemDto raffleItemDto) throws BusinessCheckException;
List<RaffleItemDto> queryRaffleItemByRaffleId2wechat(Integer raffleId) throws BusinessCheckException;
List<MtRaffleItem> doRaffleByRaffleId(Integer raffleId,Integer num, UserInfo mtUser,Integer forwardUserId) throws BusinessCheckException;
ResponseObject findRaffleList(RaffleParam raffleParam) throws BusinessCheckException;
MtRaffle queryRaffle(Integer raffleId) throws BusinessCheckException;
/**
* 保存抽奖
*
* @param reqRaffleDto
* @return
*/
int updRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException;
/**
* 保存抽奖明细
*
* @param userId
* @return
*/
List<RaffleItemDto> queryRaffleItemByUserId(Integer userId) throws BusinessCheckException;
boolean tranfer2Point(Integer raffleItemId, Integer userId) throws BusinessCheckException;
Integer userPoint(Integer userId) throws BusinessCheckException;
boolean dealRaffleItem(Integer raffleItemId, String name) throws BusinessCheckException;
/**
* 最新抽奖列表
*
* @param limit
* @return
*/
List<RaffleDto> getLatestRaffles(Integer limit) throws BusinessCheckException;
/**
* 最新中奖列表
*
* @param limit
* @return
*/
List<RaffleItemDto> getLatestWinItems(Integer limit) throws BusinessCheckException;
}

View File

@ -0,0 +1,28 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.param.RaffleTypePage;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.model.MtRaffleType;
import java.util.List;
/**
* 抽奖类型服务接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface RaffleTypeService extends IService<MtRaffleType> {
PaginationResponse<MtRaffleType> queryRaffleTypeListByPagination(RaffleTypePage page) throws BusinessCheckException;
MtRaffleType addRaffleType(MtRaffleType raffleType) throws BusinessCheckException;
MtRaffleType getRaffleTypeById(Integer id) throws BusinessCheckException;
MtRaffleType updateRaffleType(MtRaffleType raffleType) throws BusinessCheckException;
List<MtRaffleType> getAvailableRaffleType(Integer merchantId, Integer storeId) throws BusinessCheckException;
}

View File

@ -0,0 +1,59 @@
package com.fuint.common.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.fuint.common.dto.TaskDto;
import com.fuint.common.param.TaskPage;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.model.MtTask;
import java.util.List;
import java.util.Map;
/**
* 任务中心业务接口
*
* Created by Codex
*/
public interface TaskService extends IService<MtTask> {
/**
* 分页查询列表
*/
PaginationResponse<MtTask> queryTaskListByPagination(TaskPage taskPage) throws BusinessCheckException;
/**
* 添加任务
*/
MtTask addTask(TaskDto taskDto) throws BusinessCheckException;
/**
* 根据ID获取任务信息
*/
MtTask queryTaskById(Integer id) throws BusinessCheckException;
/**
* 更新任务
*/
MtTask updateTask(TaskDto taskDto) throws BusinessCheckException;
/**
* 根据条件查询任务列表
*/
List<MtTask> queryTaskListByParams(Map<String, Object> params) throws BusinessCheckException;
/**
* 会员端任务列表(含完成/领取进度)
*/
List<Map<String, Object>> queryClientTaskList(Integer merchantId, Integer storeId, Integer userId) throws BusinessCheckException;
/**
* 完成任务
*/
Map<String, Object> completeTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException;
/**
* 领取任务奖励
*/
Map<String, Object> claimTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException;
}

View File

@ -0,0 +1,137 @@
package com.fuint.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.dto.PointDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.enums.WxMessageEnum;
import com.fuint.common.service.GrowService;
import com.fuint.common.service.MemberService;
import com.fuint.common.service.PointService;
import com.fuint.common.service.WeixinService;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.annoation.OperationServiceLog;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.mapper.MtGrowMapper;
import com.fuint.repository.mapper.MtPointMapper;
import com.fuint.repository.mapper.MtUserMapper;
import com.fuint.repository.model.MtGrow;
import com.fuint.repository.model.MtPoint;
import com.fuint.repository.model.MtRaffleItem;
import com.fuint.repository.model.MtUser;
import com.fuint.utils.StringUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* 积分管理业务实现类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Service
@AllArgsConstructor
public class GrowServiceImpl extends ServiceImpl<MtGrowMapper, MtGrow> implements GrowService {
private MtGrowMapper mtGrowMapper;
private PointService pointService;
private CouponServiceImpl couponService;
@Override
public MtGrow querySignInfo(Integer userId) {
LambdaQueryWrapper<MtGrow> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtGrow::getUserId, userId);
List<MtGrow> signInfoList = mtGrowMapper.selectList(lambdaQueryWrapper);
if (signInfoList != null && signInfoList.size() > 0) {
return signInfoList.get(0);
}
MtGrow signInfo = new MtGrow();
signInfo.setUserId(userId);
signInfo.setAdvNum(0);
signInfo.setAdvTotal(3);
signInfo.setGrowTotal(0);
signInfo.setCreateTime(new Date());
signInfo.setUpdateTime(new Date());
signInfo.setOperator("SYSTEM");
mtGrowMapper.insertForId(signInfo);
return signInfo;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean doSign(Integer id) throws BusinessCheckException {
//
MtGrow grow = mtGrowMapper.selectById(id);
MtGrow newGrow = new MtGrow();
newGrow.setId(grow.getId());
newGrow.setSignTime(new Date());
newGrow.setUpdateTime(new Date());
mtGrowMapper.updateById(newGrow);
MtPoint reqPointDto = new MtPoint();
reqPointDto.setAmount(1);
reqPointDto.setUserId(grow.getUserId());
reqPointDto.setDescription("签到1积分");
reqPointDto.setOperator("系统");
pointService.addPoint(reqPointDto);
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean doAdv(Integer id) throws BusinessCheckException {
//
MtGrow grow = mtGrowMapper.selectById(id);
MtGrow newGrow = new MtGrow();
newGrow.setId(grow.getId());
newGrow.setAdvNum(grow.getAdvNum()+1);
newGrow.setGrowTotal(grow.getGrowTotal() + 1);
newGrow.setUpdateTime(new Date());
mtGrowMapper.updateById(newGrow);
MtPoint reqPointDto = new MtPoint();
reqPointDto.setAmount(1);
reqPointDto.setUserId(grow.getUserId());
reqPointDto.setDescription("视频广告1积分");
reqPointDto.setOperator("系统");
pointService.addPoint(reqPointDto);
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
int nine = (newGrow.getGrowTotal())%9;
if (nine == 0) {
couponService.sendCoupon(13, grow.getUserId(),1,true,uuid,"SYSTEM");
}
int eleven = (newGrow.getGrowTotal())%11;
if (eleven == 0) {
couponService.sendCoupon(14, grow.getUserId(),1,true,uuid,"SYSTEM");
}
return true;
}
@Override
public void clearAdvNum() {
MtGrow et = new MtGrow();
et.setAdvNum(0);
Wrapper<MtGrow> ew = new LambdaQueryWrapper<>();
mtGrowMapper.update(et,ew);
}
}

View File

@ -0,0 +1,436 @@
package com.fuint.common.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.Constants;
import com.fuint.common.dto.*;
import com.fuint.common.enums.PrizeTypeEnum;
import com.fuint.common.enums.RaffleTypeEnum;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.enums.WxMessageEnum;
import com.fuint.common.param.RaffleParam;
import com.fuint.common.service.*;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.annoation.OperationServiceLog;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.ResponseObject;
import com.fuint.module.clientApi.controller.ClientRaffleController;
import com.fuint.repository.mapper.MtPointMapper;
import com.fuint.repository.mapper.MtRaffleItemMapper;
import com.fuint.repository.mapper.MtRaffleMapper;
import com.fuint.repository.mapper.MtUserMapper;
import com.fuint.repository.model.*;
import com.fuint.utils.StringUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
/**
* 积分管理业务实现类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Service
public class RaffleServiceImpl extends ServiceImpl<MtRaffleMapper, MtRaffle> implements RaffleService {
private static final Logger logger = LoggerFactory.getLogger(RaffleServiceImpl.class);
@Resource
private MtRaffleMapper mtRaffleMapper;
@Resource
private MtRaffleItemMapper mtRaffleItemMapper;
@Resource
private MtUserMapper mtUserMapper;
@Resource
private PointService pointService;
@Autowired
private SettingService settingService;
@Resource
private BalanceService balanceService;
/**
* 分页查询积分列表
*
* @param paginationRequest
* @return
*/
@Override
public PaginationResponse<RaffleDto> queryListByPagination(PaginationRequest paginationRequest) throws BusinessCheckException {
Page<MtPoint> pageHelper = PageHelper.startPage(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
LambdaQueryWrapper<MtRaffle> lambdaQueryWrapper = Wrappers.lambdaQuery();
String status = paginationRequest.getSearchParams().get("status") == null ? "" : paginationRequest.getSearchParams().get("status").toString();
String title = paginationRequest.getSearchParams().get("title") == null ? "" : paginationRequest.getSearchParams().get("title").toString();
if (StringUtils.isNotBlank(status)) {
lambdaQueryWrapper.eq(MtRaffle::getStatus, status);
}
if (StringUtils.isNotBlank(title)) {
lambdaQueryWrapper.like(MtRaffle::getTitle, title);
}
lambdaQueryWrapper.orderByDesc(MtRaffle::getCreateTime);
List<MtRaffle> raffleList = mtRaffleMapper.selectList(lambdaQueryWrapper);
List<RaffleDto> dataList = new ArrayList<>();
for (MtRaffle raffle : raffleList) {
RaffleDto item = new RaffleDto();
item.setId(raffle.getId());
item.setBrief(raffle.getBrief());
item.setTitle(raffle.getTitle());
item.setDescription(raffle.getDescription());
item.setRafflePoint(raffle.getRafflePoint());
item.setImage(raffle.getImage());
item.setRaffleType(raffle.getRaffleType());
item.setClick(raffle.getClick());
item.setHot(raffle.getHot());
item.setSort(raffle.getSort());
item.setNowCnt(raffle.getNowCnt());
item.setAllCnt(raffle.getAllCnt());
item.setDescription(raffle.getDescription());
item.setCreateTime(raffle.getCreateTime());
item.setUpdateTime(raffle.getUpdateTime());
item.setOperator(raffle.getOperator());
item.setStatus(raffle.getStatus());
dataList.add(item);
}
PageRequest pageRequest = PageRequest.of(paginationRequest.getCurrentPage(), paginationRequest.getPageSize());
PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
PaginationResponse<RaffleDto> paginationResponse = new PaginationResponse(pageImpl, RaffleDto.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(dataList);
return paginationResponse;
}
@Override
public int addRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException {
return mtRaffleMapper.insertForId(reqRaffleDto);
}
@Override
public void addRaffleItem(MtRaffleItem reqRaffleItemDto) throws BusinessCheckException {
mtRaffleItemMapper.insert(reqRaffleItemDto);
}
@Override
public List<MtRaffleItem> queryRaffleItemByRaffleId(RaffleItemDto raffleItemDto) throws BusinessCheckException {
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getRaffleId, raffleItemDto.getRaffleId());
if (raffleItemDto.getUserId() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getUserId, raffleItemDto.getUserId());
}
if (raffleItemDto.getWin() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getWin, raffleItemDto.getWin());
}
if (raffleItemDto.getDeal() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getDeal,raffleItemDto.getDeal());
}
if (raffleItemDto.getUserNo() != null) {
lambdaQueryWrapper.eq(MtRaffleItem::getUserNo,raffleItemDto.getUserNo());
}
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
return raffleList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public List<MtRaffleItem> doRaffleByRaffleId(Integer raffleId, Integer num, UserInfo userinfo, Integer forwardUserId) throws BusinessCheckException {
MtUser user = mtUserMapper.selectById(userinfo.getId());
//获取抽奖信息
MtRaffle mtRaffle = mtRaffleMapper.selectById(raffleId);
mtRaffle.setNowCnt(mtRaffle.getNowCnt()+num);
mtRaffleMapper.updateById(mtRaffle);
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getRaffleId, raffleId);
lambdaQueryWrapper.eq(MtRaffleItem::getWin, 0); //奖品状态 1已抽中 0未抽中
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
//扣减积分
MtPoint mtPoint = new MtPoint();
mtPoint.setUserId(user.getId());
mtPoint.setAmount(mtRaffle.getRafflePoint()*-1*num);
mtPoint.setDescription("一番赏:"+mtRaffle.getTitle()+ "/" + num+"");
pointService.addPoint(mtPoint);
//更新中奖信息
String baseImage = settingService.getUploadBasePath();
List<MtRaffleItem> resultList = new ArrayList<>();
for (int i = 0; i < num; i++) {
int removeNum = new Random().nextInt(raffleList.size());
MtRaffleItem mtRaffleItem = raffleList.get(removeNum);
mtRaffleItem.setUserId(user.getId());
mtRaffleItem.setUserNo(user.getUserNo());
mtRaffleItem.setWin(1);//奖品状态 1已抽中 0未抽中
mtRaffleItem.setName(user.getName());
mtRaffleItem.setUpdateTime(new Date());
mtRaffleItem.setForwardUserId(forwardUserId);
mtRaffleItemMapper.updateById(mtRaffleItem);
mtRaffleItem.setImage(baseImage + mtRaffleItem.getImage());
raffleList.remove(removeNum);
resultList.add(mtRaffleItem);
}
//判断额外奖是随机还是最终
List<MtRaffleItem> count = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
if (count.size() == 0 && StringUtil.isNotEmpty(mtRaffle.getExtraPrize())) {
logger.info(mtRaffle.getTitle()+"抽完准备出赏");
MtRaffleItem extraItem = new MtRaffleItem();
extraItem.setTitle(mtRaffle.getTitle());
extraItem.setPrize(mtRaffle.getExtraPrize());
extraItem.setImage(mtRaffle.getExtraImage());
extraItem.setPoint(mtRaffle.getRafflePoint());
extraItem.setRaffleId(mtRaffle.getId());
extraItem.setUserId(user.getId());
extraItem.setUserNo(user.getUserNo());
extraItem.setName(user.getName());
extraItem.setWin(1);//奖品状态 1已抽中 0未抽中
extraItem.setPrizeType(PrizeTypeEnum.EXTRA.getKey());
extraItem.setUpdateTime(new Date());
if ("L".equals(mtRaffle.getExtraType())) {
extraItem.setUserId(user.getId());
extraItem.setUserNo(user.getUserNo());
extraItem.setName(user.getName());
logger.info(mtRaffle.getTitle()+"最后出赏");
} else if ("R".equals(mtRaffle.getExtraType())) {
List<Integer> userIdlist = mtRaffleItemMapper.queryUserIdByRaffleId(mtRaffle.getId());
logger.info(mtRaffle.getTitle()+"随机出赏");
logger.info("随机用户ID" + JSONArray.toJSONString(userIdlist));
Integer userId = userIdlist.get(new Random().nextInt(userIdlist.size()));
MtUser extraUser = mtUserMapper.selectById(userId);
extraItem.setUserId(extraUser.getId());
extraItem.setUserNo(extraUser.getUserNo());
extraItem.setName(extraUser.getName());
}
mtRaffleItemMapper.insert(extraItem);
}
//转发奖励积分
if (forwardUserId > 0 && forwardUserId != user.getId() && mtRaffle.getForwardPoint() > 0) {
MtPoint forwardUser = new MtPoint();
forwardUser.setUserId(forwardUserId);
forwardUser.setAmount(mtRaffle.getForwardPoint()*num);
forwardUser.setDescription("推广一番赏:"+mtRaffle.getTitle()+ "/" + num+"次,转发奖励:"+forwardUser.getAmount()+"积分");
pointService.addPoint(forwardUser);
// MtBalance dto = new MtBalance();
// dto.setUserId(forwardUserId);
// dto.setAmount(BigDecimal.valueOf(mtRaffle.getForwardPoint()*num));
// dto.setDescription("推广一番赏:"+mtRaffle.getTitle()+ "/" + num+"次,转发奖励:"+dto.getAmount());
// dto.setOperator("system");
// balanceService.addBalance(dto);
}
return resultList;
}
@Override
public ResponseObject findRaffleList(RaffleParam raffleParam) throws BusinessCheckException {
Integer pageNumber = raffleParam.getPage() == null ? Constants.PAGE_NUMBER : raffleParam.getPage();
Integer pageSize = raffleParam.getPageSize() == null ? Constants.PAGE_SIZE : raffleParam.getPageSize();
String dataType = raffleParam.getDataType() == null ? null : raffleParam.getDataType();
Page<MtPoint> pageHelper = PageHelper.startPage(pageNumber, pageSize);
LambdaQueryWrapper<MtRaffle> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffle::getStatus, StatusEnum.ENABLED.getKey());
if (dataType != null && !RaffleTypeEnum.ALL.getKey().equals(dataType)) {
lambdaQueryWrapper.eq(MtRaffle::getRaffleType, dataType);
}
lambdaQueryWrapper.orderByDesc(MtRaffle::getCreateTime);
String baseImage = settingService.getUploadBasePath();
List<MtRaffle> raffleList = mtRaffleMapper.selectList(lambdaQueryWrapper);
List<RaffleDto> resultList = new ArrayList<>();
for (MtRaffle raffle:raffleList) {
RaffleDto dto = new RaffleDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage+raffle.getImage());
if (raffle.getExtraImage() != null) {
dto.setExtraImage(baseImage + raffle.getExtraImage());
}
resultList.add(dto);
}
PageRequest pageRequest = PageRequest.of(pageNumber, pageSize);
PageImpl pageImpl = new PageImpl(resultList, pageRequest, pageHelper.getTotal());
PaginationResponse<RaffleDto> paginationResponse = new PaginationResponse(pageImpl, RaffleDto.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(resultList);
return new ResponseObject(200, "查询成功", paginationResponse);
}
@Override
public MtRaffle queryRaffle(Integer raffleId) throws BusinessCheckException {
String baseImage = settingService.getUploadBasePath();
MtRaffle raffle = mtRaffleMapper.selectById(raffleId);
raffle.setImage(baseImage+raffle.getImage());
raffle.setExtraImage(baseImage+raffle.getExtraImage());
return raffle;
}
@Override
public int updRaffle(MtRaffle reqRaffleDto) throws BusinessCheckException {
return mtRaffleMapper.updateById(reqRaffleDto);
}
@Override
public List<RaffleItemDto> queryRaffleItemByUserId(Integer userId) throws BusinessCheckException {
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getUserId, userId);
lambdaQueryWrapper.eq(MtRaffleItem::getWin,1); //1已抽中
lambdaQueryWrapper.eq(MtRaffleItem::getDeal,0);//0未处理
lambdaQueryWrapper.orderByDesc(MtRaffleItem::getCreateTime);
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
String baseImage = settingService.getUploadBasePath();
List<RaffleItemDto> resultList = new ArrayList<>();
for (MtRaffleItem raffle:raffleList) {
RaffleItemDto dto = new RaffleItemDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage+raffle.getImage());
resultList.add(dto);
}
return resultList;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean tranfer2Point(Integer raffleItemId, Integer userId) throws BusinessCheckException {
MtUser user = mtUserMapper.selectById(userId);
MtRaffleItem item = mtRaffleItemMapper.selectById(raffleItemId);
//已转化积分或者已领取
if (item.getDeal() == 1) {
return false;
}
MtPoint mtPoint = new MtPoint();
mtPoint.setUserId(user.getId());
mtPoint.setAmount(item.getPoint());
mtPoint.setDescription("转化积分:"+item.getTitle());
pointService.addPoint(mtPoint);
item.setDeal(1); //1:已处理2未处理
item.setUpdateTime(new Date());
item.setOperator("操作人:" + userId);
mtRaffleItemMapper.updateById(item);
return true;
}
@Override
public Integer userPoint(Integer userId) throws BusinessCheckException {
MtUser user = mtUserMapper.selectById(userId);
return user.getPoint();
}
@Override
public boolean dealRaffleItem(Integer raffleItemId, String name) throws BusinessCheckException {
MtRaffleItem item = new MtRaffleItem();
item.setId(raffleItemId);
item.setDeal(1);
item.setOperator("操作人:" + name);
mtRaffleItemMapper.updateById(item);
return true;
}
@Override
public List<RaffleDto> getLatestRaffles(Integer limit) throws BusinessCheckException {
int size = (limit == null || limit <= 0) ? 5 : limit;
LambdaQueryWrapper<MtRaffle> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffle::getStatus, StatusEnum.ENABLED.getKey());
lambdaQueryWrapper.orderByDesc(MtRaffle::getCreateTime);
lambdaQueryWrapper.last("limit " + size);
String baseImage = settingService.getUploadBasePath();
List<MtRaffle> raffleList = mtRaffleMapper.selectList(lambdaQueryWrapper);
List<RaffleDto> resultList = new ArrayList<>();
for (MtRaffle raffle : raffleList) {
RaffleDto dto = new RaffleDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage + raffle.getImage());
if (raffle.getExtraImage() != null) {
dto.setExtraImage(baseImage + raffle.getExtraImage());
}
resultList.add(dto);
}
return resultList;
}
@Override
public List<RaffleItemDto> getLatestWinItems(Integer limit) throws BusinessCheckException {
int size = (limit == null || limit <= 0) ? 20 : limit;
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getWin, 1);
lambdaQueryWrapper.orderByDesc(MtRaffleItem::getCreateTime);
lambdaQueryWrapper.last("limit " + size);
String baseImage = settingService.getUploadBasePath();
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
List<RaffleItemDto> resultList = new ArrayList<>();
for (MtRaffleItem raffle : raffleList) {
RaffleItemDto dto = new RaffleItemDto();
BeanUtils.copyProperties(raffle, dto);
dto.setImage(baseImage + raffle.getImage());
resultList.add(dto);
}
return resultList;
}
@Override
public List<RaffleItemDto> queryRaffleItemByRaffleId2wechat(Integer raffleId) throws BusinessCheckException {
LambdaQueryWrapper<MtRaffleItem> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleItem::getRaffleId, raffleId);
lambdaQueryWrapper.eq(MtRaffleItem::getPrizeType, PrizeTypeEnum.NORMAL.getKey());
List<MtRaffleItem> raffleList = mtRaffleItemMapper.selectList(lambdaQueryWrapper);
List<RaffleItemDto> resultList = new ArrayList<>();
String baseImage = settingService.getUploadBasePath();
for (MtRaffleItem mtRaffleItem:raffleList) {
RaffleItemDto dto = new RaffleItemDto();
BeanUtils.copyProperties(mtRaffleItem, dto);
dto.setImage(baseImage+mtRaffleItem.getImage());
resultList.add(dto);
}
return resultList;
}
}

View File

@ -0,0 +1,156 @@
package com.fuint.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.RaffleTypePage;
import com.fuint.common.service.RaffleTypeService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.mapper.MtRaffleTypeMapper;
import com.fuint.repository.model.MtRaffleType;
import com.fuint.utils.StringUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* 抽奖类型服务实现类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Service
public class RaffleTypeServiceImpl extends ServiceImpl<MtRaffleTypeMapper, MtRaffleType> implements RaffleTypeService {
private static final Logger logger = LoggerFactory.getLogger(RaffleTypeServiceImpl.class);
private MtRaffleTypeMapper mtRaffleTypeMapper;
public RaffleTypeServiceImpl(MtRaffleTypeMapper mtRaffleTypeMapper) {
this.mtRaffleTypeMapper = mtRaffleTypeMapper;
}
@Override
public PaginationResponse<MtRaffleType> queryRaffleTypeListByPagination(RaffleTypePage page) {
Page<MtRaffleType> pageHelper = PageHelper.startPage(page.getPage(), page.getPageSize());
LambdaQueryWrapper<MtRaffleType> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.ne(MtRaffleType::getStatus, StatusEnum.DISABLE.getKey());
if (StringUtil.isNotEmpty(page.getName())) {
lambdaQueryWrapper.like(MtRaffleType::getName, page.getName());
}
if (StringUtil.isNotEmpty(page.getCode())) {
lambdaQueryWrapper.like(MtRaffleType::getCode, page.getCode());
}
if (StringUtil.isNotEmpty(page.getStatus())) {
lambdaQueryWrapper.eq(MtRaffleType::getStatus, page.getStatus());
}
if (page.getMerchantId() != null && page.getMerchantId() > 0) {
lambdaQueryWrapper.eq(MtRaffleType::getMerchantId, page.getMerchantId());
}
if (page.getStoreId() != null) {
lambdaQueryWrapper.and(wq -> wq
.eq(MtRaffleType::getStoreId, 0)
.or()
.eq(MtRaffleType::getStoreId, page.getStoreId()));
}
lambdaQueryWrapper.orderByAsc(MtRaffleType::getSort);
List<MtRaffleType> dataList = mtRaffleTypeMapper.selectList(lambdaQueryWrapper);
PageRequest pageRequest = PageRequest.of(page.getPage(), page.getPageSize());
PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
PaginationResponse<MtRaffleType> paginationResponse = new PaginationResponse(pageImpl, MtRaffleType.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(dataList);
return paginationResponse;
}
@Override
public MtRaffleType addRaffleType(MtRaffleType raffleType) throws BusinessCheckException {
if (raffleType.getMerchantId() == null || raffleType.getMerchantId() <= 0) {
throw new BusinessCheckException("新增抽奖类型失败:所属商户不能为空!");
}
if (StringUtil.isEmpty(raffleType.getName())) {
throw new BusinessCheckException("抽奖类型名称不能为空!");
}
if (StringUtil.isEmpty(raffleType.getCode())) {
throw new BusinessCheckException("抽奖类型编码不能为空!");
}
MtRaffleType entity = new MtRaffleType();
entity.setMerchantId(raffleType.getMerchantId());
entity.setStoreId(raffleType.getStoreId() == null ? 0 : raffleType.getStoreId());
entity.setName(raffleType.getName());
entity.setCode(raffleType.getCode());
entity.setDescription(raffleType.getDescription());
entity.setSort(raffleType.getSort() == null ? 0 : raffleType.getSort());
entity.setOperator(raffleType.getOperator());
entity.setStatus(StringUtil.isNotEmpty(raffleType.getStatus()) ? raffleType.getStatus() : StatusEnum.ENABLED.getKey());
entity.setCreateTime(new Date());
entity.setUpdateTime(new Date());
mtRaffleTypeMapper.insert(entity);
return entity;
}
@Override
public MtRaffleType getRaffleTypeById(Integer id) {
return mtRaffleTypeMapper.selectById(id);
}
@Override
public MtRaffleType updateRaffleType(MtRaffleType raffleType) throws BusinessCheckException {
MtRaffleType entity = getRaffleTypeById(raffleType.getId());
if (entity == null) {
throw new BusinessCheckException("抽奖类型不存在");
}
if (raffleType.getName() != null) {
entity.setName(raffleType.getName());
}
if (raffleType.getCode() != null) {
entity.setCode(raffleType.getCode());
}
if (raffleType.getStoreId() != null) {
entity.setStoreId(raffleType.getStoreId());
}
if (raffleType.getDescription() != null) {
entity.setDescription(raffleType.getDescription());
}
if (raffleType.getOperator() != null) {
entity.setOperator(raffleType.getOperator());
}
if (raffleType.getStatus() != null) {
entity.setStatus(raffleType.getStatus());
}
if (raffleType.getSort() != null) {
entity.setSort(raffleType.getSort());
}
entity.setUpdateTime(new Date());
mtRaffleTypeMapper.updateById(entity);
return entity;
}
@Override
public List<MtRaffleType> getAvailableRaffleType(Integer merchantId, Integer storeId) {
LambdaQueryWrapper<MtRaffleType> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(MtRaffleType::getStatus, StatusEnum.ENABLED.getKey());
if (merchantId != null && merchantId > 0) {
lambdaQueryWrapper.eq(MtRaffleType::getMerchantId, merchantId);
}
if (storeId != null && storeId > 0) {
lambdaQueryWrapper.and(wq -> wq.eq(MtRaffleType::getStoreId, 0).or().eq(MtRaffleType::getStoreId, storeId));
}
lambdaQueryWrapper.orderByAsc(MtRaffleType::getSort);
return mtRaffleTypeMapper.selectList(lambdaQueryWrapper);
}
}

View File

@ -0,0 +1,435 @@
package com.fuint.common.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fuint.common.dto.TaskDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.TaskPage;
import com.fuint.common.service.PointService;
import com.fuint.common.service.StoreService;
import com.fuint.common.service.TaskService;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.annoation.OperationServiceLog;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.repository.mapper.MtPointMapper;
import com.fuint.repository.mapper.MtTaskMapper;
import com.fuint.repository.mapper.MtTaskRecordMapper;
import com.fuint.repository.model.MtPoint;
import com.fuint.repository.model.MtStore;
import com.fuint.repository.model.MtTask;
import com.fuint.repository.model.MtTaskRecord;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 任务中心服务实现
*
* Created by Codex
*/
@Service
@AllArgsConstructor(onConstructor_ = {@Lazy})
public class TaskServiceImpl extends ServiceImpl<MtTaskMapper, MtTask> implements TaskService {
private static final Logger logger = LoggerFactory.getLogger(TaskServiceImpl.class);
private MtTaskMapper mtTaskMapper;
private MtTaskRecordMapper mtTaskRecordMapper;
private MtPointMapper mtPointMapper;
private PointService pointService;
private StoreService storeService;
@Override
public PaginationResponse<MtTask> queryTaskListByPagination(TaskPage taskPage) {
Page<MtTask> pageHelper = PageHelper.startPage(taskPage.getPage(), taskPage.getPageSize());
LambdaQueryWrapper<MtTask> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.ne(MtTask::getStatus, StatusEnum.DISABLE.getKey());
if (StringUtils.isNotBlank(taskPage.getTaskName())) {
lambdaQueryWrapper.like(MtTask::getTaskName, taskPage.getTaskName());
}
if (StringUtils.isNotBlank(taskPage.getTaskType())) {
lambdaQueryWrapper.eq(MtTask::getTaskType, taskPage.getTaskType());
}
if (StringUtils.isNotBlank(taskPage.getStatus())) {
lambdaQueryWrapper.eq(MtTask::getStatus, taskPage.getStatus());
}
if (taskPage.getMerchantId() != null) {
lambdaQueryWrapper.eq(MtTask::getMerchantId, taskPage.getMerchantId());
}
if (taskPage.getStoreId() != null) {
lambdaQueryWrapper.eq(MtTask::getStoreId, taskPage.getStoreId());
}
lambdaQueryWrapper.orderByAsc(MtTask::getSort).orderByDesc(MtTask::getId);
List<MtTask> dataList = mtTaskMapper.selectList(lambdaQueryWrapper);
PageRequest pageRequest = PageRequest.of(taskPage.getPage(), taskPage.getPageSize());
PageImpl pageImpl = new PageImpl(dataList, pageRequest, pageHelper.getTotal());
PaginationResponse<MtTask> paginationResponse = new PaginationResponse(pageImpl, MtTask.class);
paginationResponse.setTotalPages(pageHelper.getPages());
paginationResponse.setTotalElements(pageHelper.getTotal());
paginationResponse.setContent(dataList);
return paginationResponse;
}
@Override
@OperationServiceLog(description = "新增任务")
public MtTask addTask(TaskDto taskDto) throws BusinessCheckException {
MtTask mtTask = new MtTask();
BeanUtils.copyProperties(taskDto, mtTask);
Integer storeId = taskDto.getStoreId() == null ? 0 : taskDto.getStoreId();
if (taskDto.getMerchantId() == null || taskDto.getMerchantId() <= 0) {
MtStore mtStore = storeService.queryStoreById(storeId);
if (mtStore != null) {
mtTask.setMerchantId(mtStore.getMerchantId());
}
}
if (mtTask.getMerchantId() == null || mtTask.getMerchantId() <= 0) {
throw new BusinessCheckException("新增任务失败:所属商户不能为空!");
}
if (StringUtils.isBlank(mtTask.getTaskCode())) {
throw new BusinessCheckException("任务编码不能为空");
}
if (StringUtils.isBlank(mtTask.getTaskName())) {
throw new BusinessCheckException("任务名称不能为空");
}
LambdaQueryWrapper<MtTask> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTask::getMerchantId, mtTask.getMerchantId())
.eq(MtTask::getStoreId, storeId)
.eq(MtTask::getTaskCode, mtTask.getTaskCode())
.ne(MtTask::getStatus, StatusEnum.DISABLE.getKey());
if (mtTaskMapper.selectCount(wrapper) > 0) {
throw new BusinessCheckException("任务编码已存在,请更换后重试");
}
mtTask.setStoreId(storeId);
mtTask.setRewardPoint(mtTask.getRewardPoint() == null ? 0 : mtTask.getRewardPoint());
mtTask.setDailyLimit(mtTask.getDailyLimit() == null ? 1 : mtTask.getDailyLimit());
mtTask.setSort(mtTask.getSort() == null ? 0 : mtTask.getSort());
mtTask.setStatus(StringUtils.isBlank(mtTask.getStatus()) ? StatusEnum.ENABLED.getKey() : mtTask.getStatus());
mtTask.setCreateTime(new Date());
mtTask.setUpdateTime(new Date());
Integer id = mtTaskMapper.insert(mtTask);
if (id > 0) {
return mtTask;
}
logger.error("新增任务失败.");
throw new BusinessCheckException("抱歉,新增任务失败!");
}
@Override
public MtTask queryTaskById(Integer id) {
return mtTaskMapper.selectById(id);
}
@Override
@Transactional(rollbackFor = Exception.class)
@OperationServiceLog(description = "更新任务")
public MtTask updateTask(TaskDto taskDto) throws BusinessCheckException {
MtTask mtTask = queryTaskById(taskDto.getId());
if (mtTask == null) {
throw new BusinessCheckException("该任务不存在");
}
Integer targetStoreId = taskDto.getStoreId() == null ? mtTask.getStoreId() : taskDto.getStoreId();
if (StringUtils.isNotBlank(taskDto.getTaskCode())) {
LambdaQueryWrapper<MtTask> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTask::getMerchantId, mtTask.getMerchantId())
.eq(MtTask::getStoreId, targetStoreId)
.eq(MtTask::getTaskCode, taskDto.getTaskCode())
.ne(MtTask::getStatus, StatusEnum.DISABLE.getKey())
.ne(MtTask::getId, mtTask.getId());
if (mtTaskMapper.selectCount(wrapper) > 0) {
throw new BusinessCheckException("任务编码已存在,请更换后重试");
}
mtTask.setTaskCode(taskDto.getTaskCode());
}
if (StringUtils.isNotBlank(taskDto.getTaskName())) {
mtTask.setTaskName(taskDto.getTaskName());
}
if (taskDto.getStoreId() != null) {
mtTask.setStoreId(targetStoreId);
}
if (StringUtils.isNotBlank(taskDto.getTaskType())) {
mtTask.setTaskType(taskDto.getTaskType());
}
if (taskDto.getTaskDesc() != null) {
mtTask.setTaskDesc(taskDto.getTaskDesc());
}
if (taskDto.getJumpUrl() != null) {
mtTask.setJumpUrl(taskDto.getJumpUrl());
}
if (taskDto.getRewardPoint() != null) {
mtTask.setRewardPoint(taskDto.getRewardPoint());
}
if (taskDto.getDailyLimit() != null) {
mtTask.setDailyLimit(taskDto.getDailyLimit());
}
if (taskDto.getSort() != null) {
mtTask.setSort(taskDto.getSort());
}
if (taskDto.getOperator() != null) {
mtTask.setOperator(taskDto.getOperator());
}
if (taskDto.getStatus() != null) {
mtTask.setStatus(taskDto.getStatus());
}
mtTask.setUpdateTime(new Date());
mtTaskMapper.updateById(mtTask);
return mtTask;
}
@Override
public List<MtTask> queryTaskListByParams(Map<String, Object> params) {
String status = params.get("status") == null ? StatusEnum.ENABLED.getKey() : params.get("status").toString();
String storeId = params.get("storeId") == null ? "" : params.get("storeId").toString();
String merchantId = params.get("merchantId") == null ? "" : params.get("merchantId").toString();
LambdaQueryWrapper<MtTask> lambdaQueryWrapper = Wrappers.lambdaQuery();
if (StringUtils.isNotBlank(status)) {
lambdaQueryWrapper.eq(MtTask::getStatus, status);
}
if (StringUtils.isNotBlank(merchantId)) {
lambdaQueryWrapper.eq(MtTask::getMerchantId, merchantId);
}
if (StringUtils.isNotBlank(storeId)) {
lambdaQueryWrapper.and(wq -> wq
.eq(MtTask::getStoreId, 0)
.or()
.eq(MtTask::getStoreId, storeId));
}
lambdaQueryWrapper.orderByAsc(MtTask::getSort).orderByDesc(MtTask::getId);
return mtTaskMapper.selectList(lambdaQueryWrapper);
}
@Override
public List<Map<String, Object>> queryClientTaskList(Integer merchantId, Integer storeId, Integer userId) {
Map<String, Object> params = new HashMap<>();
params.put("merchantId", merchantId);
params.put("storeId", storeId);
params.put("status", StatusEnum.ENABLED.getKey());
List<MtTask> taskList = this.queryTaskListByParams(params);
Map<Integer, MtTaskRecord> recordMap = new HashMap<>();
if (userId != null && userId > 0) {
String taskDate = DateUtil.getNow(DateUtil.PATTERN_ISO_DATE);
LambdaQueryWrapper<MtTaskRecord> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTaskRecord::getMerchantId, merchantId)
.eq(MtTaskRecord::getUserId, userId)
.eq(MtTaskRecord::getTaskDate, taskDate)
.eq(MtTaskRecord::getStatus, StatusEnum.ENABLED.getKey());
List<MtTaskRecord> recordList = mtTaskRecordMapper.selectList(wrapper);
for (MtTaskRecord record : recordList) {
recordMap.put(record.getTaskId(), record);
}
}
List<Map<String, Object>> result = new ArrayList<>();
for (MtTask task : taskList) {
MtTaskRecord record = recordMap.get(task.getId());
int completeNum = record == null || record.getCompleteNum() == null ? 0 : record.getCompleteNum();
int claimNum = record == null || record.getClaimNum() == null ? 0 : record.getClaimNum();
int dailyLimit = task.getDailyLimit() == null ? 1 : task.getDailyLimit();
int rewardPoint = task.getRewardPoint() == null ? 0 : task.getRewardPoint();
Map<String, Object> item = new HashMap<>();
item.put("id", task.getId());
item.put("taskCode", task.getTaskCode());
item.put("taskName", task.getTaskName());
item.put("taskType", task.getTaskType());
item.put("taskDesc", task.getTaskDesc());
item.put("jumpUrl", task.getJumpUrl());
item.put("rewardPoint", rewardPoint);
item.put("dailyLimit", dailyLimit);
item.put("sort", task.getSort());
item.put("completeNum", completeNum);
item.put("claimNum", claimNum);
item.put("canComplete", completeNum < dailyLimit);
item.put("canClaim", claimNum < completeNum);
item.put("finished", claimNum >= dailyLimit);
result.add(item);
}
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> completeTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException {
MtTask taskInfo = queryTaskByScope(merchantId, storeId, taskId);
if (taskInfo == null) {
throw new BusinessCheckException("任务不存在或已下线");
}
int dailyLimit = taskInfo.getDailyLimit() == null ? 1 : taskInfo.getDailyLimit();
String taskDate = DateUtil.getNow(DateUtil.PATTERN_ISO_DATE);
Date nowTime = new Date();
MtTaskRecord record = getOrCreateRecord(merchantId, storeId, userId, taskId, taskDate, operator, nowTime);
int effect = mtTaskRecordMapper.incrCompleteNum(record.getId(), dailyLimit, nowTime);
if (effect < 1) {
throw new BusinessCheckException("今日任务已达上限");
}
MtTaskRecord latest = mtTaskRecordMapper.selectById(record.getId());
return buildTaskProgress(taskInfo, latest);
}
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> claimTask(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String operator) throws BusinessCheckException {
MtTask taskInfo = queryTaskByScope(merchantId, storeId, taskId);
if (taskInfo == null) {
throw new BusinessCheckException("任务不存在或已下线");
}
int dailyLimit = taskInfo.getDailyLimit() == null ? 1 : taskInfo.getDailyLimit();
int rewardPoint = taskInfo.getRewardPoint() == null ? 0 : taskInfo.getRewardPoint();
if (rewardPoint <= 0) {
throw new BusinessCheckException("该任务未配置奖励积分");
}
String taskDate = DateUtil.getNow(DateUtil.PATTERN_ISO_DATE);
Date nowTime = new Date();
MtTaskRecord record = getOrCreateRecord(merchantId, storeId, userId, taskId, taskDate, operator, nowTime);
int completeNum = record.getCompleteNum() == null ? 0 : record.getCompleteNum();
int claimNum = record.getClaimNum() == null ? 0 : record.getClaimNum();
if (claimNum >= dailyLimit) {
throw new BusinessCheckException("今日奖励已领取完");
}
if (claimNum >= completeNum) {
throw new BusinessCheckException("请先完成任务后再领取");
}
int nextClaimNum = claimNum + 1;
String orderSn = buildOrderSn(taskId, userId, taskDate, nextClaimNum);
LambdaQueryWrapper<MtPoint> pointWrapper = Wrappers.lambdaQuery();
pointWrapper.eq(MtPoint::getUserId, userId)
.eq(MtPoint::getOrderSn, orderSn)
.eq(MtPoint::getStatus, StatusEnum.ENABLED.getKey());
MtPoint existed = mtPointMapper.selectOne(pointWrapper);
if (existed != null) {
if (claimNum < nextClaimNum) {
mtTaskRecordMapper.incrClaimNumIfMatch(record.getId(), claimNum, nowTime);
record = mtTaskRecordMapper.selectById(record.getId());
}
return buildTaskProgress(taskInfo, record);
}
int effect = mtTaskRecordMapper.incrClaimNumIfMatch(record.getId(), claimNum, nowTime);
if (effect < 1) {
MtTaskRecord latest = mtTaskRecordMapper.selectById(record.getId());
int latestClaimNum = latest.getClaimNum() == null ? 0 : latest.getClaimNum();
if (latestClaimNum >= nextClaimNum) {
return buildTaskProgress(taskInfo, latest);
}
throw new BusinessCheckException("领取过于频繁,请稍后重试");
}
// 幂等发积分:同任务同日期同轮次固定 orderSn只会发一次
pointWrapper = Wrappers.lambdaQuery();
pointWrapper.eq(MtPoint::getUserId, userId)
.eq(MtPoint::getOrderSn, orderSn)
.eq(MtPoint::getStatus, StatusEnum.ENABLED.getKey());
existed = mtPointMapper.selectOne(pointWrapper);
if (existed == null) {
MtPoint reqPointDto = new MtPoint();
reqPointDto.setUserId(userId);
reqPointDto.setOrderSn(orderSn);
reqPointDto.setAmount(rewardPoint);
reqPointDto.setDescription("任务奖励:" + taskInfo.getTaskName() + " +" + rewardPoint + "积分");
reqPointDto.setOperator(operator);
pointService.addPoint(reqPointDto);
}
MtTaskRecord latest = mtTaskRecordMapper.selectById(record.getId());
return buildTaskProgress(taskInfo, latest);
}
private MtTask queryTaskByScope(Integer merchantId, Integer storeId, Integer taskId) {
LambdaQueryWrapper<MtTask> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTask::getId, taskId)
.eq(MtTask::getMerchantId, merchantId)
.eq(MtTask::getStatus, StatusEnum.ENABLED.getKey());
if (storeId != null && storeId > 0) {
wrapper.and(wq -> wq.eq(MtTask::getStoreId, 0).or().eq(MtTask::getStoreId, storeId));
}
return mtTaskMapper.selectOne(wrapper);
}
private MtTaskRecord getOrCreateRecord(Integer merchantId, Integer storeId, Integer userId, Integer taskId, String taskDate, String operator, Date nowTime) {
LambdaQueryWrapper<MtTaskRecord> wrapper = Wrappers.lambdaQuery();
wrapper.eq(MtTaskRecord::getMerchantId, merchantId)
.eq(MtTaskRecord::getTaskId, taskId)
.eq(MtTaskRecord::getUserId, userId)
.eq(MtTaskRecord::getTaskDate, taskDate)
.eq(MtTaskRecord::getStatus, StatusEnum.ENABLED.getKey());
MtTaskRecord record = mtTaskRecordMapper.selectOne(wrapper);
if (record != null) {
return record;
}
MtTaskRecord insertItem = new MtTaskRecord();
insertItem.setMerchantId(merchantId);
insertItem.setStoreId(storeId == null ? 0 : storeId);
insertItem.setTaskId(taskId);
insertItem.setUserId(userId);
insertItem.setTaskDate(taskDate);
insertItem.setCompleteNum(0);
insertItem.setClaimNum(0);
insertItem.setCreateTime(nowTime);
insertItem.setUpdateTime(nowTime);
insertItem.setOperator(operator);
insertItem.setStatus(StatusEnum.ENABLED.getKey());
try {
mtTaskRecordMapper.insert(insertItem);
return insertItem;
} catch (Exception e) {
// 并发下可能已创建,回查最新记录
return mtTaskRecordMapper.selectOne(wrapper);
}
}
private String buildOrderSn(Integer taskId, Integer userId, String taskDate, Integer seq) {
return "TASK-" + taskId + "-" + userId + "-" + taskDate.replace("-", "") + "-" + seq;
}
private Map<String, Object> buildTaskProgress(MtTask taskInfo, MtTaskRecord record) {
int completeNum = record == null || record.getCompleteNum() == null ? 0 : record.getCompleteNum();
int claimNum = record == null || record.getClaimNum() == null ? 0 : record.getClaimNum();
int dailyLimit = taskInfo.getDailyLimit() == null ? 1 : taskInfo.getDailyLimit();
Map<String, Object> result = new HashMap<>();
result.put("taskId", taskInfo.getId());
result.put("completeNum", completeNum);
result.put("claimNum", claimNum);
result.put("dailyLimit", dailyLimit);
result.put("canComplete", completeNum < dailyLimit);
result.put("canClaim", claimNum < completeNum);
result.put("finished", claimNum >= dailyLimit);
return result;
}
}

View File

@ -0,0 +1,315 @@
package com.fuint.module.backendApi.controller;
import com.alibaba.fastjson.JSONArray;
import com.fuint.common.Constants;
import com.fuint.common.dto.*;
import com.fuint.common.enums.*;
import com.fuint.common.param.RechargeParam;
import com.fuint.common.service.*;
import com.fuint.common.util.CommonUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.*;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.*;
/**
* 积分管理controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="管理端-积分相关接口")
@RestController
@RequestMapping(value = "/backendApi/raffle")
public class BackendRaffleController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(BackendRaffleController.class);
/**
* 积分服务接口
* */
@Autowired
private RaffleService raffleService;
/**
* 系统设置服务接口
* */
@Autowired
private SettingService settingService;
/**
* 积分明细列表查询
*
* @param request HttpServletRequest对象
* @return 积分明细列表
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer page = request.getParameter("page") == null ? Constants.PAGE_NUMBER : Integer.parseInt(request.getParameter("page"));
Integer pageSize = request.getParameter("pageSize") == null ? Constants.PAGE_SIZE : Integer.parseInt(request.getParameter("pageSize"));
String status = request.getParameter("status") == null ? StatusEnum.ENABLED.getKey() : request.getParameter("status");
String title = request.getParameter("title") == null ? "" : request.getParameter("title");
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
PaginationRequest paginationRequest = new PaginationRequest();
paginationRequest.setCurrentPage(page);
paginationRequest.setPageSize(pageSize);
Map<String, Object> searchParams = new HashMap<>();
if (StringUtil.isNotEmpty(status)) {
searchParams.put("status", status);
}
if (StringUtil.isNotEmpty(title)) {
searchParams.put("title", title);
}
paginationRequest.setSearchParams(searchParams);
PaginationResponse<RaffleDto> paginationResponse = raffleService.queryListByPagination(paginationRequest);
Map<String, Object> result = new HashMap<>();
result.put("dataList", paginationResponse);
String imagePath = settingService.getUploadBasePath();
result.put("imagePath", imagePath);
return getSuccessResult(result);
}
/**
* 提交保存
*
* @param request HttpServletRequest对象
* @return
*/
@RequestMapping(value = "/save", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject saveRaffleHandler(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
String title = param.get("title") == null ? "" : param.get("title").toString();
String brief = param.get("brief") == null ? "" : param.get("brief").toString();
String status = param.get("status") == null ? "A" : param.get("status").toString();
String image = param.get("image") == null ? "" : param.get("image").toString();
String description = param.get("description") == null ? "A" : param.get("description").toString();
Integer rafflePoint = param.get("rafflePoint") == null ? 0 : Integer.parseInt(param.get("rafflePoint").toString());
List<LinkedHashMap> rafList = param.get("rafData") == null ? new ArrayList<>() : (List) param.get("rafData");
String extraImage = param.get("extraImage") == null ? "" : param.get("extraImage").toString();
String extraType = param.get("extraType") == null ? "L" : param.get("extraType").toString();
String extraPrize = param.get("extraPrize") == null ? "" : param.get("extraPrize").toString();
Integer forwardPoint = 0;
if (StringUtil.isEmpty(param.get("forwardPoint").toString())) {
forwardPoint = Integer.parseInt(param.get("forwardPoint").toString());
}
String raffleType = param.get("raffleType") == null ? "pokemon" : param.get("raffleType").toString();
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
logger.info(JSONArray.toJSONString(param));
MtRaffle dto = new MtRaffle();
dto.setRaffleType(raffleType);
dto.setTitle(title);
dto.setBrief(brief);
dto.setStatus(status);
dto.setImage(image);
dto.setDescription(description);
dto.setRafflePoint(rafflePoint);
dto.setOperator(accountInfo.getAccountName());
dto.setCreateTime(new Date());
dto.setExtraImage(extraImage);
dto.setExtraType(extraType);
dto.setExtraPrize(extraPrize);
dto.setForwardPoint(forwardPoint);
raffleService.addRaffle(dto);
int allCnt = 0;
if (rafList.size() > 0) {
for (LinkedHashMap item: rafList) {
Integer num = Integer.parseInt(item.get("num").toString());
String raffleTitle = item.get("title") == null ? "" : item.get("title").toString();
String prize = item.get("prize") == null ? "" : item.get("prize").toString();
Integer point = item.get("point") == null ? 0 : Integer.parseInt(item.get("point").toString());
String raffleImage = item.get("image") == null ? "" : item.get("image").toString();
allCnt = allCnt + num;
for (int i = 0; i < num; i++) {
MtRaffleItem raffleItem = new MtRaffleItem();
raffleItem.setRaffleId(dto.getId());
raffleItem.setPrize(prize);
raffleItem.setTitle(raffleTitle);
raffleItem.setPoint(point);
raffleItem.setImage(raffleImage);
raffleItem.setOperator(accountInfo.getAccountName());
raffleItem.setPrizeType(PrizeTypeEnum.NORMAL.getKey());
raffleService.addRaffleItem(raffleItem);
}
}
}
dto.setNowCnt(0);
dto.setAllCnt(allCnt);
raffleService.updRaffle(dto);
return getSuccessResult(true);
}
/**
* 抽奖明细
*
* @param request HttpServletRequest对象
* @return
*/
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject detailRaffleHandler(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
String raffleId = request.getParameter("raffleId") == null ? "" : request.getParameter("raffleId");
String userId = request.getParameter("userId") == null ? "" : request.getParameter("userId");
String win = request.getParameter("win") == null ? "" : request.getParameter("win");
String deal = request.getParameter("deal") == null ? "" : request.getParameter("deal");
String userNo = request.getParameter("userNo") == null ? "" : request.getParameter("userNo");
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
RaffleItemDto raffleItemDto = new RaffleItemDto();
if (StringUtil.isNotEmpty(raffleId)) {
raffleItemDto.setRaffleId(Integer.parseInt(raffleId));
}
if (StringUtil.isNotEmpty(userId)) {
raffleItemDto.setUserId(Integer.parseInt(userId));
}
if (StringUtil.isNotEmpty(win)) {
raffleItemDto.setWin(Integer.parseInt(win));
}
if (StringUtil.isNotEmpty(deal)) {
raffleItemDto.setDeal(Integer.parseInt(deal));
}
if (StringUtil.isNotEmpty(userNo)) {
raffleItemDto.setUserNo(userNo);
}
logger.info("raffle detail condition: " + JSONArray.toJSONString(raffleItemDto));
List<MtRaffleItem> raffleList = raffleService.queryRaffleItemByRaffleId(raffleItemDto);
Map<String, Object> result = new HashMap<>();
result.put("rafList", raffleList);
String imagePath = settingService.getUploadBasePath();
result.put("imagePath", imagePath);
return getSuccessResult(result);
}
/**
* 抽奖基础信息
*
* @param request HttpServletRequest对象
* @return
*/
@RequestMapping(value = "/info", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject info(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
MtRaffle raffle = raffleService.queryRaffle(id);
if (raffle == null) {
return getFailureResult(201, "抽奖不存在");
}
Map<String, Object> result = new HashMap<>();
result.put("dataList", raffle);
String imagePath = settingService.getUploadBasePath();
result.put("imagePath", imagePath);
return getSuccessResult(result);
}
@RequestMapping(value = "/deal", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject deal(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id"));
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
logger.info("deal id: " + id);
raffleService.dealRaffleItem(id, accountInfo.getAccountName());
Map<String, Object> result = new HashMap<>();
result.put("deal", "succ");
return getSuccessResult(result);
}
/**
* 更新会员状态
*
* @return
*/
@RequestMapping(value = "/change", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject updateStatus(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
Integer id = request.getParameter("id") == null ? 0 : Integer.parseInt(request.getParameter("id").toString());
String status = request.getParameter("status") == null ? StatusEnum.ENABLED.getKey() : request.getParameter("status").toString();
AccountInfo accountInfo = TokenUtil.getAccountInfoByToken(token);
if (accountInfo == null) {
return getFailureResult(1001, "请先登录");
}
logger.info("changeStatus id="+id + " status=" + status);
MtRaffle raffle = raffleService.queryRaffle(id);
if (raffle == null) {
return getFailureResult(201, "抽奖不存在");
}
MtRaffle updraffle = new MtRaffle();
updraffle.setId(id);
updraffle.setStatus(status);
updraffle.setOperator(accountInfo.getAccountName());
updraffle.setUpdateTime(new Date());
raffleService.updRaffle(updraffle);
return getSuccessResult(true);
}
}

View File

@ -0,0 +1,145 @@
package com.fuint.module.backendApi.controller;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.RaffleTypeDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.RaffleTypePage;
import com.fuint.common.service.RaffleTypeService;
import com.fuint.common.service.StoreService;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtRaffleType;
import com.fuint.repository.model.MtStore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 抽奖类型管理类controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="管理端-抽奖类型相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/raffleType")
public class BackendRaffleTypeController extends BaseController {
/**
* 抽奖类型服务接口
*/
private RaffleTypeService raffleTypeService;
/**
* 店铺服务接口
*/
private StoreService storeService;
/**
* 抽奖类型列表查询
*/
@ApiOperation(value = "抽奖类型列表查询")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(@ModelAttribute RaffleTypePage page) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
page.setMerchantId(accountInfo.getMerchantId());
}
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
page.setStoreId(accountInfo.getStoreId());
}
PaginationResponse<MtRaffleType> paginationResponse = raffleTypeService.queryRaffleTypeListByPagination(page);
List<MtStore> storeList = storeService.getMyStoreList(accountInfo.getMerchantId(), accountInfo.getStoreId(), StatusEnum.ENABLED.getKey());
Map<String, Object> result = new HashMap<>();
result.put("dataList", paginationResponse);
result.put("storeList", storeList);
return getSuccessResult(result);
}
/**
* 更新抽奖类型状态
*/
@ApiOperation(value = "更新抽奖类型状态")
@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject updateStatus(@RequestBody Map<String, Object> params) throws BusinessCheckException {
String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
Integer typeId = params.get("typeId") == null ? 0 : Integer.parseInt(params.get("typeId").toString());
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtRaffleType raffleType = raffleTypeService.getRaffleTypeById(typeId);
if (raffleType == null) {
return getFailureResult(201);
}
raffleType.setOperator(accountInfo.getAccountName());
raffleType.setStatus(status);
raffleTypeService.updateRaffleType(raffleType);
return getSuccessResult(true);
}
/**
* 保存抽奖类型
*/
@ApiOperation(value = "保存抽奖类型")
@RequestMapping(value = "/save", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject saveHandler(@RequestBody RaffleTypeDto raffleTypeDto) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
if (accountInfo.getMerchantId() == null || accountInfo.getMerchantId() < 1) {
return getFailureResult(5002);
}
MtRaffleType raffleType = new MtRaffleType();
BeanUtils.copyProperties(raffleTypeDto, raffleType);
raffleType.setOperator(accountInfo.getAccountName());
raffleType.setMerchantId(accountInfo.getMerchantId());
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
raffleType.setStoreId(accountInfo.getStoreId());
}
if (raffleTypeDto.getId() != null && raffleTypeDto.getId() > 0) {
raffleTypeService.updateRaffleType(raffleType);
} else {
raffleTypeService.addRaffleType(raffleType);
}
return getSuccessResult(true);
}
/**
* 获取抽奖类型详情
*/
@ApiOperation(value = "获取抽奖类型详情")
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject info(@PathVariable("id") Integer id) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtRaffleType raffleType = raffleTypeService.getRaffleTypeById(id);
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
if (raffleType != null && !raffleType.getMerchantId().equals(accountInfo.getMerchantId())) {
return getFailureResult(1004);
}
}
Map<String, Object> result = new HashMap<>();
result.put("raffleTypeInfo", raffleType);
return getSuccessResult(result);
}
}

View File

@ -0,0 +1,128 @@
package com.fuint.module.backendApi.controller;
import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.TaskDto;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.param.TaskPage;
import com.fuint.common.service.StoreService;
import com.fuint.common.service.TaskService;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtStore;
import com.fuint.repository.model.MtTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 任务中心管理 controller
*
* Created by Codex
*/
@Api(tags = "管理端-任务中心相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/task")
public class BackendTaskController extends BaseController {
private TaskService taskService;
private StoreService storeService;
@ApiOperation(value = "任务列表查询")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:index')")
public ResponseObject list(@ModelAttribute TaskPage taskPage) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
taskPage.setMerchantId(accountInfo.getMerchantId());
}
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
taskPage.setStoreId(accountInfo.getStoreId());
}
PaginationResponse<MtTask> paginationResponse = taskService.queryTaskListByPagination(taskPage);
List<MtStore> storeList = storeService.getMyStoreList(accountInfo.getMerchantId(), accountInfo.getStoreId(), StatusEnum.ENABLED.getKey());
Map<String, Object> result = new HashMap<>();
result.put("dataList", paginationResponse);
result.put("storeList", storeList);
return getSuccessResult(result);
}
@ApiOperation(value = "获取任务详情")
@RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:index')")
public ResponseObject info(@PathVariable("id") Integer id) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtTask taskInfo = taskService.queryTaskById(id);
if (taskInfo == null) {
return getFailureResult(201);
}
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0
&& !taskInfo.getMerchantId().equals(accountInfo.getMerchantId())) {
return getFailureResult(1004);
}
Map<String, Object> result = new HashMap<>();
result.put("taskInfo", taskInfo);
return getSuccessResult(result);
}
@ApiOperation(value = "保存任务")
@RequestMapping(value = "/save", method = RequestMethod.POST)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:add') or @pms.hasPermission('content:task:edit')")
public ResponseObject saveHandler(@RequestBody TaskDto taskDto) throws BusinessCheckException {
AccountInfo accountInfo = TokenUtil.getAccountInfo();
taskDto.setOperator(accountInfo.getAccountName());
if (accountInfo.getMerchantId() != null && accountInfo.getMerchantId() > 0) {
taskDto.setMerchantId(accountInfo.getMerchantId());
}
if (accountInfo.getStoreId() != null && accountInfo.getStoreId() > 0) {
taskDto.setStoreId(accountInfo.getStoreId());
}
if (taskDto.getId() != null && taskDto.getId() > 0) {
taskService.updateTask(taskDto);
} else {
taskService.addTask(taskDto);
}
return getSuccessResult(true);
}
@ApiOperation(value = "更新任务状态")
@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
@CrossOrigin
@PreAuthorize("@pms.hasPermission('content:task:edit')")
public ResponseObject updateStatus(@RequestBody Map<String, Object> params) throws BusinessCheckException {
String status = params.get("status") != null ? params.get("status").toString() : StatusEnum.ENABLED.getKey();
Integer id = params.get("id") == null ? 0 : Integer.parseInt(params.get("id").toString());
AccountInfo accountInfo = TokenUtil.getAccountInfo();
MtTask taskInfo = taskService.queryTaskById(id);
if (taskInfo == null) {
return getFailureResult(201);
}
TaskDto taskDto = new TaskDto();
taskDto.setId(id);
taskDto.setOperator(accountInfo.getAccountName());
taskDto.setStatus(status);
taskService.updateTask(taskDto);
return getSuccessResult(true);
}
}

View File

@ -0,0 +1,162 @@
package com.fuint.module.clientApi.controller;
import com.fuint.common.Constants;
import com.fuint.common.dto.PointDto;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.service.GrowService;
import com.fuint.common.service.PointService;
import com.fuint.common.util.DateUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtGrow;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
* 积分相关controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="会员端-增长相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/clientApi/grow")
public class ClientGrowController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ClientGrowController.class);
/**
* 服务接口
*/
private GrowService growService;
/**
* 查询我的积分明细
*
* @param request Request对象
*/
@ApiOperation(value = "查询我的签到")
@RequestMapping(value = "/sign", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject sign(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
};
MtGrow signInfo = growService.querySignInfo(mtUser.getId());
Map<String, Object> result = new HashMap<>();
result.put("growId",signInfo.getId());
if (signInfo.getSignTime() == null) {
result.put("isSign",false);
} else {
BigDecimal diff = DateUtil.getDiffDays(signInfo.getSignTime(), new Date());
if (diff.intValue() == 0) {
result.put("isSign",true);
} else {
result.put("isSign",false);
}
}
if (signInfo.getAdvNum() == null) {
result.put("advNum", 0);
} else {
result.put("advNum", signInfo.getAdvNum());
}
result.put("advTotal",signInfo.getAdvTotal());
result.put("growTotal",signInfo.getGrowTotal());
result.put("growDisp",true);
return getSuccessResult(result);
}
/**
* 签到
*
*/
@ApiOperation(value = "签到")
@RequestMapping(value = "/doSign", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doSign(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer growId = request.getParameter("growId") == null ? 0:Integer.parseInt(request.getParameter("growId"));
logger.info("dosign growid: " + growId);
try {
growService.doSign(growId);
return getSuccessResult(true);
} catch (BusinessCheckException e) {
return getFailureResult(3008, "失败");
}
}
/**
* 点击广告
*
*/
@ApiOperation(value = "点击广告")
@RequestMapping(value = "/doAdv", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doAdv(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
Integer growId = request.getParameter("growId") == null ? 0:Integer.parseInt(request.getParameter("growId"));
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
logger.info("doAdv growid: " + growId);
try {
growService.doAdv(growId);
return getSuccessResult(true);
} catch (BusinessCheckException e) {
return getFailureResult(3008, "失败");
}
}
}

View File

@ -0,0 +1,446 @@
package com.fuint.module.clientApi.controller;
import com.alibaba.fastjson.JSONArray;
import com.fuint.common.dto.OrderDto;
import com.fuint.common.dto.RaffleDto;
import com.fuint.common.dto.RaffleItemDto;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.enums.OrderStatusEnum;
import com.fuint.common.enums.PayStatusEnum;
import com.fuint.common.enums.PayTypeEnum;
import com.fuint.common.enums.YesOrNoEnum;
import com.fuint.common.param.RaffleParam;
import com.fuint.common.param.RechargeParam;
import com.fuint.common.service.MemberService;
import com.fuint.common.service.OrderService;
import com.fuint.common.service.PaymentService;
import com.fuint.common.service.RaffleService;
import com.fuint.common.util.CommonUtil;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtOrder;
import com.fuint.repository.model.MtRaffle;
import com.fuint.repository.model.MtRaffleItem;
import com.fuint.repository.model.MtUser;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
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.*;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 抽奖相关controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="会员端-抽奖相关接口")
@RestController
@RequestMapping(value = "/clientApi/raffle")
public class ClientRaffleController extends BaseController {
private static final Logger logger = LoggerFactory.getLogger(ClientRaffleController.class);
/**
* 抽奖服务接口
*/
@Autowired
private RaffleService raffleService;
/**
* 订单服务接口
* */
@Autowired
private OrderService orderService;
/**
* 会员服务接口
*/
@Autowired
private MemberService memberService;
/**
* 支付服务接口
* */
@Autowired
private PaymentService paymentService;
/**
* 查询我的积分明细
*
* @param request Request对象
*/
@ApiOperation(value = "抽奖列表")
@RequestMapping(value = "/list", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject list(HttpServletRequest request, @RequestBody RaffleParam raffleParam) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
logger.info("微信一番赏一览数据:" + JSONArray.toJSONString(raffleParam));
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
ResponseObject rafList = raffleService.findRaffleList(raffleParam);
return getSuccessResult(rafList.getData());
}
/**
* 最新抽奖
*/
@ApiOperation(value = "最新抽奖")
@RequestMapping(value = "/latest", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject latest(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
List<RaffleDto> list = raffleService.getLatestRaffles(5);
return getSuccessResult(list);
}
/**
* 最新中奖
*/
@ApiOperation(value = "最新中奖")
@RequestMapping(value = "/latestWins", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject latestWins(HttpServletRequest request) throws BusinessCheckException {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
List<RaffleItemDto> list = raffleService.getLatestWinItems(20);
return getSuccessResult(list);
}
/**
* 抽奖详情
*
* @param request Request对象
*/
@ApiOperation(value = "抽奖详情")
@RequestMapping(value = "/detail", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject detailRaffle(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleId = request.getParameter("raffleId") == null ? 0:Integer.parseInt(request.getParameter("raffleId"));
try {
Map<String, Object> result = new HashMap<>();
List<RaffleItemDto> detail = raffleService.queryRaffleItemByRaffleId2wechat(raffleId);
result.put("detail", detail);
MtRaffle raffle = raffleService.queryRaffle(raffleId);
MtRaffle updClick = new MtRaffle();
updClick.setId(raffle.getId());
if (raffle.getClick() == null) {
updClick.setClick(1);
} else {
updClick.setClick(raffle.getClick() + 1);
}
updClick.setUpdateTime(raffle.getUpdateTime());
raffleService.updRaffle(updClick);
result.put("raffle", raffle);
Integer point = raffleService.userPoint(mtUser.getId());
result.put("point", point);
result.put("userId", mtUser.getId());
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 抽一发
*
* @param request Request对象
*/
@ApiOperation(value = "抽一发")
@RequestMapping(value = "/doRaffle", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doRaffle(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleId = request.getParameter("raffleId") == null ? 0:Integer.parseInt(request.getParameter("raffleId"));
Integer num = request.getParameter("num") == null ? 0:Integer.parseInt(request.getParameter("num"));
logger.info("抽一抽:"+raffleId+""+ num+"");
Integer forwardUserId = 0;
try {
forwardUserId = Integer.parseInt(request.getParameter("forwardUserId"));
} catch (NumberFormatException ne) {
logger.info("抽一抽 forwardUserId"+forwardUserId);
}
logger.info("抽一抽转发人:"+forwardUserId);
try {
List<MtRaffleItem> item = raffleService.doRaffleByRaffleId(raffleId, num, mtUser, forwardUserId);
Map<String, Object> result = new HashMap<>();
result.put("stat", "yes");
result.put("item", item);
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 排队
*
* @param request Request对象
*/
@ApiOperation(value = "排队")
@RequestMapping(value = "/doQueue", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject doQueue(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleId = request.getParameter("raffleId") == null ? 0:Integer.parseInt(request.getParameter("raffleId"));
try {
MtRaffle raffle = raffleService.queryRaffle(raffleId);
long diff = 1000;
if (raffle.getUserTime() != null) {
long userTIme = raffle.getUserTime().getTime();
long now = new Date().getTime();
diff = (now - userTIme)/1000;
}
logger.info("diff " + diff);
Map<String, String> result = new HashMap<>();
if (diff <= 60) {
result.put("stat", "no");
result.put("time", String.valueOf(60-diff));
return getSuccessResult(result);
}
MtRaffle newRaffle = new MtRaffle();
newRaffle.setId(raffleId);
newRaffle.setUserId(mtUser.getId());
newRaffle.setUserTime(new Date());
raffleService.updRaffle(newRaffle);
result.put("stat", "yes");
result.put("time", "60");
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 背包
*
* @param request Request对象
*/
@ApiOperation(value = "背包")
@RequestMapping(value = "/findBag", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject findBag(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
try {
List<RaffleItemDto> items = raffleService.queryRaffleItemByUserId(mtUser.getId());
MtUser member = memberService.queryMemberById(mtUser.getId());
Map<String,Object> result = new HashMap<>();
result.put("item", items);
result.put("member", member);
return getSuccessResult(items);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 转化积分
*
* @param request Request对象
*/
@ApiOperation(value = "转化积分")
@RequestMapping(value = "/sellPoint", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject sellPoint(HttpServletRequest request) {
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo mtUser = TokenUtil.getUserInfoByToken(token);
if (null == mtUser) {
return getFailureResult(1001);
}
Integer raffleItemId = request.getParameter("raffleItemId") == null ? 0:Integer.parseInt(request.getParameter("raffleItemId"));
try {
boolean result = raffleService.tranfer2Point(raffleItemId,mtUser.getId());
return getSuccessResult(result);
} catch (BusinessCheckException e) {
return getFailureResult(3008, e.getMessage());
}
}
/**
* 充值积分
* */
@RequestMapping(value = "/doCharge", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject doCharge(HttpServletRequest request, @RequestBody RechargeParam rechargeParam) throws BusinessCheckException {
Integer storeId = request.getHeader("storeId") == null ? 0 : Integer.parseInt(request.getHeader("storeId"));
String platform = request.getHeader("platform") == null ? "" : request.getHeader("platform");
String token = request.getHeader("Access-Token");
if (StringUtil.isEmpty(token)) {
return getFailureResult(1001);
}
UserInfo userInfo = TokenUtil.getUserInfoByToken(token);
if (null == userInfo) {
return getFailureResult(1001);
}
String rechargeAmount = rechargeParam.getRechargeAmount() == null ? "" : rechargeParam.getRechargeAmount();
String customAmount = rechargeParam.getCustomAmount() == null ? "" : rechargeParam.getCustomAmount();
if (StringUtil.isEmpty(rechargeAmount) && StringUtil.isEmpty(customAmount)) {
return getFailureResult(2000, "请确认充值金额");
}
logger.info("rechargeAmount: " + rechargeAmount);
logger.info("customAmount: " + customAmount);
String ruleParam = "";
// 自定义充值没有赠送金额
if (StringUtil.isEmpty(rechargeAmount)) {
ruleParam = customAmount + "_0";
}
BigDecimal amount = new BigDecimal(customAmount);
logger.info("amount: " + amount);
OrderDto orderDto = new OrderDto();
orderDto.setType("pointChange");
orderDto.setUserId(userInfo.getId());
orderDto.setStoreId(storeId);
orderDto.setAmount(amount);
orderDto.setUsePoint(0);
orderDto.setRemark("积分充值");
orderDto.setParam(ruleParam);
orderDto.setStatus(OrderStatusEnum.CREATED.getKey());
orderDto.setPayStatus(PayStatusEnum.WAIT.getKey());
orderDto.setPointAmount(new BigDecimal("0"));
orderDto.setOrderMode("");
orderDto.setCouponId(0);
orderDto.setPlatform(platform);
MtOrder orderInfo = orderService.saveOrder(orderDto);
MtUser mtUser = memberService.queryMemberById(userInfo.getId());
String ip = CommonUtil.getIPFromHttpRequest(request);
BigDecimal pay = amount.multiply(new BigDecimal("100"));
orderInfo.setPayType(PayTypeEnum.JSAPI.getKey());
ResponseObject paymentInfo = paymentService.createPrepayOrder(mtUser, orderInfo, (pay.intValue()), "", 0, ip, platform, YesOrNoEnum.YES.getKey());
if (paymentInfo.getData() == null) {
return getFailureResult(201, "抱歉,发起支付失败");
}
Object payment = paymentInfo.getData();
Map<String, Object> data = new HashMap();
data.put("payment", payment);
data.put("orderInfo", orderInfo);
return getSuccessResult(data);
}
}

View File

@ -0,0 +1,65 @@
package com.fuint.module.clientApi.controller;
import com.fuint.common.service.MerchantService;
import com.fuint.common.service.RaffleTypeService;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.repository.model.MtRaffleType;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 抽奖类型controller
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Api(tags="会员端-抽奖类型相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/clientApi/raffleType")
public class ClientRaffleTypeController extends BaseController {
/**
* 抽奖类型服务接口
*/
private RaffleTypeService raffleTypeService;
/**
* 商户服务接口
*/
private MerchantService merchantService;
/**
* 抽奖类型列表
*/
@ApiOperation(value = "抽奖类型列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
Integer merchantId = 0;
if (StringUtil.isNotEmpty(merchantNo)) {
merchantId = merchantService.getMerchantId(merchantNo);
}
List<MtRaffleType> typeList = raffleTypeService.getAvailableRaffleType(merchantId, storeId);
Map<String, Object> result = new HashMap<>();
result.put("typeList", typeList);
return getSuccessResult(result);
}
}

View File

@ -0,0 +1,113 @@
package com.fuint.module.clientApi.controller;
import com.fuint.common.dto.UserInfo;
import com.fuint.common.service.MerchantService;
import com.fuint.common.service.TaskService;
import com.fuint.common.util.TokenUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.ResponseObject;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 任务中心接口 controller
*
* Created by Codex
*/
@Api(tags = "会员端-任务中心相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/clientApi/task")
public class ClientTaskController extends BaseController {
private TaskService taskService;
private MerchantService merchantService;
@ApiOperation(value = "任务列表")
@RequestMapping(value = "/list", method = RequestMethod.GET)
@CrossOrigin
public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
UserInfo userInfo = TokenUtil.getUserInfo();
Integer userId = userInfo == null ? 0 : userInfo.getId();
Integer merchantId = merchantService.getMerchantId(merchantNo);
if (merchantId <= 0) {
return getFailureResult(201, "商户信息异常");
}
List<Map<String, Object>> taskList = taskService.queryClientTaskList(merchantId, storeId, userId);
int totalDailyPoints = 0;
for (Map<String, Object> task : taskList) {
int rewardPoint = task.get("rewardPoint") == null ? 0 : Integer.parseInt(task.get("rewardPoint").toString());
int dailyLimit = task.get("dailyLimit") == null ? 1 : Integer.parseInt(task.get("dailyLimit").toString());
totalDailyPoints += rewardPoint * dailyLimit;
}
Map<String, Object> outParams = new HashMap<>();
outParams.put("taskList", taskList);
outParams.put("totalDailyPoints", totalDailyPoints);
return getSuccessResult(outParams);
}
@ApiOperation(value = "完成任务")
@RequestMapping(value = "/complete", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject complete(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
UserInfo userInfo = TokenUtil.getUserInfo();
if (userInfo == null) {
return getFailureResult(1001);
}
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
Integer taskId = param.get("taskId") == null ? 0 : Integer.parseInt(param.get("taskId").toString());
if (taskId <= 0) {
return getFailureResult(201, "任务ID不能为空");
}
Integer merchantId = merchantService.getMerchantId(merchantNo);
if (merchantId <= 0) {
return getFailureResult(201, "商户信息异常");
}
Map<String, Object> result = taskService.completeTask(merchantId, storeId, userInfo.getId(), taskId, "USER");
return getSuccessResult(result);
}
@ApiOperation(value = "领取任务奖励")
@RequestMapping(value = "/claim", method = RequestMethod.POST)
@CrossOrigin
public ResponseObject claim(HttpServletRequest request, @RequestBody Map<String, Object> param) throws BusinessCheckException {
UserInfo userInfo = TokenUtil.getUserInfo();
if (userInfo == null) {
return getFailureResult(1001);
}
String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
Integer storeId = StringUtil.isEmpty(request.getHeader("storeId")) ? 0 : Integer.parseInt(request.getHeader("storeId"));
Integer taskId = param.get("taskId") == null ? 0 : Integer.parseInt(param.get("taskId").toString());
if (taskId <= 0) {
return getFailureResult(201, "任务ID不能为空");
}
Integer merchantId = merchantService.getMerchantId(merchantNo);
if (merchantId <= 0) {
return getFailureResult(201, "商户信息异常");
}
Map<String, Object> result = taskService.claimTask(merchantId, storeId, userInfo.getId(), taskId, "USER");
return getSuccessResult(result);
}
}

View File

@ -0,0 +1,52 @@
package com.fuint.module.schedule;
import com.fuint.common.enums.PayStatusEnum;
import com.fuint.common.service.CommissionLogService;
import com.fuint.common.service.GrowService;
import com.fuint.common.service.OrderService;
import com.fuint.common.util.DateUtil;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.model.MtOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
/**
* 定时任务
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@EnableScheduling
@Component("GrowJob")
public class GrowJob {
private Logger logger = LoggerFactory.getLogger(GrowJob.class);
/**
* 系统环境变量
* */
@Autowired
private Environment environment;
@Autowired
private GrowService growService;
@Scheduled(cron = "${grow.job.time}")
@Transactional(rollbackFor = Exception.class)
public void dealGrow() throws BusinessCheckException {
String theSwitch = environment.getProperty("grow.job.switch");
if (theSwitch != null && theSwitch.equals("1")) {
logger.info("GrowJobStart!!!");
growService.clearAdvNum();
logger.info("GrowJobEnd!!!");
}
}
}

View File

@ -0,0 +1,20 @@
package com.fuint.repository.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.repository.model.MtGrow;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.SelectKey;
/**
* 积分变化表 Mapper 接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface MtGrowMapper extends BaseMapper<MtGrow> {
@Insert("insert into mt_grow values (#{id},#{userId},#{signTime},#{consecutiveDays},#{createTime},#{updateTime},#{operator},#{status},#{advNum},#{advTotal},#{growTotal})")
@SelectKey(statement="select last_insert_id() from dual",before=false,
resultType = Integer.class, keyColumn="id",keyProperty = "id")
int insertForId(MtGrow signInfo);
}

View File

@ -0,0 +1,23 @@
package com.fuint.repository.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.repository.model.MtRaffle;
import com.fuint.repository.model.MtRaffleItem;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
* 会员个人信息 Mapper 接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface MtRaffleItemMapper extends BaseMapper<MtRaffleItem> {
public List<MtRaffleItem> queryListByRaffleId(@Param("raffleId") Integer raffleId);
public List<Integer> queryUserIdByRaffleId(@Param("raffleId") Integer raffleId);
}

View File

@ -0,0 +1,25 @@
package com.fuint.repository.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.repository.model.MtRaffle;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectKey;
import java.util.Date;
import java.util.List;
/**
* 会员个人信息 Mapper 接口
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public interface MtRaffleMapper extends BaseMapper<MtRaffle> {
@Insert("insert into mt_raffle values (#{id},#{raffleType},#{title},#{brief},#{hot},#{image},#{description},#{click}," +
"#{nowCnt},#{allCnt},#{extraPrize},#{extraImage},#{extraType},#{createTime},#{updateTime},#{operator}," +
"#{sort},#{status},#{rafflePoint},#{userId},#{userTime},#{forwardPoint})")
@SelectKey(statement="select last_insert_id() from dual",before=false,
resultType = Integer.class, keyColumn="id",keyProperty = "id")
int insertForId(MtRaffle mtRaffle);
}

View File

@ -0,0 +1,15 @@
package com.fuint.repository.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.repository.model.MtRaffleType;
import org.apache.ibatis.annotations.Mapper;
/**
* 抽奖类型 Mapper
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Mapper
public interface MtRaffleTypeMapper extends BaseMapper<MtRaffleType> {
}

View File

@ -0,0 +1,12 @@
package com.fuint.repository.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.repository.model.MtTask;
/**
* 任务中心 Mapper 接口
*
* Created by Codex
*/
public interface MtTaskMapper extends BaseMapper<MtTask> {
}

View File

@ -0,0 +1,24 @@
package com.fuint.repository.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fuint.repository.model.MtTaskRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.Date;
/**
* 任务记录 Mapper 接口
*
* Created by Codex
*/
public interface MtTaskRecordMapper extends BaseMapper<MtTaskRecord> {
@Update("UPDATE mt_task_record SET COMPLETE_NUM = COMPLETE_NUM + 1, LAST_COMPLETE_TIME = #{now}, UPDATE_TIME = #{now} " +
"WHERE ID = #{id} AND COMPLETE_NUM < #{dailyLimit}")
int incrCompleteNum(@Param("id") Integer id, @Param("dailyLimit") Integer dailyLimit, @Param("now") Date now);
@Update("UPDATE mt_task_record SET CLAIM_NUM = CLAIM_NUM + 1, LAST_CLAIM_TIME = #{now}, UPDATE_TIME = #{now} " +
"WHERE ID = #{id} AND CLAIM_NUM = #{oldClaimNum} AND CLAIM_NUM < COMPLETE_NUM")
int incrClaimNumIfMatch(@Param("id") Integer id, @Param("oldClaimNum") Integer oldClaimNum, @Param("now") Date now);
}

View File

@ -0,0 +1,61 @@
package com.fuint.repository.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Date;
/**
* 会员积分记录表
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Getter
@Setter
@TableName("mt_grow")
@ApiModel(value = "MtGrow对象", description = "签到记录表")
public class MtGrow implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("自增ID")
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("用户 ID")
private Integer userId;
@ApiModelProperty("签到日期")
private Date signTime;
@ApiModelProperty("连续签到次数")
private Integer consecutiveDays;
@ApiModelProperty("广告次数")
private Integer advNum;
@ApiModelProperty("广告总次数")
private Integer advTotal;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("最后操作人")
private String operator;
@ApiModelProperty("状态A正常D作废")
private String status;
@ApiModelProperty("成长积分")
private Integer growTotal;
}

View File

@ -0,0 +1,94 @@
package com.fuint.repository.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 抽奖表
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Getter
@Setter
@TableName("mt_raffle")
@ApiModel(value = "MtRaffle对象", description = "抽奖表")
public class MtRaffle implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("自增ID")
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("抽奖类型")
private String raffleType;
@ApiModelProperty("标题")
private String title;
@ApiModelProperty("简介")
private String brief;
@ApiModelProperty("热度")
private String hot;
@ApiModelProperty("图片地址")
private String image;
@ApiModelProperty("额外奖奖品")
private String extraPrize;
@ApiModelProperty("额外奖图片")
private String extraImage;
@ApiModelProperty("额外奖类型")
private String extraType;
@ApiModelProperty("排队人")
private Integer userId;
@ApiModelProperty("排队时间")
private Date userTime;
@ApiModelProperty("已抽去数")
private Integer nowCnt;
@ApiModelProperty("总数")
private Integer allCnt;
@ApiModelProperty("抽奖积分")
private Integer rafflePoint;
@ApiModelProperty("描述")
private String description;
@ApiModelProperty("点击次数")
private Integer click;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("状态")
private String status;
@ApiModelProperty("最后操作人")
private String operator;
@ApiModelProperty("转发赠送积分")
private Integer forwardPoint;
}

View File

@ -0,0 +1,78 @@
package com.fuint.repository.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.Date;
/**
* 抽奖表
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Getter
@Setter
@TableName("mt_raffle_item")
@ApiModel(value = "MtRaffleItem对象", description = "抽奖明细表")
public class MtRaffleItem implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("自增ID")
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("抽奖表ID")
private Integer raffleId;
@ApiModelProperty("抽奖项目")
private String title;
@ApiModelProperty("抽奖奖品")
private String prize;
@ApiModelProperty("积分价值")
private Integer point;
@ApiModelProperty("中奖用户")
private Integer userId;
@ApiModelProperty("会员号")
private String userNo;
@ApiModelProperty("称呼")
private String name;
@ApiModelProperty("图片")
private String image;
@ApiModelProperty("奖品状态")
private Integer win;
@ApiModelProperty("领取状态")
private Integer deal;
@ApiModelProperty("描述")
private String description;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("最后操作人")
private String operator;
@ApiModelProperty("转发人")
private Integer forwardUserId;
@ApiModelProperty("奖品类型")
private String prizeType;
}

View File

@ -0,0 +1,56 @@
package com.fuint.repository.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 抽奖类型表
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
@Data
@TableName("mt_raffle_type")
@ApiModel(value = "MtRaffleType对象", description = "MtRaffleType表对象")
public class MtRaffleType implements Serializable {
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("商户ID")
private Integer merchantId;
@ApiModelProperty("店铺ID")
private Integer storeId;
@ApiModelProperty("类型编码")
private String code;
@ApiModelProperty("类型名称")
private String name;
@ApiModelProperty("备注")
private String description;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("操作人")
private String operator;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("状态")
private String status;
}

View File

@ -0,0 +1,70 @@
package com.fuint.repository.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 任务中心配置
*
* Created by Codex
*/
@Data
@TableName("mt_task")
@ApiModel(value = "MtTask对象", description = "MtTask表对象")
public class MtTask implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("自增ID")
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("所属商户ID")
private Integer merchantId;
@ApiModelProperty("所属店铺ID")
private Integer storeId;
@ApiModelProperty("任务编码")
private String taskCode;
@ApiModelProperty("任务名称")
private String taskName;
@ApiModelProperty("任务类型")
private String taskType;
@ApiModelProperty("任务描述")
private String taskDesc;
@ApiModelProperty("任务跳转链接")
private String jumpUrl;
@ApiModelProperty("奖励积分")
private Integer rewardPoint;
@ApiModelProperty("每日可领取次数")
private Integer dailyLimit;
@ApiModelProperty("排序")
private Integer sort;
@ApiModelProperty("最后操作人")
private String operator;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("状态A正常D删除")
private String status;
}

View File

@ -0,0 +1,67 @@
package com.fuint.repository.model;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* 任务完成记录
*
* Created by Codex
*/
@Data
@TableName("mt_task_record")
@ApiModel(value = "MtTaskRecord对象", description = "任务完成记录表")
public class MtTaskRecord implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("自增ID")
@TableId(value = "ID", type = IdType.AUTO)
private Integer id;
@ApiModelProperty("商户ID")
private Integer merchantId;
@ApiModelProperty("店铺ID")
private Integer storeId;
@ApiModelProperty("任务ID")
private Integer taskId;
@ApiModelProperty("会员ID")
private Integer userId;
@ApiModelProperty("任务日期(yyyy-MM-dd)")
private String taskDate;
@ApiModelProperty("完成次数")
private Integer completeNum;
@ApiModelProperty("已领取次数")
private Integer claimNum;
@ApiModelProperty("最近完成时间")
private Date lastCompleteTime;
@ApiModelProperty("最近领取时间")
private Date lastClaimTime;
@ApiModelProperty("创建时间")
private Date createTime;
@ApiModelProperty("更新时间")
private Date updateTime;
@ApiModelProperty("最后操作人")
private String operator;
@ApiModelProperty("状态A正常D删除")
private String status;
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuint.repository.mapper.MtGrowMapper">
</mapper>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuint.repository.mapper.MtRaffleItemMapper">
<select id="queryListByRaffleId" resultType="com.fuint.repository.model.MtRaffleItem">
select * from mt_raffle_item t where t.raffle_id = #{raffleId} by id asc
</select>
<select id="queryUserIdByRaffleId" resultType="java.lang.Integer">
select user_id from mt_raffle_item t where t.raffle_id = #{raffleId} and user_id is not null
</select>
</mapper>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fuint.repository.mapper.MtRaffleMapper">
</mapper>

View File

@ -0,0 +1,135 @@
package com.fuint.utils;
import com.sun.org.apache.xerces.internal.impl.dv.util.HexBin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
/**
* AES对称加/解密工具类
*
* Created by FSQ
* CopyRight https://www.fuint.cn
*/
public class AESUtil {
private static final Logger logger = LoggerFactory.getLogger(AESUtil.class);
//密钥生成算法
private static String KEY_AES = "AES";
//密钥长度
private static int KEY_LENGTH = 128;
//默认字符集
private static final String CHARSET = "UTF-8";
/**
* AES加密
*
* @param data 待加密的内容
* @param password 加密密码
* @return byte[]
*/
public static String encrypt(byte[] data, String password) {
try {
SecretKeySpec key = getKey(password);
Cipher cipher = Cipher.getInstance(KEY_AES);// 创建密码器
cipher.init(Cipher.ENCRYPT_MODE, key);// 初始化
return HexBin.encode(cipher.doFinal(data));
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage(), e);
} catch (IllegalBlockSizeException e) {
logger.error(e.getMessage(), e);
} catch (InvalidKeyException e) {
logger.error(e.getMessage(), e);
} catch (BadPaddingException e) {
logger.error(e.getMessage(), e);
} catch (NoSuchPaddingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
/**
* AES加密
*
* @param data 待加密的内容
* @param password 加密密码
* @return String
*/
public static String encrypt(String data, String password) {
try {
return encrypt(data.getBytes(CHARSET), password);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
/**
* AES解密
*
* @param data 待解密内容
* @param password 解密密钥
* @return byte[]
*/
public static byte[] decrypt(byte[] data, String password) {
try {
SecretKeySpec key = getKey(password);
Cipher cipher = Cipher.getInstance(KEY_AES);// 创建密码器
cipher.init(Cipher.DECRYPT_MODE, key);// 初始化
return cipher.doFinal(HexBin.decode(new String(data, CHARSET)));
} catch (NoSuchAlgorithmException e) {
logger.error(e.getMessage(), e);
} catch (IllegalBlockSizeException e) {
logger.error(e.getMessage(), e);
} catch (InvalidKeyException e) {
logger.error(e.getMessage(), e);
} catch (BadPaddingException e) {
logger.error(e.getMessage(), e);
} catch (NoSuchPaddingException e) {
logger.error(e.getMessage(), e);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
/**
* AES解密
*
* @param data 待解密内容
* @param password 解密密钥
* @return String
*/
public static String decrypt(String data, String password) {
try {
byte[] bytes = decrypt(data.getBytes(CHARSET), password);
return new String(bytes, CHARSET);
} catch (UnsupportedEncodingException e) {
logger.error(e.getMessage(), e);
}
return null;
}
/**
* 通过密码计算key
*
* @param password 对称密码
* @return SecretKeySpec 计算的128位随机key
* @throws NoSuchAlgorithmException
*/
private static SecretKeySpec getKey(String password) throws NoSuchAlgorithmException {
KeyGenerator kgen = KeyGenerator.getInstance(KEY_AES);
kgen.init(KEY_LENGTH, new SecureRandom(password.getBytes()));
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
return new SecretKeySpec(enCodeFormat, KEY_AES);
}
}

View File

@ -0,0 +1,205 @@
package net.xpyun.platform.opensdk.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import net.xpyun.platform.opensdk.util.HttpClientUtil;
import net.xpyun.platform.opensdk.vo.*;
import java.util.List;
/**
* 云打印相关接口封装类
* @author JavaLyl
*/
public class PrintService {
private static String BASE_URL = "https://open.xpyun.net/api/openapi";
/**
* 1.批量添加打印机
* @param restRequest
* @return
*/
public ObjectRestResponse<PrinterResult> addPrinters(AddPrinterRequest restRequest) {
String url = BASE_URL + "/xprinter/addPrinters";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<PrinterResult> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<PrinterResult>>(){});
return result;
}
/**
* 2.设置打印机语音类型
* @param restRequest
* @return
*/
public ObjectRestResponse<Boolean> setPrinterVoiceType(SetVoiceTypeRequest restRequest) {
String url = BASE_URL + "/xprinter/setVoiceType";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<Boolean> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<Boolean>>(){});
return result;
}
/**
* 3.打印小票订单
* @param restRequest
* @return
*/
public ObjectRestResponse<String> print(PrintRequest restRequest) {
String url = BASE_URL + "/xprinter/print";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<String> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<String>>(){});
return result;
}
/**
* 4.打印标签订单
* @param restRequest
* @return
*/
public ObjectRestResponse<String> printLabel(PrintRequest restRequest) {
String url = BASE_URL + "/xprinter/printLabel";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<String> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<String>>(){});
return result;
}
/**
* 5.批量删除打印机
* @param restRequest
* @return
*/
public ObjectRestResponse<PrinterResult> delPrinters(DelPrinterRequest restRequest) {
String url = BASE_URL + "/xprinter/delPrinters";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<PrinterResult> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<PrinterResult>>(){});
return result;
}
/**
* 6.修改打印机信息
* @param restRequest
* @return
*/
public ObjectRestResponse<Boolean> updPrinter(UpdPrinterRequest restRequest) {
String url = BASE_URL + "/xprinter/updPrinter";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<Boolean> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<Boolean>>(){});
return result;
}
/**
* 7.清空待打印队列
* @param restRequest
* @return
*/
public ObjectRestResponse<Boolean> delPrinterQueue(PrinterRequest restRequest) {
String url = BASE_URL + "/xprinter/delPrinterQueue";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<Boolean> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<Boolean>>(){});
return result;
}
/**
* 8.查询订单是否打印成功
* @param restRequest
* @return
*/
public ObjectRestResponse<Boolean> queryOrderState(QueryOrderStateRequest restRequest) {
String url = BASE_URL + "/xprinter/queryOrderState";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<Boolean> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<Boolean>>(){});
return result;
}
/**
* 9.查询打印机某天的订单统计数
* @param restRequest
* @return
*/
public ObjectRestResponse<OrderStatisResult> queryOrderStatis(QueryOrderStatisRequest restRequest) {
String url = BASE_URL + "/xprinter/queryOrderStatis";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<OrderStatisResult> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<OrderStatisResult>>(){});
return result;
}
/**
* 10.查询打印机状态
*
* 0、离线 1、在线正常 2、在线不正常
* 备注异常一般是无纸离线的判断是打印机与服务器失去联系超过30秒
* @param restRequest
* @return
*/
public ObjectRestResponse<Integer> queryPrinterStatus(PrinterRequest restRequest) {
String url = BASE_URL + "/xprinter/queryPrinterStatus";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<Integer> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<Integer>>(){});
return result;
}
/**
* 10.批量查询打印机状态
*
* 0、离线 1、在线正常 2、在线不正常
* 备注异常一般是无纸离线的判断是打印机与服务器失去联系超过30秒
* @param restRequest
* @return
*/
public ObjectRestResponse<List<Integer>> queryPrintersStatus(PrintersRequest restRequest) {
String url = BASE_URL + "/xprinter/queryPrintersStatus";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<List<Integer>> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<List<Integer>>>(){});
return result;
}
/**
* 11.云喇叭播放语音
* @param restRequest
* @return
*/
public ObjectRestResponse<String> playVoice(VoiceRequest restRequest) {
String url = BASE_URL + "/xprinter/playVoice";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<String> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<String>>(){});
return result;
}
/**
* 12.POS指令
* @param restRequest
* @return
*/
public ObjectRestResponse<String> pos(PrintRequest restRequest) {
String url = BASE_URL + "/xprinter/pos";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<String> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<String>>(){});
return result;
}
/**
* 13.钱箱控制
* @param restRequest
* @return
*/
public ObjectRestResponse<String> controlBox(PrintRequest restRequest) {
String url = BASE_URL + "/xprinter/controlBox";
String jsonRequest = JSON.toJSONString(restRequest);
String resp = HttpClientUtil.doPostJSON(url, jsonRequest);
ObjectRestResponse<String> result = JSON.parseObject(resp, new TypeReference<ObjectRestResponse<String>>(){});
return result;
}
}

View File

@ -0,0 +1,46 @@
package net.xpyun.platform.opensdk.util;
import net.xpyun.platform.opensdk.vo.RestRequest;
/**
* @author LylJavas
* @create 2021/2/26 15:14
* @description 公共配置类
*/
public class Config {
/**
* *必填*开发者ID 芯烨云后台注册账号即邮箱地址或开发者ID开发者用户注册成功之后登录芯烨云后台在【个人中心=》账号信息】下可查看开发者ID
*
* 当前【xxxxxxxxxxxxxxx】只是样例需修改再使用
*/
public static final String USER_NAME = "zztect@163.com";
/**
* *必填*:开发者密钥 :芯烨云后台注册账号后自动生成的开发者密钥,开发者用户注册成功之后,登录芯烨云后台,在【个人中心=》账号信息】下可查看开发者密钥
*
* 当前【xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx】只是样例需修改再使用
*/
public static final String USER_KEY = "d963972a67dc4dbf820fab428ac851f8";
/**
* *必填*:打印机设备编号,必须要在芯烨云管理后台的【打印管理->打印机管理】下添加打印机或调用API接口添加打印机测试小票机和标签机的时候注意替换打印机编号
* 打印机设备编号获取方式在打印机底部会有带PID或SN字样的二维码且PID或SN后面的一串字符即为打印机编号
*
* 当前【xxxxxxxxxxxxxxx】只是样例需修改再使用此处只是作为测试样例所以打印机编号采用常量化开发者可根据自己的实际需要进行变量化
*/
public static final String OK_PRINTER_SN = "xxxxxxxxxxxxxxx";
/**
* 生成通用的请求头
*
* @param request 所有请求都必须传递的参数。
*/
public static void createRequestHeader(RestRequest request) {
//*必填*:芯烨云平台注册用户名(开发者 ID
request.setUser(USER_NAME);
//*必填*当前UNIX时间戳
request.setTimestamp(System.currentTimeMillis() + "");
//*必填*:对参数 user + UserKEY + timestamp 拼接后(+号表示连接符进行SHA1加密得到签名值为40位小写字符串其中 UserKEY 为用户开发者密钥
request.setSign(HashSignUtil.sign(request.getUser() + USER_KEY + request.getTimestamp()));
//debug=1返回非json格式的数据仅测试时候使用
request.setDebug("0");
}
}

View File

@ -0,0 +1,49 @@
package net.xpyun.platform.opensdk.util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Formatter;
/**
* 哈稀签名工具类
*
* @author RabyGao
* @date Aug 9, 2019
*/
public class HashSignUtil {
/**
* 哈稀签名
* @param signSource - 源字符串
* @return
*/
public static String sign(String signSource) {
String signature = "";
try {
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(signSource.getBytes("UTF-8"));
signature = byteToHex(crypt.digest());
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return signature;
}
private static String byteToHex(final byte[] hash) {
Formatter formatter = new Formatter();
for (byte b : hash)
{
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}
}

View File

@ -0,0 +1,274 @@
package net.xpyun.platform.opensdk.util;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.*;
/**
* 基于 apache httpClient4.5 的HTTP工具类
*
* @author RabyGao
* @date Aug 9, 2019
*/
public class HttpClientUtil {
public static String doGet(String url) {
return doGet(url, null);
}
public static String doGet(String url, Map<String, String> headers) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
String result = "";
try {
// 通过址默认配置创建一个httpClient实例
httpClient = HttpClients.createDefault();
// 创建httpGet远程连接实例
HttpGet httpGet = new HttpGet(url);
if (headers != null && headers.size() > 0) {
for(Map.Entry<String, String> entry : headers.entrySet()){
httpGet.addHeader(entry.getKey(), entry.getValue());
}
}
// 设置配置请求参数
// 连接主机服务超时时间、请求超时时间、数据读取超时时间
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(10000)
.build();
// 为httpGet实例设置配置
httpGet.setConfig(requestConfig);
// 执行get请求得到返回对象
response = httpClient.execute(httpGet);
// 通过返回对象获取返回数据
HttpEntity entity = response.getEntity();
// 通过EntityUtils中的toString方法将结果转换为字符串
result = EntityUtils.toString(entity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭资源
if (null != response) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
public static String doPost(String url, Map<String, Object> paramMap) {
return doPost(url, paramMap, null);
}
public static String doPost(String url, Map<String, Object> paramMap, Map<String, String> headers) {
return doPost(url, paramMap, headers, "application/x-www-form-urlencoded", "UTF-8");
}
public static String doPost(String url, Map<String, Object> paramMap, Map<String, String> headers, String contentType, String charset) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse httpResponse = null;
String result = "";
// 创建httpClient实例
httpClient = HttpClients.createDefault();
// 创建httpPost远程连接实例
HttpPost httpPost = new HttpPost(url);
// 配置请求参数实例
// 连接主机服务超时时间、请求超时时间、数据读取超时时间
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(10000)
.build();
// 为httpPost实例设置配置
httpPost.setConfig(requestConfig);
// 设置请求头
httpPost.addHeader("Content-Type", contentType);
if (headers != null && headers.size() > 0) {
for(Map.Entry<String, String> entry : headers.entrySet()){
httpPost.addHeader(entry.getKey(), entry.getValue());
}
}
// 封装post请求参数
if (null != paramMap && paramMap.size() > 0) {
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
// 通过map集成entrySet方法获取entity
Set<Map.Entry<String, Object>> entrySet = paramMap.entrySet();
// 循环遍历,获取迭代器
Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> mapEntry = iterator.next();
nvps.add(new BasicNameValuePair(mapEntry.getKey(), mapEntry.getValue().toString()));
}
// 为httpPost设置封装好的请求参数
try {
httpPost.setEntity(new UrlEncodedFormEntity(nvps, charset));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
try {
// httpClient对象执行post请求,并返回响应参数对象
httpResponse = httpClient.execute(httpPost);
// 从响应对象中获取响应内容
HttpEntity entity = httpResponse.getEntity();
result = EntityUtils.toString(entity);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭资源
if (null != httpResponse) {
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
public static String doPostJSON(String url, String json) {
return doPostJSON(url, json, null);
}
public static String doPostJSON(String url, String json, Map<String, String> headers) {
CloseableHttpClient httpClient = null;
try {
httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(10000).build();
// 为httpPost实例设置配置
httpPost.setConfig(requestConfig);
// 设置请求头
httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
if (headers != null && headers.size() > 0) {
for (String key:headers.keySet()) {
httpPost.addHeader(key, headers.get(key));
}
}
// 解决中文乱码问题
StringEntity stringEntity = new StringEntity(json, "UTF-8");
stringEntity.setContentEncoding("UTF-8");
httpPost.setEntity(stringEntity);
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
@Override
public String handleResponse(final HttpResponse response)
throws ClientProtocolException, IOException {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else {
throw new ClientProtocolException("Unexpected response status: " + status);
}
}
};
return httpClient.execute(httpPost, responseHandler);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpClient != null) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
public static String doPostGetLocation(String url, Map<String, Object> paramMap) {
CloseableHttpResponse httpResponse = null;
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(10000).build();
// 为httpPost实例设置配置
httpPost.setConfig(requestConfig);
httpPost.addHeader("Content-Type", "application/x-www-form-urlencoded");
// 封装post请求参数
if (null != paramMap && paramMap.size() > 0) {
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
Set<Map.Entry<String, Object>> entrySet = paramMap.entrySet();
Iterator<Map.Entry<String, Object>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
Map.Entry<String, Object> mapEntry = iterator.next();
nvps.add(new BasicNameValuePair(mapEntry.getKey(), mapEntry.getValue().toString()));
}
try {
httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
try {
// httpClient对象执行post请求,并返回响应参数对象
httpResponse = httpClient.execute(httpPost);
if (httpResponse.getStatusLine().getStatusCode() == 302 && httpResponse.getHeaders("Location").length > 0) {
return httpResponse.getHeaders("Location")[0].getValue();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭资源
if (null != httpResponse) {
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
}

View File

@ -0,0 +1,278 @@
package net.xpyun.platform.opensdk.util;
import org.apache.commons.lang.StringUtils;
import java.io.UnsupportedEncodingException;
import java.text.DecimalFormat;
/**
* @author LylJavas
* @create 2021/2/26 15:16
* @description 小票格式化器
*/
public class NoteFormatter {
/**
* 58mm 系列打印机每行可以打印的字符数
*/
private static final Integer ROW_MAX_CHAR_LEN = 32;
private static final Integer MAX_NAME_CHAR_LEN = 20;
private static final Integer LAST_ROW_MAX_NAME_CHAR_LEN = 9;
private static final Integer MAX_QUANTITY_CHAR_LEN = 6;
private static final Integer MAX_PRICE_CHAR_LEN = 6;
/**
* 80mm 系列打印机每行可以打印的字符数
*/
private static final Integer ROW_MAX_CHAR_LEN80 = 48;
private static final Integer MAX_NAME_CHAR_LEN80 = 36;
private static final Integer LAST_ROW_MAX_NAME_CHAR_LEN80 = 17;
private static final Integer MAX_QUANTITY_CHAR_LEN80 = 6;
private static final Integer MAX_PRICE_CHAR_LEN80 = 6;
private static String orderNameEmpty = StringUtils.repeat(" ", MAX_NAME_CHAR_LEN);
/**
* 格式化订单数据 80mm打印机使用
*
* @param foodName
* @param quantity
* @param price
* @return
* @throws Exception
*/
public static String formatPrintOrderItemBy4Column(String foodName, Integer quantity, Double singlePrice, Double price) throws Exception {
StringBuilder builder = new StringBuilder();
byte[] itemNames = foodName.getBytes("GBK");
Integer mod = itemNames.length % ROW_MAX_CHAR_LEN;
String quanityStr = quantity.toString();
byte[] itemQuans = quanityStr.getBytes("GBK");
String priceStr = roundByTwo(price);
byte[] itemPrices = (priceStr).getBytes("GBK");
if (mod <= LAST_ROW_MAX_NAME_CHAR_LEN) {
builder.append("<C>").append(foodName).append("</C>");
// 在同一行,留4个英文字符的空格
//if in the same row, fill with 4 spaces at the end of name column
builder.append(StringUtils.repeat(" ", (MAX_NAME_CHAR_LEN - mod)));
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN - itemPrices.length)));
} else {
// 对菜名进行猜分
builder.append(foodName);
// 另起新行
// new line
builder.append("<BR>");
builder.append(orderNameEmpty);
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN - itemPrices.length)));
}
builder.append("<BR>");
return builder.toString();
}
/**
* 格式化菜名名称,菜名名称打满一行自动换行
*
* @param foodName
* @param quantity
* @param price
* @return
* @throws Exception
*/
public static String formatPrintOrderItemByFull(String foodName, Integer quantity, Double price) throws Exception {
StringBuilder builder = new StringBuilder();
byte[] itemNames = foodName.getBytes("GBK");
Integer mod = itemNames.length % ROW_MAX_CHAR_LEN;
String quanityStr = quantity.toString();
byte[] itemQuans = quanityStr.getBytes("GBK");
String priceStr = roundByTwo(price);
byte[] itemPrices = (priceStr).getBytes("GBK");
if (mod <= LAST_ROW_MAX_NAME_CHAR_LEN) {
builder.append(foodName);
// 在同一行,留4个英文字符的空格
//if in the same row, fill with 4 spaces at the end of name column
builder.append(StringUtils.repeat(" ", (MAX_NAME_CHAR_LEN - mod)));
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN - itemPrices.length)));
} else {
// 对菜名进行猜分
builder.append(foodName);
// 另起新行
// new line
builder.append("<BR>");
builder.append(orderNameEmpty);
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN - itemPrices.length)));
}
builder.append("<BR>");
return builder.toString();
}
/**
* 格式化菜品列表用于58mm打印机
* 注意:默认字体排版,若是字体宽度倍大后不适用
* 58mm打印机一行可打印32个字符 汉子按照2个字符算
* 分3列 名称20字符一般用16字符4空格填充 数量6字符 单价6字符不足用英文空格填充 名称过长换行
* Format the dish list (for 58 mm printer)
* Note: this is default font typesetting, not applicable if the font width is doubled
* The 58mm printer can print 32 characters per line
* Divided into 3 columns: name(20 characters), quanity(6 characters),price(6 characters)
* The name column is generally filled with 16 your characters and 4 spaces
* Long name column will cause auto line break
*
* @param foodName 菜品名称
* @param quantity 数量
* @param price 价格
* @throws Exception
*/
public static String formatPrintOrderItemForNewLine58(String foodName, Integer quantity, Double price) throws Exception {
StringBuilder builder = new StringBuilder();
byte[] itemNames = foodName.getBytes("GBK");
Integer mod = itemNames.length % ROW_MAX_CHAR_LEN;
if (mod <= LAST_ROW_MAX_NAME_CHAR_LEN) {
builder.append(foodName);
// 在同一行,留4个英文字符的空格
//if in the same row, fill with 4 spaces at the end of name column
builder.append(StringUtils.repeat(" ", (MAX_NAME_CHAR_LEN - mod)));
String quanityStr = quantity.toString();
byte[] itemQuans = quanityStr.getBytes("GBK");
String priceStr = roundByTwo(price);
byte[] itemPrices = (priceStr).getBytes("GBK");
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN - itemPrices.length)));
} else {
getFoodNameSplit58(foodName, builder, quantity, price);
}
builder.append("<BR>");
return builder.toString();
}
/**
* 格式化菜品列表用于58mm打印机
* 注意:默认字体排版,若是字体宽度倍大后不适用
* 58mm打印机一行可打印32个字符 汉子按照2个字符算
* 分3列 名称20字符一般用16字符4空格填充 数量6字符 单价6字符不足用英文空格填充 名称过长换行
* Format the dish list (for 58 mm printer)
* Note: this is default font typesetting, not applicable if the font width is doubled
* The 58mm printer can print 32 characters per line
* Divided into 3 columns: name(20 characters), quanity(6 characters),price(6 characters)
* The name column is generally filled with 16 your characters and 4 spaces
* Long name column will cause auto line break
*
* @param foodName 菜品名称
* @param quantity 数量
* @param price 价格
* @throws Exception
*/
public static String formatPrintOrderItemForNewLine80(String foodName, Integer quantity, Double price) throws Exception {
StringBuilder builder = new StringBuilder();
byte[] itemNames = foodName.getBytes("GBK");
Integer mod = itemNames.length % ROW_MAX_CHAR_LEN80;
if (mod <= LAST_ROW_MAX_NAME_CHAR_LEN80) {
builder.append(foodName);
// 在同一行,留4个英文字符的空格
//if in the same row, fill with 4 spaces at the end of name column
builder.append(StringUtils.repeat(" ", (MAX_NAME_CHAR_LEN80 - mod)));
String quanityStr = quantity.toString();
byte[] itemQuans = quanityStr.getBytes("GBK");
String priceStr = roundByTwo(price);
byte[] itemPrices = (priceStr).getBytes("GBK");
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN80 - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN80 - itemPrices.length)));
} else {
getFoodNameSplit80(foodName, builder, quantity, price);
}
builder.append("<BR>");
return builder.toString();
}
private static void getFoodNameSplit58(String foodName, StringBuilder builder, Integer quantity, Double price) throws UnsupportedEncodingException {
String[] foodNames = string2StringArray(foodName, LAST_ROW_MAX_NAME_CHAR_LEN);
String quanityStr = quantity.toString();
byte[] itemQuans = quanityStr.getBytes("GBK");
String priceStr = roundByTwo(price);
byte[] itemPrices = (priceStr).getBytes("GBK");
for (int i = 0; i < foodNames.length; i++) {
if (i == 0) {
byte[] itemNames = foodNames[i].getBytes("GBK");
Integer mod = itemNames.length % ROW_MAX_CHAR_LEN;
builder.append(foodNames[i]);
builder.append(StringUtils.repeat(" ", (MAX_NAME_CHAR_LEN - mod)));
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN - itemPrices.length)));
} else {
builder.append(foodNames[i]).append("<BR>");
}
}
}
private static void getFoodNameSplit80(String foodName, StringBuilder builder, Integer quantity, Double price) throws UnsupportedEncodingException {
String[] foodNames = string2StringArray(foodName, LAST_ROW_MAX_NAME_CHAR_LEN80);
String quanityStr = quantity.toString();
byte[] itemQuans = quanityStr.getBytes("GBK");
String priceStr = roundByTwo(price);
byte[] itemPrices = (priceStr).getBytes("GBK");
for (int i = 0; i < foodNames.length; i++) {
if (i == 0) {
byte[] itemNames = foodNames[i].getBytes("GBK");
Integer mod = itemNames.length % ROW_MAX_CHAR_LEN80;
builder.append(foodNames[i]);
builder.append(StringUtils.repeat(" ", (MAX_NAME_CHAR_LEN80 - mod)));
builder.append(quanityStr).append(StringUtils.repeat(" ", (MAX_QUANTITY_CHAR_LEN80 - itemQuans.length)));
builder.append(priceStr).append(StringUtils.repeat(" ", (MAX_PRICE_CHAR_LEN80 - itemPrices.length)));
} else {
builder.append(foodNames[i]).append("<BR>");
}
}
}
private static String[] string2StringArray(String src, Integer length) {
if (StringUtils.isBlank(src) || length <= 0) {
return null;
}
int n = (src.length() + length - 1) / length;
String[] splits = new String[n];
for (int i = 0; i < n; i++) {
if (i < (n - 1)) {
splits[i] = src.substring(i * length, (i + 1) * length);
} else {
splits[i] = src.substring(i * length);
}
}
return splits;
}
/**
* 将double格式化为指定小数位的String不足小数位用0补全 (小数点后保留2位)
* Format the double as a String with specified decimal places, fill in with 0 if the decimal place is not enough
*
* @param v - 需要格式化的数字 Number to be formatted
* @return 返回指定位数的字符串 Returns a string with a specified number of digits
*/
public static String roundByTwo(double v) {
return roundByScale(v, 2);
}
/**
* 将double格式化为指定小数位的String不足小数位用0补全
* Format the double as a String with specified decimal places, and use 0 to complete the decimal places
*
* @param v - 需要格式化的数字 number to be formatted
* @param scale - 小数点后保留几位 places after the decimal point
* @return 返回指定位数的字符串 Returns a string with a specified number of digits
*/
public static String roundByScale(double v, int scale) {
if (scale == 0) {
return new DecimalFormat("0").format(v);
}
String formatStr = "0.";
for (int i = 0; i < scale; i++) {
formatStr = formatStr + "0";
}
return new DecimalFormat(formatStr).format(v);
}
}

View File

@ -0,0 +1,24 @@
package net.xpyun.platform.opensdk.vo;
/**
* 添加打印机请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class AddPrinterRequest extends RestRequest {
public AddPrinterRequestItem[] getItems() {
return items;
}
public void setItems(AddPrinterRequestItem[] items) {
this.items = items;
}
/**
* 请求项集合
*/
private AddPrinterRequestItem[] items;
}

View File

@ -0,0 +1,35 @@
package net.xpyun.platform.opensdk.vo;
/**
* 添加打印机请求项
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class AddPrinterRequestItem {
/**
* 打印机编号
*/
private String sn;
/**
* 打印机名称
*/
private String name;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,23 @@
package net.xpyun.platform.opensdk.vo;
/**
* 删除打印机请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class DelPrinterRequest extends RestRequest {
/**
* 打印机编号集合
*/
private String[] snlist;
public String[] getSnlist() {
return snlist;
}
public void setSnlist(String[] snlist) {
this.snlist = snlist;
}
}

View File

@ -0,0 +1,95 @@
package net.xpyun.platform.opensdk.vo;
/**
* 返回公共参数
*
* @param <T>
* @author RabyGao
* @date Aug 7, 2019
*/
public class ObjectRestResponse<T> {
public static final String REST_RESPONSE_OK = "ok";
/**
* 返回码正确返回0【注意结果正确与否的判断请用此返回参数】错误返回非零
*/
private int code;
/**
* 结果提示信息正确返回”ok”如果有错误返回错误信息
*/
private String msg;
/**
* 数据类型和内容详看私有返回参数data如果有错误返回null
*/
private T data;
/**
* 服务器程序执行时间,单位:毫秒
*/
private long serverExecutedTime;
public ObjectRestResponse() {
this.setCode(0);
this.setMsg(REST_RESPONSE_OK);
}
public ObjectRestResponse code(int code) {
this.setCode(code);
return this;
}
public ObjectRestResponse data(T data) {
this.setData(data);
return this;
}
public ObjectRestResponse msg(String msg) {
this.setMsg(msg);
return this;
}
public ObjectRestResponse setResult(int code, T data) {
this.setCode(code);
this.setData(data);
return this;
}
public ObjectRestResponse setResult(int code, T data, String msg) {
this.setCode(code);
this.setData(data);
this.setMsg(msg);
return this;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public long getServerExecutedTime() {
return serverExecutedTime;
}
public void setServerExecutedTime(long serverExecutedTime) {
this.serverExecutedTime = serverExecutedTime;
}
}

View File

@ -0,0 +1,36 @@
package net.xpyun.platform.opensdk.vo;
/**
* 订单统计结果
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class OrderStatisResult {
/**
* 已打印订单数
*/
private int printed;
/**
* 等待打印订单数
*/
private int waiting;
public int getPrinted() {
return printed;
}
public void setPrinted(int printed) {
this.printed = printed;
}
public int getWaiting() {
return waiting;
}
public void setWaiting(int waiting) {
this.waiting = waiting;
}
}

View File

@ -0,0 +1,43 @@
package net.xpyun.platform.opensdk.vo;
/**
* 订单状态
*
* @author RabyGao
* @date Aug 8, 2019
*/
public enum OrderStatusType {
/**
* 处理中
*/
Processing(0),
/**
* 完成
*/
Completed(1),
/**
* 失败
*/
Failed(2);
private final int val;
public int getVal() {
return val;
}
OrderStatusType(int num) {
this.val = num;
}
public static OrderStatusType getOrderStatusType(int val) {
for (OrderStatusType type : OrderStatusType.values()) {
if (type.getVal() == val) {
return type;
}
}
return Processing;
}
}

View File

@ -0,0 +1,124 @@
package net.xpyun.platform.opensdk.vo;
/**
* 打印机打印请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class PrintRequest extends RestRequest {
/**
* 打印机编号
*/
private String sn;
/**
* 打印内容,不能超过5000字节
*/
private String content;
/**
* 打印份数默认为1
*/
private int copies = 1;
/**
* 打印模式默认为0
*/
private int mode = 0;
/**
* 支付方式41~55支付宝 微信 ...
*/
private Integer payType;
/**
* 支付与否59~61退款 到账 消费
*/
private Integer payMode;
/**
* 支付金额
*/
private Double money;
/**
* 声音播放模式0 为取消订单模式1 为静音模式2 为来单播放模式,默认为 2 来单播放模式
*/
private Integer voice;
/**
* 打印接口回调地址对应标识(取值范围 [ 1 - 5 ] 的整数)对于web管理后台 “功能设置” 菜单设置界面的打印接口回调标识。
*/
private Integer backurlFlag;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getCopies() {
return copies;
}
public void setCopies(int copies) {
this.copies = copies;
}
public int getMode() {
return mode;
}
public void setMode(int mode) {
this.mode = mode;
}
public Integer getPayType() {
return payType;
}
public void setPayType(Integer payType) {
this.payType = payType;
}
public Integer getPayMode() {
return payMode;
}
public void setPayMode(Integer payMode) {
this.payMode = payMode;
}
public Double getMoney() {
return money;
}
public void setMoney(Double money) {
this.money = money;
}
public Integer getVoice() {
return voice;
}
public void setVoice(Integer voice) {
this.voice = voice;
}
public Integer getBackurlFlag() {
return backurlFlag;
}
public void setBackurlFlag(Integer backurlFlag) {
this.backurlFlag = backurlFlag;
}
}

View File

@ -0,0 +1,23 @@
package net.xpyun.platform.opensdk.vo;
/**
* 打印机请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class PrinterRequest extends RestRequest {
/**
* 打印机编号
*/
private String sn;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
}

View File

@ -0,0 +1,57 @@
package net.xpyun.platform.opensdk.vo;
import java.util.ArrayList;
import java.util.List;
/**
* 批量添加或删除打印机结果
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class PrinterResult{
public PrinterResult() {
success = new ArrayList<>();
fail = new ArrayList<>();
failMsg=new ArrayList<>();
}
/**
* 成功的打印机编号集合
*/
private List<String> success;
/**
* 失败的打印机编号集合
*/
private List<String> fail;
/**
* 失败原因集合 设备编号:失败原因
*/
private List<String> failMsg ;
public List<String> getSuccess() {
return success;
}
public void setSuccess(List<String> success) {
this.success = success;
}
public List<String> getFail() {
return fail;
}
public void setFail(List<String> fail) {
this.fail = fail;
}
public List<String> getFailMsg() {
return failMsg;
}
public void setFailMsg(List<String> failMsg) {
this.failMsg = failMsg;
}
}

View File

@ -0,0 +1,43 @@
package net.xpyun.platform.opensdk.vo;
/**
* 打印机状态
*
* @author RabyGao
* @date Aug 8, 2019
*/
public enum PrinterStatusType {
/**
* 离线
*/
Offline(0),
/**
* 在线正常
*/
OnlinNormal(1),
/**
* 在线缺纸
*/
OnlineMissingPaper(2);
private final int val;
public int getVal() {
return val;
}
private PrinterStatusType(int num) {
this.val = num;
}
public static PrinterStatusType getPrinterStatusType(int val) {
for (PrinterStatusType type : PrinterStatusType.values()) {
if (type.getVal() == val) {
return type;
}
}
return Offline;
}
}

View File

@ -0,0 +1,24 @@
package net.xpyun.platform.opensdk.vo;
import java.util.List;
/**
* @author LylJavas
* @create 2021/4/14 18:01
* @description 批量打印机请求参数
*/
public class PrintersRequest extends RestRequest {
/**
* 打印机编号列表
*/
private List<String> snlist;
public List<String> getSnlist() {
return snlist;
}
public void setSnlist(List<String> snlist) {
this.snlist = snlist;
}
}

View File

@ -0,0 +1,23 @@
package net.xpyun.platform.opensdk.vo;
/**
* 查询订单状态请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class QueryOrderStateRequest extends RestRequest {
/**
* 订单编号
*/
private String orderId;
public String getOrderId() {
return orderId;
}
public void setOrderId(String orderId) {
this.orderId = orderId;
}
}

View File

@ -0,0 +1,35 @@
package net.xpyun.platform.opensdk.vo;
/**
* 查询订单统计请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class QueryOrderStatisRequest extends RestRequest {
/**
* 打印机编号
*/
private String sn;
/**
* 查询日期格式YY-MM-DD2016-09-20
*/
private String date;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}

View File

@ -0,0 +1,59 @@
package net.xpyun.platform.opensdk.vo;
/**
* 请求公共参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class RestRequest {
/**
* 芯烨云后台注册用户名
*/
private String user;
/**
* 当前UNIX时间戳10位精确到秒
*/
private String timestamp;
/**
* 对参数 user + UKEY + timestamp 拼接后(+号表示连接符进行SHA1加密得到签名值为40位小写字符串
*/
private String sign;
/**
* debug=1返回非json格式的数据。仅测试时候使用
*/
private String debug;
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getTimestamp() {
return timestamp;
}
public void setTimestamp(String timestamp) {
this.timestamp = timestamp;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getDebug() {
return debug;
}
public void setDebug(String debug) {
this.debug = debug;
}
}

View File

@ -0,0 +1,37 @@
package net.xpyun.platform.opensdk.vo;
/**
* 设置打印机语音类型请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class SetVoiceTypeRequest extends RestRequest {
/**
* 打印机编号
*/
private String sn;
/**
* 声音类型: 0真人语音 1真人语音 2真人语音 3 嘀嘀声 4 静音
*/
private Integer voiceType;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public Integer getVoiceType() {
return voiceType;
}
public void setVoiceType(Integer voiceType) {
this.voiceType = voiceType;
}
}

View File

@ -0,0 +1,60 @@
package net.xpyun.platform.opensdk.vo;
/**
* 修改打印机请求参数
*
* @author RabyGao
* @date Aug 7, 2019
*/
public class UpdPrinterRequest extends RestRequest {
/**
* 打印机编号
*/
private String sn;
/**
* 打印机名称
*/
private String name;
/**
* 打印机识别码
*/
private String idcode;
/**
* 流量卡号码
*/
private String cardno;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getIdcode() {
return idcode;
}
public void setIdcode(String idcode) {
this.idcode = idcode;
}
public String getCardno() {
return cardno;
}
public void setCardno(String cardno) {
this.cardno = cardno;
}
}

View File

@ -0,0 +1,61 @@
package net.xpyun.platform.opensdk.vo;
/**
* 云喇叭播放语音请求参数
*
* @author RabyGao
* @date Aug 5, 2020
*/
public class VoiceRequest extends RestRequest {
/**
* 打印机编号
*/
private String sn;
/**
* 支付方式41~55支付宝 微信 ...
*/
private Integer payType;
/**
* 支付与否59~61退款 到账 消费
*/
private Integer payMode;
/**
* 支付金额
*/
private Double money;
public String getSn() {
return sn;
}
public void setSn(String sn) {
this.sn = sn;
}
public Integer getPayType() {
return payType;
}
public void setPayType(Integer payType) {
this.payType = payType;
}
public Integer getPayMode() {
return payMode;
}
public void setPayMode(Integer payMode) {
this.payMode = payMode;
}
public Double getMoney() {
return money;
}
public void setMoney(Double money) {
this.money = money;
}
}