package com.stylefeng.guns.modular.system.controller.general;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.stylefeng.guns.core.shiro.ShiroKit;
|
import com.stylefeng.guns.core.util.SinataUtil;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.DateUtil;
|
import com.stylefeng.guns.modular.system.util.RedisUtil;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import com.sun.org.apache.regexp.internal.RE;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
/**
|
* 首页统计
|
*/
|
@Controller
|
@RequestMapping("/home")
|
public class HomeController {
|
|
@Autowired
|
private ITUserService tUserService;
|
|
@Autowired
|
private ITDriverService tDriverService;
|
|
@Autowired
|
private ITOrderTaxiService tOrderTaxiService;
|
|
@Autowired
|
private ITCarService tCarService;
|
|
@Autowired
|
private RedisUtil redisUtil;
|
|
@Autowired
|
private IUserService userService;
|
|
@Autowired
|
private ITCompanyService tCompanyService;
|
|
@Autowired
|
private ITCarBrandService carBrandService;
|
|
@Autowired
|
private ITCarModelService carModelService;
|
|
private List<TCompany> companys = null;
|
|
|
@Autowired
|
private ITOrderPrivateCarService itOrderPrivateCarService;
|
|
@Autowired
|
private ITOrderCrossCityService itOrderCrossCityService;
|
|
@Autowired
|
private ITOrderLogisticsService itOrderLogisticsService;
|
|
@Autowired
|
private IDriverOnlineService driverOnlineService;
|
|
|
@RequestMapping("/openNetCarInfo")
|
public Object openNetCarInfo(Integer id, Model model){
|
model.addAttribute("id", id);
|
return "/netCarInfo.html";
|
}
|
|
@RequestMapping("/showDriverOnline")
|
public String showDriverOnline(){
|
return "/driverOnline.html";
|
}
|
|
|
|
|
@ResponseBody
|
@PostMapping("/getSumData")
|
public Object getSumData(Integer companyId, Date addDate, Date start, Date end){
|
Integer id = ShiroKit.getUser().getId();
|
User user = userService.selectById(id);
|
if(companyId == null && user.getRoleType() != 1){
|
companyId = user.getObjectId();
|
}
|
Map<String, Object> map = new HashMap<>();
|
Date date = new Date();
|
Calendar calendar1 = Calendar.getInstance();
|
Calendar calendar2 = Calendar.getInstance();
|
Calendar calendar3 = Calendar.getInstance();
|
Calendar calendar4 = Calendar.getInstance();
|
if(addDate == null){
|
calendar1.setTime(date);
|
calendar2.setTime(date);
|
}else{
|
calendar1.setTime(addDate);
|
calendar2.setTime(addDate);
|
}
|
if(start == null || end == null){
|
calendar3.setTime(date);
|
calendar4.setTime(date);
|
}else{
|
calendar3.setTime(start);
|
calendar4.setTime(end);
|
}
|
calendar1.set(Calendar.HOUR_OF_DAY, 00);
|
calendar1.set(Calendar.MINUTE, 00);
|
calendar1.set(Calendar.SECOND, 00);
|
calendar2.set(Calendar.HOUR_OF_DAY, 23);
|
calendar2.set(Calendar.MINUTE, 59);
|
calendar2.set(Calendar.SECOND, 59);
|
calendar3.set(Calendar.HOUR_OF_DAY, 00);
|
calendar3.set(Calendar.MINUTE, 00);
|
calendar3.set(Calendar.SECOND, 00);
|
calendar4.set(Calendar.HOUR_OF_DAY, 23);
|
calendar4.set(Calendar.MINUTE, 59);
|
calendar4.set(Calendar.SECOND, 59);
|
|
//【今日运行情况】
|
Map<String, Object> map1 = new HashMap<>();
|
Wrapper<TUser> ne = new EntityWrapper<TUser>().between("insertTime", calendar1.getTime(), calendar2.getTime()).ne("flag", 3);
|
if(companyId != null){
|
ne.eq("companyId", companyId);
|
}
|
int i = tUserService.selectCount(ne);
|
map1.put("passengerInfo", i); //新增用户
|
|
Wrapper<TDriver> ne1 = new EntityWrapper<TDriver>().ne("state", 1).eq("authState", 2).ne("flag", 3);
|
if(companyId != null){
|
ne1.eq("companyId", companyId).or().eq("franchiseeId", companyId);
|
}
|
List<TDriver> tDrivers = tDriverService.selectList(ne1);
|
String keys = "";
|
for(TDriver driver : tDrivers){
|
keys += "DRIVER" + driver.getId() + ",";
|
}
|
String value = redisUtil.getValues(keys.substring(0, keys.length() - 1));
|
JSONArray jsonArray = JSON.parseArray(value);
|
int size = driverOnlineService.queryOnlineDriverCount(null, null);
|
map1.put("netcardriver", size); //在线司机
|
|
Wrapper<TOrderTaxi> travelTime1 = new EntityWrapper<TOrderTaxi>().between("travelTime", calendar1.getTime(), calendar2.getTime());
|
if(companyId != null){
|
travelTime1.eq("companyId", companyId);
|
}
|
int i1 = tOrderTaxiService.selectCount(travelTime1);
|
map1.put("orderDetail2", i1); //出租车订单
|
|
Wrapper<TOrderPrivateCar> zcTodayTme = new EntityWrapper<TOrderPrivateCar>().between("travelTime", calendar1.getTime(), calendar2.getTime());
|
if(companyId != null){
|
zcTodayTme.eq("companyId", companyId);
|
}
|
int zcTodayNum = itOrderPrivateCarService.selectCount(zcTodayTme);
|
map1.put("orderDetail1", zcTodayNum); //专车订单
|
|
Wrapper<TOrderCrossCity> kcTodayTme = new EntityWrapper<TOrderCrossCity>().between("travelTime", calendar1.getTime(), calendar2.getTime());
|
if(companyId != null){
|
kcTodayTme.eq("companyId", companyId);
|
}
|
int kcTodayNum = itOrderCrossCityService.selectCount(kcTodayTme);
|
map1.put("orderDetail3", kcTodayNum); //跨城订单
|
|
Wrapper<TOrderLogistics> tcxTodayTme = new EntityWrapper<TOrderLogistics>().between("travelTime", calendar1.getTime(), calendar2.getTime());
|
if(companyId != null){
|
tcxTodayTme.eq("companyId", companyId);
|
}
|
tcxTodayTme.eq("type",4);
|
int tcxTodayNum = itOrderLogisticsService.selectCount(tcxTodayTme);
|
map1.put("orderDetail4", tcxTodayNum); //同城物流订单
|
|
Wrapper<TOrderLogistics> kcxTodayTme = new EntityWrapper<TOrderLogistics>().between("travelTime", calendar1.getTime(), calendar2.getTime());
|
if(companyId != null){
|
kcxTodayTme.eq("companyId", companyId);
|
}
|
tcxTodayTme.eq("type",5);
|
int kcxTodayNum = itOrderLogisticsService.selectCount(kcxTodayTme);
|
map1.put("orderDetail5", kcxTodayNum); //跨城物流订单
|
|
map.put("operationStatus", map1);
|
|
//【全部运营总数据】
|
map1 = new HashMap<>();
|
Wrapper<TUser> flag1 = new EntityWrapper<TUser>().ne("flag", 3);
|
if(companyId != null){
|
flag1.eq("companyId", companyId);
|
}
|
int flag = tUserService.selectCount(flag1);
|
map1.put("passengerInfoSum", flag); //总用户
|
|
Wrapper<TDriver> ne4 = new EntityWrapper<TDriver>().eq("authState", 2).ne("flag", 3);
|
if(companyId != null){
|
ne4.eq("companyId", companyId).or().eq("franchiseeId", companyId);
|
}
|
int i2 = tDriverService.selectCount(ne4);
|
map1.put("netcarDriverSum", i2); //总司机
|
|
Wrapper<TCar> state3 = new EntityWrapper<TCar>().eq("state", 1);
|
if(companyId != null){
|
state3.eq("companyId", companyId).or().eq("franchiseeId", companyId);
|
}
|
int state1 = tCarService.selectCount(state3);
|
map1.put("netCarSum", state1); //总车辆
|
|
Integer i3 = tOrderTaxiService.getAllOrderNum(companyId,null,null);
|
map1.put("orderDetailSum", i3); //总订单
|
|
Double allTradeMoney = tOrderTaxiService.getAllTradeMoney(companyId, null, null);
|
Double allIncomeMoney = tOrderTaxiService.getAllIncomeMoney(companyId, null, null);
|
map1.put("paiceSum", allTradeMoney); //交易总金额
|
map1.put("paySum", allIncomeMoney); //总收益
|
map.put("operationSum", map1);
|
|
//【运营数据增长查询】
|
map1 = new HashMap<>();
|
Wrapper<TUser> ne2 = new EntityWrapper<TUser>().between("insertTime", calendar3.getTime(), calendar4.getTime()).ne("flag", 3);
|
if(companyId != null){
|
ne2.eq("companyId", companyId);
|
}
|
int i4 = tUserService.selectCount(ne2);
|
map1.put("passengerInfoSum", i4);
|
|
Wrapper<TDriver> ne3 = new EntityWrapper<TDriver>().between("insertTime", calendar3.getTime(), calendar4.getTime()).eq("authState", 2).ne("flag", 3);
|
if(companyId != null){
|
ne3.eq("companyId", companyId).or().eq("franchiseeId", companyId);
|
}
|
int i5 = tDriverService.selectCount(ne3);
|
map1.put("netcarDriverSum", i5);
|
|
Wrapper<TOrderPrivateCar> zcTodayTmeByConditions = new EntityWrapper<TOrderPrivateCar>().between("travelTime", calendar3.getTime(), calendar4.getTime());
|
if(companyId != null){
|
zcTodayTmeByConditions.eq("companyId", companyId);
|
}
|
int zcTodayNum1 = itOrderPrivateCarService.selectCount(zcTodayTmeByConditions);
|
map1.put("orderDetail1", zcTodayNum1); //专车订单
|
|
Wrapper<TOrderTaxi> travelTime2 = new EntityWrapper<TOrderTaxi>().between("travelTime", calendar3.getTime(), calendar4.getTime());
|
if(companyId != null){
|
travelTime2.eq("companyId", companyId);
|
}
|
int travelTime = tOrderTaxiService.selectCount(travelTime2);
|
map1.put("orderDetail2", travelTime); //出租车订单
|
|
Wrapper<TOrderCrossCity> kcTodayTmeByConditions = new EntityWrapper<TOrderCrossCity>().between("travelTime", calendar3.getTime(), calendar4.getTime());
|
if(companyId != null){
|
kcTodayTmeByConditions.eq("companyId", companyId);
|
}
|
int kcTodayNum1 = itOrderCrossCityService.selectCount(kcTodayTmeByConditions);
|
map1.put("orderDetail3", kcTodayNum1); //跨城订单
|
|
Wrapper<TOrderLogistics> tcxTodayTmeByConditions = new EntityWrapper<TOrderLogistics>().between("travelTime", calendar3.getTime(), calendar4.getTime());
|
if(companyId != null){
|
tcxTodayTmeByConditions.eq("companyId", companyId);
|
}
|
tcxTodayTmeByConditions.eq("type",4);
|
int tcxTodayNum1 = itOrderLogisticsService.selectCount(tcxTodayTmeByConditions);
|
map1.put("orderDetail4", tcxTodayNum1); //同城物流订单
|
|
Wrapper<TOrderLogistics> kcxTodayTmeByConditions = new EntityWrapper<TOrderLogistics>().between("travelTime", calendar3.getTime(), calendar4.getTime());
|
if(companyId != null){
|
kcxTodayTmeByConditions.eq("companyId", companyId);
|
}
|
kcxTodayTmeByConditions.eq("type",5);
|
int kcxTodayNum1 = itOrderLogisticsService.selectCount(kcxTodayTmeByConditions);
|
map1.put("orderDetail5", kcxTodayNum1); //跨城物流订单
|
|
String startTime = null;
|
if (SinataUtil.isNotEmpty(start)){
|
startTime = DateUtil.format(start, "yyyy-MM-dd");
|
}
|
String endTime = null;
|
if (SinataUtil.isNotEmpty(end)){
|
endTime = DateUtil.format(end, "yyyy-MM-dd");
|
}
|
Double allTradeMoneyByTime = tOrderTaxiService.getAllTradeMoney(companyId, startTime, endTime);
|
Double allIncomeMoneyByTime = tOrderTaxiService.getAllIncomeMoney(companyId, startTime, endTime);
|
map1.put("paiceSum", allTradeMoneyByTime); //交易总金额
|
map1.put("paySum", allIncomeMoneyByTime); //总收益
|
map.put("operationGrow", map1);
|
|
|
//【运营总趋势】
|
Integer[] states = new Integer[]{8, 9};
|
map1 = new HashMap<>();
|
List<Integer> m1 = new ArrayList<>();
|
List<Integer> m2 = new ArrayList<>();
|
List<Integer> m3 = new ArrayList<>();
|
List<Integer> m4 = new ArrayList<>();
|
List<Integer> m5 = new ArrayList<>();
|
List<Integer> m6 = new ArrayList<>();
|
List<Integer> m7 = new ArrayList<>();
|
for(int j = 30; j > 0; j--){
|
Calendar s1 = Calendar.getInstance();
|
s1.setTime(date);
|
s1.set(s1.get(Calendar.YEAR), s1.get(Calendar.MONTH), s1.get(Calendar.DAY_OF_MONTH) - j, 0, 0, 1);
|
Calendar e1 = Calendar.getInstance();
|
e1.setTime(date);
|
e1.set(e1.get(Calendar.YEAR), e1.get(Calendar.MONTH), e1.get(Calendar.DAY_OF_MONTH) - j, 23, 59, 59);
|
|
//出租车订单趋势图
|
Wrapper<TOrderTaxi> in = new EntityWrapper<TOrderTaxi>().between("travelTime", s1.getTime(), e1.getTime()).in("state", states);
|
if(companyId != null){
|
in.eq("companyId", companyId);
|
}
|
int i6 = tOrderTaxiService.selectCount(in);
|
m1.add(i6);
|
|
//用户注册趋势图
|
Wrapper<TUser> ne5 = new EntityWrapper<TUser>().between("insertTime", s1.getTime(), e1.getTime()).ne("flag", 3);
|
if(companyId != null){
|
ne5.eq("companyId", companyId);
|
}
|
int i7 = tUserService.selectCount(ne5);
|
m2.add(i7);
|
|
//订单数趋势图
|
String startTime1 = DateUtil.format(s1.getTime(), "yyyy-MM-dd");
|
String endTime1 = DateUtil.format(e1.getTime(), "yyyy-MM-dd");
|
Integer allOrderNum = tOrderTaxiService.getAllOrderNum(companyId, startTime1, endTime1);
|
m3.add(allOrderNum);
|
|
//专车订单趋势图
|
Wrapper<TOrderPrivateCar> inZC = new EntityWrapper<TOrderPrivateCar>().between("travelTime", s1.getTime(), e1.getTime()).in("state", states);
|
if(companyId != null){
|
inZC.eq("companyId", companyId);
|
}
|
int zc = itOrderPrivateCarService.selectCount(inZC);
|
m4.add(zc);
|
|
//跨城订单趋势图
|
Wrapper<TOrderCrossCity> inKC = new EntityWrapper<TOrderCrossCity>().between("travelTime", s1.getTime(), e1.getTime()).in("state", states);
|
if(companyId != null){
|
inKC.eq("companyId", companyId);
|
}
|
int kc = itOrderCrossCityService.selectCount(inKC);
|
m5.add(kc);
|
|
//同城物流订单趋势图
|
Wrapper<TOrderLogistics> inTCX = new EntityWrapper<TOrderLogistics>().between("travelTime", s1.getTime(), e1.getTime()).in("state", states);
|
if(companyId != null){
|
inTCX.eq("companyId", companyId);
|
}
|
inTCX.eq("type",4);
|
int tcx = itOrderLogisticsService.selectCount(inTCX);
|
m6.add(tcx);
|
|
//跨城物流订单趋势图
|
Wrapper<TOrderLogistics> inKCX = new EntityWrapper<TOrderLogistics>().between("travelTime", s1.getTime(), e1.getTime()).in("state", states);
|
if(companyId != null){
|
inKCX.eq("companyId", companyId);
|
}
|
inKCX.eq("type",5);
|
int kcx = itOrderLogisticsService.selectCount(inKCX);
|
m7.add(kcx);
|
|
}
|
map1.put("orderDetail5", m7); //跨城物流订单数趋势图
|
map1.put("orderDetail4", m6); //同城物流订单数趋势图
|
map1.put("orderDetail3", m5); //跨城订单数趋势图
|
map1.put("orderDetail1", m4); //专车订单数趋势图
|
map1.put("orderDetailSum", m3); //全部订单数趋势图
|
map1.put("passengerInfoSum", m2); //用户注册趋势图
|
map1.put("orderDetail2", m1); //出租车订单趋势图
|
map.put("operationTrend", map1);
|
|
return map;
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/getDriverPosition")
|
public Object getDriverPosition(Integer companyId){
|
Integer id = ShiroKit.getUser().getId();
|
User user = userService.selectById(id);
|
if(companyId == null && user.getRoleType() != 1){
|
companyId = user.getObjectId();
|
}
|
Wrapper<TDriver> ne = new EntityWrapper<TDriver>().eq("authState", 2).eq("state", 2).ne("flag", 3);
|
if(companyId != null){
|
ne.eq("companyId", companyId).or().eq("franchiseeId", companyId);
|
}
|
List<TDriver> tDrivers = tDriverService.selectList(ne);
|
Map<String, Object> map = new HashMap<>();
|
List<Object> list = new ArrayList<>();
|
for(TDriver tDriver : tDrivers){
|
Map<String, Object> d = new HashMap<>();
|
String value = redisUtil.getValue("DRIVER" + tDriver.getId());
|
if(ToolUtil.isEmpty(value)){
|
continue;
|
}
|
d.put("driver", tDriver);
|
d.put("lon", value.split(",")[0]);
|
d.put("lat", value.split(",")[1]);
|
list.add(d);
|
}
|
map.put("driver", list);
|
|
Map<String, Object> map2 = new HashMap<>();
|
Wrapper<TOrderTaxi> eq = new EntityWrapper<TOrderTaxi>().eq("state", 1).eq("isDelete", 1);
|
if(companyId != null){
|
eq.eq("companyId", companyId);
|
}
|
List<TOrderTaxi> tOrderTaxis = tOrderTaxiService.selectList(eq);
|
list = new ArrayList<>();
|
for(TOrderTaxi t : tOrderTaxis){
|
Map<String, Object> map1 = new HashMap<>();
|
map1.put("start", t.getStartAddress());
|
map1.put("end", t.getEndAddress());
|
map1.put("travelTime", t.getTravelTime());
|
map1.put("carModel", "");
|
map1.put("num", 1);
|
list.add(map1);
|
}
|
map2.put("chuzu", list);
|
map.put("order", map2);
|
|
return map;
|
}
|
|
|
@ResponseBody
|
@PostMapping("/getAllOrder")
|
public Object getAllOrder(){
|
List<TOrderTaxi> tOrderTaxis = tOrderTaxiService.selectList(new EntityWrapper<TOrderTaxi>().eq("isDelete", 1));
|
List list = new ArrayList<>();
|
for(TOrderTaxi t : tOrderTaxis){
|
Map<String, Object> map = new HashMap<>();
|
map.put("lon", t.getStartLon());
|
map.put("lat", t.getStartLat());
|
list.add(map);
|
}
|
return list;
|
}
|
|
|
@ResponseBody
|
@PostMapping("/getCompanyInfoByUserId")
|
public Object getCompanyInfoByUserId(){
|
Integer id = ShiroKit.getUser().getId();
|
User user = userService.selectById(id);
|
companys = new ArrayList<>();
|
List<TCompany> ids = new ArrayList<>();
|
TCompany tCompany = null;
|
if(user.getRoleType() == 1 && user.getObjectId() == null){
|
tCompany = tCompanyService.selectById(1);
|
}else{
|
tCompany = tCompanyService.selectById(user.getObjectId());
|
}
|
ids.add(tCompany);
|
companys.addAll(ids);
|
this.getCompanyIds(ids);
|
return companys;
|
}
|
|
|
@ResponseBody
|
@RequestMapping(value = "/getDriverInfo", method = RequestMethod.POST)
|
public Object getDriverInfo(Integer driverId){
|
Map<String, Object> map = new HashMap<>();
|
TDriver tDriver = tDriverService.selectById(driverId);
|
TCar tCar = tCarService.selectById(tDriver.getCarId());
|
TCarBrand tCarBrand = null;
|
TCarModel tCarModel = null;
|
if(null != tCar){
|
tCarBrand = carBrandService.selectById(tCar.getCarBrandId());
|
tCarModel = carModelService.selectById(tCar.getCarModelId());
|
}
|
Integer[] states = new Integer[]{2, 3, 4, 5, 6, 11};
|
Wrapper<TOrderTaxi> state4 = new EntityWrapper<TOrderTaxi>().in("state", states).eq("driverId", driverId).eq("isDelete", 1);
|
List<TOrderTaxi> tOrderTaxis = tOrderTaxiService.selectList(state4);
|
map.put("netcarDriver", tDriver);
|
map.put("netcar", tCar);
|
map.put("carBrand", null != tCarBrand ? tCarBrand.getName() : "");
|
map.put("carModel", null != tCarModel ? tCarModel.getName() : "");
|
map.put("order", tOrderTaxis);
|
return map;
|
}
|
|
|
|
public void getCompanyIds(List<TCompany> ids){
|
List<TCompany> ids_ = new ArrayList<>();
|
for(TCompany id : ids){
|
if(id.getId() == 1){
|
List<TCompany> tCompanies = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("superiorId", id.getId()).or().isNull("superiorId").eq("state", 0).ne("flag", 3).ne("type", 1));
|
ids_.addAll(tCompanies);
|
companys.addAll(tCompanies);
|
}else{
|
List<TCompany> tCompanies = tCompanyService.selectList(new EntityWrapper<TCompany>().eq("superiorId", id.getId()).eq("state", 0).ne("flag", 3));
|
ids_.addAll(tCompanies);
|
companys.addAll(tCompanies);
|
}
|
}
|
if(ids_.size() == 0){
|
return;
|
}
|
this.getCompanyIds(ids_);
|
}
|
|
|
|
@ResponseBody
|
@RequestMapping(value = "/queryOnlineDriver", method = RequestMethod.POST)
|
public Object queryOnlineDriver(String name, String phone, Integer offset, Integer limit){
|
try {
|
return driverOnlineService.queryOnlineDriver(name, phone, offset, limit);
|
}catch (Exception e){
|
e.printStackTrace();
|
return ResultUtil.runErr();
|
}
|
}
|
}
|