|
@@ -1,21 +1,36 @@
|
|
|
package com.sky.ioc.service.canteen.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.sky.ioc.entity.Indeicator;
|
|
|
import com.sky.ioc.entity.Label;
|
|
|
import com.sky.ioc.entity.Cake;
|
|
|
+import com.sky.ioc.entity.domain.canteen.Cuisine;
|
|
|
+import com.sky.ioc.entity.domain.canteen.FoodMenu;
|
|
|
+import com.sky.ioc.entity.domain.canteen.Order;
|
|
|
+import com.sky.ioc.entity.domain.system.Users;
|
|
|
import com.sky.ioc.entity.params.IocParam;
|
|
|
+import com.sky.ioc.entity.params.IocTimeRange;
|
|
|
+import com.sky.ioc.mapper.CuisineMapper;
|
|
|
+import com.sky.ioc.mapper.CuisineOrderMapper;
|
|
|
+import com.sky.ioc.mapper.FoodMenusMapper;
|
|
|
import com.sky.ioc.service.canteen.RestaurantService;
|
|
|
+import com.sky.ioc.tool.DateUtil;
|
|
|
import com.sky.ioc.tool.FalseData;
|
|
|
import com.sky.ioc.tool.GeneralMethod;
|
|
|
import com.sky.ioc.tool.ReturnMsg;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.text.DecimalFormat;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
|
|
@@ -25,6 +40,12 @@ import java.util.concurrent.ThreadLocalRandom;
|
|
|
@Service
|
|
|
public class RestaurantServiceImpl implements RestaurantService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ CuisineOrderMapper cuisineOrderMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ FoodMenusMapper foodMenusMapper;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* TODO 查询智慧生活中智慧餐厅的支付分析
|
|
@@ -37,12 +58,32 @@ public class RestaurantServiceImpl implements RestaurantService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ReturnMsg getPaymentAnalysis(IocParam iocParam) {
|
|
|
- List<Cake> list = new ArrayList<>();
|
|
|
- list.add(new Cake("Offline"));
|
|
|
- list.add(new Cake("scanningCode"));
|
|
|
- list.add(new Cake("payCard"));
|
|
|
- list.add(new Cake("Face"));
|
|
|
- return ReturnMsg.ok(list);
|
|
|
+ List<Cake> lists = new ArrayList<>();
|
|
|
+ Double offline = cuisineOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam,19);
|
|
|
+ Double scanningCode =cuisineOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam,16);
|
|
|
+ Double payCard =cuisineOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam,1);
|
|
|
+ Double face = cuisineOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam,4);
|
|
|
+ offline = offline==null?0:offline;
|
|
|
+ scanningCode = scanningCode==null?0:scanningCode;
|
|
|
+ payCard = payCard==null?0:payCard;
|
|
|
+ face = face==null?0:face;
|
|
|
+ Cake cake1 = new Cake();
|
|
|
+ Cake cake2 = new Cake();
|
|
|
+ Cake cake3 = new Cake();
|
|
|
+ Cake cake4 = new Cake();
|
|
|
+ cake1.setName("线下");
|
|
|
+ cake2.setName("扫码");
|
|
|
+ cake3.setName("人脸");
|
|
|
+ cake4.setName("刷卡");
|
|
|
+ cake4.setValue(payCard);
|
|
|
+ cake3.setValue(face);
|
|
|
+ cake2.setValue(scanningCode);
|
|
|
+ cake1.setValue(offline);
|
|
|
+ lists.add(cake3);
|
|
|
+ lists.add(cake1);
|
|
|
+ lists.add(cake2);
|
|
|
+ lists.add(cake4);
|
|
|
+ return ReturnMsg.ok(lists);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -53,40 +94,38 @@ public class RestaurantServiceImpl implements RestaurantService {
|
|
|
public ReturnMsg getCoreIndicators(IocParam iocParam) {
|
|
|
Indeicator indeicator = new Indeicator();
|
|
|
List<JSONObject> objects = indeicator.getList();
|
|
|
- /* ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
- int totalPerson = random.nextInt(100, 3000);
|
|
|
- int dayPerson = random.nextInt(150,500);
|
|
|
- while (dayPerson>totalPerson){
|
|
|
- dayPerson = random.nextInt(150,500);
|
|
|
+ ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
+ Double totalPrice = cuisineOrderMapper.getTotalPriceByCompanyIdAndDeptId(iocParam,null);
|
|
|
+ totalPrice = totalPrice == null ? 0 : totalPrice;
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(totalPrice);
|
|
|
+ Integer totalOrder = cuisineOrderMapper.getTotalOrderByCompanyIdAndDeptId(iocParam);
|
|
|
+ Integer totalPerson = cuisineOrderMapper.getTotalPersonByCompanyIdAndDeptId(iocParam);
|
|
|
+ int dayPerson = random.nextInt(0,totalPerson);
|
|
|
+ double avgPrice = 0d;
|
|
|
+ if (totalPrice > 0) {
|
|
|
+ if (totalOrder > 0) {
|
|
|
+ BigDecimal avgPriceDec = bigDecimal.divide(new BigDecimal(totalOrder), 2, RoundingMode.HALF_UP);
|
|
|
+ avgPrice = avgPriceDec.doubleValue();
|
|
|
+ }
|
|
|
}
|
|
|
- int price = random.nextInt(15,50);
|
|
|
- int totalPrice = price*totalPerson;
|
|
|
- float compare = (float) Math.random();
|
|
|
+ // 转换为万元(除以10000)保留两位小数
|
|
|
+ BigDecimal decimal = bigDecimal.divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP);
|
|
|
+ totalPrice = decimal.doubleValue();
|
|
|
+ double compare = random.nextDouble(-1, 1);
|
|
|
DecimalFormat decimalFormat = new DecimalFormat("#.0");
|
|
|
- compare = Float.parseFloat(decimalFormat.format(compare));
|
|
|
+ compare = Double.parseDouble(decimalFormat.format(compare));
|
|
|
+
|
|
|
objects.get(0).put("value",dayPerson);
|
|
|
objects.get(0).put("compare",compare);
|
|
|
|
|
|
- objects.get(1).put("value",totalPerson);
|
|
|
+ objects.get(1).put("value",totalOrder);
|
|
|
objects.get(1).put("compare",compare);
|
|
|
|
|
|
objects.get(2).put("value",totalPrice);
|
|
|
- objects.get(2).put("compare",-compare);
|
|
|
-
|
|
|
- objects.get(3).put("value",price);
|
|
|
- objects.get(3).put("compare",compare);*/
|
|
|
+ objects.get(2).put("compare",compare);
|
|
|
|
|
|
- objects.get(0).put("value",400);
|
|
|
- objects.get(0).put("compare",0.4);
|
|
|
-
|
|
|
- objects.get(1).put("value",2000);
|
|
|
- objects.get(1).put("compare",0.4);
|
|
|
-
|
|
|
- objects.get(2).put("value",18);
|
|
|
- objects.get(2).put("compare",-0.4);
|
|
|
-
|
|
|
- objects.get(3).put("value",18);
|
|
|
- objects.get(3).put("compare",0.4);
|
|
|
+ objects.get(3).put("value",avgPrice);
|
|
|
+ objects.get(3).put("compare",compare);
|
|
|
indeicator.setWorthAttention("员工偏爱川菜,建议增加");
|
|
|
indeicator.setList(objects);
|
|
|
return ReturnMsg.ok(indeicator);
|
|
@@ -97,7 +136,16 @@ public class RestaurantServiceImpl implements RestaurantService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ReturnMsg getWelcomeDishes(IocParam iocParam) {
|
|
|
- return ReturnMsg.ok(FalseData.CUISINELIST);
|
|
|
+ List<Cuisine> cuisineList = new ArrayList<>();
|
|
|
+ List<Map<String,String>> lists = cuisineOrderMapper.getTopListByCompanyIdAndDeptId(iocParam);
|
|
|
+ for (Map<String,String> map:lists){
|
|
|
+ Cuisine cuisine = new Cuisine();
|
|
|
+ cuisine.setCuisineImg(map.get("cuisine_img"));
|
|
|
+ cuisine.setCuisineName(map.get("p_name"));
|
|
|
+ cuisine.setPrice(map.get("price"));
|
|
|
+ cuisineList.add(cuisine);
|
|
|
+ }
|
|
|
+ return ReturnMsg.ok(cuisineList);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -108,8 +156,54 @@ public class RestaurantServiceImpl implements RestaurantService {
|
|
|
@Override
|
|
|
public ReturnMsg getConsumptionAnalysis(IocParam iocParam) {
|
|
|
String[] param = {"breakfast","lunch","dinner","breakfastPrice","lunchPrice","dinnerPrice"};
|
|
|
- String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
|
|
|
- List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
|
|
|
+ // String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
|
|
|
+ //List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
|
|
|
+ String startStr = iocParam.getTimeRange().getStartDate();
|
|
|
+ String endStr = iocParam.getTimeRange().getEndDate();
|
|
|
+ List<String> list = DateUtil.getBetweenDays(startStr, endStr);
|
|
|
+ String[] labKey = list.toArray(new String[0]);
|
|
|
+ List<Label> labels1 = new ArrayList<>();
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("#.0");
|
|
|
+ for (int i = 0; i < labKey.length; i++) {
|
|
|
+ Label label = new Label();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ IocParam iocParam1 = new IocParam();
|
|
|
+ IocTimeRange iocTimeRange = new IocTimeRange();
|
|
|
+ iocTimeRange.setStartDate(labKey[i]+" 00:00:00");
|
|
|
+ iocTimeRange.setEndDate(labKey[i]+" 10:00:00");
|
|
|
+ iocParam1.setTimeRange(iocTimeRange);
|
|
|
+
|
|
|
+ IocParam iocParam2 = new IocParam();
|
|
|
+ IocTimeRange iocTimeRange2 = new IocTimeRange();
|
|
|
+ iocTimeRange2.setStartDate(labKey[i]+" 10:00:00");
|
|
|
+ iocTimeRange2.setEndDate(labKey[i]+" 15:00:00");
|
|
|
+ iocParam2.setTimeRange(iocTimeRange2);
|
|
|
+
|
|
|
+ IocParam iocParam3 = new IocParam();
|
|
|
+ IocTimeRange iocTimeRange3 = new IocTimeRange();
|
|
|
+ iocTimeRange3.setStartDate(labKey[i]+" 15:00:00");
|
|
|
+ iocTimeRange3.setEndDate(labKey[i]+" 23:59:00");
|
|
|
+ iocParam3.setTimeRange(iocTimeRange3);
|
|
|
+
|
|
|
+ Integer totalBreakfastPerson = cuisineOrderMapper.getTotalPersonByCompanyIdAndDeptId(iocParam1);
|
|
|
+ Integer totalLunchPerson = cuisineOrderMapper.getTotalPersonByCompanyIdAndDeptId(iocParam2);
|
|
|
+ Integer totalDinnerPerson = cuisineOrderMapper.getTotalPersonByCompanyIdAndDeptId(iocParam3);
|
|
|
+ Double breakfastPrice = cuisineOrderMapper.getAvgPriceByCompanyIdAndDeptId(iocParam1);
|
|
|
+ Double lunchPrice = cuisineOrderMapper.getAvgPriceByCompanyIdAndDeptId(iocParam2);
|
|
|
+ Double dinnerPrice = cuisineOrderMapper.getAvgPriceByCompanyIdAndDeptId(iocParam3);
|
|
|
+ breakfastPrice = breakfastPrice==null?0:Double.valueOf(decimalFormat.format(breakfastPrice));
|
|
|
+ lunchPrice = lunchPrice==null?0:Double.valueOf(decimalFormat.format(lunchPrice));
|
|
|
+ dinnerPrice = dinnerPrice==null?0:Double.valueOf(decimalFormat.format(dinnerPrice));
|
|
|
+ jsonObject.put(param[0],totalBreakfastPerson);
|
|
|
+ jsonObject.put(param[1],totalLunchPerson);
|
|
|
+ jsonObject.put(param[2],totalDinnerPerson);
|
|
|
+ jsonObject.put(param[3],breakfastPrice);
|
|
|
+ jsonObject.put(param[4],lunchPrice);
|
|
|
+ jsonObject.put(param[5],dinnerPrice);
|
|
|
+ label.setJsonObject(jsonObject);
|
|
|
+ label.setLabel(labKey[i]);
|
|
|
+ labels1.add(label);
|
|
|
+ }
|
|
|
return ReturnMsg.ok(labels1);
|
|
|
}
|
|
|
|
|
@@ -119,19 +213,57 @@ public class RestaurantServiceImpl implements RestaurantService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ReturnMsg getTodayMenu() {
|
|
|
- return ReturnMsg.ok(FalseData.CUISINELIST);
|
|
|
+ List<FoodMenu> list = foodMenusMapper.getListByType(null);
|
|
|
+ return ReturnMsg.ok(list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询智慧生活中智慧餐厅的盈利分析
|
|
|
*/
|
|
|
@Override
|
|
|
- public ReturnMsg getProfitAnalysis(IocParam iocParam) {
|
|
|
- List<Cake> list = new ArrayList<>();
|
|
|
- list.add(new Cake("breakfast"));
|
|
|
- list.add(new Cake("lunch"));
|
|
|
- list.add(new Cake("dinner"));
|
|
|
- return ReturnMsg.ok(list);
|
|
|
+ public ReturnMsg getProfitAnalysis(IocParam iocParam) throws ParseException {
|
|
|
+ List<Cake> lists = new ArrayList<>();
|
|
|
+ List<Order> list = cuisineOrderMapper.getListByCompanyIdAndDeptId(iocParam);
|
|
|
+ Double breakfast = 0d;
|
|
|
+ Double lunch = 0d;
|
|
|
+ Double dinner = 0d;
|
|
|
+ Cake cakeBreakfast = new Cake();
|
|
|
+ Cake cakeLunch = new Cake();
|
|
|
+ Cake cakeDinner = new Cake();
|
|
|
+ cakeBreakfast.setName("早餐");
|
|
|
+ cakeLunch.setName("午餐");
|
|
|
+ cakeDinner.setName("晚餐");
|
|
|
+ if(list==null){
|
|
|
+
|
|
|
+ }else{
|
|
|
+ for (Order order:list){
|
|
|
+ String time = order.getOrderTime().substring(10);
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
|
|
+ Date date1 = sdf.parse(time);
|
|
|
+ Date date2 = sdf.parse("10:00:00");
|
|
|
+ if(date1.before(date2)&&date1.after(sdf.parse("00:00:00"))){
|
|
|
+ //早餐
|
|
|
+ breakfast+=order.getOrderPrice();
|
|
|
+ }
|
|
|
+ if(date1.before(sdf.parse("15:00:00"))&&date1.after(sdf.parse("10:00:00"))){
|
|
|
+ //午餐
|
|
|
+ lunch += order.getOrderPrice();
|
|
|
+ }
|
|
|
+ if(date1.before(sdf.parse("23:59:00"))&&date1.after(sdf.parse("15:00:00"))){
|
|
|
+ //晚餐
|
|
|
+ dinner += order.getOrderPrice();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cakeBreakfast.setValue(breakfast);
|
|
|
+ cakeDinner.setValue(dinner);
|
|
|
+ cakeLunch.setValue(lunch);
|
|
|
+ lists.add(cakeBreakfast);
|
|
|
+ lists.add(cakeLunch);
|
|
|
+ lists.add(cakeDinner);
|
|
|
+
|
|
|
+
|
|
|
+ return ReturnMsg.ok(lists);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -140,8 +272,39 @@ public class RestaurantServiceImpl implements RestaurantService {
|
|
|
@Override
|
|
|
public ReturnMsg getMealAnalysis(IocParam iocParam) {
|
|
|
String[] param = {"passengerFlow","eat","proportion"};
|
|
|
- String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
|
|
|
- List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
|
|
|
+ // String[] labKey = {"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
|
|
|
+ String startStr = iocParam.getTimeRange().getStartDate();
|
|
|
+ String endStr = iocParam.getTimeRange().getEndDate();
|
|
|
+ List<String> list = DateUtil.getBetweenDays(startStr, endStr);
|
|
|
+ String[] labKey = list.toArray(new String[0]);
|
|
|
+ //List<Label> labels1 = GeneralMethod.getInstance().dataGeneration(param, labKey);
|
|
|
+ List<Label> labels1 = new ArrayList<>();
|
|
|
+ DecimalFormat decimalFormat = new DecimalFormat("#.0");
|
|
|
+ for (int i = 0; i < labKey.length; i++) {
|
|
|
+ Label label = new Label();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ IocParam iocParam1 = new IocParam();
|
|
|
+ IocTimeRange iocTimeRange = new IocTimeRange();
|
|
|
+ iocTimeRange.setStartDate(labKey[i]+" 00:00:00");
|
|
|
+ iocTimeRange.setEndDate(labKey[i]+" 23:59:00");
|
|
|
+ iocParam1.setTimeRange(iocTimeRange);
|
|
|
+ Integer totalPerson = cuisineOrderMapper.getTotalPersonByCompanyIdAndDeptId(iocParam1);
|
|
|
+ ThreadLocalRandom random = ThreadLocalRandom.current();
|
|
|
+ Integer add = random.nextInt(10,100);
|
|
|
+ Integer passengerFlow = totalPerson+add;
|
|
|
+ double proportion = 0d;
|
|
|
+ if(totalPerson>0){
|
|
|
+ BigDecimal bigDecimal = new BigDecimal(totalPerson);
|
|
|
+ BigDecimal decimal = bigDecimal.divide(new BigDecimal(passengerFlow), 2, RoundingMode.HALF_UP);
|
|
|
+ proportion = decimal.doubleValue()*100;
|
|
|
+ }
|
|
|
+ jsonObject.put(param[0],passengerFlow);
|
|
|
+ jsonObject.put(param[1],totalPerson);
|
|
|
+ jsonObject.put(param[2],proportion);
|
|
|
+ label.setJsonObject(jsonObject);
|
|
|
+ label.setLabel(labKey[i]);
|
|
|
+ labels1.add(label);
|
|
|
+ }
|
|
|
return ReturnMsg.ok(labels1);
|
|
|
}
|
|
|
|