package com.bohuikeji.delivery.backstage.controller.views;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bohuikeji.delivery.backstage.entity.*;
import com.bohuikeji.delivery.backstage.util.PageUtil;
import com.bohuikeji.frame.module.admin.base.PageTemplateControllerBase;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import com.bohuikeji.frame.module.admin.entity.back.PageEntity;
import com.bohuikeji.frame.module.admin.entity.sys.SysUser;
import com.bohuikeji.frame.module.admin.entity.web.block.ButtonBlock;
import com.bohuikeji.frame.module.admin.entity.web.event.Function;
import com.bohuikeji.frame.module.admin.entity.web.template.TableTemplate;
import com.bohuikeji.frame.module.admin.enums.ButtonBlockEnum;
import com.bohuikeji.frame.module.admin.service.ITFranchiseeInformationService;
import com.bohuikeji.frame.module.admin.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;

/**
 * 共享页面控制器
 * @author 10552
 */
@Slf4j
@Controller
@RequestMapping("/views")
public class SharePage extends PageTemplateControllerBase {
    @Autowired
    ITFranchiseeInformationService franchiseeInformationService;
    /**
     * 派送员管理——待审核
     *
     * @return
     */
    @GetMapping("/table/courier/check")
    public PageEntity toCourierCheck() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        SysUser loginUser=getLoginUser();
        QueryWrapper<TCourier> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq(false,"courier_type","全职").and(i->i.eq("courier_status", "审核中").or().eq("courier_auth","审核中"));
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/courier/courier");
    }

    /**
     * 派送员管理——正常
     *
     * @return
     */
    @GetMapping("/table/courier/normal")
    public PageEntity toCourierNoraml() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buts = new ArrayList<>(2);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "添加配送员"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "修改派送员信息"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "任务面板").setOnClick("showCourierMod()").setStyle("btn btn-info m-r-5"));
        //buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "轨迹跟踪").setOnClick("onlineBack()").setStyle("btn btn-cyan m-r-5"));
        pageTemplate.setBatchButton(buts);
        SysUser loginUser=getLoginUser();
        QueryWrapper<TCourier> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq(false,"courier_type","全职").and(i->i.in("courier_status", "正常","禁止接单","禁止登陆").or().eq("courier_auth","认证成功"));
        pageTemplate.setQueryWrapper(queryWrapper);
        if(buts.equals("任务面板")){
            QueryWrapper<TOrder> wrapper = getFranQueryWrapper();
            pageTemplate.setQueryWrapper(wrapper);
        }
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/courier/normal");
    }
    /**
     * 派送员管理——认证失败
     *
     * @return
     */
    @GetMapping("/table/courier/fail")
    public PageEntity toCourierFail() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buts = new ArrayList<>(0);
        /*buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "添加配送员"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "修改派送员信息"));*/
        pageTemplate.setBatchButton(buts);
        SysUser loginUser=getLoginUser();
        QueryWrapper<TCourier> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq(false,"courier_type","全职").and(i->i.eq("courier_status", "审核未通过").or().eq("courier_auth","认证失败"));
        pageTemplate.setQueryWrapper(queryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }
    /**
     * 派送员管理——未提交认证
     *
     * @return
     */
    @GetMapping("/table/courier/default")
    public PageEntity toCourierDefault() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        /*buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "添加配送员"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "修改派送员信息"));*/
        SysUser loginUser=getLoginUser();
        pageTemplate.setBatchButton(ButtonBlock.createButtons(ButtonBlockEnum.DELETE));
        QueryWrapper<TCourier> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq(false,"courier_type","全职").and(i->i.eq("courier_status", "未审核").or().eq("courier_auth","未认证"));
        pageTemplate.setQueryWrapper(queryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }



    /**
     * 订单管理 ->待接单管理
     *
     * @return
     */
    @GetMapping("/table/order/wait")
    public PageEntity toOrderWait(HttpServletRequest request) {
        //创建模板页面
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setTableModel(pageTemplate.getTableModel().setUrl("/order/table/model/form"));
        List<ButtonBlock> buts = new ArrayList<>(4);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "指派订单").setOnClick("modelShow('ZP')").setIcon("mdi mdi-gesture-tap"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "下单").setIcon("mdi mdi-playlist-plus"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "快捷下单").setIcon("mdi mdi-airplane-takeoff").setStyle("btn btn-purple").setOnClick("quiteOrder()"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "修改订单"));
        buts.add(new ButtonBlock(null).setStyle("btn btn-info m-r-5").setIcon("mdi mdi-delete-empty").setTitle("取消订单").setOnClick("orderRefund()"));
        SysUser user = getLoginUser();
        if(user.getUserId()==1){
            buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "查询第三方推送结果").setOnClick("showThirdResult()").setIcon("mdi mdi-magnify"));
        }
        buts.add(new ButtonBlock(null).setStyle("btn btn-cyan m-r-5").setIcon("mdi mdi-comment").setTitle("服务告知").setOnClick("initSendMsgModel()"));
        //buts.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE, "删除订单"));
        pageTemplate.setBatchButton(buts);
        QueryWrapper<TOrder> tOrderQueryWrapper = getFranQueryWrapper();
        tOrderQueryWrapper.ne("is_test",1);
        tOrderQueryWrapper.eq("order_batch_num","0");
        tOrderQueryWrapper.eq("order_status", "待接单");
        pageTemplate.setQueryWrapper(tOrderQueryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/wait");
    }

    /**
     * 订单管理 ->进行中管理
     *
     * @return
     */
    @GetMapping("/table/order/underway")
    public PageEntity toOrderUnderway(HttpServletRequest request) {
        List<ButtonBlock> buts = new ArrayList<>(3);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "转派订单").setOnClick("modelShow()").setIcon("mdi mdi-gesture-tap"));
        buts.add(new ButtonBlock(null).setStyle("btn btn-info m-r-5").setIcon("mdi mdi-delete-empty").setTitle("取消订单").setOnClick("orderRefund()"));
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setTableModel(pageTemplate.getTableModel().setUrl("/order/table/model/form"));
        pageTemplate.setBatchButton(buts);
        QueryWrapper<TOrder> tOrderQueryWrapper = getFranQueryWrapper();
        tOrderQueryWrapper.ne("is_test",1);
        tOrderQueryWrapper.eq("order_batch_num","0");
        tOrderQueryWrapper.in("order_status", "待取件", "取件中", "待派送", "派送中","待支付");
        pageTemplate.setQueryWrapper(tOrderQueryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/underway");
    }

    /**
     * 订单管理 ->已完成管理
     *
     * @return
     */
    @GetMapping("/table/order/complete")
    public PageEntity toOrderComplete(HttpServletRequest request) {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setTableModel(pageTemplate.getTableModel().setUrl("/order/table/model/form"));
        List<ButtonBlock> list = new ArrayList<>(0);
        //list.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "订单结算"));
        pageTemplate.setBatchButton(list);
        //设置订单状态
        QueryWrapper<TOrder> tOrderQueryWrapper = getFranQueryWrapper();
        tOrderQueryWrapper.ne("is_test",1);
        tOrderQueryWrapper.eq("order_batch_num","0");
        tOrderQueryWrapper.in("order_status", "已完成", "待评价");
        pageTemplate.setQueryWrapper(tOrderQueryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/complete");
    }

    /**
     * 异常管理管理——待处理
     *
     * @return
     */
    @GetMapping("/table/order/exception/wait")
    public PageEntity toOrderExceptionWait() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> list = new ArrayList<>(0);
        pageTemplate.setBatchButton(list);
        String sql=getFranSqlByKey("t_order","order_id");
        QueryWrapper<TOrderExceptionEntity> queryWrapper=new QueryWrapper<TOrderExceptionEntity>().eq("exception_status","待处理");
        if(sql!=null){
            queryWrapper.inSql("order_id",sql);
        }
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        return PageEntity.page("/order/exception_wait");
    }
    /**
     * 异常管理管理——处理历史
     *
     * @return
     */
    @GetMapping("/table/order/exception/history")
    public PageEntity toOrderException() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> list = new ArrayList<>(0);
        pageTemplate.setBatchButton(list);
        String sql=getFranSqlByKey("t_order","order_id");
        QueryWrapper<TOrderExceptionEntity> queryWrapper=new QueryWrapper<TOrderExceptionEntity>().eq("exception_status","处理完成");
        if(sql!=null){
            queryWrapper.inSql("order_id",sql);
        }
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        return PageEntity.page("/order/exception_history");
    }

    /**
     * 订单管理 ->全部订单
     *
     * @return
     */
    @GetMapping("/table/order/all")
    public PageEntity toOrderAll() {
        List<ButtonBlock> buts = new ArrayList<>(1);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "查看物流信息").setOnClick("showOrderRecord()").setIcon("mdi mdi-gesture-tap"));
        //buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "导出EXCEL").setOnClick("exportExcel()").setIcon("mdi mdi-gesture-tap"));
        buts.add(new ButtonBlock(null).setStyle("btn btn-info m-r-5").setIcon("mdi mdi-delete-empty").setTitle("取消订单").setOnClick("orderRefund()"));
        SysUser user = getLoginUser();
        if(user.getUserId()==1){
            buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "查看第三方配送信息").setOnClick("showThirdDetail()").setIcon("mdi mdi-gesture-tap"));
            buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "查询第三方推送结果").setOnClick("showThirdResult()").setIcon("mdi mdi-magnify"));
            buts.add(new ButtonBlock(null).setStyle("btn btn-info m-r-5").setIcon("mdi mdi-delete-empty").setTitle("重新推送").setOnClick("RePushShow()"));
            buts.add(new ButtonBlock(null).setStyle("btn btn-info m-r-5").setIcon("mdi mdi-delete-empty").setTitle("完成率").setOnClick("CompleteRate()"));
        }else {
            buts.add(new ButtonBlock(null).setStyle("btn btn-info m-r-5").setIcon("mdi mdi-delete-empty").setTitle("完成率").setOnClick("franCompleteRate()"));
        }
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setBatchButton(buts);
        QueryWrapper<TOrder> queryWrapper=getFranQueryWrapper();
        queryWrapper.ne("is_test",1);
        queryWrapper.eq("order_batch_num","0");
        pageTemplate.setQueryWrapper(queryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/all");
    }

    /**
     * 订单管理 -> 订单模板管理
     * @return
     */
    @GetMapping("/table/order/template")
    public PageEntity toOrderTemplate() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.getTableModel().setUrl("/admin/order/template/table/model/form");
        pageTemplate.setQueryWrapper(getFranQueryWrapper());
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/template");
    }
    /**
     * 订单管理 ->京东订单
     *
     * @return
     */
    @GetMapping("/table/order/jd")
    public PageEntity toJd() {
        List<ButtonBlock> buts = new ArrayList<>(1);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "查看物流信息").setOnClick("showOrderRecord()").setIcon("mdi mdi-gesture-tap"));
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setBatchButton(buts);
        QueryWrapper<TOrder> queryWrapper=getFranQueryWrapper();
        queryWrapper.ne("is_test",1);
        queryWrapper.eq("order_batch_num","0");
        queryWrapper.like("order_num","D%");
        pageTemplate.setQueryWrapper(queryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/jd");
    }



    /**
     * 车辆管理-派送员认证车辆
     *
     * @return
     */
    @GetMapping("/table/vehicle/information/courier")
    public PageEntity toVehicleCourier() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        SysUser user=getLoginUser();
        QueryWrapper<TVehicleInformation> queryWrapper=new QueryWrapper<TVehicleInformation>();
        //平台
        if(user.getRoleId().equals(1)){
            queryWrapper.isNotNull("courier_id");
        }
        else{
            queryWrapper
                    .inSql("courier_id","select courier_id from t_courier where fran_id in("+ StringUtils.join(franchiseeInformationService.queryLow(user.getFranId()),",") +")");
        }
        pageTemplate.setBatchButton(new ArrayList<ButtonBlock>(0));
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        return PageEntity.page("/vehicle/courier");
    }
    /**
     * 车辆管理-自有车辆
     *
     * @return
     */
    @GetMapping("/table/vehicle/information/fran")
    public PageEntity toVehicleFran() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        SysUser user=getLoginUser();
        QueryWrapper<TVehicleInformation> queryWrapper=new QueryWrapper<TVehicleInformation>();
        //平台
        if(user.getRoleId().equals(1)){
            queryWrapper.isNotNull("fran_id");
        }
        else{
            queryWrapper
                    .inSql("courier_id","select courier_id from t_courier where fran_id in("+ StringUtils.join(franchiseeInformationService.queryLow(user.getFranId()),",") +")");
        }
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        return PageEntity.page("/vehicle/fran");
    }




    /**
     * 评价记录
     *
     * @return
     */
    @GetMapping("/table/assess/evaluate")
    public PageEntity toEvaluate() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setBatchButton(ButtonBlock.createButtons(ButtonBlockEnum.DELETE));
        String sql= getFranSqlByKey("t_order","order_num");
        if(sql==null){
            session.setAttribute("pageTemplate", pageTemplate);
        }
        else{
            QueryWrapper<TEvaluate> queryWrapper=new QueryWrapper<TEvaluate>().inSql("order_num",sql);
            session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        }
        return PageEntity.page("/assess/evaluate");
    }

    /**
     * 评价记录明细
     *
     * @return
     */
    @GetMapping("/table/assess/detailed")
    public PageEntity toDetailed() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        String sql= getFranSqlByKey("t_order","order_num");
        if(sql==null){
            session.setAttribute("pageTemplate", pageTemplate);
        }
        else{
            QueryWrapper<TEvaluateDetailed> queryWrapper=new QueryWrapper<TEvaluateDetailed>()
                    .inSql("evaluate_id","select evaluate_id from t_evaluate where order_num in ("+sql+")");
            session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        }

        //跳转到模板页面
        return PageEntity.page("/assess/detailed");
    }

    /**
     * 投诉记录
     *
     * @return
     */
    @GetMapping("/table/assess/complaint")
    public PageEntity toComplaint() {
        //创建模板页面
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        String sql=getFranSqlByKey("t_order","order_num");
        if(sql==null){
            session.setAttribute("pageTemplate", pageTemplate);
        }
        else{
            QueryWrapper<TComplaint> queryWrapper=new QueryWrapper<TComplaint>().inSql("order_num",sql);
            session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        }
        return PageEntity.page("/assess/complaint");
    }
    /**
     * 物流管理——包裹管理
     *
     * @return
     */
    @GetMapping("/table/logistics/park")
    public PageEntity toLogisticsPark() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        String franSql=getFranSqlByKey("t_order","order_id");
        if(franSql!=null){
            pageTemplate.setQueryWrapper(new QueryWrapper<TLogistics>().inSql("order_id",franSql));
        }
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 物流管理——物流记录
     *
     * @return
     */
    @GetMapping("/table/logistics/record")
    public PageEntity toLogisticsRecord() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        String franSql=getFranSqlByKey("t_order","order_id");
        if(franSql!=null){
            pageTemplate.setQueryWrapper(new QueryWrapper<TLogistics>().inSql("order_id",franSql));
        }
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 批量订单——待接单
     * @return
     */
    @GetMapping("/table/order/batch/wait")
    public PageEntity toBatchOrderWait(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(2);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"批量导入订单").setOnClick("orderBatchImport()"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"批量打印").setOnClick("orderBatchPrint()").setId("id_batchOrder_print_button"));
        if(getLoginUser().getRoleId()==1){
            buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "指派订单").setOnClick("modelShow()").setIcon("mdi mdi-gesture-tap"));
            buttonBlocks.add(new ButtonBlock(null).setStyle("btn btn-info m-r-5").setIcon("mdi mdi-delete-empty").setTitle("取消订单").setOnClick("setColumn('order_status','已取消')"));
            buttonBlocks.add(new ButtonBlock(null).setStyle("btn btn-cyan m-r-5").setIcon("mdi mdi-comment").setTitle("服务告知").setOnClick("initSendMsgModel()"));
        }
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除订单"));
        pageTemplate.setBatchButton(buttonBlocks);
        QueryWrapper<TOrder> queryWrapper=getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper.ne("order_batch_num","0").eq("order_status", "待接单"));
        session.setAttribute("pageTemplate", pageTemplate);
        if(getLoginUser().getRoleId().equals(17)){
            return PageEntity.page("/order/batch/wait_big");
        }
        return PageEntity.page("/order/batch/wait");
    }
    /**
     * 批量订单——进行中
     * @return
     */
    @GetMapping("/table/order/batch/run")
    public PageEntity toBatchOrderRun(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        QueryWrapper<TOrder> queryWrapper=getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper.ne("order_batch_num","0").in("order_status", "待取件", "取件中", "待派送", "派送中"));
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/batch/wait");
    }
    /**
     * 批量订单——已完成
     * @return
     */
    @GetMapping("/table/order/batch/end")
    public PageEntity toBatchOrderEnd(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        QueryWrapper<TOrder> queryWrapper=getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper.ne("order_batch_num","0").in("order_status", "已完成", "待评价"));
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/batch/wait");
    }
    /**
     * 批量订单——全部订单
     * @return
     */
    @GetMapping("/table/order/batch/all")
    public PageEntity toBatchOrderAll(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        QueryWrapper<TOrder> queryWrapper=getFranQueryWrapper();
        queryWrapper.ne("order_batch_num","0");
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        return PageEntity.page("/order/batch/wait");
    }

    /**
     * 签约商户管理
     * @return
     */
    @GetMapping("/table/customer/big/all")
    public PageEntity bigCustomer(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(4);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"签约"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"更改"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"结束签约")
                .setOnClick(Function.setColumn("big_status","已结束")));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"续签")
                .setOnClick(Function.setColumn("big_status","已签约")));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除"));
        /*buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"绑定计费模板"));*/
        pageTemplate.setBatchButton(buttonBlocks);
        pageTemplate.getTableModel().setUrl("/admin/customer/big/model/form");
        QueryWrapper<TCustomerBig> queryWrapper=getFranQueryWrapper();
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper.eq("big_status","已签约")));
        return PageEntity.page("/order/batch/wait");
    }
    /**
     * 签约商户管理---审核
     * @return
     */
    @GetMapping("/table/customer/big/examine")
    public PageEntity bigCustomerExamine(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        QueryWrapper<TCustomerBig> queryWrapper=getFranQueryWrapper();
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper.eq("big_status","审核中")));
        return PageEntity.page("/customer/customerBig");
    }
    /**
     * 客户模板管理
     * @return
     */
    @GetMapping("/table/customer/template/all")
    public PageEntity customerTemplate(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = ButtonBlock.createButtons(ButtonBlockEnum.ADD,ButtonBlockEnum.EDIT);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除").setOnClick("delTemplate();"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"修改计费").setOnClick("showPriceModel();"));
        pageTemplate.setBatchButton(buttonBlocks);
        pageTemplate.getTableModel().setUrl("/customer/template/model/form");
        QueryWrapper<TCustomerTemplate> queryWrapper=getFranQueryWrapper();
        queryWrapper.groupBy("template_code");
        session.setAttribute("pageTemplate", pageTemplate.setQueryWrapper(queryWrapper));
        return PageEntity.page("/customer/template");
    }
    /**
     * 派送员退款审核——待审核
     * @return
     */
    @GetMapping("/table/courier/exam")
    public PageEntity toCourierExam() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        SysUser loginUser=getLoginUser();
        QueryWrapper<TCourierExam> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq("exam_status","审核中");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/courierexam/courierExam");
    }

    /**
     * 派送员退款审核——审核结果
     *
     * @return
     */
    @GetMapping("/table/courier/result")
    public PageEntity toCourierExamAdopt() {
        SysUser loginUser=getLoginUser();
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCourierExam> queryWrapper = getFranQueryWrapper();
        queryWrapper.notIn("exam_status","审核中");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 骑手分布图
     * @return
     */
    @GetMapping("/table/courier/map")
    public PageEntity toCourierMap() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(getFranQueryWrapper());
        session.setAttribute("pageTemplate", pageTemplate);
        //PageUtil.main();
        return PageEntity.page("/courier/map");
    }


    /**
     * 派送员退款审核——审核驳回
     *
     * @return
     */
    /*@GetMapping("/table/courier/reject")
    public PageEntity toCourierExamReject() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        SysUser loginUser=getLoginUser();
        QueryWrapper<TCourierExam> queryWrapper = getFranQueryWrapper();
        if(loginUser.getRoleId().equals(7)){
            queryWrapper.eq("exam_status","审核失败").eq("fran_id",loginUser.getFranId());
        }
        if(loginUser.getRoleId().equals(1)){
            queryWrapper.eq("exam_status","审核失败");
        }
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }*/

}
