员工报餐 api:人脸核销,清空停餐信息

This commit is contained in:
ryoeiken 2021-01-13 11:43:38 +08:00
parent 7782d98641
commit 5efc76dfc8
10 changed files with 197 additions and 59 deletions

View File

@ -3,7 +3,9 @@ package com.ruoyi.system.fantang.common;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.ruoyi.system.fantang.service.IFtConfigDaoService;
import com.ruoyi.system.fantang.service.impl.FtConfigDaoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Date;
import java.util.Map;
@ -15,36 +17,35 @@ public class DinnerTypeUtils {
public static DinnerTypeUtils instance;
public static DinnerTypeUtils getInstance() {
public static DinnerTypeUtils getInstance(IFtConfigDaoService configDaoService ) {
if (instance == null) {
instance = new DinnerTypeUtils();
instance = new DinnerTypeUtils(configDaoService );
}
return instance;
}
private Date breakfastStart;
private Date breakfastEnd;
private final Date breakfastStart;
private final Date breakfastEnd;
private Date lunchStart;
private Date lunchEnd;
private final Date lunchStart;
private final Date lunchEnd;
private Date dinnerStart;
private Date dinnerEnd;
private final Date dinnerStart;
private final Date dinnerEnd;
@Autowired
IFtConfigDaoService configDaoService;
private DinnerTypeUtils() {
private DinnerTypeUtils(IFtConfigDaoService configDaoService) {
Map<String, String> setting = configDaoService.getDinnerTimeSetting();
String today = DateUtil.today();
this.breakfastStart = DateUtil.parse(today + setting.get("breakfastStart"));
this.breakfastEnd = DateUtil.parse(today + setting.get("breakfastEnd"));
this.breakfastStart = DateUtil.parse(today + " " + setting.get("breakfastStart"));
this.breakfastEnd = DateUtil.parse(today + " " + setting.get("breakfastEnd"));
this.lunchStart = DateUtil.parse(today + setting.get("lunchStart"));
this.lunchEnd = DateUtil.parse(today + setting.get("lunchEnd"));
this.lunchStart = DateUtil.parse(today + " " + setting.get("lunchStart"));
this.lunchEnd = DateUtil.parse(today + " " + setting.get("lunchEnd"));
this.dinnerStart = DateUtil.parse(today + setting.get("dinnerStart"));
this.dinnerEnd = DateUtil.parse(today + setting.get("dinnerEnd"));
this.dinnerStart = DateUtil.parse(today + " " + setting.get("dinnerStart"));
this.dinnerEnd = DateUtil.parse(today + " " + setting.get("dinnerEnd"));
}
@ -53,7 +54,7 @@ public class DinnerTypeUtils {
*
* @return 返回就餐类型的枚举类
*/
public DinnerType GetDinnerType() {
public DinnerType getDinnerType() {
DateTime now = new DateTime(DateTime.now());
if (now.isIn(this.breakfastStart, this.breakfastEnd)) {

View File

@ -6,10 +6,8 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.fantang.common.DinnerType;
import com.ruoyi.system.fantang.common.DinnerTypeUtils;
import com.ruoyi.system.fantang.domain.*;
import com.ruoyi.system.fantang.mapper.FtFaceEventDaoMapper;
import com.ruoyi.system.fantang.service.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -17,13 +15,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@Slf4j
@ -31,9 +25,7 @@ import java.util.List;
@RestController
@RequestMapping("/client_api/staff")
public class ClientController extends BaseController {
/**
* 获取用餐时间
*/
@Autowired
private IFtConfigDaoService iFtConfigDaoService;
@ -50,7 +42,7 @@ public class ClientController extends BaseController {
private IFtWeekMenuDaoService weekMenuDaoService;
@Autowired
private IFtReportMealsDaoService reportMealsDaoService;
private IFtFaceinfoDaoService faceinfoDaoService;
@Autowired
private IFtStaffSubsidyDaoService staffSubsidyDaoService;
@ -65,7 +57,7 @@ public class ClientController extends BaseController {
private IFtFoodDefaultDaoService foodDefaultDaoService;
@Autowired
private IFtFaceEventService faceEventService;
private IFtStaffStopMealsDaoService staffStopMealsDaoService;
/**
* 获取用餐时间信息
@ -85,7 +77,7 @@ public class ClientController extends BaseController {
* 日期2020年12月11日
* 作者陈智兴
*
* @return
* @return AjaxResult
*/
@GetMapping("/getOrderOfToday/{staffId}")
public AjaxResult getOrderOfToday(@PathVariable("staffId") Long staffId) {
@ -287,8 +279,9 @@ public class ClientController extends BaseController {
Calendar cal = Calendar.getInstance();
cal.setTime(params.getDate("date"));
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
if (w < 0)
if (w < 0) {
w = 0;
}
return weekMenuDaoService.getMenuOfDay(weekDays[w]);
}
@ -399,8 +392,9 @@ public class ClientController extends BaseController {
/**
* 获取各餐品的价格清单
* @author : 陈智兴
*
* @param
* @author : 陈智兴
*/
@GetMapping("/getDinnerPriceList")
public AjaxResult getDinnerPriceList() {
@ -433,10 +427,10 @@ public class ClientController extends BaseController {
Integer type = params.getInteger("type");
// 总价
BigDecimal totalPrice = params.getBigDecimal("receipts");
BigDecimal totalPrice = params.getBigDecimal("receipts");
// 生成新订单
FtOrderDao orderDao = new FtOrderDao();
FtOrderDao orderDao = new FtOrderDao();
orderDao.setOrderType(type);
orderDao.setStaffId(staffId);
orderDao.setTotalPrice(totalPrice);
@ -492,7 +486,7 @@ public class ClientController extends BaseController {
*/
@Transactional
@PostMapping("/orderRefund")
public AjaxResult orderRefund(@RequestBody JSONObject params){
public AjaxResult orderRefund(@RequestBody JSONObject params) {
// 订单 id
Integer orderId = params.getInteger("orderId");
@ -554,14 +548,14 @@ public class ClientController extends BaseController {
}
/**
* 人脸识别设备心跳信号
*
* @param request
* @return
*/
@PostMapping("/heartbeat")
public String faceDeviceHeartbeatEvent(@RequestBody JSONObject request){
public String faceDeviceHeartbeatEvent(@RequestBody JSONObject request) {
System.out.println("face device heartbeat.....");
System.out.println(request);
return "ok";
@ -583,23 +577,59 @@ public class ClientController extends BaseController {
@PostMapping("/verify")
public String faceDeviceVerifyEvent(@RequestBody JSONObject request){
public String faceDeviceVerifyEvent(@RequestBody JSONObject request) {
// 判断是否在用餐时间否则只写日志不处理事件
DinnerType dinnerType = DinnerType.GetDinnerType();
DinnerTypeUtils.DinnerType dinnerType = DinnerTypeUtils.getInstance(iFtConfigDaoService).getDinnerType();
System.out.println(request);
if (dinnerType == DinnerType.notMatch) {
log.info("data : {} " , request);
if (dinnerType == DinnerTypeUtils.DinnerType.notMatch) {
log.info("data : {} ", request);
return request.toJSONString();
}
// 从数据中获取人脸id
JSONObject info = request.getJSONObject("info");
Integer personId = info.getInteger("PersonID");
Long deviceId = info.getLong("DeviceID");
// 是否有该员工
FtStaffInfoDao staffInfoDao = staffInfoDaoService.inStaff(personId);
if (staffInfoDao != null) {
// 获取员工 id
Long staffId = staffInfoDao.getStaffId();
String message;
// 进行核销如果该员工没有订餐则自动生成一个订餐记录并核销
switch (dinnerType) {
case breakfast:
message = orderDaoService.setWriteOff(staffId, 1, deviceId);
break;
case lunch:
message = orderDaoService.setWriteOff(staffId, 2, deviceId);
break;
case dinner:
message = orderDaoService.setWriteOff(staffId, 3, deviceId);
break;
default:
throw new IllegalStateException("Unexpected value: " + dinnerType);
}
log.info("人脸核销结果: {}", message);
return message;
} else {
// 如果该人脸id没有对应的员工则记录找日志中
return "没有找到该员工";
}
// 跟进人脸id信息查找该id对应的员工id的当餐订单
// 将该订餐设置为核销状态
// StringBuffer data = new StringBuffer();
//
// try {
@ -628,7 +658,19 @@ public class ClientController extends BaseController {
// } catch (IOException e) {
// } finally {
// }
return "ok";
}
/**
* 自动切换手动报餐时清空停餐记录
*/
@DeleteMapping("deleteStopMeals/{staffId}")
public AjaxResult deleteStopMeals(@PathVariable Long staffId) {
QueryWrapper<FtStaffStopMealsDao> wrapper = new QueryWrapper<>();
wrapper.eq("staff_id", staffId);
staffStopMealsDaoService.remove(wrapper);
return AjaxResult.success("已删除");
}
}

View File

@ -49,4 +49,38 @@ public interface FtOrderDaoMapper extends BaseMapper<FtOrderDao> {
List<FtOrderDao> listDetailedByDate(@Param("orderType") Integer orderType, @Param("start") String start, @Param("end") String end);
List<FtOrderDao> listAllDetailedByDate(String start, String end);
@Select("SELECT\n" +
"\t* \n" +
"FROM\n" +
"\tft_order \n" +
"WHERE\n" +
"\tstaff_id = #{staffId} \n" +
"\tAND order_type = #{type} \n" +
"\tAND order_date BETWEEN DATE(\n" +
"\tNOW()) \n" +
"\tAND date_add(\n" +
"\tnow(),\n" +
"\tINTERVAL 1 DAY)")
FtOrderDao getNowOrder(@Param("staffId") Long staffId, @Param("type") int type);
@Insert("INSERT INTO ft_order ( order_type, staff_id, order_list, total_price, create_at, pay_type, pay_flag, write_off_flag, write_off_at, device_id, order_date ) SELECT\n" +
"#{type},\n" +
"#{staffId},\n" +
"b.food_list,\n" +
"b.price,\n" +
"now(),\n" +
"1,\n" +
"1,\n" +
"1,\n" +
"NOW(),\n" +
"#{deviceId},\n" +
"NOW() \n" +
"FROM\n" +
"\tft_food_default b \n" +
"WHERE\n" +
"\tb.type = #{type}")
void insertOrderAndWriteOff(@Param("staffId") Long staffId, @Param("type") int type, @Param("deviceId") Long deviceId);
}

View File

@ -37,13 +37,15 @@ public interface IFtOrderDaoService extends IService<FtOrderDao> {
AjaxResult statisGetOrderOfWeek(Date date);
AjaxResult statisGetOrderOfWeekByPerson(Date date, Integer pageNum, Integer pageSize);
AjaxResult statisGetOrderOfWeekByPerson(Date date, Integer pageNum, Integer pageSize);
AjaxResult statisGetOrderOfMonth(Date date);
AjaxResult statisGetOrderOfMonthByPerson(Date date, Integer pageNum, Integer pageSize);
AjaxResult statisGetOrderOfMonthByPerson(Date date, Integer pageNum, Integer pageSize);
List<FtOrderDao> listDetailedByDate(Integer orderType, String start, String end);
List<FtOrderDao> listAllDetailedByDate(String start, String end);
String setWriteOff(Long staffId, int type, Long deviceId);
}

View File

@ -2,7 +2,6 @@ package com.ruoyi.system.fantang.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.fantang.domain.FtDepartDao;
import com.ruoyi.system.fantang.domain.FtStaffInfoDao;
import java.util.List;
@ -22,4 +21,6 @@ public interface IFtStaffInfoDaoService extends IService<FtStaffInfoDao> {
AjaxResult logout(Long staffId);
FtStaffInfoDao getDepartInfo(Long staffId);
FtStaffInfoDao inStaff(Integer personId);
}

View File

@ -0,0 +1,8 @@
package com.ruoyi.system.fantang.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.ruoyi.system.fantang.domain.FtStaffStopMealsDao;
public interface IFtStaffStopMealsDaoService extends IService<FtStaffStopMealsDao> {
}

View File

@ -1,16 +1,15 @@
package com.ruoyi.system.fantang.service.impl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.StringUtils;
import com.ruoyi.system.fantang.mapper.FtFaceinfoDaoMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.fantang.domain.FtFaceinfoDao;
import com.ruoyi.system.fantang.mapper.FtFaceinfoDaoMapper;
import com.ruoyi.system.fantang.service.IFtFaceinfoDaoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;
/**
* 人脸信息Service业务层处理
@ -24,14 +23,14 @@ public class FtFaceinfoDaoServiceImpl extends ServiceImpl<FtFaceinfoDaoMapper, F
@Override
public List<FtFaceinfoDao> queryList(FtFaceinfoDao ftFaceinfoDao) {
LambdaQueryWrapper<FtFaceinfoDao> lqw = Wrappers.lambdaQuery();
if (StringUtils.isNotBlank(ftFaceinfoDao.getDeviceId())){
lqw.eq(FtFaceinfoDao::getDeviceId ,ftFaceinfoDao.getDeviceId());
if (StringUtils.isNotBlank(ftFaceinfoDao.getDeviceId())) {
lqw.eq(FtFaceinfoDao::getDeviceId, ftFaceinfoDao.getDeviceId());
}
if (ftFaceinfoDao.getPersonId() != null){
lqw.eq(FtFaceinfoDao::getPersonId ,ftFaceinfoDao.getPersonId());
if (ftFaceinfoDao.getPersonId() != null) {
lqw.eq(FtFaceinfoDao::getPersonId, ftFaceinfoDao.getPersonId());
}
if (StringUtils.isNotBlank(ftFaceinfoDao.getPhone())){
lqw.eq(FtFaceinfoDao::getPhone ,ftFaceinfoDao.getPhone());
if (StringUtils.isNotBlank(ftFaceinfoDao.getPhone())) {
lqw.eq(FtFaceinfoDao::getPhone, ftFaceinfoDao.getPhone());
}
return this.list(lqw);
}

View File

@ -168,4 +168,36 @@ public class FtOrderDaoServiceImpl extends ServiceImpl<FtOrderDaoMapper, FtOrder
public List<FtOrderDao> listAllDetailedByDate(String start, String end) {
return this.baseMapper.listAllDetailedByDate(start, end);
}
@Override
public String setWriteOff(Long staffId, int type, Long deviceId) {
FtOrderDao orderDao = this.baseMapper.getNowOrder(staffId, type);
if (orderDao != null) {
// 判断该订单是否已核销
if (orderDao.getWriteOffFlag() != 1) {
// 核销该订单
orderDao.setPayType(1);
orderDao.setPayFlag(1);
orderDao.setWriteOffFlag(1);
orderDao.setWriteOffAt(new Date());
orderDao.setDeviceId(deviceId);
this.baseMapper.updateById(orderDao);
return "该订单已核销";
}
return "该订单已核销,请勿重复刷脸";
} else {
// 没有该订单则自动生成一个订餐记录并核销
this.baseMapper.insertOrderAndWriteOff(staffId, type, deviceId);
return "已生产订单并核销";
}
}
}

View File

@ -62,4 +62,11 @@ public class FtStaffInfoDaoServiceImpl extends ServiceImpl<FtStaffInfoDaoMapper,
public FtStaffInfoDao getDepartInfo(Long staffId) {
return this.baseMapper.getDepartInfo(staffId);
}
@Override
public FtStaffInfoDao inStaff(Integer personId) {
QueryWrapper<FtStaffInfoDao> wrapper = new QueryWrapper<>();
wrapper.eq("person_id", personId);
return this.baseMapper.selectOne(wrapper);
}
}

View File

@ -0,0 +1,12 @@
package com.ruoyi.system.fantang.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.fantang.domain.FtStaffStopMealsDao;
import com.ruoyi.system.fantang.mapper.FtStaffStopMealsDaoMapper;
import com.ruoyi.system.fantang.service.IFtStaffStopMealsDaoService;
import org.springframework.stereotype.Service;
@Service
public class FtStaffStopMealsDaoServiceImpl extends ServiceImpl<FtStaffStopMealsDaoMapper, FtStaffStopMealsDao> implements IFtStaffStopMealsDaoService {
}