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.OrderExpressListDao;
import com.liquidnet.service.kylin.dao.PerformanceExpressPerformanceListAdminDao;
import com.liquidnet.service.kylin.dao.PerformanceExpressPerformanceOrderListAdminDao;
import com.liquidnet.service.kylin.dto.param.PerformanceExpressSearchAdminParam;
import com.liquidnet.service.kylin.dto.vo.express.KylinOrderExpressPrintVo;
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: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: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: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());
        }
    }

    /**
     * 实际运费主动查询 暂时可先不用
     */
    @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());
        }
    }

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

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

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

    /**
     * 批量下单
     */
    @RequiresPermissions("kylin:performancesExpress:batchPlaceOrder")
    @PostMapping("/batchPlaceOrder")
    @ResponseBody
    public AjaxResult batchPlaceOrder(@RequestParam("ids") String performanceId) {
        try {
            performancesExpressServiceImpl.batchPlaceOrder(performanceId);
            return success();
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 批量取消
     */
    @RequiresPermissions("kylin:performancesExpress:batchCancelOrder")
    @PostMapping("/batchCancelOrder")
    @ResponseBody
    public AjaxResult batchCancelOrder(@RequestParam("ids") String performanceId) {
        try {
            performancesExpressServiceImpl.batchCancelOrder(performanceId);
            return success();
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 批量下载图片
     */
    @RequiresPermissions("kylin:performancesExpress:batchGenerateImage")
    @PostMapping("/batchGenerateImage")
    @ResponseBody
    public ResponseDto batchGenerateImage(@RequestParam("ids") String performanceId) {
        String res = performancesExpressServiceImpl.batchGenerateImage(performanceId);
        try {
            if (res.isEmpty()) {
                return ResponseDto.failure("处理失败");
            } else {
                return ResponseDto.success(res);
            }
        } catch (Exception e) {
            return ResponseDto.failure(e.getMessage());
        }
    }

    /**
     * 下载图片
     */
    @RequiresPermissions("kylin:performancesExpress:generateImage")
    @PostMapping("/generateImage")
    @ResponseBody
    public ResponseDto generateImage(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        String res = performancesExpressServiceImpl.generateImage(performanceExpressSearchAdminParam);
        try {
            if (res.isEmpty()) {
                return ResponseDto.failure("处理失败");
            } else {
                return ResponseDto.success(res);
            }
        } catch (Exception e) {
            return ResponseDto.failure(e.getMessage());
        }
    }

    /**
     * 批量打印获取数据
     */
    @RequiresPermissions("kylin:performancesExpress:batchPrintExpress")
    @PostMapping("/batchPrintExpress")
    @ResponseBody
    public ResponseDto<KylinOrderExpressPrintVo> batchPrintExpress(@RequestParam("ids") String performanceId) {
        KylinOrderExpressPrintVo res = performancesExpressServiceImpl.batchPrintExpress(performanceId);
        try {
            return ResponseDto.success(res);
        } catch (Exception e) {
            return ResponseDto.failure(e.getMessage());
        }
    }

    /**
     * 打印单条获取数据
     */
    @RequiresPermissions("kylin:performancesExpress:printExpress")
    @PostMapping("/printExpress")
    @ResponseBody
    public ResponseDto<KylinOrderExpressPrintVo> printExpress(PerformanceExpressSearchAdminParam performanceExpressSearchAdminParam) {
        KylinOrderExpressPrintVo res = performancesExpressServiceImpl.printExpress(performanceExpressSearchAdminParam);
        try {
            return ResponseDto.success(res);
        } catch (Exception e) {
            return ResponseDto.failure(e.getMessage());
        }
    }

}
