package com.steerinfo.dil.controller;

import com.steerinfo.dil.mapper.UniversalMapper;
import com.steerinfo.dil.service.impl.UniversalServiceImpl;
import com.steerinfo.dil.util.BaseRESTfulController;
import com.steerinfo.dil.util.ColumnDataUtil;
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.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
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 org.springframework.web.bind.annotation.*;


import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ author    :TXF
 * @ time      :2021/10/19 18:06
 * 通用接口
 */
@RequestMapping("${api.version}/uc")
@RestController
public class UniversalController extends BaseRESTfulController {

    @Autowired
    UniversalServiceImpl universalService;

    @Autowired
    UniversalMapper universalMapper;

    @Autowired
    ColumnDataUtil columnDataUtil;


    @ApiOperation(value="查询数据打印提货单接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mapValue", value = "运输订单号", required = false, dataType = "Map"),
    })
    @PostMapping("/printTHD")
    public RESTfulResult printTiHuoDan(@RequestBody(required=false) Map<String, Object> mapValue){
        Map<String, Object> tiHuoDan = universalService.printTiHuoDan((String) mapValue.get("orderNumber"));
        return success(tiHuoDan);
    }


    @ApiModelProperty(value = "模糊查询发货单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "247", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/querySupplierByLike")
    public RESTfulResult querySupplierByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Integer apiId,
                                             String index) {
        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(index != null){
            mapValue.put("index","%" + index + "%");
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.querySupplierByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId,columnList);
        return success(data);
    }

    @ApiModelProperty(value = "查询所有发货单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "247", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/queryAllSupplierByLike")
    public RESTfulResult queryAllSupplierByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Integer apiId,
                                             String index) {
        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(index != null){
            mapValue.put("index","%" + index + "%");
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.queryAllSupplierByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }



    @ApiModelProperty(value = "通过物资ID查询该物资的发货单位信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "247", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/getSupplierMesByMaterialId")
    public RESTfulResult getSupplierMesByMaterialId(@RequestBody(required = false) Map<String,Object> mapValue,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Integer apiId,
                                             String index, String materialId) {
        if(mapValue == null)
            mapValue = new HashMap<>();

        if(!"null".equals(materialId))
            mapValue.put("materialId",materialId);

        if(index != null){
            mapValue.put("index","%" + index + "%");
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.getSupplierMesByMaterialId(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }


    @ApiOperation(value="查询所有运力信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
            @ApiImplicitParam(name = "apiId(248)", value = "动态表头", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer"),
    })
    @PostMapping("/getAllCapacityByCarrierLike")
    public RESTfulResult getAllCapacityByCarrierLike(@RequestBody(required=false) Map<String,Object> mapValue,
                                        Integer apiId,
                                        Integer pageNum,
                                        Integer pageSize,
                                        String carrierSsoId,
                                        String index,
                                        String con
    ){
        if(mapValue == null){
            mapValue = new HashMap<>();
        }
        if(index != null){
            mapValue.put("index", index);
        }
        if (con != null&& !con.equals("undefined")){
            mapValue.put("con",con);
        }
        if (carrierSsoId != null && carrierSsoId.equals("undefined")) {
            carrierSsoId = null;
        }
        if (carrierSsoId != null) {
          BigDecimal carrierId = universalMapper.getCarrierIdBySSO(carrierSsoId);
          mapValue.put("carrierId",carrierId);
        }
        //不分页筛选数据
        PageHelper.startPage(pageNum,pageSize);
        //分页数据
        List<Map<String, Object>> capacity = universalMapper.getAllCapacityByCarrierLike(mapValue);
        PageListAdd pageList = columnDataUtil.tableColumnData(apiId, capacity);
        return success(pageList);
    }




    @ApiOperation(value="查询运力类型")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
            @ApiImplicitParam(name = "apiId(248)", value = "动态表头", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer"),
    })
    @PostMapping("/getCapacityType")
    public RESTfulResult getCapacityType(@RequestBody(required=false) Map<String,Object> mapValue,
                                                     Integer apiId,
                                                     Integer pageNum,
                                                     Integer pageSize,
                                                     String index
    ){
        if(mapValue == null){
            mapValue = new HashMap<>();
        }
        if(index != null&&!index.equals("null")){
            mapValue.put("index", index);
        }
        //不分页筛选数据
        PageHelper.startPage(pageNum,pageSize);
        //分页数据
        List<Map<String, Object>> capacity = universalMapper.getCapacityType(mapValue);
        PageListAdd pageList = columnDataUtil.tableColumnData(apiId, capacity);
        return success(pageList);
    }



    @ApiOperation(value="通过订单ID查询订单下所有物资")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mapValue", value = "表头和参数", required = false, dataType = "map"),
            @ApiImplicitParam(name = "apiId(395)", value = "动态表头", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "页", required = false, dataType = "Integer"),
    })
    @PostMapping("/getMaterialMesByOrderId")
    public RESTfulResult getMaterialMesByOrderId(@RequestBody(required=false) Map<String,Object> mapValue,
                                                     Integer apiId,
                                                     Integer pageNum,
                                                     Integer pageSize,
                                                     String orderId
    ){
        if(mapValue == null){
            mapValue = new HashMap<>();
        }
        if(orderId != null){
            mapValue.put("orderId", orderId);
        }
        //不分页筛选数据
        PageHelper.startPage(pageNum,pageSize);
        //分页数据
        List<Map<String, Object>> capacity = universalMapper.getMaterialMesByOrderId(mapValue);
        PageListAdd pageList = columnDataUtil.tableColumnData(apiId, capacity);
        return success(pageList);
    }


    @ApiModelProperty(value = "边输边查发货单位")
    @PostMapping("/getSupplierMesByLike")
    public RESTfulResult getSupplierMesByLike(@RequestParam("index") String index) {
        List<Map<String, Object>> list = universalMapper.getSupplierMesByLike(index == null ? "" : index);
        return success(list);
    }

    @ApiModelProperty(value = "边输边查用车单位")
    @PostMapping("/getRequireUnitName")
    public RESTfulResult getRequireUnitName(@RequestParam("index") String index) {
        List<Map<String,Object>>list = universalMapper.getRequireUnitName(index == null ? "" : "%" + index + "%");
        return success(list);
    }

    @ApiModelProperty(value = "边输边查收货单位")
    @PostMapping("/getConsigneeByLike")
    public RESTfulResult getConsigneeByLike(@RequestParam("index") String index) {
        List<Map<String, Object>> list = universalMapper.getConsigneeByLike(index == null ? "" : index);
        return success(list);
    }


    @ApiModelProperty(value = "通过订单ID查询订单下物资信息")
    @PostMapping("/getOrderMaterialMesByOrderId/{orderId}")
    public RESTfulResult getMaterialMesByOrderId(@PathVariable("orderId") Integer orderId){
        List<Map<String, Object>> mes = universalMapper.getOrderMaterialMesByOrderId(new BigDecimal(orderId));
        return success(mes);
    }

    @ApiModelProperty(value = "模糊查询物资")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "244", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/queryAPOMaterialByLike")
    public RESTfulResult queryAPOMaterialByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                                Integer pageNum,
                                                Integer pageSize,
                                                Integer apiId,
                                                String index,
                                                Integer supplierId) {

        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(index != null && !"".equals(index) &&!"null".equals(index)){
            mapValue.put("index", index);
        }
        if(supplierId != null){
            mapValue.put("supplierId", supplierId);
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.queryAPOMaterialByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }


    @ApiModelProperty(value = "模糊查询卸货点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "374", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/getUnloadingMesByLike")
    public RESTfulResult getUnloadingMesByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Integer apiId,
                                             Integer type,
                                             String index) {

        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(type != null){
            mapValue.put("type", type);
        }
        if(index != null){
            mapValue.put("index", index);
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.getUnloadingMesByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiModelProperty(value = "模糊查询物资")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "244", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/queryMaterialByLike")
    public RESTfulResult queryMaterialByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Integer apiId,
                                             String index) {

        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(index != null){
            mapValue.put("index", index);
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.queryMaterialByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiModelProperty(value = "模糊查询批次")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "244", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/queryBatchByLike")
    public RESTfulResult queryBatchByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Integer apiId,
                                             String index) {

        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(index != null){
            mapValue.put("index", index);
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.getBatchAndOrderMes(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiModelProperty(value = "边输边查承运商")
    @PostMapping("/getCarrierMesByLike")
    public RESTfulResult getCarrierMesByLike(@RequestParam("index") String index) {
        List<Map<String, Object>> list = universalMapper.getCarrierMesByLike(index == null ? "" : index);
        return success(list);
    }

    @ApiModelProperty(value = "模糊查询收货单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "396", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/queryConsigneeByLike")
    public RESTfulResult queryConsigneeByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                             Integer pageNum,
                                             Integer pageSize,
                                             Integer apiId,
                                             String index) {
        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(index != null){
            mapValue.put("index", index);
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.queryConsigneeByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiModelProperty(value = "模糊查询物资信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "395", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/selectAllMaterialName")
    public RESTfulResult selectAllMaterialName(@RequestBody(required = false) Map<String,Object> mapValue,
                                              Integer pageNum,
                                              Integer pageSize,
                                              Integer apiId,
                                              String index) {
        if(mapValue == null) {
            mapValue = new HashMap<>();
        }
        if(index != null){
            mapValue.put("index", index);
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.selectAllMaterialName(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiModelProperty(value = "返回sha1加密字符串")
    @RequestMapping(value = "/sha1DigestUtils", method = {RequestMethod.GET,RequestMethod.POST})
    public String sha1DigestUtils(String text){
        return universalService.sha1DigestUtils(text);
    }

    @ApiModelProperty(value = "查装货卸货点")
    @PostMapping("/selectUnloadingPoint")
    public List<Map<String, Object>> selectUnloadingPoint() {
        return universalMapper.selectUnloadingPoint();
    }

    @ApiModelProperty(value = "模糊查询承运商")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "412", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/getCarrierListByLike")
    public RESTfulResult getCarrierListByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                              Integer apiId,
                                              Integer pageNum,
                                              Integer pageSize,
                                              String index) {
        if(index != null){
            if(index.length() == 0){
                index = null;
            }else {
                index = "%" + index + "%";
            }
        }
        if (mapValue == null) {
            mapValue = new HashMap<>();
        }
        mapValue.put("index",index);
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.getCarrierListByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiModelProperty(value = "所有门岗下拉框")
    @GetMapping("/getAllGatepost")
    public List<Map<String,Object>> getAllGatepost(){
        return universalMapper.getAllGatepost();
    }

    //通过承运商id获取userId
    @PostMapping("/getUserIdByCarrierId")
    public String getUserIdByCarrierId(@RequestBody Map<String,Object> map){
        //获取承运商id
        Integer carrierId =(Integer) map.get("carrierId");
        return universalMapper.getUserIdbyCarrierId(carrierId);
    }



    @ApiModelProperty(value = "已经在sso权限模块承运商下拉框")
    @GetMapping("/getAllCarrierIdForSso")
    public List<Map<String,Object>> getAllCarrierIdForSso(){
        return universalMapper.getAllCarrierIdForSso();
    }


    @ApiModelProperty(value = "模糊查询收货单位")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "418", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/getConsigneeListByLike")
    public RESTfulResult getConsigneeListByLike(@RequestBody(required = false) Map<String,Object> mapValue,
                                              Integer apiId,
                                              Integer pageNum,
                                              Integer pageSize,
                                              String index) {
        if(index != null){
            if(index.length() == 0){
                index = null;
            }else {
                index = "%" + index + "%";
            }
        }
        if (mapValue == null) {
            mapValue = new HashMap<>();
        }
        mapValue.put("index",index);
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.getConsigneeListByLike(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiOperation("通过运输订单id查询销售订单审核状态")
    @PostMapping("/getSaleOrderStatus")
    public Integer getSaleOrderStatus(@RequestParam Integer orderId) {
        Integer saleStatus = universalMapper.getSaleOrderStatus(new BigDecimal(orderId));
        return saleStatus;
    }

    @ApiOperation("查询所有的汽车衡")
    @GetMapping("/getAllCalculateMes")
    public List<Map<String, Object>> getAllCalculateMes() {
        return universalMapper.getAllCalculateMes();
    }

    @ApiOperation("查询所有的焦炭子类")
    @GetMapping("/getAllMaterialCoke")
    public List<Map<String, Object>> getAllMaterialCoke() {
        return universalMapper.getAllMaterialCoke();
    }

    @ApiModelProperty(value = "边输边查车牌号")
    @PostMapping("/getCapacityByLike")
    public RESTfulResult getCapacityByLike(@RequestParam("index") String index) {
        List<Map<String, Object>> list = universalMapper.getCapacityByLike(index == null ? "" : index);
        return success(list);
    }

    @ApiModelProperty(value = "边输边查批次")
    @GetMapping("/getBatchByLike")
    public RESTfulResult getBatchByLike(@RequestParam("index") String index) {
        List<Map<String, Object>> list = universalMapper.getBatchByLike(index == null ? "" : index);
        return success(list);
    }

    @ApiModelProperty(value = "根据运力id查询所有承运商(下拉框)")
    @GetMapping("/getCarrierByCapacityId")
    public RESTfulResult getCarrierByCapacityId(@RequestParam("capacityId") Integer capacityId) {
        List<Map<String, Object>> list = universalMapper.getCarrierByCapacityId(new BigDecimal(capacityId));
        return success(list);
    }

    @ApiModelProperty(value = "根据收货客户查询承运商")
    @PostMapping("/getCarrierByConsignee")
    public RESTfulResult getCarrierByConsignee(@RequestBody Map<String,Object> mapValue) {
        Map<String, Object> map = universalService.getCarrierByConsignee(mapValue);
        return success(map);
    }

    @ApiModelProperty(value = "确认车牌号与承运商关系是否存在")
    @PostMapping("/isInCapacityCarrier")
    public RESTfulResult isInCapacityCarrier(@RequestBody Map<String,Object> mapValue) {
        Map<String,Object> map = universalService.isInCapacityCarrier(mapValue);
        BigDecimal capacityId = (BigDecimal) map.get("capacityId");
        BigDecimal capacityCarrierId = (BigDecimal) map.get("capacityCarrierId");
        if (capacityId == null) {
            return failed();
        }
        if (capacityCarrierId == null) {
            return failed(capacityId);
        }
        return success(map);
    }

    @ApiModelProperty(value = "得到所有油价联动计费公式(apiId:444)")
    @PostMapping("/getOilFormula")
    public RESTfulResult getOilFormula(@RequestBody(required = false) Map<String,Object> mapValue,
                                       Integer apiId,
                                       Integer pageNum,
                                       Integer pageSize) {
        if (mapValue == null) {
            mapValue = new HashMap<>();
        }
        mapValue.put("con", "%执行运价公式");
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.getOilFormula(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiModelProperty(value = "获得港口下拉框")
    @GetMapping("/getPortId")
    public RESTfulResult getPortId() {
        return success(universalService.getPortId());
    }

    @ApiModelProperty(value = "获取车牌号边输边查")
    @GetMapping("/getCapacityNumber")
    public RESTfulResult getCapacityNumber(String index) {
        if(index.length() < 3){
            return failed();
        }
        return success(universalService.getCapacityNumber(index));
    }

    @ApiModelProperty(value = "获得订单号及订单号下面物资")
    @GetMapping("/getOrderNumber")
    public RESTfulResult getOrderNumber(String capacityId) {
        return success(universalService.getOrderNumber(capacityId));
    }

    @ApiModelProperty(value = "根据订单查询物资")
    @GetMapping("/getMaterialIdByOrderId")
    public RESTfulResult getMaterialIdByOrderId(Integer orderId) {
        return success(universalService.getMaterialIdByOrderId(orderId));
    }

    @ApiOperation(value = "修改路段顺序号")
    @PostMapping("/updateLineSqe")
    public RESTfulResult updateLineSqe(@RequestBody Map<String,Object> map) {
        int i = universalMapper.updateLineSqe(map);
        return success(i);
    }

    @ApiModelProperty(value = "边输边查物资")
    @GetMapping("/getMaterialByLike")
    public RESTfulResult getMaterialByLike(@RequestParam("index") String index) {
        List<Map<String, Object>> list = universalMapper.getMaterialByLike(index == null ? "" : index);
        return success(list);
    }

    @ApiOperation(value="通过一个carrierSsoId获得承运商对象")
    @GetMapping("/getRmsCarrierByCarrierSsoId")
    public RESTfulResult getRmsCarrierByCarrierSsoId(String carrierSsoId){
       Map<String,Object> carrier= universalMapper.getRmsCarrierByCarrierSsoId(carrierSsoId);
       if (carrier==null){
           failed();
       }
       return success(carrier);
    }

    @ApiModelProperty(value = "模糊查询钢材物资")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "apiId", value = "244", required = false, dataType = "BigDecimal")
    })
    @PostMapping("/getSteelMaterial")
    public RESTfulResult getSteelMaterial(@RequestBody(required = false) Map<String, Object> mapValue,
                                          Integer pageNum,
                                          Integer pageSize,
                                          Integer apiId,
                                          String materialNameText,
                                          String materialSpecificationText,
                                          String materialModelText) {
        if (mapValue == null) {
            mapValue = new HashMap<>();
        }
        if (materialNameText != null && !materialNameText.equals("undefined") && !materialNameText.equals("null")) {
            mapValue.put("materialNameText", materialNameText);
        }
        if (materialSpecificationText != null && !materialSpecificationText.equals("undefined") && !materialSpecificationText.equals("null")) {
            mapValue.put("materialSpecificationText", materialSpecificationText);
        }
        if (materialModelText != null && !materialModelText.equals("undefined") && !materialModelText.equals("null")) {
            mapValue.put("materialModelText", materialModelText);
        }
        PageHelper.startPage(pageNum, pageSize);
        //分页查询数据
        List<Map<String, Object>> columnList = universalMapper.getSteelMaterial(mapValue);
        PageListAdd data = columnDataUtil.tableColumnData(apiId, columnList);
        return success(data);
    }

    @ApiOperation(value="得到所有省份")
    @PostMapping("/getAllProvince")
    public RESTfulResult getAllProvince(){
        List<Map<String,Object>> provinceList = universalMapper.getAllProvince();
        return success(provinceList);
    }

    @ApiOperation(value="根据省份得到下面的地级市")
    @PostMapping("/getDistrictByProvince")
    public RESTfulResult getDistrictByProvince(@RequestParam String addressProvince){
        List<Map<String,Object>> districtList = universalMapper.getDistrictByProvince(addressProvince);
        return success(districtList);
    }

    @ApiOperation(value="根据地级市得到下面的区/县")
    @PostMapping("/getTownByDistrict")
    public RESTfulResult getTownByDistrict(@RequestParam String addressDistrict){
        List<Map<String,Object>> townList = universalMapper.getTownByDistrict(addressDistrict);
        return success(townList);
    }

    @ApiOperation(value="根据省市县得到下面的详细地址")
    @PostMapping("/getPlaceByAllAddress")
    public RESTfulResult getPlaceByAllAddress(@RequestBody Map<String,Object> mapValue){
        List<Map<String,Object>> townList = universalMapper.getPlaceByAllAddress(mapValue);
        return success(townList);
    }

    @ApiOperation(value="获得销售员下拉框")
    @GetMapping("/getSalerList")
    public RESTfulResult getSalerList(){
        List<Map<String,Object>> salerList= universalMapper.getSalerList();
        return success(salerList);
    }

    @ApiOperation(value="通过收货客户匹配销售组")
    @PostMapping("/getSaleArea")
    public RESTfulResult getSaleArea(@RequestParam Integer receiveId) {
        String saleArea = universalMapper.getSaleArea(new BigDecimal(receiveId));
        return success(saleArea);
    }

    @ApiOperation(value = "质保书前端展示")
    @PostMapping("/getWarranty")
    public RESTfulResult getWarranty(@RequestParam("orderNumber") String orderNumber) {

        //List<String> list = universalService.getWarrantyAndPrint(orderNumber);
        List<String> list= universalService.getWarranty(orderNumber);
        if(list.get(0).equals("-1")){
            return failed(-1,"质保书正在紧张制作中,请耐心等待!");
        }else if(list.get(0).equals("-2")){
            return failed(-2,"该车还未装货");
        }
        return success(list);
    }
    @ApiOperation(value = "查询待分解计划数量")
    @PostMapping("/getPlanCount")
    public Integer getPlanCount(){
        return universalMapper.getPlanCount();
    }

    @ApiOperation(value = "查询承运起止地点下拉框")
    @GetMapping("/getTransRange")
    public RESTfulResult getTransRange(){
        return success(universalMapper.getTransRange());

    }

//    //测试质保书回显
//    @PostMapping("/getTest")
//    public RESTfulResult getTest(@RequestBody Map<String,Object> map){
//       List<String> list = universalService.getTest(map);
//       if(list.get(0).equals("0")){
//           return failed("质保书正在紧张制作中,请耐心等待!");
//       }
//       return success(list);
//    }

    @ApiOperation(value = "收货地址下匹配不到任何承运商")
    @GetMapping("/getNoListCarrier")
    public RESTfulResult getNoListCarrier() {
        return success(universalMapper.getNoListCarrier());
    }

    @ApiOperation(value = "查询承运起止地点下拉框")
    @GetMapping("/getNotReceiveOrderQuantity")
    public Integer getNotReceiveOrderQuantity(@RequestParam("capacityNumber") String capacityNumber){
        return universalMapper.getNotReceiveOrderQuantity(capacityNumber);
    }

    @ApiModelProperty(value = "边输边查发站到站")
    @GetMapping("/getArrivalByLike")
    public RESTfulResult getArrivalByLike(@RequestParam("index") String index){
        List <Map<String,Object>> list = universalMapper.getArrivalByLike(index == null ? "" : index);
        return success(list);
    }

    @ApiModelProperty(value = "司机APP订单小红点")
    @GetMapping("/getOrderNum")
    public int getOrderNum(@RequestParam("capacityNumber") String capacityNumber){
        return universalMapper.getOrderNum(capacityNumber);
    }

    @ApiModelProperty(value = "补录计量实绩")
    @PostMapping("/recordingWeightResult")
    public int recordingWeightResult(@RequestBody(required = false)List<Map<String,Object>>mapList){
        try {
            return universalService.recordingWeightResult(mapList);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return 1;
    }
}