| | |
| | | package com.stylefeng.guns.modular.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.core.shiro.ShiroKit; |
| | | import com.stylefeng.guns.core.util.DateUtil; |
| | | import com.stylefeng.guns.modular.system.controller.resp.DataStatisticsOrderYearResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.PerformanceTableResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TOrderResp; |
| | | import com.stylefeng.guns.modular.system.controller.resp.TOrderServerResp; |
| | | import com.stylefeng.guns.modular.system.dao.TAppUserMapper; |
| | | import com.stylefeng.guns.modular.system.dao.TBranchOfficeMapper; |
| | | import com.stylefeng.guns.modular.system.dao.TDriverMapper; |
| | | import com.stylefeng.guns.modular.system.dao.TOrderMapper; |
| | | import com.stylefeng.guns.modular.system.enums.OrderStateEnum; |
| | | import com.stylefeng.guns.modular.system.model.TAppUser; |
| | | import com.stylefeng.guns.modular.system.model.TBranchOffice; |
| | | import com.stylefeng.guns.modular.system.model.TDriver; |
| | | import com.stylefeng.guns.modular.system.model.TOrder; |
| | | import com.stylefeng.guns.modular.system.dao.TOrderMapper; |
| | | import com.stylefeng.guns.modular.system.service.ITOrderService; |
| | | import com.baomidou.mybatisplus.service.impl.ServiceImpl; |
| | | import com.stylefeng.guns.modular.system.util.DateUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.ui.Model; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class TOrderServiceImpl extends ServiceImpl<TOrderMapper, TOrder> implements ITOrderService { |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private TOrderMapper tOrderMapper; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private TAppUserMapper tAppUserMapper; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private TDriverMapper tDriverMapper; |
| | | @Autowired |
| | | |
| | | @Resource |
| | | private TBranchOfficeMapper tBranchOfficeMapper; |
| | | |
| | | @Override |
| | |
| | | // 开始,结束时间 |
| | | if(StringUtils.hasLength(createTime)){ |
| | | String[] split = createTime.split(" - "); |
| | | startTime = split[0]; |
| | | endTime = split[1]; |
| | | startTime = split[0] + " 00:00:00"; |
| | | endTime = split[1] + " 23:59:59"; |
| | | } |
| | | Integer roleType = Objects.requireNonNull(ShiroKit.getUser()).getRoleType(); |
| | | Integer objectId = Objects.requireNonNull(ShiroKit.getUser()).getObjectId(); |
| | |
| | | public void orderDetail(Integer orderId, Model model) { |
| | | // 订单信息 |
| | | TOrder tOrder = tOrderMapper.selectById(orderId); |
| | | model.addAttribute("id", orderId); |
| | | model.addAttribute("createTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tOrder.getCreateTime()));//下单时间 |
| | | model.addAttribute("code",tOrder.getCode());//订单编号 |
| | | model.addAttribute("source",tOrder.getSource());//订单来源 |
| | | model.addAttribute("startAddress",tOrder.getStartAddress());//起点 |
| | | model.addAttribute("startLng",tOrder.getStartLng());// 起点经度 |
| | | model.addAttribute("startLat",tOrder.getStartLat());// 起点纬度 |
| | | model.addAttribute("endAddress",tOrder.getEndAddress());//终点 |
| | | model.addAttribute("startTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tOrder.getStartTime()));//乘车时间 |
| | | model.addAttribute("boardingTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tOrder.getBoardingTime()));//上车时间 |
| | | model.addAttribute("getoffTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tOrder.getGetoffTime()));//下车时间 |
| | | model.addAttribute("endLng",tOrder.getEndLng());// 终点经度 |
| | | model.addAttribute("endLat",tOrder.getEndLat());// 终点纬度 |
| | | |
| | | if(Objects.nonNull(tOrder.getStartTime())){ |
| | | model.addAttribute("startTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tOrder.getStartTime()));//乘车时间 |
| | | }else { |
| | | model.addAttribute("startTime","");//乘车时间 |
| | | } |
| | | if(Objects.nonNull(tOrder.getBoardingTime())){ |
| | | model.addAttribute("boardingTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tOrder.getBoardingTime()));//乘车时间 |
| | | }else { |
| | | model.addAttribute("boardingTime","");//乘车时间 |
| | | } |
| | | if(Objects.nonNull(tOrder.getGetoffTime())){ |
| | | model.addAttribute("getoffTime",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(tOrder.getGetoffTime()));//乘车时间 |
| | | }else { |
| | | model.addAttribute("getoffTime","");//乘车时间 |
| | | } |
| | | model.addAttribute("startPrice",tOrder.getStartPrice());//起步价 |
| | | model.addAttribute("overDrivePrice",tOrder.getOverDrivePrice());//里程费 |
| | | model.addAttribute("waitTimePrice",tOrder.getWaitTimePrice());//等待费 |
| | | model.addAttribute("waitTimePrice",tOrder.getWaitTimePrice().add(tOrder.getOutWaitTimePrice()));//等待费 |
| | | model.addAttribute("badWeatherPrice",tOrder.getBadWeatherPrice());//恶劣天气费用 |
| | | model.addAttribute("orderMoney",tOrder.getOrderMoney());//实际费用 |
| | | model.addAttribute("payMoney",tOrder.getPayMoney());//实际支付费用 |
| | |
| | | model.addAttribute("payType",tOrder.getPayType());//支付方式 |
| | | model.addAttribute("discountAmount",tOrder.getDiscountAmount());//折扣金额 |
| | | model.addAttribute("userId",tOrder.getUserId());//用户id |
| | | model.addAttribute("routeRecord",tOrder.getRouteRecord());//行程录音 |
| | | model.addAttribute("userPhone",tOrder.getUserPhone());//用户手机号 |
| | | model.addAttribute("userName",tOrder.getUserName());//用户名称 |
| | | |
| | | // 查询用户 |
| | | TAppUser tAppUser = tAppUserMapper.selectById(tOrder.getUserId()); |
| | | model.addAttribute("userName",tAppUser.getNickname()); |
| | | model.addAttribute("userPhone",tAppUser.getPhone()); |
| | | model.addAttribute("havDiscount",tAppUser.getHavDiscount()); |
| | | if(1 == tAppUser.getHavDiscount()){ |
| | | // 计算9折优惠金额 |
| | | BigDecimal multiply = tOrder.getOrderMoney().multiply(new BigDecimal("0.1")).setScale(2); |
| | | model.addAttribute("multiply",multiply); |
| | | if(Objects.nonNull(tAppUser)){ |
| | | model.addAttribute("havDiscount",tAppUser.getHavDiscount()); |
| | | if(1 == tAppUser.getHavDiscount()){ |
| | | BigDecimal subtract = tOrder.getOrderMoney().subtract(tOrder.getDiscountedPrice()); |
| | | // 计算95折优惠金额 |
| | | BigDecimal multiply = subtract.multiply(new BigDecimal("0.05"), new MathContext(2, RoundingMode.HALF_EVEN)); |
| | | model.addAttribute("multiply",multiply); |
| | | }else { |
| | | model.addAttribute("multiply",0); |
| | | } |
| | | }else { |
| | | model.addAttribute("havDiscount",0); |
| | | model.addAttribute("multiply",0); |
| | | } |
| | | |
| | | // 查询司机 |
| | | TDriver tDriver = tDriverMapper.selectById(tOrder.getDriverId()); |
| | | model.addAttribute("driverName",tDriver.getName()); |
| | | |
| | | // 查询司机所属分公司 |
| | | TBranchOffice tBranchOffice = tBranchOfficeMapper.selectById(tDriver.getBranchOfficeId()); |
| | | if(Objects.nonNull(tBranchOffice)){ |
| | | model.addAttribute("branchOfficeName",tBranchOffice.getPrincipal()); |
| | | if(Objects.nonNull(tDriver)){ |
| | | model.addAttribute("driverName",tDriver.getName()); |
| | | model.addAttribute("driverPhone",tDriver.getPhone()); |
| | | // 查询司机所属分公司 |
| | | TBranchOffice tBranchOffice = tBranchOfficeMapper.selectById(tDriver.getBranchOfficeId()); |
| | | if(Objects.nonNull(tBranchOffice)){ |
| | | model.addAttribute("branchOfficeName",tBranchOffice.getPrincipal()); |
| | | }else { |
| | | model.addAttribute("branchOfficeName",""); |
| | | } |
| | | }else { |
| | | model.addAttribute("branchOfficeName",""); |
| | | model.addAttribute("driverName",""); |
| | | model.addAttribute("driverPhone",""); |
| | | } |
| | | |
| | | } |
| | |
| | | this.orderDetail(orderId,model); |
| | | model.addAttribute("orderId",orderId); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsByYear(Integer agentId,String yearDate, Model model,Map<String, Object> map) { |
| | | |
| | | List<DataStatisticsOrderYearResp> data = tOrderMapper.getDataStatisticsByYear(agentId,yearDate); |
| | | List<DataStatisticsOrderYearResp> resps =new ArrayList<>(); |
| | | for (int i = 1; i < 13; i++) { |
| | | DataStatisticsOrderYearResp dataStatisticsOrderYearResp = new DataStatisticsOrderYearResp(); |
| | | if(i < 10){ |
| | | dataStatisticsOrderYearResp.setMonth("0" + i); |
| | | }else { |
| | | dataStatisticsOrderYearResp.setMonth(String.valueOf(i)); |
| | | } |
| | | dataStatisticsOrderYearResp.setOrderCount(0); |
| | | resps.add(dataStatisticsOrderYearResp); |
| | | } |
| | | if(!CollectionUtils.isEmpty(data)){ |
| | | for (DataStatisticsOrderYearResp datum : data) { |
| | | for (DataStatisticsOrderYearResp resp : resps) { |
| | | if(resp.getMonth().equals(datum.getMonth())){ |
| | | resp.setOrderCount(datum.getOrderCount()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | model.addAttribute("yearResp",resps); |
| | | map.put("yearResp",resps); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsOrderCount(Integer agentId, String monthDate, Model model,Map<String, Object> map) { |
| | | List<PerformanceTableResp> list = tOrderMapper.getDataStatisticsOrderCount(agentId,monthDate); |
| | | model.addAttribute("performanceResp",list); |
| | | map.put("performanceResp",list); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsCount(Integer agentId, Model model) { |
| | | Integer pendingOrderCount = tOrderMapper.getDataStatisticsCount(agentId, OrderStateEnum.PENDING_ORDER.getCode(), LocalDate.now()); |
| | | Integer finishCount = tOrderMapper.getDataStatisticsCount(agentId, OrderStateEnum.FINISH.getCode(),LocalDate.now()); |
| | | Integer cancelCount = tOrderMapper.getDataStatisticsCount(agentId, OrderStateEnum.CANCELED.getCode(),LocalDate.now()); |
| | | |
| | | Integer serverCount = tOrderMapper.getDataStatisticsServerCount(agentId, LocalDate.now()); |
| | | |
| | | model.addAttribute("pendingOrderCount",pendingOrderCount); |
| | | model.addAttribute("finishCount",finishCount); |
| | | model.addAttribute("cancelCount",cancelCount); |
| | | model.addAttribute("serverCount",serverCount); |
| | | } |
| | | |
| | | @Override |
| | | public List<TOrderServerResp> getDataStatisticsServerList(Integer agentId) { |
| | | return tOrderMapper.getDataStatisticsServerList(agentId,LocalDate.now()); |
| | | } |
| | | |
| | | @Override |
| | | public List<TOrder> getDataStatisticsAllList(Integer agentId,Integer type) { |
| | | return tOrderMapper.getDataStatisticsAllList(agentId,type,LocalDate.now()); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsCountByIds(List<Integer> ids, Model model) { |
| | | Integer pendingOrderCount = tOrderMapper.getDataStatisticsCountByIds(ids, 1, LocalDate.now()); |
| | | Integer finishCount = tOrderMapper.getDataStatisticsCountByIds(ids, 2,LocalDate.now()); |
| | | Integer cancelCount = tOrderMapper.getDataStatisticsCountByIds(ids, 3,LocalDate.now()); |
| | | Integer serverCount = tOrderMapper.getDataStatisticsServerCountByIds(ids, LocalDate.now()); |
| | | |
| | | model.addAttribute("pendingOrderCount",pendingOrderCount); |
| | | model.addAttribute("finishCount",finishCount); |
| | | model.addAttribute("cancelCount",cancelCount); |
| | | model.addAttribute("serverCount",serverCount); |
| | | } |
| | | |
| | | @Override |
| | | public List<TOrderServerResp> getDataStatisticsServerListByIds(List<Integer> ids) { |
| | | return tOrderMapper.getDataStatisticsServerListByIds(ids,LocalDate.now()); |
| | | } |
| | | |
| | | @Override |
| | | public List<TOrder> getDataStatisticsAllListByIds(List<Integer> ids,Integer type) { |
| | | return tOrderMapper.getDataStatisticsAllListByIds(ids,type,LocalDate.now()); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsCountGetMap(Integer agentId, HashMap<String, Object> map) { |
| | | Integer pendingOrderCount = tOrderMapper.getDataStatisticsCount(agentId, OrderStateEnum.PENDING_ORDER.getCode(), LocalDate.now()); |
| | | Integer finishCount = tOrderMapper.getDataStatisticsCount(agentId, OrderStateEnum.FINISH.getCode(),LocalDate.now()); |
| | | Integer cancelCount = tOrderMapper.getDataStatisticsCount(agentId, OrderStateEnum.CANCELED.getCode(),LocalDate.now()); |
| | | |
| | | Integer serverCount = tOrderMapper.getDataStatisticsServerCount(agentId, LocalDate.now()); |
| | | |
| | | map.put("pendingOrderCount",pendingOrderCount); |
| | | map.put("finishCount",finishCount); |
| | | map.put("cancelCount",cancelCount); |
| | | map.put("serverCount",serverCount); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsCountByIdsGetMap(List<Integer> ids, HashMap<String, Object> map) { |
| | | Integer pendingOrderCount = tOrderMapper.getDataStatisticsCountByIds(ids, 1, LocalDate.now()); |
| | | Integer finishCount = tOrderMapper.getDataStatisticsCountByIds(ids, 2,LocalDate.now()); |
| | | Integer cancelCount = tOrderMapper.getDataStatisticsCountByIds(ids, 3,LocalDate.now()); |
| | | Integer serverCount = tOrderMapper.getDataStatisticsServerCountByIds(ids, LocalDate.now()); |
| | | |
| | | map.put("pendingOrderCount",pendingOrderCount); |
| | | map.put("finishCount",finishCount); |
| | | map.put("cancelCount",cancelCount); |
| | | map.put("serverCount",serverCount); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsByYearByIds(List<Integer> ids, String yearDate, Model model, Map<String, Object> map) { |
| | | |
| | | List<DataStatisticsOrderYearResp> data = tOrderMapper.getDataStatisticsByYearByIds(ids,yearDate); |
| | | List<DataStatisticsOrderYearResp> resps =new ArrayList<>(); |
| | | for (int i = 1; i < 13; i++) { |
| | | DataStatisticsOrderYearResp dataStatisticsOrderYearResp = new DataStatisticsOrderYearResp(); |
| | | if(i < 10){ |
| | | dataStatisticsOrderYearResp.setMonth("0" + i); |
| | | }else { |
| | | dataStatisticsOrderYearResp.setMonth(String.valueOf(i)); |
| | | } |
| | | dataStatisticsOrderYearResp.setOrderCount(0); |
| | | resps.add(dataStatisticsOrderYearResp); |
| | | } |
| | | if(!CollectionUtils.isEmpty(data)){ |
| | | for (DataStatisticsOrderYearResp datum : data) { |
| | | for (DataStatisticsOrderYearResp resp : resps) { |
| | | if(resp.getMonth().equals(datum.getMonth())){ |
| | | resp.setOrderCount(datum.getOrderCount()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | model.addAttribute("yearResp",resps); |
| | | map.put("yearResp",resps); |
| | | } |
| | | |
| | | @Override |
| | | public void getDataStatisticsOrderCountByIds(List<Integer> ids, String monthDate, Model model, Map<String, Object> map) { |
| | | List<PerformanceTableResp> list = tOrderMapper.getDataStatisticsOrderCountByIds(ids,monthDate); |
| | | model.addAttribute("performanceResp",list); |
| | | map.put("performanceResp",list); |
| | | } |
| | | |
| | | @Override |
| | | public void getStatisticsOrderByMonth(Integer agentId, String dayDate, Model model, Map<String, Object> map) { |
| | | List<DataStatisticsOrderYearResp> data = tOrderMapper.getStatisticsOrderByMonth(agentId,dayDate); |
| | | List<DataStatisticsOrderYearResp> resps =new ArrayList<>(); |
| | | int month = DateUtil.getDaysOfMonth(new Date()); |
| | | for (int i = 1; i <= month; i++) { |
| | | DataStatisticsOrderYearResp dataStatisticsOrderYearResp = new DataStatisticsOrderYearResp(); |
| | | if(i < 10){ |
| | | dataStatisticsOrderYearResp.setMonth("0" + i); |
| | | }else { |
| | | dataStatisticsOrderYearResp.setMonth(String.valueOf(i)); |
| | | } |
| | | dataStatisticsOrderYearResp.setOrderCount(0); |
| | | resps.add(dataStatisticsOrderYearResp); |
| | | } |
| | | if(!CollectionUtils.isEmpty(data)){ |
| | | for (DataStatisticsOrderYearResp datum : data) { |
| | | for (DataStatisticsOrderYearResp resp : resps) { |
| | | if(resp.getMonth().equals(datum.getMonth())){ |
| | | resp.setOrderCount(datum.getOrderCount()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | model.addAttribute("monthResp",resps); |
| | | map.put("monthResp",resps); |
| | | } |
| | | |
| | | @Override |
| | | public void getStatisticsOrderByMonthIds(List<Integer> ids, String dayDate, Model model, Map<String, Object> map) { |
| | | List<DataStatisticsOrderYearResp> data = tOrderMapper.getStatisticsOrderByMonthIds(ids,dayDate); |
| | | List<DataStatisticsOrderYearResp> resps =new ArrayList<>(); |
| | | int month = DateUtil.getDaysOfMonth(new Date()); |
| | | for (int i = 1; i <= month; i++) { |
| | | DataStatisticsOrderYearResp dataStatisticsOrderYearResp = new DataStatisticsOrderYearResp(); |
| | | if(i < 10){ |
| | | dataStatisticsOrderYearResp.setMonth("0" + i); |
| | | }else { |
| | | dataStatisticsOrderYearResp.setMonth(String.valueOf(i)); |
| | | } |
| | | dataStatisticsOrderYearResp.setOrderCount(0); |
| | | resps.add(dataStatisticsOrderYearResp); |
| | | } |
| | | if(!CollectionUtils.isEmpty(data)){ |
| | | for (DataStatisticsOrderYearResp datum : data) { |
| | | for (DataStatisticsOrderYearResp resp : resps) { |
| | | if(resp.getMonth().equals(datum.getMonth())){ |
| | | resp.setOrderCount(datum.getOrderCount()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | model.addAttribute("monthResp",resps); |
| | | map.put("monthResp",resps); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public Integer getValidOrderCount(Integer driverId, BigDecimal orderMoney, String month) { |
| | | // 查询司机当月有效订单数量 |
| | | return tOrderMapper.getValidOrderCount(driverId,orderMoney,month); |
| | | } |
| | | } |