package com.liquidnet.client.admin.web.controller.zhengzai.kylin;

import com.liquidnet.client.admin.common.core.controller.BaseController;
import com.liquidnet.client.admin.common.core.domain.AjaxResult;
import com.liquidnet.client.admin.common.core.page.TableDataInfo;
import com.liquidnet.client.admin.zhengzai.kylin.service.impl.PerformancesExpressServiceImpl;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.kylin.dao.PerformanceExpressPerformanceListAdminDao;
import com.liquidnet.service.kylin.dao.PerformanceExpressPerformanceOrderListAdminDao;
import com.liquidnet.service.kylin.dto.param.PerformanceExpressSearchAdminParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 演出快递
 * </p>
 *
 * @author jiangxiulong
 * @since 2021-06-21
 */

@Controller
@RequestMapping("/kylin/performancesExpress")
public class PerformancesExpressController extends BaseController {

    private String prefix = "zhengzai/kylin/performancesExpress";

    @Autowired
    private PerformancesExpressServiceImpl performancesExpressServiceImpl;

    /**
     * 查询演出列表
     */
    @RequiresPermissions("kylin:performancesExpress:view")
    @GetMapping()
    public String performancesListView() {
        return prefix + "/performancesList";
    }

    @RequiresPermissions("kylin:performancesExpress:performancesList")
    @PostMapping("/performancesList")
    @ResponseBody
    public TableDataInfo performancesList(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        List<PerformanceExpressPerformanceListAdminDao> result = performancesExpressServiceImpl.getPerformancesList(performanceExpressSearchAdminParam);
        return getDataTable(result);
    }

    /**
     * 查询演出订单列表
     */
    @RequiresPermissions("kylin:performancesExpress:performanceOrderList")
    @GetMapping("performanceOrderList/{id}")
    public String performanceOrderListView(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("performancesId", id);
        return prefix + "/performanceOrderList";
    }

    @RequiresPermissions("kylin:performancesExpress:performanceOrderList")
    @PostMapping("/performanceOrderList")
    @ResponseBody
    public TableDataInfo performanceOrderList(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        List<PerformanceExpressPerformanceOrderListAdminDao> result = performancesExpressServiceImpl.getPerformancesOrderList(performanceExpressSearchAdminParam);
        return getDataTable(result);
    }

    /**
     * 下单
     */
    @RequiresPermissions("kylin:performancesExpress:placeOrder")
    @PostMapping("/placeOrder")
    @ResponseBody
    public AjaxResult placeOrder(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        ResponseDto res = performancesExpressServiceImpl.placeOrder(performanceExpressSearchAdminParam);
        try {
            if (res.isSuccess()) {
                return success();
            } else {
                return error(res.getMessage());
            }
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 取消
     */
    @RequiresPermissions("kylin:performancesExpress:cancelOrder")
    @PostMapping("/cancelOrder")
    @ResponseBody
    public AjaxResult cancelOrder(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        ResponseDto res = performancesExpressServiceImpl.cancelOrder(performanceExpressSearchAdminParam);
        try {
            if (res.isSuccess()) {
                return success();
            } else {
                return error(res.getMessage());
            }
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 订单运费估算
     */
    @RequiresPermissions("kylin:performancesExpress:getFreight")
    @PostMapping("/getFreight")
    @ResponseBody
    public AjaxResult getFreight(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        ResponseDto res = performancesExpressServiceImpl.getFreight(performanceExpressSearchAdminParam);
        try {
            if (res.isSuccess()) {
                return success();
            } else {
                return error(res.getMessage());
            }
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 下单结果主动查询
     */
    @RequiresPermissions("kylin:performancesExpress:getResult")
    @PostMapping("/getResult")
    @ResponseBody
    public AjaxResult getResult(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        ResponseDto res = performancesExpressServiceImpl.getResult(performanceExpressSearchAdminParam);
        try {
            if (res.isSuccess()) {
                return success();
            } else {
                return error(res.getMessage());
            }
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 运费主动查询
     */
    @RequiresPermissions("kylin:performancesExpress:getListFreight")
    @PostMapping("/getListFreight")
    @ResponseBody
    public AjaxResult getListFreight(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        ResponseDto res = performancesExpressServiceImpl.getListFreight(performanceExpressSearchAdminParam);
        try {
            if (res.isSuccess()) {
                return success();
            } else {
                return error(res.getMessage());
            }
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 路由主动查询
     */
    @RequiresPermissions("kylin:performancesExpress:listOrderRoute")
    @PostMapping("/listOrderRoute")
    @ResponseBody
    public AjaxResult listOrderRoute(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        ResponseDto res = performancesExpressServiceImpl.listOrderRoute(performanceExpressSearchAdminParam);
        try {
            if (res.isSuccess()) {
                return success();
            } else {
                return error(res.getMessage());
            }
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 订单状态推送
     */

    /**
     * 路由推送
     */

    /**
     * 清单运费推送
     */

    /**
     * 预计派件时间
     */

    /**
     * 通缉拦截
     * 该接口只能在揽收后，派送成功前生效
     * 同一订单在成功通缉拦截一次后，不可再次进行通缉拦截
     * 1-转寄；2-退回；3-优派；4-再派；5-改自取（改派-其他自取点取件）；6-改派送（上门派送）；7-更改派送时间；8-修改收件人信息；9-更改付款方式；10-修改代收货款；12-作废；
     */

    /**
     * 订单确认 快递员上门揽收前，如需修改部分下单内容（如收件人信息等
     */

}
