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.service.ITCourierWithdrawService;
import com.bohuikeji.frame.module.admin.base.EntityBase;
import com.bohuikeji.frame.module.admin.base.PageTemplateControllerBase;
import com.bohuikeji.frame.module.admin.entity.back.PageEntity;
import com.bohuikeji.frame.module.admin.entity.sys.*;
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.ISysChartService;
import com.bohuikeji.frame.module.admin.service.ISysConfigService;
import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.Magic;
import com.github.abel533.echarts.code.MarkType;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.data.PointData;
import com.github.abel533.echarts.feature.MagicType;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 运营公司页面控制器
 * /views对应resources下的templates文件夹
 *
 * @author 10552
 */
@Slf4j
@Controller
@RequestMapping("/views")
@RequiredArgsConstructor
public class OperatePage extends PageTemplateControllerBase {

    final ISysChartService chartService;
    final ISysConfigService configService;
    final ITCourierWithdrawService courierWithdrawService;

    /**
     * 首页——统计
     *
     * @return
     */
    @GetMapping("/operate/index")
    public PageEntity toIndex() {
        List<SysConfig> configList = configService.getListByGroup("index_count_group_operate");
        configList.forEach(config -> {
            config.setConfigValue(config.sql().selectObj(config.getConfigValue()).toString());
        });
        //地址：http://echarts.baidu.com/doc/example/bar1.html
        GsonOption option = new GsonOption();
        option.title().text("某地区蒸发量和降水量").subtext("纯属虚构");
        option.tooltip().trigger(Trigger.axis);
        option.legend("蒸发量", "降水量");
        option.toolbox().show(true).feature(Tool.mark, Tool.dataView, new MagicType(Magic.line, Magic.bar).show(true), Tool.restore, Tool.saveAsImage);
        option.calculable(true);
        option.xAxis(new CategoryAxis().data("1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"));
        option.yAxis(new ValueAxis());

        Bar bar = new Bar("蒸发量");
        bar.data(2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3);
        bar.markPoint().data(new PointData().type(MarkType.max).name("最大值"), new PointData().type(MarkType.min).name("最小值"));
        bar.markLine().data(new PointData().type(MarkType.average).name("平均值"));

        Bar bar2 = new Bar("降水量");
        List<Double> list = Arrays.asList(2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3);
        bar2.data(list);
        bar2.markPoint().data(new PointData("年最高", 182.2).xAxis(7).yAxis(183).symbolSize(18), new PointData("年最低", 2.3).xAxis(11).yAxis(3));
        bar2.markLine().data(new PointData().type(MarkType.average).name("平均值"));

        option.series(bar, bar2);
        option.exportToHtml("bar1.html");
        option.view();

        return PageEntity.page("/index_operate").add("countTerm", configList);
    }

    /**
     * 加盟商管理-加盟商信息
     *
     * @return
     */
    @GetMapping("/table/franchisee/information")
    public PageEntity toFranchiseeInformation() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(getFranQueryWrapper());
        List<ButtonBlock> blockList=ButtonBlock.createButtons(ButtonBlockEnum.ADD,ButtonBlockEnum.EDIT,ButtonBlockEnum.DELETE);
        blockList.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"C端计费配置").setOnClick("showFranPriceModel()"));
        blockList.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"B端计费配置").setOnClick("showMerchantModel()"));
        blockList.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"三方抽成配置").setOnClick("showDividedModel()"));
        pageTemplate.setBatchButton(blockList);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/franchisee/information");
    }

    /**
     *站长管理
     * @return
     */
    @GetMapping("/table/manage/get/list")
    public PageEntity toManage() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(getFranQueryWrapper());
        List<ButtonBlock> buttonBlocks=new ArrayList<>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"新增站长"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改站长"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除站长"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 客户管理
     * 信息维护
     *
     * @return
     */
    @GetMapping("/table/customer/customer")
    public PageEntity toCustomer(HttpServletRequest request) {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCustomer> queryWrapper=new QueryWrapper<TCustomer>();
        queryWrapper.notIn("customer_status","待审核");
        List<ButtonBlock> buttonBlocks=new ArrayList<>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"绑定计费模板"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"解绑计费模板").setOnClick("setColumn('template_id','')"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"绑定大商户"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/customer/customer");
    }

    /**
     * 客户地址
     * 信息维护
     *
     * @return
     */
    @GetMapping("/table/customer/address/list")
    public PageEntity toCustomerAddressList() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCustomerAddress> queryWrapper=new QueryWrapper<TCustomerAddress>();
        List<ButtonBlock> buttonBlocks=new ArrayList<>(1);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 客户管理
     * 商家入驻
     *
     * @return
     */
   /* @GetMapping("/table/customer/business/settled")
    public PageEntity settled() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCustomer> queryWrapper=new QueryWrapper<TCustomer>();
        queryWrapper.eq("customer_status","待审核");
        List<ButtonBlock> buttonBlocks=new ArrayList<>(1);
        pageTemplate.setQueryWrapper(queryWrapper);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/customer/settled");
    }*/


    /**
     * 审核记录表
     *
     * @return
     */
    @GetMapping("/table/audit/records")
    public PageEntity toAuditRecords() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/audit/records");
    }


    /**
     * 审核模板定义表
     *
     * @return
     */
    @GetMapping("/table/audit/definition")
    public PageEntity toAuditDefinition() {
        //创建模板页面
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        //跳转到模板页面
        return PageEntity.page("/audit/definition");
    }

    /**
     * 审核模板配置表
     *
     * @return
     */
    @GetMapping("/table/audit/config")
    public PageEntity toAuditConfig() {
        //创建模板页面
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        //跳转到模板页面
        return PageEntity.page("/audit/config");
    }


    /**
     * 结算中心——结算审核
     *
     * @return
     */
    @GetMapping("/table/company/verify")
    public PageEntity toCompanyVerify() {
        //创建模板页面
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(2);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"结算审核").setOnClick("toVerify()"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        //跳转到模板页面
        return PageEntity.page("/company/verify");
    }

    /**
     * 总结算中心——结算申请
     *
     * @return
     */
    @GetMapping("/table/company/fran")
    public PageEntity toCompanyFran() {
        List<SysChart> cardList=chartService.fullChartList(chartService.listByColumn("chart_group","settlement_fran"),getLoginUser());
        //创建模板页面
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(2);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"发起结算").setOnClick("toComp()"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"撤销").setOnClick("del()"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"收款账户管理").setOnClick("showBuildModel()"));
        if (getLoginUser().getFranId()!=1){
            pageTemplate.setQueryWrapper(new QueryWrapper<EntityBase>().eq("fran_id",getLoginUser().getFranId()));
        }
        pageTemplate.setBatchButton(buttonBlocks);

        session.setAttribute("pageTemplate", pageTemplate);
        //跳转到模板页面
        return PageEntity.page("/company/fran").addCared(cardList);
    }

    /**
     * 总结算中心——结算明细
     *
     * @return
     */
    @GetMapping("/table/company/detail")
    public PageEntity toCompanyDetail() {
        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.eq("order_batch_num","0");
        tOrderQueryWrapper.in("order_status", "已完成", "待评价");
        pageTemplate.setQueryWrapper(tOrderQueryWrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        //跳转到模板页面
        return PageEntity.page("/table/index");
    }

    /**
     * 加盟商对配送员结算
     *
     * @return
     */
    @GetMapping("/table/company/franCourier")
    public PageEntity toFranCourier() {
        //创建模板页面
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/company/franCourier");
    }

    /**
     * 仓库信息
     *
     * @return
     */
    @GetMapping("/table/warehouse/warehouse")
    public PageEntity toWarehouse() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/warehouse/warehouse");
    }

    /**
     * 仓库记录
     *
     * @return
     */
    @GetMapping("/table/warehouse/warehousing")
    public PageEntity toWarehousing() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/warehouse/warehousing");
    }

    /**
     * 货架信息表
     *
     * @return
     */
    @GetMapping("/table/warehouse/shelves")
    public PageEntity toShelves() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/warehouse/shelves");
    }

    /**
     * 信息发布
     *
     * @return
     */
    @GetMapping("/table/news/news")
    public PageEntity toNews() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TNews> wrapper = new QueryWrapper<TNews>().eq("news_type", 1);
        List<ButtonBlock> buts = new ArrayList<>(0);
        pageTemplate.setBatchButton(buts);
        pageTemplate.setQueryWrapper(wrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/news/news");
    }

    /**
     * 通知公告
     *
     * @return
     */
    @GetMapping("/table/news/notice")
    public PageEntity toNotice() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TNews> wrapper = new QueryWrapper<TNews>().eq("news_type", 2);
        List<ButtonBlock> buts = new ArrayList<>(3);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD, "新增消息").setIcon("mdi mdi-playlist-plus"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "修改消息"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE, "删除消息"));
        pageTemplate.setBatchButton(buts);
        pageTemplate.setQueryWrapper(wrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/news/notice");
    }



    /**
     * 账户配置
     *
     * @return
     */
    @GetMapping("/table/account/roles")
    public PageEntity toRoles() {
        SysUser user = (SysUser) session.getAttribute("loginUser");
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<SysRole> wrapper = new QueryWrapper<SysRole>().eq("fran_id", user.getFranId());
        pageTemplate.setQueryWrapper(wrapper);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 交易中心——入驻缴费
     *
     * @return
     */
    /*@GetMapping("/table/pay/courier")
    public PageEntity toPayCourier() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TPay> wrapper = new QueryWrapper<TPay>().eq("pay_scenario", "入驻缴费").isNotNull("pay_channel_num");
        pageTemplate.setQueryWrapper(wrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "退款").setOnClick("courierRefund()").setStyle("btn btn-danger m-r-5").setIcon("mdi mdi-close"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/courier/courier_refund");
    }*/
    @GetMapping("/table/pay/courier")
    public PageEntity toPayCourier() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCourierPay> wrapper = new QueryWrapper<TCourierPay>().eq("pay_scenario", "入驻缴费").isNotNull("pay_channel_num");
        pageTemplate.setQueryWrapper(wrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT, "退款").setOnClick("courierRefund()").setStyle("btn btn-danger m-r-5").setIcon("mdi mdi-close"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/courier/courier_refund");
    }

    /**
     * 打赏记录
     * @return
     */
    @GetMapping("/table/reward/pay/list")
    public PageEntity getRewardList() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TRewardPay> wrapper = new QueryWrapper<TRewardPay>();
        pageTemplate.setQueryWrapper(wrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 交易中心——业务支付
     *
     * @return
     */
    @GetMapping("/table/pay/server")
    public PageEntity toPayServer() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TPay> wrapper = new QueryWrapper<TPay>().notIn("pay_scenario", "入驻缴费").isNotNull("pay_channel_num");
        pageTemplate.setQueryWrapper(wrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 交易中心——其他方式
     *
     * @return
     */
    @GetMapping("/table/pay/other")
    public PageEntity toPayOther() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TPay> wrapper = new QueryWrapper<TPay>().notIn("pay_way", "支付宝", "微信");
        pageTemplate.setQueryWrapper(wrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 交易中心——退款记录
     *
     * @return
     */
    @GetMapping("/table/refund")
    public PageEntity toRefund() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }


    /**
     * 系统设置——菜单管理
     *
     * @return
     */
    @GetMapping("/table/system/menu")
    public PageEntity toMenu() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = ButtonBlock.createButtons(ButtonBlockEnum.EDIT);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 配置中心——计费规则配置
     *
     * @return
     */
    @GetMapping("/table/config/charging")
    public PageEntity toCharging() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<SysConfig>()
                        .in("config_group", "car_type_xshc", "car_type_pkc", "car_type_mbc", "car_type_ddc", "service_type"));
        List<ButtonBlock> buttonBlocks = ButtonBlock.createButtons(ButtonBlockEnum.EDIT);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 配置中心——客服问答
     *
     * @return
     */
    @GetMapping("/table/config/question")
    public PageEntity toQuestion() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<SysConfig>()
                        .in("config_group", "common_problem"));
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"添加"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 提现管理——提现申请处理
     * .lt("create_date",LocalDateTime.now().format(StringUtils.dataTimeFormat)).gt("create_date",LocalDateTime.now().minusHours(12).format(StringUtils.dataTimeFormat))
     * @return
     */
    @GetMapping("/table/courier/withdraw/apply")
    public PageEntity toWithdrawApply() {
        SysUser loginUser=getLoginUser();
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCourierWithdraw> queryWrapper=new QueryWrapper<TCourierWithdraw>().eq("withdraw_state", "审核中").eq("withdraw_type","订单");
        if(loginUser.getRoleId().equals(7)){
            queryWrapper.eq("fran_id",loginUser.getFranId());
        }
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/courier/withdraw");
    }

    /**
     * 提现管理——提现成功记录
     *
     * @return
     */
    @GetMapping("/table/courier/withdraw/end")
    public PageEntity toWithdrawEnd() {
        SysUser loginUser=getLoginUser();
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCourierWithdraw> queryWrapper=new QueryWrapper<TCourierWithdraw>().notIn("withdraw_state", "审核中");
        if(loginUser.getRoleId().equals(7)){
            queryWrapper.eq("fran_id",loginUser.getFranId());
        }
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(0);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);

        return PageEntity.page("/table/index");
    }

    /**
     * 计费规则——车辆计费
     *
     * @return
     */
    @GetMapping("/table/config/price/car")
    public PageEntity toPriceCar() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TCourierWithdraw>()
                        .in("cinfig_super", 12, 14, 15));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改计费"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }
    /**
     * 计费规则——配送方式
     *
     * @return
     */
    @GetMapping("/table/config/price/way")
    public PageEntity toPriceWay() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TCourierWithdraw>()
                        .eq("config_group", "service_type"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改计费"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 计费规则——最低付款
     * @return
     */
    @GetMapping("/table/config/price/min")
    public PageEntity toPriceMin() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TCourierWithdraw>()
                        .eq("config_group", "customer_price_min"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改金额"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }
    /**
     * 计费规则——品类计费
     * @return
     */
    @GetMapping("/table/config/price/cargo")
    public PageEntity toPriceCargo() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TCourierWithdraw>()
                        .eq("config_group", "cargo_type"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改金额"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }
    /**
     * 计费规则——入驻费用
     * @return
     */
    @GetMapping("/table/config/price/courier")
    public PageEntity toPriceCourier() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TCourierWithdraw>()
                        .eq("config_group", "courier_add_price"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改金额"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 计费规则-加盟商计费
     * @return
     */
    @GetMapping("/table/config/fran/price")
    public PageEntity bigCustomer(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        List<ButtonBlock> buttonBlocks = new ArrayList<>(4);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"签约").setOnClick("showPriceModel()"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/franchisee/price");

    }

    /**
     * 加盟合作——申请列表
     * @return
     */
    @GetMapping("/table/partner/apply")
    public PageEntity toPartnerApply(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TPartner>()
                        .eq("partner_status", "已申请"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(2);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"标记为处理中")
                .setOnClick(Function.setColumn("partner_status","处理中")));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 加盟合作——处理列表
     * @return
     */
    @GetMapping("/table/partner/start")
    public PageEntity toPartnerStart(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TPartner>()
                        .eq("partner_status", "处理中"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"标记为已处理").setOnClick("setColumn('partner_status','已处理')"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 加盟合作——完成列表
     * @return
     */
    @GetMapping("/table/partner/end")
    public PageEntity toPartnerEnd(){
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(
                new QueryWrapper<TPartner>()
                        .eq("partner_status", "已处理"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(2);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"重置为已申请").setOnClick("setColumn('partner_status','已申请')"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 订单根据时间与距离推送
     *
     * @return
     */
    @GetMapping("/table/config/order/dist")
    public PageEntity toOrdeRConfig() {
        SysUser user = (SysUser) session.getAttribute("loginUser");
        System.out.println("当前登陆用户id:"+ user.getUserId());
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(new QueryWrapper<SysConfig>().in("config_group", "kilometre"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改配置"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 订单消息推送
     *
     * @return
     */
    @GetMapping("/table/config/order/notice")
    public PageEntity toOrderNotice() {
        SysUser user = (SysUser) session.getAttribute("loginUser");
        System.out.println("当前登陆用户id:"+ user.getUserId());
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(new QueryWrapper<SysConfig>().in("config_group", "kilometre_time"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改配置"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }


    /**
     * 招商加盟入驻轮播设置
     *
     * @return
     */
    @GetMapping("/table/carousel/setup")
    public PageEntity carouselSetup() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCarousel> queryWrapper = getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"添加设置"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改配置"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 招商加盟入驻说明
     *
     * @return
     */
    @GetMapping("/table/carousel/explain")
    public PageEntity carouselExplain() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCarouselExplain> queryWrapper = getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"添加设置"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改配置"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 招商加盟入驻录入信息——申请列表
     *
     * @return
     */
    @GetMapping("/table/invitejoin/start")
    public PageEntity inviteJoinStart() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TInviteJoin> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq("join_sate","已申请");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(3);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"确认处理").setOnClick("handle()"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"发送短信并处理").setOnClick("sendMsgView()"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除").setOnClick("delJoin()"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        //return PageEntity.page("/table/index");
        return PageEntity.page("/invitejoin/join");
    }

    /**
     * 招商加盟入驻录入信息——正在处理
     *
     * @return
     */
    @GetMapping("/table/invitejoin/conduct")
    public PageEntity inviteJoinConduct() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TInviteJoin> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq("join_sate","处理中");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"确认完成").setOnClick("setColumn('join_sate','已处理')"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 招商加盟入驻录入信息——处理完成
     *
     * @return
     */
    @GetMapping("/table/invitejoin/end")
    public PageEntity inviteJoinEnd() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TInviteJoin> queryWrapper = getFranQueryWrapper();
        queryWrapper.eq("join_sate","已处理");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"重置为初始状态").setOnClick("setColumn('join_sate','已申请')"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 骑手端更新
     *
     * @return
     */
    @GetMapping("/table/config/courier/update")
    public PageEntity courierUpdate() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.getQueryWrapper().orderByDesc("gmt_modified");
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"更新骑手端").setOnClick("uploadApp('courier')"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/update/index");
    }

    /**
     * 骑手入驻费用设置
     *
     * @return
     */
    @GetMapping("/table/courier/cost/set")
    public PageEntity costSet() {
        SysUser user = (SysUser) session.getAttribute("loginUser");
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(new QueryWrapper<SysConfig>().in("config_group", "cost_set"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改配置"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 订单保价设置
     *
     * @return
     */
    @GetMapping("/table/admin/insured/set")
    public PageEntity InsuredSet() {
        //SysUser user = (SysUser) session.getAttribute("loginUser");
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        pageTemplate.setQueryWrapper(new QueryWrapper<SysConfig>().in("config_group", "order_Insured_price"));
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        //buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"新增配置"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改配置"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }
    /**
     * 骑手类型切换申请
     *.lt("examine_create_time",LocalDateTime.now().format(StringUtils.dataTimeFormat)).gt("examine_create_time",LocalDateTime.now().minusHours(12).format(StringUtils.dataTimeFormat))
     * @return
     */
    @GetMapping("/table/courier/type/setup")
    public PageEntity setupType() {
        SysUser user = (SysUser) session.getAttribute("loginUser");
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCourierTypeExamine> queryWrapper = new QueryWrapper<TCourierTypeExamine>().eq("examine_status", "审核中");
        if(user.getRoleId().equals(7)){
            queryWrapper.eq("fran_id",user.getFranId());
        }
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/TCourierTypeExamine/courierTypeExamine");
    }
    /**
     * 骑手类型切换结果
     *
     * @return
     */
    @GetMapping("/table/courier/type/result")
    public PageEntity setupResult() {
        SysUser user = (SysUser) session.getAttribute("loginUser");
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TCourierTypeExamine> queryWrapper = new QueryWrapper<TCourierTypeExamine>().notIn("examine_status", "审核中");
        if(user.getRoleId().equals(7)){
            queryWrapper.eq("fran_id",user.getFranId());
        }
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(1);
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 客户端更新
     *
     * @return
     */
    @GetMapping("/table/config/customer/update")
    public PageEntity customerUpdate() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<SysApp> queryWrapper = new QueryWrapper<SysApp>().ne("system","ios").orderByDesc("gmt_modified");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(3);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"【客户端】更新").setOnClick("uploadApp('client')"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"【骑手端】更新").setOnClick("uploadApp('courier')"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"【管理端】更新").setOnClick("uploadApp('admin')"));
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/update/index");
    }

    /**
     * 欠费订单
     * @return
     */
    @GetMapping("/table/order/tckd/arrears")
    public PageEntity orderArrears() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TOrderArrears> queryWrapper = new QueryWrapper<TOrderArrears>().eq("arrears_status","欠费").orderByAsc("gmt_modified");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buttonBlocks = new ArrayList<ButtonBlock>(3);
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"查看催缴记录").setOnClick("getCallRecord()"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"发送催缴短信").setOnClick("sendMsgView()"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"核销").setOnClick("setColumn('arrears_status','核销')"));
        /*buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"添加催缴记录").setOnClick("uploadApp('courier')"));
        buttonBlocks.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"核销").setOnClick("uploadApp('admin')"));*/
        pageTemplate.setBatchButton(buttonBlocks);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/order/arrears");
    }

}
