扫码排队增删改查接口
This commit is contained in:
parent
b1e5ae969b
commit
62c28fe2f6
|
|
@ -0,0 +1,106 @@
|
|||
package cn.ysk.cashier.controller;
|
||||
|
||||
import cn.ysk.cashier.annotation.AnonymousAccess;
|
||||
import cn.ysk.cashier.dto.calltable.*;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.service.app.TbCallService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* 叫号
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/callTable")
|
||||
@AllArgsConstructor
|
||||
public class TbCallTableController {
|
||||
|
||||
private final TbCallService tbCallService;
|
||||
|
||||
@AnonymousAccess
|
||||
@GetMapping
|
||||
public ResponseEntity<?> get(
|
||||
@RequestParam(required = false) Integer callTableId,
|
||||
@RequestParam Integer shopId,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) Integer state
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.get(page, size, shopId, callTableId, state));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@PostMapping
|
||||
public ResponseEntity<?> add(
|
||||
@Validated @RequestBody CallTableDTO addCallTableDTO
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.add(addCallTableDTO));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@PutMapping
|
||||
public ResponseEntity<?> update(
|
||||
@Validated @RequestBody UpdateCallTableDTO callTableDTO
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.update(callTableDTO));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@DeleteMapping
|
||||
public ResponseEntity<?> delete(
|
||||
@Validated @RequestBody BaseCallTableDTO baseCallTableDTO
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.delete(baseCallTableDTO));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@PostMapping("takeNumber")
|
||||
public ResponseEntity<?> takeNumber(
|
||||
@Validated @RequestBody TakeNumberDTO takeNumberDTO
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.takeNumber(takeNumberDTO));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@GetMapping("takeNumberCode")
|
||||
public ResponseEntity<?> takeNumberCode(
|
||||
@RequestParam Integer shopId,
|
||||
@RequestParam Integer callTableId
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.takeNumberCode(shopId, callTableId));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@PostMapping("call")
|
||||
public ResponseEntity<?> call(
|
||||
@Validated @RequestBody CallQueueDTO callQueueDTO
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.call(callQueueDTO));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@PutMapping("updateState")
|
||||
public ResponseEntity<?> confirm(
|
||||
@Validated @RequestBody UpdateCallQueueDTO updateCallQueueDTO
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.updateInfo(updateCallQueueDTO));
|
||||
}
|
||||
|
||||
@AnonymousAccess
|
||||
@GetMapping("queue")
|
||||
public ResponseEntity<?> getQueue(
|
||||
@RequestParam Integer shopId,
|
||||
@RequestParam(required = false) Integer callTableId,
|
||||
@RequestParam(required = false) Integer state,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size
|
||||
) {
|
||||
return ResponseEntity.ok(tbCallService.getQueue(shopId, callTableId, state, page, size));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package cn.ysk.cashier.dto.calltable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Getter
|
||||
public class UpdateCallQueueDTO extends CallQueueDTO{
|
||||
@NotNull
|
||||
private Byte state;
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package cn.ysk.cashier.dto.calltable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class UpdateCallTableDTO{
|
||||
@NotNull
|
||||
private Integer callTableId;
|
||||
@NotNull
|
||||
private Integer shopId;
|
||||
private String name;
|
||||
private String note;
|
||||
@Min(1)
|
||||
private Integer waitTime;
|
||||
private String prefix;
|
||||
@Min(1)
|
||||
private Integer start;
|
||||
@Min(1)
|
||||
private Integer nearNum;
|
||||
}
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package cn.ysk.cashier.mybatis.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_call_queue")
|
||||
public class TbCallQueue {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "call_table_id")
|
||||
private Integer callTableId;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "phone")
|
||||
private String phone;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "shop_name")
|
||||
private String shopName;
|
||||
|
||||
@Column(name = "shop_id")
|
||||
private Integer shopId;
|
||||
|
||||
@Column(name = "state")
|
||||
private Byte state;
|
||||
|
||||
@Column(name = "create_time")
|
||||
private Instant createTime;
|
||||
|
||||
@Column(name = "call_time")
|
||||
private Instant callTime;
|
||||
|
||||
@Column(name = "call_count")
|
||||
private Integer callCount;
|
||||
|
||||
@Column(name = "pass_time")
|
||||
private Instant passTime;
|
||||
|
||||
@Column(name = "cancel_time")
|
||||
private Instant cancelTime;
|
||||
|
||||
@Column(name = "confirm_time")
|
||||
private Instant confirmTime;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "note")
|
||||
private String note;
|
||||
|
||||
@Column(name = "user_id")
|
||||
private Integer userId;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "open_id")
|
||||
private String openId;
|
||||
|
||||
@Column(name = "sub_state")
|
||||
private Integer subState;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
package cn.ysk.cashier.mybatis.entity;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.time.Instant;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name = "tb_call_table")
|
||||
public class TbCallTable {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", nullable = false)
|
||||
private Integer id;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "note")
|
||||
private String note;
|
||||
|
||||
@Column(name = "wait_time")
|
||||
private Integer waitTime;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "prefix")
|
||||
private String prefix;
|
||||
|
||||
@Column(name = "start")
|
||||
private Integer start;
|
||||
|
||||
@Column(name = "near_num")
|
||||
private Integer nearNum;
|
||||
|
||||
@Column(name = "state")
|
||||
private Byte state;
|
||||
|
||||
@Column(name = "shop_id")
|
||||
private Integer shopId;
|
||||
|
||||
@Size(max = 255)
|
||||
@Column(name = "qrcode")
|
||||
private String qrcode;
|
||||
|
||||
@Column(name = "create_time")
|
||||
private Instant createTime;
|
||||
|
||||
@Column(name = "update_time")
|
||||
private Instant updateTime;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallQueue;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_call_queue】的数据库操作Mapper
|
||||
* @createDate 2024-09-12 15:34:30
|
||||
* @Entity cn.ysk.cashier.mybatis.entity.TbCallQueue
|
||||
*/
|
||||
public interface TbCallQueueMapper extends BaseMapper<TbCallQueue> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package cn.ysk.cashier.mybatis.mapper;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallTable;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_call_table】的数据库操作Mapper
|
||||
* @createDate 2024-09-12 15:07:15
|
||||
* @Entity cn.ysk.cashier.mybatis.entity.TbCallTable
|
||||
*/
|
||||
public interface TbCallTableMapper extends BaseMapper<TbCallTable> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallQueue;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_call_queue】的数据库操作Service
|
||||
* @createDate 2024-09-12 15:34:30
|
||||
*/
|
||||
public interface TbCallQueueService extends IService<TbCallQueue> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package cn.ysk.cashier.mybatis.service;
|
||||
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallTable;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_call_table】的数据库操作Service
|
||||
* @createDate 2024-09-12 15:07:15
|
||||
*/
|
||||
public interface TbCallTableService extends IService<TbCallTable> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallQueue;
|
||||
import cn.ysk.cashier.mybatis.service.TbCallQueueService;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbCallQueueMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_call_queue】的数据库操作Service实现
|
||||
* @createDate 2024-09-12 15:34:30
|
||||
*/
|
||||
@Service
|
||||
public class TbCallQueueServiceImpl extends ServiceImpl<TbCallQueueMapper, TbCallQueue>
|
||||
implements TbCallQueueService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package cn.ysk.cashier.mybatis.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallTable;
|
||||
import cn.ysk.cashier.mybatis.service.TbCallTableService;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbCallTableMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
* @description 针对表【tb_call_table】的数据库操作Service实现
|
||||
* @createDate 2024-09-12 15:07:15
|
||||
*/
|
||||
@Service
|
||||
public class TbCallTableServiceImpl extends ServiceImpl<TbCallTableMapper, TbCallTable>
|
||||
implements TbCallTableService{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package cn.ysk.cashier.service.app;
|
||||
|
||||
import cn.ysk.cashier.dto.calltable.*;
|
||||
|
||||
public interface TbCallService {
|
||||
Object add(CallTableDTO addCallTableDTO);
|
||||
|
||||
Object update(UpdateCallTableDTO callTableDTO);
|
||||
|
||||
Object delete(BaseCallTableDTO baseCallTableDTO);
|
||||
|
||||
Object takeNumber(TakeNumberDTO takeNumber);
|
||||
|
||||
Object call(CallQueueDTO callQueueDTO);
|
||||
|
||||
Object updateInfo(UpdateCallQueueDTO updateCallQueueDTO);
|
||||
|
||||
Object get(Integer page, Integer size, Integer shopId, Integer callTableId, Integer state);
|
||||
|
||||
Object takeNumberCode(Integer shopId, Integer callTableId);
|
||||
|
||||
Object getQueue(Integer shopId, Integer callTableId, Integer state, Integer page, Integer size);
|
||||
}
|
||||
|
|
@ -0,0 +1,296 @@
|
|||
package cn.ysk.cashier.service.impl.app;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import cn.hutool.extra.qrcode.QrConfig;
|
||||
import cn.ysk.cashier.dto.calltable.*;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallQueue;
|
||||
import cn.ysk.cashier.mybatis.entity.TbCallTable;
|
||||
import cn.ysk.cashier.mybatis.mapper.TbShopUserMapper;
|
||||
import cn.ysk.cashier.mybatis.service.TbCallQueueService;
|
||||
import cn.ysk.cashier.mybatis.service.TbCallTableService;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbShopUser;
|
||||
import cn.ysk.cashier.repository.shop.TbShopInfoRepository;
|
||||
import cn.ysk.cashier.service.app.TbCallService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class TbCallServiceImpl implements TbCallService {
|
||||
|
||||
private final TbCallTableService callTableService;
|
||||
private final TbCallQueueService callQueueService;
|
||||
private final TbShopUserMapper shopUserMapper;
|
||||
private final TbShopInfoRepository shopInfoRepository;
|
||||
|
||||
@Override
|
||||
public Object add(CallTableDTO addCallTableDTO) {
|
||||
Long count = callTableService.lambdaQuery()
|
||||
.eq(TbCallTable::getShopId, addCallTableDTO.getShopId())
|
||||
.and(q -> {
|
||||
q.eq(TbCallTable::getName, addCallTableDTO.getName())
|
||||
.or()
|
||||
.eq(TbCallTable::getPrefix, addCallTableDTO.getPrefix());
|
||||
}).count();
|
||||
if (count > 0) {
|
||||
throw new BadRequestException("名称或前缀已存在");
|
||||
}
|
||||
|
||||
TbCallTable callTable = BeanUtil.copyProperties(addCallTableDTO, TbCallTable.class);
|
||||
callTable.setCreateTime(DateUtil.date().toInstant());
|
||||
return callTableService.save(callTable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object update(UpdateCallTableDTO callTableDTO) {
|
||||
TbCallTable callTable = callTableService.lambdaQuery()
|
||||
.eq(TbCallTable::getShopId, callTableDTO.getShopId())
|
||||
.eq(TbCallTable::getId, callTableDTO.getCallTableId()).one();
|
||||
|
||||
if (callTable == null) {
|
||||
throw new BadRequestException("桌型不存在");
|
||||
}
|
||||
TbCallTable newInfo = BeanUtil.copyProperties(callTableDTO, TbCallTable.class);
|
||||
newInfo.setId(callTable.getId());
|
||||
newInfo.setUpdateTime(DateUtil.date().toInstant());
|
||||
|
||||
return callTableService.updateById(newInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object delete(BaseCallTableDTO baseCallTableDTO) {
|
||||
return callTableService.remove(new LambdaQueryWrapper<TbCallTable>()
|
||||
.eq(TbCallTable::getId, baseCallTableDTO.getCallTableId())
|
||||
.eq(TbCallTable::getShopId, baseCallTableDTO.getShopId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object takeNumber(TakeNumberDTO takeNumberDTO) {
|
||||
TbShopInfo shopInfo = shopInfoRepository.findById(takeNumberDTO.getShopId()).orElse(null);
|
||||
if (shopInfo == null) {
|
||||
throw new BadRequestException("店铺信息不存在");
|
||||
}
|
||||
|
||||
TbCallTable callTable = callTableService.lambdaQuery()
|
||||
.eq(TbCallTable::getShopId, takeNumberDTO.getShopId())
|
||||
.eq(TbCallTable::getId, takeNumberDTO.getCallTableId()).one();
|
||||
if (callTable == null) {
|
||||
throw new BadRequestException("桌型不存在");
|
||||
}
|
||||
|
||||
// 拿取系统内部用户信息
|
||||
TbCallQueue callQueue;
|
||||
if (takeNumberDTO.getUserId() != null) {
|
||||
TbShopUser shopUser = shopUserMapper.selectOne(new LambdaQueryWrapper<TbShopUser>()
|
||||
.eq(TbShopUser::getStatus, 1)
|
||||
.eq(TbShopUser::getShopId, takeNumberDTO.getShopId())
|
||||
.eq(TbShopUser::getId, takeNumberDTO.getUserId()));
|
||||
if (shopUser == null) {
|
||||
throw new BadRequestException("用户不存在");
|
||||
}
|
||||
|
||||
callQueue = callQueueService.lambdaQuery()
|
||||
.eq(TbCallQueue::getUserId, shopUser.getId())
|
||||
.eq(TbCallQueue::getShopId, takeNumberDTO.getShopId())
|
||||
.eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one();
|
||||
if (callQueue != null) {
|
||||
throw new BadRequestException("当前用户已取号");
|
||||
}
|
||||
|
||||
callQueue = BeanUtil.copyProperties(takeNumberDTO, TbCallQueue.class);
|
||||
callQueue.setPhone(StrUtil.isBlank(takeNumberDTO.getPhone()) ? shopUser.getTelephone() : takeNumberDTO.getPhone());
|
||||
|
||||
// callQueue.setOpenId(shopUser.getMiniOpenId());
|
||||
|
||||
}else {
|
||||
// if (StrUtil.isBlank(takeNumberDTO.getPhone()) || StrUtil.isBlank(takeNumberDTO.getOpenId())) {
|
||||
// throw new BadRequestException("手机号或openId不能为空");
|
||||
// }
|
||||
|
||||
callQueue = callQueueService.lambdaQuery()
|
||||
.eq(TbCallQueue::getPhone, takeNumberDTO.getPhone())
|
||||
.eq(TbCallQueue::getShopId, takeNumberDTO.getShopId())
|
||||
.eq(TbCallQueue::getCallTableId, takeNumberDTO.getCallTableId()).one();
|
||||
if (callQueue != null) {
|
||||
throw new BadRequestException("当前用户已取号");
|
||||
}
|
||||
|
||||
callQueue = BeanUtil.copyProperties(takeNumberDTO, TbCallQueue.class);
|
||||
callQueue.setPhone(takeNumberDTO.getPhone());
|
||||
// callQueue.setOpenId(takeNumberDTO.getOpenId());
|
||||
callQueue.setSubState(1);
|
||||
}
|
||||
|
||||
callQueue.setCreateTime(DateUtil.date().toInstant());
|
||||
callQueue.setShopId(shopInfo.getId());
|
||||
callQueue.setShopName(shopInfo.getShopName());
|
||||
|
||||
return callQueueService.save(callQueue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(CallQueueDTO callQueueDTO) {
|
||||
TbCallQueue callQueue = callQueueService.lambdaQuery()
|
||||
.notIn(TbCallQueue::getState, -1, 2)
|
||||
.eq(TbCallQueue::getShopId, callQueueDTO.getShopId())
|
||||
.one();
|
||||
|
||||
if (callQueue == null) {
|
||||
throw new BadRequestException("叫号用户不存在");
|
||||
}
|
||||
|
||||
if (callQueue.getSubState().equals(0)) {
|
||||
throw new BadRequestException("当前用户未订阅微信提醒");
|
||||
}
|
||||
|
||||
callQueue.setState((byte) 1);
|
||||
callQueue.setCallCount(callQueue.getCallCount() + 1);
|
||||
callQueue.setCallTime(DateUtil.date().toInstant());
|
||||
|
||||
// 发送模板消息通知用户
|
||||
|
||||
return callQueueService.updateById(callQueue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object updateInfo(UpdateCallQueueDTO updateCallQueueDTO) {
|
||||
TbCallQueue callQueue = callQueueService.lambdaQuery()
|
||||
.eq(TbCallQueue::getShopId, updateCallQueueDTO.getShopId())
|
||||
.eq(TbCallQueue::getId, updateCallQueueDTO.getCallQueueId()).one();
|
||||
if (callQueue == null) {
|
||||
throw new BadRequestException("叫号用户不存在");
|
||||
}
|
||||
|
||||
switch (updateCallQueueDTO.getState()) {
|
||||
case -1:
|
||||
callQueue.setCancelTime(DateUtil.date().toInstant());
|
||||
break;
|
||||
case 0:
|
||||
if (callQueue.getSubState().equals(0)) {
|
||||
throw new BadRequestException("当前用户未订阅微信提醒");
|
||||
}
|
||||
|
||||
callQueue.setState((byte) 1);
|
||||
callQueue.setCallCount(callQueue.getCallCount() + 1);
|
||||
callQueue.setCallTime(DateUtil.date().toInstant());
|
||||
break;
|
||||
case 2:
|
||||
callQueue.setConfirmTime(DateUtil.date().toInstant());
|
||||
break;
|
||||
case 3:
|
||||
callQueue.setPassTime(DateUtil.date().toInstant());
|
||||
break;
|
||||
default:
|
||||
throw new BadRequestException("错误类型");
|
||||
|
||||
}
|
||||
|
||||
callQueue.setState(updateCallQueueDTO.getState());
|
||||
|
||||
return callQueueService.updateById(callQueue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(Integer page, Integer size, Integer shopId, Integer callTableId, Integer state) {
|
||||
LambdaQueryWrapper<TbCallTable> query = new LambdaQueryWrapper<TbCallTable>()
|
||||
.eq(TbCallTable::getShopId, shopId)
|
||||
.eq(TbCallTable::getState, 1);
|
||||
|
||||
if (callTableId != null) {
|
||||
query.eq(TbCallTable::getId, callTableId);
|
||||
}
|
||||
|
||||
if (state != null) {
|
||||
query.eq(TbCallTable::getState, state);
|
||||
}
|
||||
return callTableService.page(new Page<>(page, size), query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object takeNumberCode(Integer shopId, Integer callTableId) {
|
||||
// 创建二维码配置对象,设置宽度和高度为400
|
||||
QrConfig config = new QrConfig(400, 400);
|
||||
|
||||
// 使用字节数组输出流来存储二维码图片
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
// 生成二维码图片,输出到字节数组输出流
|
||||
QrCodeUtil.generate("Your QR Code Content Here", config, "png", outputStream);
|
||||
|
||||
// 将图片转换为 Base64 字符串
|
||||
String base64 = Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
||||
|
||||
// 返回Base64格式的图片字符串
|
||||
return "data:image/png;base64," + base64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getQueue(Integer shopId, Integer callTableId, Integer state, Integer page, Integer size) {
|
||||
List<Integer> tableIds;
|
||||
if (callTableId != null) {
|
||||
tableIds = Collections.singletonList(callTableId);
|
||||
}else {
|
||||
List<TbCallTable> list = callTableService.lambdaQuery()
|
||||
.eq(TbCallTable::getShopId, shopId)
|
||||
.eq(TbCallTable::getState, 1).list();
|
||||
if (list.isEmpty()) {
|
||||
return new Page<>();
|
||||
}
|
||||
tableIds = list.stream()
|
||||
.map(TbCallTable::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
LambdaQueryChainWrapper<TbCallQueue> query = callQueueService.lambdaQuery()
|
||||
.eq(TbCallQueue::getShopId, shopId)
|
||||
.in(TbCallQueue::getCallTableId, tableIds);
|
||||
if (state != null) {
|
||||
query.eq(TbCallQueue::getState, state);
|
||||
}
|
||||
Page<TbCallQueue> pageInfo = query
|
||||
.orderByAsc(TbCallQueue::getCreateTime)
|
||||
.orderByDesc(TbCallQueue::getState)
|
||||
.page(new Page<>(page, size));
|
||||
|
||||
List<TbCallQueue> list1 = pageInfo.getRecords();
|
||||
|
||||
// 创建返回的结果集
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
|
||||
// 遍历每一个叫号中的记录,计算前面状态为"0" (排队中) 的人数
|
||||
for (TbCallQueue calling : list1) {
|
||||
// 计算前面等待的人数 (状态为"0"且在叫号记录创建时间之前的)
|
||||
long waitingCount = 0;
|
||||
if (calling.getState() == 0) {
|
||||
waitingCount = list1.stream()
|
||||
.filter(item -> item.getState() == 0 || item.getState() == 1) // 过滤出状态为"排队中"的
|
||||
.filter(item -> item.getCreateTime().compareTo(calling.getCreateTime()) < 0 ) // 时间在当前叫号之前
|
||||
.count();
|
||||
}
|
||||
|
||||
// 创建一个Map来保存叫号中的记录及其前面排队的人数
|
||||
Map<String, Object> map = BeanUtil.beanToMap(calling, false, false);
|
||||
map.put("waitingCount", waitingCount);
|
||||
// 将该map加入结果集
|
||||
resultList.add(map);
|
||||
}
|
||||
|
||||
Map<String, Object> toMap = BeanUtil.beanToMap(pageInfo, false, false);
|
||||
toMap.put("records", resultList);
|
||||
|
||||
// 返回结果列表
|
||||
return toMap;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
package cn.ysk.cashier.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class WxMiniUtils {
|
||||
|
||||
// @Value("${wx.msg.appId}")
|
||||
// private String appId;
|
||||
//
|
||||
// @Value("${wx.msg.secrete}")
|
||||
// private String secrete;
|
||||
//
|
||||
// @Value("${wx.msg.warnMsgTmpId}")
|
||||
// private String msgTmpId;
|
||||
//
|
||||
// static LinkedHashMap<String,String> linkedHashMap=new LinkedHashMap<>();
|
||||
//
|
||||
// static {
|
||||
//
|
||||
// linkedHashMap.put("40001","获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口");
|
||||
// linkedHashMap.put("40003","不合法的 OpenID ,请开发者确认 OpenID (该用户)是否已关注公众号,或是否是其他公众号的 OpenID");
|
||||
// linkedHashMap.put("40014","不合法的 access_token ,请开发者认真比对 access_token 的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口");
|
||||
// linkedHashMap.put("40037","不合法的 template_id");
|
||||
// linkedHashMap.put("43101","用户未订阅消息");
|
||||
// linkedHashMap.put("43107","订阅消息能力封禁");
|
||||
// linkedHashMap.put("43108","并发下发消息给同一个粉丝");
|
||||
// linkedHashMap.put("45168","命中敏感词");
|
||||
// linkedHashMap.put("47003","参数错误");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// public JSONObject getAccessToken(){
|
||||
// String requestUrl = "https://api.weixin.qq.com/cgi-bin/token";
|
||||
// Map<String, String> requestUrlParam = new HashMap<>();
|
||||
// //小程序appId
|
||||
// requestUrlParam.put("appid", appId);
|
||||
// //小程序secret
|
||||
// requestUrlParam.put("secret", secrete);
|
||||
// //默认参数
|
||||
// requestUrlParam.put("grant_type", "client_credential");
|
||||
// JSONObject jsonObject = JSON.parseObject(HttpClientUtil.doGet(requestUrl,requestUrlParam));
|
||||
// return jsonObject;
|
||||
// }
|
||||
//
|
||||
// public static void main(String[] args) {
|
||||
// String id ="kSxJL9TR4s_UmOmNLE";
|
||||
//// sendStockWarnMsg("123", "1231", "1231", "23321", id);
|
||||
// }
|
||||
//
|
||||
// public JSONObject sendStockWarnMsg(String shopName, String productName, String stock, String note, String toUserOpenId) {
|
||||
// Map<String, Object> data = new HashMap<String, Object>() {{
|
||||
// put("thing1", new HashMap<String, Object>(){{
|
||||
// put("value", shopName);
|
||||
// }});
|
||||
// put("thing6", new HashMap<String, Object>(){{
|
||||
// put("value", productName);
|
||||
// }});
|
||||
// put("number7", new HashMap<String, Object>(){{
|
||||
// put("value", stock);
|
||||
// }});
|
||||
// put("thing5", new HashMap<String, Object>(){{
|
||||
// put("value", note);
|
||||
// }});
|
||||
// }};
|
||||
// log.info("开始发送库存预警消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||
// return sendTempMsg(msgTmpId, toUserOpenId, data);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public JSONObject sendTempMsg(String tempId, String toUserOpenId, Map<String, Object> data) {
|
||||
// log.info("开始发送微信模板消息, 接收用户openId: {}, 消息数据: {}", toUserOpenId, data);
|
||||
// JSONObject object= getAccessToken();
|
||||
// String accessToken=object.get("access_token")+"";
|
||||
//
|
||||
// JSONObject object1=new JSONObject();
|
||||
//
|
||||
// object1.put("template_id", tempId);
|
||||
// object1.put("touser", toUserOpenId);
|
||||
// object1.put("data",data);
|
||||
//
|
||||
// object1.put("miniprogram_state","trial");
|
||||
// object1.put("lang","zh_CN");
|
||||
//
|
||||
// String response= HttpRequest.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=".concat(accessToken)).body(object1.toString()).execute().body();
|
||||
// log.info("微信模板消息发送成功,相应内容:{}",response);
|
||||
// JSONObject resObj=JSONObject.parseObject(response);
|
||||
// if(ObjectUtil.isNotEmpty(resObj)&&ObjectUtil.isNotNull(resObj)&&"0".equals(resObj.get("errcode")+"")){
|
||||
// return resObj;
|
||||
// }
|
||||
//
|
||||
// throw new RuntimeException(linkedHashMap.getOrDefault(resObj.get("errcode") + "", "未知错误"));
|
||||
// }
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?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="cn.ysk.cashier.mybatis.mapper.TbCallQueueMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="cn.ysk.cashier.mybatis.entity.TbCallQueue">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="call_table_id" column="call_table_id" jdbcType="INTEGER"/>
|
||||
<result property="phone" column="phone" jdbcType="VARCHAR"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="shop_name" column="shop_name" jdbcType="VARCHAR"/>
|
||||
<result property="shop_id" column="shop_id" jdbcType="INTEGER"/>
|
||||
<result property="state" column="state" jdbcType="TINYINT"/>
|
||||
<result property="create_time" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="call_time" column="call_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="call_count" column="call_count" jdbcType="INTEGER"/>
|
||||
<result property="pass_time" column="pass_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="cancel_time" column="cancel_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="note" column="note" jdbcType="VARCHAR"/>
|
||||
<result property="user_id" column="user_id" jdbcType="INTEGER"/>
|
||||
<result property="open_id" column="open_id" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,call_table_id,phone,
|
||||
name,shop_name,shop_id,
|
||||
state,create_time,call_time,
|
||||
call_count,pass_time,cancel_time,
|
||||
note,user_id,open_id
|
||||
</sql>
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
<?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="cn.ysk.cashier.mybatis.mapper.TbCallTableMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="cn.ysk.cashier.mybatis.entity.TbCallTable">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="name" column="name" jdbcType="VARCHAR"/>
|
||||
<result property="note" column="note" jdbcType="VARCHAR"/>
|
||||
<result property="wait_time" column="wait_time" jdbcType="INTEGER"/>
|
||||
<result property="prefix" column="prefix" jdbcType="VARCHAR"/>
|
||||
<result property="start" column="start" jdbcType="INTEGER"/>
|
||||
<result property="near_num" column="near_num" jdbcType="INTEGER"/>
|
||||
<result property="state" column="state" jdbcType="TINYINT"/>
|
||||
<result property="shop_id" column="shop_id" jdbcType="INTEGER"/>
|
||||
<result property="qrcode" column="qrcode" jdbcType="VARCHAR"/>
|
||||
<result property="create_time" column="create_time" jdbcType="TIMESTAMP"/>
|
||||
<result property="update_time" column="update_time" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,name,note,
|
||||
wait_time,prefix,start,
|
||||
near_num,state,shop_id,
|
||||
qrcode,create_time,update_time
|
||||
</sql>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue