|
@@ -0,0 +1,164 @@
|
|
|
|
|
+package com.management.platform.service.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.management.platform.entity.MealApplications;
|
|
|
|
|
+import com.management.platform.entity.MealTypes;
|
|
|
|
|
+import com.management.platform.entity.User;
|
|
|
|
|
+import com.management.platform.entity.Factory;
|
|
|
|
|
+import com.management.platform.mapper.FactoryMapper;
|
|
|
|
|
+import com.management.platform.mapper.MealApplicationsMapper;
|
|
|
|
|
+import com.management.platform.mapper.MealTypesMapper;
|
|
|
|
|
+import com.management.platform.mapper.UserMapper;
|
|
|
|
|
+import com.management.platform.service.MealApplicationsService;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
+import com.management.platform.util.HttpRespMsg;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 服务实现类
|
|
|
|
|
+ * </p>
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author Seyason
|
|
|
|
|
+ * @since 2025-11-11
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+public class MealApplicationsServiceImpl extends ServiceImpl<MealApplicationsMapper, MealApplications> implements MealApplicationsService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private HttpServletRequest request;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private MealApplicationsMapper mealApplicationsMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private MealTypesMapper mealTypesMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UserMapper userMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FactoryMapper factoryMapper;
|
|
|
|
|
+
|
|
|
|
|
+ //获取当天订餐列表
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpRespMsg getDinnerBookingList(String date, Integer status) {
|
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
|
+ String factoryCode = request.getHeader("factoryCode");
|
|
|
|
|
+ if (factoryCode == null) {
|
|
|
|
|
+ msg.setError("factoryCode is null");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ Factory factoryItem = factoryMapper.selectOne(new QueryWrapper<Factory>().eq("code", factoryCode));
|
|
|
|
|
+ if (factoryItem == null) {
|
|
|
|
|
+ msg.setError("factory code not exists");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("is_active", 1));
|
|
|
|
|
+ List<MealTypes> mealTypesList = mealTypesMapper.selectList(new QueryWrapper<MealTypes>());
|
|
|
|
|
+ //按收银机所在厂区查看
|
|
|
|
|
+ QueryWrapper<MealApplications> queryWrapper = new QueryWrapper<MealApplications>()
|
|
|
|
|
+ .eq("factory_id", factoryItem.getId()).eq("application_date", date).orderByDesc("id");
|
|
|
|
|
+ if (status != null && status != -1) {
|
|
|
|
|
+ queryWrapper.eq("status", status);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<MealApplications> mealApplicationsList = mealApplicationsMapper.selectList(queryWrapper);
|
|
|
|
|
+ //绑定数据
|
|
|
|
|
+ for (MealApplications mealApplications : mealApplicationsList) {
|
|
|
|
|
+ for (User user : userList) {
|
|
|
|
|
+ if (user.getId().equals(mealApplications.getUserId())) {
|
|
|
|
|
+ mealApplications.setUserName(user.getName());
|
|
|
|
|
+ mealApplications.setJobNumber(user.getJobNumber());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mealTypesList.stream().filter(mealTypes -> mealTypes.getId().equals(mealApplications.getMealTypeId())).forEach(mealTypes -> mealApplications.setMealTypeName(mealTypes.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ msg.setData(mealApplicationsList);
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 核销预定码
|
|
|
|
|
+ * @param code
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpRespMsg writeOffCode(String code) {
|
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
|
+ String factoryCode = request.getHeader("factoryCode");
|
|
|
|
|
+ if (factoryCode == null) {
|
|
|
|
|
+ msg.setError("factory is null");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ Factory factoryItem = factoryMapper.selectOne(new QueryWrapper<Factory>().eq("code", factoryCode));
|
|
|
|
|
+ if (factoryItem == null) {
|
|
|
|
|
+ msg.setError("factory not exists");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ MealApplications mealApplications = mealApplicationsMapper.selectOne(new QueryWrapper<MealApplications>().eq("code", code));
|
|
|
|
|
+ if (mealApplications == null) {
|
|
|
|
|
+ msg.setError("预定码不存在,无法核销");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ } else if (mealApplications.getFactoryId().equals(factoryItem.getId())) {
|
|
|
|
|
+ msg.setError("预定码不属于当前厂区,无法核销");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ } else if (!mealApplications.getStatus().equals(0)) {
|
|
|
|
|
+ if (mealApplications.getStatus().equals(1)) {
|
|
|
|
|
+ msg.setError("预定码已核销");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ } else if (mealApplications.getStatus().equals(2)) {
|
|
|
|
|
+ msg.setError("预定码已取消");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ } else if (mealApplications.getStatus().equals(3)) {
|
|
|
|
|
+ msg.setError("预定码已过期");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //预约码可用
|
|
|
|
|
+ mealApplications.setUsedAt(LocalDateTime.now());
|
|
|
|
|
+ mealApplications.setStatus(1);
|
|
|
|
|
+ mealApplicationsMapper.updateById(mealApplications);
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public HttpRespMsg getTodayStatistics() {
|
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
|
+ String factoryCode = request.getHeader("factoryCode");
|
|
|
|
|
+ System.out.println("getTodayStatistics, factoryCode:"+factoryCode);
|
|
|
|
|
+ if (factoryCode == null) {
|
|
|
|
|
+ msg.setError("factory is null");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ Factory factoryItem = factoryMapper.selectOne(new QueryWrapper<Factory>().eq("code", factoryCode));
|
|
|
|
|
+ if (factoryItem == null) {
|
|
|
|
|
+ msg.setError("factory not exists");
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ //取今天的
|
|
|
|
|
+ String date = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
|
+
|
|
|
|
|
+ QueryWrapper<MealApplications> queryWrapper = new QueryWrapper<MealApplications>().eq("factory_id", factoryItem.getId()).eq("application_date", date).ne("status", 2);
|
|
|
|
|
+ List<MealApplications> mealApplicationsList = mealApplicationsMapper.selectList(queryWrapper);
|
|
|
|
|
+ //按用餐类型统计人数
|
|
|
|
|
+ List<MealTypes> mealTypesList = mealTypesMapper.selectList(new QueryWrapper<MealTypes>());
|
|
|
|
|
+ for (MealTypes mealTypes : mealTypesList) {
|
|
|
|
|
+ int count = 0;
|
|
|
|
|
+ for (MealApplications mealApplications : mealApplicationsList) {
|
|
|
|
|
+ if (mealTypes.getId().equals(mealApplications.getMealTypeId())) {
|
|
|
|
|
+ count++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ mealTypes.setCount(count);
|
|
|
|
|
+ }
|
|
|
|
|
+ msg.setData(mealTypesList);
|
|
|
|
|
+ return msg;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|