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 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 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 map1 = new HashMap<>(); Wrapper ne = new EntityWrapper().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 ne1 = new EntityWrapper().ne("state", 1).eq("authState", 2).ne("flag", 3); if(companyId != null){ ne1.eq("companyId", companyId).or().eq("franchiseeId", companyId); } List tDrivers = tDriverService.selectList(ne1); String keys = ""; for(TDriver driver : tDrivers){ keys += "DRIVER" + driver.getId() + ","; } String value = redisUtil.getValue(keys.substring(0, keys.length() - 1)); JSONArray jsonArray = JSON.parseArray(value); int size = driverOnlineService.queryOnlineDriverCount(null, null); map1.put("netcardriver", size); //在线司机 Wrapper travelTime1 = new EntityWrapper().between("travelTime", calendar1.getTime(), calendar2.getTime()); if(companyId != null){ travelTime1.eq("companyId", companyId); } int i1 = tOrderTaxiService.selectCount(travelTime1); map1.put("orderDetail2", i1); //出租车订单 Wrapper zcTodayTme = new EntityWrapper().between("travelTime", calendar1.getTime(), calendar2.getTime()); if(companyId != null){ zcTodayTme.eq("companyId", companyId); } int zcTodayNum = itOrderPrivateCarService.selectCount(zcTodayTme); map1.put("orderDetail1", zcTodayNum); //专车订单 Wrapper kcTodayTme = new EntityWrapper().between("travelTime", calendar1.getTime(), calendar2.getTime()); if(companyId != null){ kcTodayTme.eq("companyId", companyId); } int kcTodayNum = itOrderCrossCityService.selectCount(kcTodayTme); map1.put("orderDetail3", kcTodayNum); //跨城订单 Wrapper tcxTodayTme = new EntityWrapper().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 kcxTodayTme = new EntityWrapper().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 flag1 = new EntityWrapper().ne("flag", 3); if(companyId != null){ flag1.eq("companyId", companyId); } int flag = tUserService.selectCount(flag1); map1.put("passengerInfoSum", flag); //总用户 Wrapper ne4 = new EntityWrapper().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 state3 = new EntityWrapper().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 ne2 = new EntityWrapper().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 ne3 = new EntityWrapper().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 zcTodayTmeByConditions = new EntityWrapper().between("travelTime", calendar3.getTime(), calendar4.getTime()); if(companyId != null){ zcTodayTmeByConditions.eq("companyId", companyId); } int zcTodayNum1 = itOrderPrivateCarService.selectCount(zcTodayTmeByConditions); map1.put("orderDetail1", zcTodayNum1); //专车订单 Wrapper travelTime2 = new EntityWrapper().between("travelTime", calendar3.getTime(), calendar4.getTime()); if(companyId != null){ travelTime2.eq("companyId", companyId); } int travelTime = tOrderTaxiService.selectCount(travelTime2); map1.put("orderDetail2", travelTime); //出租车订单 Wrapper kcTodayTmeByConditions = new EntityWrapper().between("travelTime", calendar3.getTime(), calendar4.getTime()); if(companyId != null){ kcTodayTmeByConditions.eq("companyId", companyId); } int kcTodayNum1 = itOrderCrossCityService.selectCount(kcTodayTmeByConditions); map1.put("orderDetail3", kcTodayNum1); //跨城订单 Wrapper tcxTodayTmeByConditions = new EntityWrapper().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 kcxTodayTmeByConditions = new EntityWrapper().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 m1 = new ArrayList<>(); List m2 = new ArrayList<>(); List m3 = new ArrayList<>(); List m4 = new ArrayList<>(); List m5 = new ArrayList<>(); List m6 = new ArrayList<>(); List 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 in = new EntityWrapper().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 ne5 = new EntityWrapper().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 inZC = new EntityWrapper().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 inKC = new EntityWrapper().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 inTCX = new EntityWrapper().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 inKCX = new EntityWrapper().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 ne = new EntityWrapper().eq("authState", 2).eq("state", 2).ne("flag", 3); if(companyId != null){ ne.eq("companyId", companyId).or().eq("franchiseeId", companyId); } List tDrivers = tDriverService.selectList(ne); Map map = new HashMap<>(); List list = new ArrayList<>(); for(TDriver tDriver : tDrivers){ Map 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 map2 = new HashMap<>(); Wrapper eq = new EntityWrapper().eq("state", 1).eq("isDelete", 1); if(companyId != null){ eq.eq("companyId", companyId); } List tOrderTaxis = tOrderTaxiService.selectList(eq); list = new ArrayList<>(); for(TOrderTaxi t : tOrderTaxis){ Map 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 tOrderTaxis = tOrderTaxiService.selectList(new EntityWrapper().eq("isDelete", 1)); List list = new ArrayList<>(); for(TOrderTaxi t : tOrderTaxis){ Map 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 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 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 state4 = new EntityWrapper().in("state", states).eq("driverId", driverId).eq("isDelete", 1); List 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 ids){ List ids_ = new ArrayList<>(); for(TCompany id : ids){ if(id.getId() == 1){ List tCompanies = tCompanyService.selectList(new EntityWrapper().eq("superiorId", id.getId()).or().isNull("superiorId").eq("state", 0).ne("flag", 3).ne("type", 1)); ids_.addAll(tCompanies); companys.addAll(tCompanies); }else{ List tCompanies = tCompanyService.selectList(new EntityWrapper().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(); } } }