package com.steerinfo.dil.controller;

import com.steerinfo.dil.model.TmstrainPleaseApproveResult;
import com.steerinfo.dil.service.ITmstrainPleaseApproveResultService;
import com.steerinfo.dil.util.BaseRESTfulController;
import com.steerinfo.dil.util.ColumnDataUtil;
import com.steerinfo.dil.util.DataChange;
import com.steerinfo.dil.util.PageListAdd;

import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TmstrainPleaseApproveResult RESTful接口:
 * @author generator
 * @version 1.0-SNAPSHORT 2021-08-30 02:27
 * 类描述
 * 修订历史:
 * 日期:2021-08-30
 * 作者:generator
 * 参考:
 * 描述:TmstrainPleaseApproveResult RESTful接口
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@RestController
@RequestMapping("/${api.version}/tmstrainpleaseapproveresults")
public class TmstrainPleaseApproveResultController extends BaseRESTfulController {

    @Autowired
    ITmstrainPleaseApproveResultService tmstrainPleaseApproveResultService;

    @Autowired
    ColumnDataUtil columnDataUtil;

    @ApiOperation(value="查询请车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
            @ApiImplicitParam(name = "apiId(57)", value = "动态表头", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "status", value = "状态码", required = false, dataType = "Integer"),
    })
    @PostMapping("/getAllWagonPlease")
    public RESTfulResult getAllWagonPlease(@RequestBody(required=false) Map<String,Object> mapValue,
                                           Integer apiId,
                                           Integer pageNum,
                                           Integer pageSize,
                                           Integer status,
                                           Integer resultType){
        mapValue.put("status", status);
        mapValue.put("resultType", resultType);
        //不分页筛选数据
        List<Map<String, Object>> wagonPleaseTotal = tmstrainPleaseApproveResultService.getAllWagonPlease(mapValue);
        PageHelper.startPage(pageNum,pageSize);
        //分页数据
        List<Map<String, Object>> wagonPlease = tmstrainPleaseApproveResultService.getAllWagonPlease(mapValue);
        DataChange.changeDateToDayDate(wagonPlease, "resultPleaseDate", "resultPlanDate");
        PageListAdd pageList = columnDataUtil.tableColumnData(apiId, wagonPleaseTotal,wagonPlease);
        return success(pageList);
    }

    @ApiOperation(value="通过Id查询请车作业")
    @PostMapping ("/getWagonPleaseById/{resultId}")
    public RESTfulResult getWagonPleaseById(@PathVariable("resultId")Integer resultId){
        List<Map<String, Object>> wagonPleaseById = tmstrainPleaseApproveResultService.getWagonPleaseById(resultId);
        return success(wagonPleaseById);
    }


    @ApiOperation(value="新增请车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "amstrainWagonPlease", value = "请车作业对象", required = false, dataType = "AmstrainWagonPlease"),
    })
    @PostMapping("/addWagonPlease")
    public RESTfulResult addWagonPlease(@RequestBody TmstrainPleaseApproveResult tmstrainPleaseApproveResult){
        int i = tmstrainPleaseApproveResultService.insertSelective(tmstrainPleaseApproveResult);
        return success(i);
    }


    @ApiOperation(value="修改请车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tmstrainPleaseApproveResult", value = "请车作业实绩对象", required = false, dataType = "TmstrainPleaseApproveResult"),
    })
    @PostMapping("/updateWagonPlease")
    public RESTfulResult updateWagonPlease(@RequestBody TmstrainPleaseApproveResult tmstrainPleaseApproveResult){
        tmstrainPleaseApproveResult.setUpdateTime(new Date());
        int i = tmstrainPleaseApproveResultService.updateByPrimaryKeySelective(tmstrainPleaseApproveResult);
        return success(i);
    }

    @ApiOperation(value="逻辑删除请车作业 设置状态码为 3")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tmstrainPleaseApproveResult", value = "请车作业实绩对象", required = false, dataType = "TmstrainPleaseApproveResult"),
    })
    @PostMapping("/deleteWagonPlease/{resultId}")
    public RESTfulResult deleteWagonPlease(@PathVariable("resultId") Integer resultId){
        TmstrainPleaseApproveResult tmstrainPleaseApproveResult = new TmstrainPleaseApproveResult();
        tmstrainPleaseApproveResult.setResultId(new BigDecimal(resultId));
        tmstrainPleaseApproveResult.setStatus(new BigDecimal(3));
        int i = tmstrainPleaseApproveResultService.updateByPrimaryKeySelective(tmstrainPleaseApproveResult);
        return success(i);
    }

    @ApiOperation(value="下发请车作业 设置状态码为 1")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resultId", value = "请车作业实绩对象", required = false, dataType = "Integer"),
    })
    @PostMapping("/sendWagonPlease/{resultId}")
    public RESTfulResult sendWagonPlease(@PathVariable("resultId") Integer resultId){
        TmstrainPleaseApproveResult tmstrainPleaseApproveResult = new TmstrainPleaseApproveResult();
        tmstrainPleaseApproveResult.setResultId(new BigDecimal(resultId));
        tmstrainPleaseApproveResult.setStatus(new BigDecimal(1));
        int i = tmstrainPleaseApproveResultService.updateByPrimaryKeySelective(tmstrainPleaseApproveResult);
        return success(i);
    }

    //********************************下拉框******************************************

    @ApiOperation(value="查询所有发货单位")
    @GetMapping("/getShipper")
    public RESTfulResult getShipper(){
        List<Map<String, Object>> shipper = tmstrainPleaseApproveResultService.getShipper();
        return success(shipper);
    }

    @ApiOperation(value="查询所有发运计划")
    @GetMapping("/getRailPlan")
    public RESTfulResult getRailPlan(){
        List<Map<String, Object>> shipper = tmstrainPleaseApproveResultService.getRailPlan();
        return success(shipper);
    }
    //内转物流
    @ApiOperation(value="查询所有发站/到站")
    @GetMapping("/getArrivalSend")
    public RESTfulResult getArrivalSend(){
        List<Map<String, Object>> send = tmstrainPleaseApproveResultService.getArrivalSend();
        return success(send);
    }
    //查询请车计划号
    @ApiOperation(value="查询请车计划号")
    @GetMapping("/getPleasePlanNo")
    public RESTfulResult getPleasePlanNo(){
        List<Map<String, Object>> PlanNo = tmstrainPleaseApproveResultService.getPleasePlanNo();
        return success(PlanNo);
    }

    //******************************批车作业**************************************

    @ApiOperation(value="查询批车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
            @ApiImplicitParam(name = "apiId(70)", value = "动态表头", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "status", value = "状态码", required = false, dataType = "Integer"),
    })
    @PostMapping("/getApproveAllWagonPlease")
    public RESTfulResult getApproveAllWagonPlease(@RequestBody(required=false) Map<String,Object> mapValue,
                                           Integer apiId,
                                           Integer pageNum,
                                           Integer pageSize,
                                                  Integer resultType){
        mapValue.put("resultType", resultType);
        //不分页筛选数据
        List<Map<String, Object>> wagonPleaseTotal = tmstrainPleaseApproveResultService.getAllApproveWagonPlease(mapValue);
        PageHelper.startPage(pageNum,pageSize);
        //分页数据
        List<Map<String, Object>> wagonPlease = tmstrainPleaseApproveResultService.getAllApproveWagonPlease(mapValue);
        DataChange.changeDateToDayDate(wagonPlease, "resultApproveDate");
        PageListAdd pageList = columnDataUtil.tableColumnData(apiId, wagonPleaseTotal,wagonPlease);
        return success(pageList);
    }

    @ApiOperation(value="通过Id查询批车作业")
    @PostMapping ("/getApproveWagonPleaseById/{resultId}")
    public RESTfulResult getApproveWagonPleaseById(@PathVariable("resultId")Integer resultId){
        List<Map<String, Object>> approveWagonPleaseById = tmstrainPleaseApproveResultService.getApproveWagonPleaseById(resultId);
        return success(approveWagonPleaseById);
    }

    @ApiOperation(value="新增批车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tmstrainPleaseApproveResult", value = "请车作业实绩对象", required = false, dataType = "TmstrainPleaseApproveResult"),
    })
    @PostMapping("/addApproveWagonPlease")
    public RESTfulResult addApproveWagonPlease(@RequestBody TmstrainPleaseApproveResult tmstrainPleaseApproveResult){
        tmstrainPleaseApproveResult.setStatus(new BigDecimal(2));
        int i = tmstrainPleaseApproveResultService.updateByPrimaryKeySelective(tmstrainPleaseApproveResult);
        return success(i);
    }

    @ApiOperation(value="修改批车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tmstrainPleaseApproveResult", value = "请车作业实绩对象", required = false, dataType = "TmstrainPleaseApproveResult"),
    })
    @PostMapping("/updateApproveWagonPlease")
    public RESTfulResult updateApproveWagonPlease(@RequestBody TmstrainPleaseApproveResult tmstrainPleaseApproveResult){
        tmstrainPleaseApproveResult.setUpdateTime(new Date()); //设置更新时间
        int i = tmstrainPleaseApproveResultService.updateByPrimaryKeySelective(tmstrainPleaseApproveResult);
        return success(i);
    }



    @ApiOperation(value="逻辑删除批车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "resultId", value = "请车作业实绩对象", required = false, dataType = "Integer"),
    })
    @PostMapping("/deleteApproveWagonPlease/{resultId}")
    public RESTfulResult deleteApproveWagonPlease(@PathVariable("resultId") Integer resultId){
        TmstrainPleaseApproveResult tmstrainPleaseApproveResult = new TmstrainPleaseApproveResult();
        tmstrainPleaseApproveResult.setStatus(new BigDecimal(3));
        tmstrainPleaseApproveResult.setResultId(new BigDecimal(resultId));
        int i = tmstrainPleaseApproveResultService.updateByPrimaryKeySelective(tmstrainPleaseApproveResult);
        return success(i);
    }


    /********************************************内转物流***************************************************
     /**
     * 内转物流,新增请车作业
     * @param map
     * @return
     */

    @ApiOperation(value="新增请车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "amstrainWagonPlease", value = "请车作业对象", required = false, dataType = "AmstrainWagonPlease"),
    })
    @PostMapping("/addWagonApprove")
    public RESTfulResult addWagonApprove(@RequestBody Map<String,Object> map){
        int i = tmstrainPleaseApproveResultService.addPleaseApprove(map);
        return success(i);
    }
    /**
     * 内转查询请车实绩
     * @return
     */

    @ApiOperation(value="查询请车作业")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
            @ApiImplicitParam(name = "apiId(199)", value = "动态表头", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "status", value = "状态码", required = false, dataType = "Integer"),
    })
    @PostMapping("/getAllWagonPleaseForConverted")
    public RESTfulResult getAllWagonPleaseForConverted(@RequestBody(required=false) Map<String,Object> mapValue,
                                                       Integer apiId,
                                                       Integer pageNum,
                                                       Integer pageSize,
                                                       Integer status){
        if(mapValue == null){
            mapValue = new HashMap<>();
        }
        mapValue.put("status", status);
        //不分页筛选数据
        List<Map<String, Object>> wagonPleaseTotal = tmstrainPleaseApproveResultService.selectPleaseApprovePlanForConverted(mapValue);
        PageHelper.startPage(pageNum,pageSize);
        //分页数据
        List<Map<String, Object>> wagonPlease = tmstrainPleaseApproveResultService.selectPleaseApprovePlanForConverted(mapValue);
        DataChange.changeDateToDayDate(wagonPlease, "resultPleaseDate", "resultPlanDate");
        PageListAdd pageList = columnDataUtil.tableColumnData(apiId, wagonPleaseTotal,wagonPlease);
        return success(pageList);
    }

    /**
     * 通过id查询请车作业
     * @param resultId
     * @return
     */
    @ApiOperation(value="通过Id查询请车作业")
    @PostMapping ("/getPleasePlanByResultId/{resultId}")
    public RESTfulResult getPleasePlanByResultId(@PathVariable("resultId")Integer resultId){
        List<Map<String, Object>> WagonPleaseById = tmstrainPleaseApproveResultService.selectPleasePlanByResultId(resultId);
        return success(WagonPleaseById);
    }

    /**
     * 通过id查询批车作业
     * @param resultId
     * @return
     */
    @ApiOperation(value="通过id查询批车作业")
    @PostMapping ("/getApproveByResultId/{resultId}")
    public RESTfulResult getApproveByResultId(@PathVariable("resultId")Integer resultId){
        List<Map<String, Object>> ApproveBYResultId = tmstrainPleaseApproveResultService.selectApproveBYResultId(resultId);
        return success(ApproveBYResultId);
    }


}