package com.steerinfo.appservice.appmeterworkcaractual.controller;

import com.steerinfo.appservice.appmeterworkcaractual.model.AppMeterWorkCarActual;
import com.steerinfo.appservice.appmeterworkcaractual.service.IAppMeterWorkCarActualService;
import com.steerinfo.appservice.dto.AppMeterWorkCarActualDemo;
import com.steerinfo.appservice.dto.LoadLinkDemo;
import com.steerinfo.appservice.dto.companyDemo;
import com.steerinfo.baseinfo.combaseinfo.model.ComBaseInfo;
import com.steerinfo.baseinfo.meterbasematterinfo.model.MeterBaseMatterInfo;
import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkcaractualfirst.model.MeterWorkCarActualFirst;
import com.steerinfo.pretrack.pretrackscale.model.PreTrackScale;
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.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * MeterWorkCarActual RESTful接口：
 *
 * @author generator
 * @version 1.0-SNAPSHORT 2020-09-17 11:03
 * 类描述
 * 修订历史：
 * 日期：2020-09-17
 * 作者：generator
 * 参考：
 * 描述：MeterWorkCarActual RESTful接口
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 * @see null
 */
@RestController
@RequestMapping("/${api.version}/appservice/meterworkcaractuals")
public class AppMeterWorkCarActualController extends BaseRESTfulController {

    @Autowired
    IAppMeterWorkCarActualService appmeterWorkCarActualService;

    @ApiOperation(value = "供应商获取总数", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    @GetMapping(value = "/selectSumForApp")
    public RESTfulResult selectSumForApp(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<AppMeterWorkCarActualDemo> list = appmeterWorkCarActualService.queryForApp(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "下拉框获取业务编号", notes = "")
    @GetMapping(value = "/selectMeterType")
    public RESTfulResult selectMeterType(@RequestParam HashMap parmas) {
        try {
            List<ComBaseInfo> list = appmeterWorkCarActualService.selectMeterType(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "下拉框获取物料", notes = "")
    @GetMapping(value = "/selectMatter")
    public RESTfulResult selectMatter(@RequestParam HashMap parmas) {
        try {
            List<MeterBaseMatterInfo> list = appmeterWorkCarActualService.selectMatter(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "根据供应商参数查询数据", notes = "查询明细数据")
    @GetMapping(value = "/selectNet")
    public RESTfulResult selectNet(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<AppMeterWorkCarActual> list = appmeterWorkCarActualService.selectNet(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "通过车号获取总数", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    @GetMapping(value = "/selectSumForAppByCar")
    public RESTfulResult selectSumForAppByCar(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<AppMeterWorkCarActualDemo> list = appmeterWorkCarActualService.selectSumForAppByCar(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "根据车号参数查询数据", notes = "查询明细数据")
    @GetMapping(value = "/selectNetByCar")
    public RESTfulResult selectNetByCar(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<AppMeterWorkCarActual> list = appmeterWorkCarActualService.selectNetByCar(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "卸货确认-查询-金川", notes = "分页查询")
    @GetMapping(value = "/selectForLoad")
    public RESTfulResult selectForLoad(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkCarActualFirst> list = appmeterWorkCarActualService.selectForLoad(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "卸货确认-待卸货数据查询-九钢", notes = "分页查询")
    @GetMapping(value = "/selectToBeUnLoad")
    public RESTfulResult selectToBeUnLoad(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            parmas.put("linkCode", "001021004");
            parmas.put("valueFlag", "0");
            PageList<MeterWorkCarActualFirst> list = appmeterWorkCarActualService.selectToBeDidUnLoad(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "卸货确认-已卸货数据查询-九钢", notes = "分页查询")
    @GetMapping(value = "/selectDidUnLoad")
    public RESTfulResult selectDidUnLoad(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            parmas.put("linkCode", "001021004");
            parmas.put("valueFlag", "1");
            PageList<MeterWorkCarActualFirst> list = appmeterWorkCarActualService.selectToBeDidUnLoad(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }


    @ApiOperation(value = "装货确认-待装货数据查询-九钢", notes = "分页查询")
    @GetMapping(value = "/selectToBeLoad")
    public RESTfulResult selectToBeLoad(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            parmas.put("linkCode", "001021007");
            parmas.put("valueFlag", "0");
            PageList<MeterWorkCarActualFirst> list = appmeterWorkCarActualService.selectToBeDidLoad(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "装货确认-已装货数据查询-九钢", notes = "分页查询")
    @GetMapping(value = "/selectDidLoad")
    public RESTfulResult selectDidLoad(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            parmas.put("linkCode", "001021007");
            parmas.put("valueFlag", "1");
            PageList<MeterWorkCarActualFirst> list = appmeterWorkCarActualService.selectToBeDidLoad(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "卸货确认-确认", notes = "进行确认操作，确认人及愉快编号不允许为空")
    @PostMapping(value = "/UpdateForUnLoad", produces = "application/json;charset=UTF-8")
    public RESTfulResult UpdateForUnLoad(@RequestBody MeterWorkCarActualFirst model) {
        RESTfulResult rm = failed();
        try {
            String no = appmeterWorkCarActualService.UpdateForUnLoad(model,"卸货");
            return success(no);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "卸货确认-取消确认", notes = "取消卸货确认，确认人及愉快编号不允许为空")
    @PostMapping(value = "/UpdateForUnLoadRecover", produces = "application/json;charset=UTF-8")
    public RESTfulResult UpdateForUnLoadRecover(@RequestBody MeterWorkCarActualFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = appmeterWorkCarActualService.updateForUnLoadRecover(model,"卸货");
            if (num >= 1) {
                return success(num);
            } else {
                return failed("新增失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }


    @ApiOperation(value = "装货确认-确认", notes = "进行确认操作，确认人及愉快编号不允许为空")
    @PostMapping(value = "/UpdateForLoad", produces = "application/json;charset=UTF-8")
    public RESTfulResult UpdateForLoad(@RequestBody MeterWorkCarActualFirst model) {
        RESTfulResult rm = failed();
        try {
            String no = appmeterWorkCarActualService.UpdateForUnLoad(model,"装货");
            return success(no);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "装货确认-取消确认",  notes = "取消卸货确认，确认人及愉快编号不允许为空")
    @PostMapping(value = "/UpdateForLoadRecover", produces = "application/json;charset=UTF-8")
    public RESTfulResult UpdateForLoadRecover(@RequestBody MeterWorkCarActualFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = appmeterWorkCarActualService.updateForUnLoadRecover(model,"装货");
            if (num >= 1) {
                return success(num);
            } else {
                return failed("新增失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "卸货实绩-不用了，留着过度", notes = "查询明细数据")
    @GetMapping(value = "/selectLoadLinkDemo")
    public RESTfulResult selectLoadLinkDemo(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<LoadLinkDemo> list = appmeterWorkCarActualService.selectLoadLinkDemo(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "卸货实绩查询-查询结净表的数据", notes = "查询明细数据")
    @GetMapping(value = "/selectLoadLinkActual")
    public RESTfulResult selectLoadLinkActual(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<LoadLinkDemo> list = appmeterWorkCarActualService.selectLoadLinkActual(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "获取收发货单位", notes = "")
    @GetMapping(value = "/selectReAndFo")
    public RESTfulResult selectReAndFo(@RequestParam HashMap parmas) {
        try {
            List<companyDemo> list = appmeterWorkCarActualService.selectReAndFo(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "修改卸货点", notes = "")
    @PostMapping(value = "/updateLoadPoint")
    public RESTfulResult updateLoadPoint(@RequestBody MeterWorkCarActualFirst model) {
        try {
            String no = appmeterWorkCarActualService.updateLoadPoint(model);
            return success(no);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "计量卸货时间判断", notes = "")
    @PostMapping(value = "/judgeDuration")
    public RESTfulResult judgeDuration(@RequestBody MeterWorkCarActualFirst model) {
        RESTfulResult rm = failed();
        try {
            String no = appmeterWorkCarActualService.judgeDuration(model);
            return success(no);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "选择是将计量数据作废", notes = "")
    @PostMapping(value = "/abolishData")
    public RESTfulResult abolishData(@RequestBody MeterWorkCarActualFirst model) {
        try {
            String no = appmeterWorkCarActualService.abolishData(model);
            return success(no);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "判断是否能够出厂", notes = "")
    @PostMapping(value = "/judgeOutDoor")
    public RESTfulResult judgeOutDoor(@RequestBody PreTrackScale model) {
        RESTfulResult rm = failed();
        try {
            String str = appmeterWorkCarActualService.judgeOutDoor(model);
            return success(str);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }
}
