package com.prolog.rdc.tms.controller.planMng;

import com.prolog.common.util.DateUtils;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.planMng.*;
import com.prolog.rdc.tms.model.vo.planMng.TransportPlanBillVO;
import com.prolog.rdc.tms.model.vo.planMng.TransportPlanQueryVO;
import com.prolog.rdc.tms.service.planMng.TransportPlanBillService;
import com.prolog.wms.base.util.ExcelUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 计划管理-待排计划单控制层
 *
 * @author lhb
 * @since 2023-06-07 09:04:35
 */
@RestController
@Api(tags = "计划管理-待排计划单控制层")
@RequestMapping("/transport_plan_bill")
public class TransportPlanBillController {

    @Autowired
    private TransportPlanBillService pendingArrangePlanService;

    @UserLog("待排计划单分页查询")
    @ApiOperation(value = "待排计划单分页查询", notes = "待排计划单分页查询")
    @PostMapping("/pending_plan_page")
    public RestMessage<Page<PendingPlanBillQueryDTO>> pagePendingPlanExecute(@RequestBody TransportPlanQueryVO vo) {
        try {
            Page<PendingPlanBillQueryDTO> PlanQueryDTOS = pendingArrangePlanService.pagePendingPlanBillData(vo);
            return RestMessage.newInstance(true, "查询成功", PlanQueryDTOS);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("计划单保存")
    @ApiOperation(value = "计划单保存", notes = "计划单保存")
    @PostMapping("/save")
    public RestMessage<Object> savePlanBillExecute(@RequestBody TransportPlanBillVO vo) {
        try {
            String id = pendingArrangePlanService.savePlanBillData(vo);
            return RestMessage.newInstance(true, "保存成功", id);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("计划单修改")
    @ApiOperation(value = "计划单修改", notes = "计划单修改")
    @PostMapping("/update")
    public RestMessage<Object> updatePlanBillExecute(@RequestBody TransportPlanBillVO vo) {
        try {
            String id = pendingArrangePlanService.updatePlanBillData(vo);
            return RestMessage.newInstance(true, "修改成功", id);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("计划单删除")
    @ApiOperation(value = "计划单删除", notes = "计划单删除")
    @PostMapping("/delete")
    public RestMessage<Object> deletePlanBillExecute(@RequestBody List<String> planBillIds) {
        try {
            pendingArrangePlanService.deletePlanBillData(planBillIds);
            return RestMessage.newInstance(true, "删除成功", null);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("周日历计划单查询")
    @ApiOperation(value = "周日历计划单查询", notes = "周日历计划单查询")
    @PostMapping("/week_plan_bill")
    public RestMessage<List<PlanBillCalendarDTO>> queryWeekPlanBillExecute(@RequestBody TransportPlanQueryVO vo) {
        try {
            List<PlanBillCalendarDTO> weekDTOS = pendingArrangePlanService.queryWeekPlanBillData(vo);
            return RestMessage.newInstance(true, "查询成功", weekDTOS);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("月日历计划单查询")
    @ApiOperation(value = "月日历计划单查询", notes = "月日历计划单查询")
    @PostMapping("/month_plan_bill")
    public RestMessage<List<PlanBillCalendarDTO>> queryMonthPlanBillExecute(@RequestBody TransportPlanQueryVO vo) {
        try {
            List<PlanBillCalendarDTO> weekDTOS = pendingArrangePlanService.queryMonthPlanBillData(vo);
            return RestMessage.newInstance(true, "查询成功", weekDTOS);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }


    @UserLog("计划单分页查询")
    @ApiOperation(value = "计划单分页查询", notes = "计划单分页查询")
    @PostMapping("/plan_bill_page")
    public RestMessage<Page<PlanBillQueryDTO>> pagePlanBillExecute(@RequestBody TransportPlanQueryVO vo) {
        try {
            Page<PlanBillQueryDTO> pagePlanBillData = pendingArrangePlanService.pagePlanBillData(vo);
            return RestMessage.newInstance(true, "查询成功", pagePlanBillData);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("计划单详情查询")
    @ApiOperation(value = "计划单详情查询", notes = "计划单详情查询")
    @PostMapping("/plan_bill_view")
    public RestMessage<PlanBillViewQueryDTO> queryPlanBillViewExecute(@RequestBody TransportPlanQueryVO vo) {
        try {
            PlanBillViewQueryDTO planBillViewData = pendingArrangePlanService.queryPlanBillViewData(vo);
            return RestMessage.newInstance(true, "查询成功", planBillViewData);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("计划单运单明细详情查询")
    @ApiOperation(value = "计划单运单明细详情查询", notes = "计划单运单明细详情查询")
    @PostMapping("/plan_bill_detail_view")
    public RestMessage<List<PlanBillDetailDTO>> queryPlanBillDetailViewExecute(@RequestBody TransportPlanQueryVO vo) {
        try {
            List<PlanBillDetailDTO> planBillDetailDTOS = pendingArrangePlanService.queryPlanBillDetailViewData(vo);
            return RestMessage.newInstance(true, "查询成功", planBillDetailDTOS);
        } catch (Exception e) {
            e.printStackTrace();
            return RestMessage.newInstance(false, e.getMessage(), null);
        }
    }

    @UserLog("所有计划单导出")
    @ApiOperation(value = "所有计划单导出", notes = "所有计划单导出")
    @PostMapping("/export")
    public RestMessage<Object> export(@RequestBody TransportPlanQueryVO vo, HttpServletResponse response) throws Exception {
        List<PlanBillExportDTO> list = pendingArrangePlanService.export(vo);
        ExcelUtils.export(response, PlanBillExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("计划单分页导出")
    @ApiOperation(value = "计划单分页导出", notes = "计划单分页导出")
    @PostMapping("/exportPage")
    public RestMessage<Object> exportPage(@RequestBody TransportPlanQueryVO vo, HttpServletResponse response) throws Exception {
        List<PlanBillExportDTO> list = pendingArrangePlanService.exportPage(vo);
        ExcelUtils.export(response, PlanBillExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("计划单选中行导出")
    @ApiOperation(value = "计划单选中行导出", notes = "计划单选中行导出")
    @PostMapping("/exportSelected")
    public RestMessage<Object> exportSelected(@RequestBody List<String> planBillIds, HttpServletResponse response) throws Exception {
        List<PlanBillExportDTO> list = pendingArrangePlanService.exportSelected(planBillIds);
        ExcelUtils.export(response, PlanBillExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

}
