|
|
@@ -1,25 +1,25 @@
|
|
|
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.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.management.platform.entity.*;
|
|
|
+import com.management.platform.mapper.*;
|
|
|
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 org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
|
@@ -43,6 +43,15 @@ public class MealApplicationsServiceImpl extends ServiceImpl<MealApplicationsMap
|
|
|
private UserMapper userMapper;
|
|
|
@Resource
|
|
|
private FactoryMapper factoryMapper;
|
|
|
+ @Resource
|
|
|
+ private DepartmentMapper departmentMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getDinnerBookingList(String date) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//获取当天订餐列表
|
|
|
@Override
|
|
|
@@ -169,4 +178,166 @@ public class MealApplicationsServiceImpl extends ServiceImpl<MealApplicationsMap
|
|
|
msg.setData(mealTypesList);
|
|
|
return msg;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg getMealApplicationList(String deptIds, String userId, String startDate, String endDate, Integer pageIndex, Integer pageSize, Integer mealTypeId) {
|
|
|
+ HttpRespMsg httpRespMsg=new HttpRespMsg();
|
|
|
+ HashMap resultMap=new HashMap();
|
|
|
+ DateTimeFormatter dtf=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ DateTimeFormatter dtf1=DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
+ List<LocalDate> dateList = getDays(LocalDate.parse(startDate, dtf), LocalDate.parse(endDate, dtf));
|
|
|
+ List<String> dataStringList=new ArrayList<>();
|
|
|
+ //日期列表
|
|
|
+ for (LocalDate localDate : dateList) {
|
|
|
+ dataStringList.add(localDate.format(dtf1));
|
|
|
+ }
|
|
|
+ resultMap.put("header",dataStringList);
|
|
|
+
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", user.getCompanyId()));
|
|
|
+ Integer companyId = user.getCompanyId();
|
|
|
+
|
|
|
+ QueryWrapper<User> queryWrapper=new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("company_id",companyId);
|
|
|
+ List<Integer> deptIdList=new ArrayList<>();
|
|
|
+ if(deptIds!=null&&!StringUtils.isEmpty(deptIds)){
|
|
|
+ String[] split = deptIds.split(",");
|
|
|
+ for (String deptId : split) {
|
|
|
+ List<Integer> branchDepartment = getBranchDepartment(Integer.valueOf(deptId), departmentList);
|
|
|
+ deptIdList.addAll(branchDepartment);
|
|
|
+ }
|
|
|
+ queryWrapper.in("department_id",deptIdList);
|
|
|
+ }
|
|
|
+ if(!StringUtils.isEmpty(userId)){
|
|
|
+ queryWrapper.eq("id",userId);
|
|
|
+ }
|
|
|
+ String mealTypeIdString = "";
|
|
|
+ if(mealTypeId!=null){
|
|
|
+ mealTypeIdString = mealTypeId.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.eq("is_active",1);
|
|
|
+ queryWrapper.orderByAsc("department_id");
|
|
|
+ IPage<User> userIPage = userMapper.selectPage(new Page<>(pageIndex, pageSize), queryWrapper);
|
|
|
+ List<User> userList = userIPage.getRecords();
|
|
|
+
|
|
|
+ //先将数据全部取出来,再根据人员和部门进行筛选
|
|
|
+ List<Map<String,Object>> mealList = mealApplicationsMapper.getMealList(companyId,startDate,endDate,deptIdList,userId,mealTypeIdString);
|
|
|
+
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
|
|
+ for(Map<String,Object>mealMap:mealList){
|
|
|
+ //mealMap.get("date")为Date类型
|
|
|
+ if(mealMap.get("date") != null && mealMap.get("date") instanceof Date) {
|
|
|
+ Date date = (Date) mealMap.get("date");
|
|
|
+ mealMap.put("date",sdf.format(date));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ List<Map<String,Object>> totalList=new ArrayList<>();
|
|
|
+ for (String date : dataStringList) {
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
+ List<Map<String, Object>> targetList = mealList.stream().filter(p -> p.get("date").equals(date)).collect(Collectors.toList());
|
|
|
+ int ApplyAmount=0;//总报餐
|
|
|
+ int getMeal=0;//已用餐
|
|
|
+ int cancel=0;//已取消
|
|
|
+ int overLine=0;//已过期
|
|
|
+ for (Map<String, Object> mealMap : targetList) {
|
|
|
+ Integer status = (Integer) mealMap.get("status");
|
|
|
+ if (status != null) {
|
|
|
+ switch (status) {
|
|
|
+ case 0 :
|
|
|
+ ApplyAmount += 1;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ ApplyAmount += 1;
|
|
|
+ getMeal += 1;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ cancel += 1;
|
|
|
+ case 3:
|
|
|
+ ApplyAmount += 1;
|
|
|
+ cancel += 1;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put("userId","0");
|
|
|
+ map.put("date",date);
|
|
|
+ map.put("applyAmount",ApplyAmount);//总报餐
|
|
|
+ map.put("getMeal",getMeal);//已用餐
|
|
|
+ map.put("cancel",cancel);//已取消
|
|
|
+ map.put("overLine",overLine);//已过期
|
|
|
+ totalList.add(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ mealList.addAll(totalList);
|
|
|
+
|
|
|
+ List<Map<String,Object>> records= new ArrayList<>();
|
|
|
+ if(!StringUtils.isEmpty(deptIds)){
|
|
|
+ String[] split = deptIds.split(",");
|
|
|
+ for (String deptId : split) {
|
|
|
+ List<Integer> branchDepartment = getBranchDepartment(Integer.valueOf(deptId), departmentList);
|
|
|
+ deptIdList.addAll(branchDepartment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for(User itemUser:userList){
|
|
|
+ Map<String,Object> map=new HashMap<>();
|
|
|
+ String personId = itemUser.getId();
|
|
|
+ map.put("userId",itemUser.getId());
|
|
|
+ map.put("name",itemUser.getName());
|
|
|
+ if (map.get("userId").equals("0")) {
|
|
|
+ map.put("name","小计");
|
|
|
+ }
|
|
|
+ map.put("departmentId",itemUser.getDepartmentId());
|
|
|
+ String departmentName="未设置部门";
|
|
|
+
|
|
|
+ Integer departmentId = Integer.valueOf(String.valueOf(map.get("departmentId")));
|
|
|
+ map.put("departmentName", getBranchDepartment(departmentId, departmentList));
|
|
|
+
|
|
|
+ List<Map<String,Object>> personList = new ArrayList<>();
|
|
|
+ if (personId!= null){
|
|
|
+ personList = totalList.stream().filter(p -> p.get("userId").equals(personId)).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ map.put("personList",personList);
|
|
|
+
|
|
|
+ records.add(map);
|
|
|
+ }
|
|
|
+ resultMap.put("total",userIPage.getTotal());
|
|
|
+ resultMap.put("records",records);
|
|
|
+ httpRespMsg.setData(resultMap);
|
|
|
+
|
|
|
+
|
|
|
+ return httpRespMsg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private List<LocalDate> getDays(LocalDate start, LocalDate end) {
|
|
|
+ List<LocalDate> result = new ArrayList();
|
|
|
+ while (start.isBefore(end)) {
|
|
|
+ result.add(start);
|
|
|
+ start=start.plusDays(1);
|
|
|
+ }
|
|
|
+ result.add(start);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Integer> getBranchDepartment(Integer departmentId, List<Department> departmentList) {
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ list.add(departmentId);
|
|
|
+ //搜到子部门进行添加
|
|
|
+ for (Department department : departmentList) {
|
|
|
+ if (departmentId.equals(department.getSuperiorId())) {
|
|
|
+ list.addAll(getBranchDepartment(department.getDepartmentId(), departmentList));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
}
|