package com.steerinfo.meterwork.meterworkrailwayactualbak.controller;

import com.steerinfo.baseinfo.meterbasecar.model.MeterBaseCar;
import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.exception.RESTException;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.framework.utils.collection.ListUtils;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkcaractual.model.MeterWorkCarActual;
import com.steerinfo.meterwork.meterworkrailwayactfirst.model.MeterWorkRailwayActFirst;
import com.steerinfo.meterwork.meterworkrailwayactfirstbak.model.MeterWorkRailwayActFirstBak;
import com.steerinfo.meterwork.meterworkrailwayactual.model.MeterWorkRailwayActual;
import com.steerinfo.meterwork.meterworkrailwayactual.service.IMeterWorkRailwayActualService;
import com.steerinfo.meterwork.meterworkrailwayactualbak.model.MeterWorkRailwayActualBak;
import com.steerinfo.meterwork.meterworkrailwayactualbak.service.IMeterWorkRailwayActualBakService;
import com.steerinfo.pretrack.prerailwayscale.model.PreRailwayScale;
import com.steerinfo.util.CommonPage;
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.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

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

    @Resource
    IMeterWorkRailwayActualBakService meterWorkRailwayActualBakService;

    @ApiOperation(value = "获取列表", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterworkrailwayactual:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkRailwayActualBak> list = meterWorkRailwayActualBakService.queryForPage(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")
    })
    //@RequiresPermissions("meterworkrailwayactual:view")
    @GetMapping(value = "/like/")
    public RESTfulResult listLike(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkRailwayActualBak> list = meterWorkRailwayActualBakService.queryLikeForPage(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")
    })
    //@RequiresPermissions("meterworkrailwayactual:view")
    @PostMapping(value = "/likeByDesc")
    public RESTfulResult likeByDesc(@RequestBody HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkRailwayActualBak> list = meterWorkRailwayActualBakService.likeByDesc(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "C#获取列表", notes = "不分页分页模糊查询")
    @PostMapping(value = "/noPage")
    public RESTfulResult noPage(@RequestBody HashMap parmas) {
        try {
            List<MeterWorkRailwayActualBak> list = meterWorkRailwayActualBakService.noPage(parmas);
            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")
    })
    //@RequiresPermissions("meterworkrailwayactual:view")
    @GetMapping(value = "/likeByDesc/")
    public RESTfulResult likeByDesc01(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkRailwayActualBak> list = meterWorkRailwayActualBakService.likeByDesc(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "自动获取轨道衡打印信息", notes = "根据车号、收发货单位获取打印信息")
    //@RequiresPermissions("meterworkrailwayactual:view")
    @GetMapping(value = "/autoPrintRailway/")
    public RESTfulResult autoPrintRailway(@RequestParam HashMap params) {
        try {
            RESTfulResult rm  = meterWorkRailwayActualBakService.autoPrintRailway(params);
            return rm;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "创建", notes = "根据MeterWorkRailwayActual对象创建")
    @ApiImplicitParam(name = "meterWorkRailwayActual", value = "详细实体meterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkrailwayactual:create")
    @PostMapping(value = "/")
    public RESTfulResult add(@ModelAttribute MeterWorkRailwayActualBak model) {
        try {
            MeterWorkRailwayActualBak meterWorkRailwayActual = meterWorkRailwayActualBakService.add(model);
            return success(meterWorkRailwayActual);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "新增数据-手输皮重", notes = "根据选中的毛重数据和输入的皮重新增一条净重数据")
    @ApiImplicitParam(name = "meterWorkRailwayActual", value = "详细实体meterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkrailwayactual:create")
    @PostMapping(value = "/add")
    public RESTfulResult addData(@RequestBody MeterWorkRailwayActualBak model) {
        try {
            int num = meterWorkRailwayActualBakService.addData(model);
            if (num >= 1) {
                return success(num);
            } else {
                return failed("操作失败");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "获取详细信息", notes = "根据url的id来获取详细信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
    //@RequiresPermissions("meterworkrailwayactual:view")
    @GetMapping(value = "/{id}")
    public RESTfulResult get(@PathVariable String id) {
        try {
            MeterWorkRailwayActualBak meterWorkRailwayActual = meterWorkRailwayActualBakService.getById(id);
            return success(meterWorkRailwayActual);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "降序获取列表", notes = "web端不分页模糊查询")
    @PostMapping(value = "/webByLikeDesc")
    public RESTfulResult webByLikeDesc(@RequestBody HashMap parmas) {
        try {
            List<MeterWorkRailwayActualBak> list = meterWorkRailwayActualBakService.webByLikeDesc(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "火车号汇总统计汇总", notes = "根据传入时间和火车号，查询给定时间段去重车号")
    @GetMapping(value = "/distinctRailwayNo")
    public RESTfulResult distinctRailwayNo(@RequestParam HashMap param) {
        RESTfulResult rm = failed();
        try {
            List<String> rows = meterWorkRailwayActualBakService.distinctRailwayNo(param);
            return success(rows);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "火车号汇总统计汇总", notes = "根据传入时间和火车号，查询给定时间段去重车号")
    @PostMapping(value = "/distinctRailwayNo")
    public RESTfulResult distinctRailwayNoPost(@RequestBody HashMap param) {
        RESTfulResult rm = failed();
        try {
            List<String> rows = meterWorkRailwayActualBakService.distinctRailwayNo(param);
            return success(rows);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "结净数据维护-网页", notes = "根据传入时间查询去重列次编号")
    @PostMapping(value = "/distinctLcNo")
    public RESTfulResult distinctLcNo(@RequestBody HashMap param) {
        RESTfulResult rm = failed();
        try {
            List<String> rows = meterWorkRailwayActualBakService.distinctLcNo(param);
            return success(rows);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            //rm.setCode("200");
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "一次数据维护-查询车次车号", notes = "根据传入时间、火车号、计量站点、物料名称、委托号、数据状态、发货单位和收货单位查询去重车次车号")
    @PostMapping(value = "/distinctLcNoAndRailwayNo")
    public RESTfulResult distinctLcNoAndRailwayNo(@RequestBody HashMap param) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActualBakService.distinctLcNoAndRailwayNo(param);
            return rm;
        }catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>" + e.getMessage());
        }
        return rm;
    }

    @ApiOperation(value = "更新详细信息", notes = "根据url的id来指定更新对象，并根据传过来的meterWorkRailwayActual信息来更新详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "meterWorkRailwayActual", value = "详细实体meterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    })
    //@RequiresPermissions("meterworkrailwayactual:update")
    @PutMapping(value = "/{id}", produces = "application/json;charset=UTF-8")
    public RESTfulResult update(@PathVariable String id, @RequestBody MeterWorkRailwayActualBak model) {
        try {
            model.setId(id);
            MeterWorkRailwayActualBak meterWorkRailwayActual = meterWorkRailwayActualBakService.modify(model);
            return success(meterWorkRailwayActual);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "匹配委托")
    @PostMapping(value = "/matchPrediction")
    public RESTfulResult matchPrediction(@RequestParam String actualNo, String predictionNo, String note) {
        RESTfulResult rm = failed();
        try {
            MeterWorkRailwayActualBak mwca = meterWorkRailwayActualBakService.matchPrediction(actualNo, predictionNo, note);
            return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }


    @ApiOperation(value = "动轨匹配委托")
    @PostMapping(value = "/matchPredictionD")
    public RESTfulResult matchPredictionD(@RequestBody HashMap map) {
        RESTfulResult rm = failed();
        try {
            String actualNo = map.get("actualNo") == null ? "": map.get("actualNo").toString();
            String predictionNo = map.get("predictionNo") == null ? "": map.get("predictionNo").toString();
            String note = map.get("note") == null ? "": map.get("note").toString();
            MeterWorkRailwayActualBak mwca = meterWorkRailwayActualBakService.matchPrediction(actualNo, predictionNo, note);
            return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "解除委托")
    @PostMapping(value = "/removePrediction")
    public RESTfulResult removePrediction(@RequestBody MeterWorkRailwayActualBak model) {
        RESTfulResult rm = failed();
        try {
            MeterWorkRailwayActualBak mwca = meterWorkRailwayActualBakService.cleanPrediction(model);
            return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "删除", notes = "根据url的id来指定删除对象")
    @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String")
    //@RequiresPermissions("meterworkrailwayactual:delete")
    @DeleteMapping(value = "/{id}")//String
    public RESTfulResult delete(@PathVariable String id) {
        try {
            List<String> list = Arrays.asList(id.split(","));
            if (ListUtils.isNotEmpty(list)) {
                List<String> ids = ListUtils.convertList(list);
                meterWorkRailwayActualBakService.delete(ids);
            }
            return success();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "数据审核", notes = "根据MeterWorkRailwayActual对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体MeterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/audit")
    public RESTfulResult audit(@RequestBody List<MeterWorkRailwayActualBak> model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.audit(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 = "根据MeterWorkRailwayActual对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体MeterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/unaudit")
    public RESTfulResult unaudit(@RequestBody List<MeterWorkRailwayActualBak> model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.unaudit(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 = "将结净数据重置为未发布状态")
    @ApiImplicitParam(name = "model", value = "详细实体MeterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    @PostMapping(value = "/cancel")
    public RESTfulResult cancel(@RequestBody MeterWorkRailwayActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.cancel(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 = "将结净数据重置为未发布状态")
    @ApiImplicitParam(name = "model", value = "详细实体MeterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    @PostMapping(value = "/publish")
    public RESTfulResult publish(@RequestBody MeterWorkRailwayActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.publish(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 = "/selectView")
    public RESTfulResult selectView(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkRailwayActualBak> pageInfo = meterWorkRailwayActualBakService.selectView(parmas, pageNum, pageSize);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }


    @ApiOperation(value = "结净")
    @PostMapping(value = "/clean")
    public RESTfulResult clean(@RequestParam String actualFirstNo, String dataNo, String predictionNo) {
        RESTfulResult rm = failed();
        try {
            MeterWorkRailwayActualBak mwca = meterWorkRailwayActualBakService.clean(actualFirstNo, dataNo, predictionNo);
            return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "根据两个一次计量编号和原因文本进行手动匹配结净", notes = "根据传入参数进行结净")
    @PostMapping(value = "/cleanByfirstNoAndNotes")
    public RESTfulResult cleanByfirstNoAndNotes(@RequestParam String actFirstNo01, String actFirstNo02, String predictionNo, String Notes) {
        RESTfulResult rm = failed();
        try {
            if(com.steerinfo.util.StringUtils.isEmpty(actFirstNo01) ||
                    com.steerinfo.util.StringUtils.isEmpty(actFirstNo02)){
                rm.setMessage("一次数据编号不能为空！！");
                return rm;
            }
            if(com.steerinfo.util.StringUtils.isEmpty(Notes)){
                rm.setMessage("异地计量原因不能为空！！");
                return rm;
            }
            rm = meterWorkRailwayActualBakService.cleanByfirstNoAndNotes(actFirstNo01, actFirstNo02, predictionNo, Notes);
            return success(rm);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "解除", notes = "将结净后的数据进行还原")
    @PostMapping(value = "/remove")
    public RESTfulResult remove(@RequestBody List<MeterWorkRailwayActualBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.remove(models);
            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 = "/commonRemove")
    public RESTfulResult commonRemove(@RequestBody HashMap params) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActualBakService.commonRemove(params);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "解除动态衡结净数据", notes = "将结净后的数据进行还原")
    @PostMapping(value = "/removeDynamicModel")
    public RESTfulResult removeDynamicModel(@RequestBody MeterWorkRailwayActualBak model) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActualBakService.removeDynamicModel(model);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }


    @ApiOperation(value = "解除", notes = "将动轨结净后的数据进行还原")
    @PostMapping(value = "/removeDt")
    public RESTfulResult removeDt(@RequestBody List<MeterWorkRailwayActualBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.removeDt(models);
            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 = "/selectDiff")
    public RESTfulResult selectDiff(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkRailwayActualBak> pageInfo = meterWorkRailwayActualBakService.selectDiff(parmas, pageNum, pageSize);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "固定皮重结净")
    @PostMapping(value = "/termclean")
    public RESTfulResult termclean(@RequestParam String actualFirstNo, String dataNo) {
        RESTfulResult rm = failed();
        try {
            MeterWorkRailwayActualBak mwca = meterWorkRailwayActualBakService.termclean(actualFirstNo, dataNo);
            return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "WF获取列表")
    @PostMapping(value = "/doQueryWf")
    public RESTfulResult doQueryWf(@RequestBody CommonPage<MeterWorkRailwayActualBak> oci) {
        try {
            RESTfulResult rm = meterWorkRailwayActualBakService.doQueryWf(oci);
            return rm;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "WF获取列表动轨")
    @GetMapping(value = "/doQueryActWf")
    public RESTfulResult doQueryActWf(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkRailwayActualBak> list = meterWorkRailwayActualBakService.doQueryActWf(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }


    @ApiOperation(value = "数据批量修改", notes = "根据MeterWorkRailwayActual对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体MeterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/batchEditActual")
    public RESTfulResult batchEditActual(@RequestParam(value = "actual", required = false) List<MeterWorkRailwayActualBak> actual
            , @RequestParam(value = "actualFirst", required = false) List<MeterWorkRailwayActFirstBak> actualFirst
            , @RequestParam(value = "scales", required = false) List<PreRailwayScale> scales) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.batchEditActual(actual, actualFirst, scales);
            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 = "根据MeterWorkRailwayActual对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体PreRailwayScale", required = true, dataType = "PreRailwayScale")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/batchEditScales")
    public RESTfulResult batchEditScales(@RequestBody List<PreRailwayScale> scales) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.batchEditScales(scales);
            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 = "根据MeterWorkRailwayActFirst对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体MeterWorkRailwayActFirst", required = true, dataType = "MeterWorkRailwayActFirst")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/batchEditActFirsts")
    public RESTfulResult batchEditActFirsts(@RequestBody List<MeterWorkRailwayActFirstBak> actualFirsts) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.batchEditActFirsts(actualFirsts);
            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 = "根据MeterWorkRailwayActual对象创建")
    @ApiImplicitParam(name = "model", value = "详细实体MeterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/batchEditActuals")
    public RESTfulResult batchEditActuals(@RequestBody List<MeterWorkRailwayActualBak> actuals) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.batchEditActuals(actuals);
            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 = "返回平均皮重")
    @ApiImplicitParam(name = "model", value = "返回平均皮重", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/getTareAvg")
    public RESTfulResult getGrossAvg(@RequestBody HashMap actual) {
        RESTfulResult rm = failed();
        try {
            double num = meterWorkRailwayActualBakService.getGrossAvg(actual);
            if (num >= 0) {
                return success(num);
            } else {
                return failed("未找到时间范围内的平均毛重");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "计量票据录入", notes = "根据MeterWorkRailwayActual对象创建")
    @ApiImplicitParam(name = "MeterWorkRailwayActual", value = "详细实体MeterWorkRailwayActual", required = true, dataType = "MeterWorkRailwayActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/checkandadditional")
    public RESTfulResult checkandadditional(@RequestBody MeterWorkRailwayActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActualBakService.checkandadditional(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 = "根据MeterWorkRailwayActual对象创建")
    @PostMapping(value = "/supplementaryData")
    public RESTfulResult supplementaryData(@RequestBody HashMap map) {
        RESTfulResult rm = failed();
        try {
            SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
            String grossTimeTemp = map.get("grossTime").toString().replaceAll("-", "/");
            String tareTimeTemp = map.get("tareTime").toString().replaceAll("-", "/");
            String netTimeTemp = map.get("netTime").toString().replaceAll("-", "/");

            Date grossTime = simpleFormat.parse(grossTimeTemp);
            Date tareTime = simpleFormat.parse(tareTimeTemp);
            Date netTime = simpleFormat.parse(netTimeTemp);
            MeterWorkRailwayActualBak model = new MeterWorkRailwayActualBak();
            if(map.get("predictionNo") != null) {
                model.setPredictionNo(map.get("predictionNo").toString());
            }
            model.setBaseSpot1No(map.get("baseSpot1No").toString());
            model.setBaseSpot1Name(map.get("baseSpot1Name").toString());
//            model.setBaseSpot1No(meterWorkRailwayActualBakService.subStr(map.get("baseSpot1No").toString(), "0"));
//            model.setBaseSpot1Name(meterWorkRailwayActualBakService.subStr(map.get("baseSpot1No").toString(), "1"));
            model.setGrossManNo(map.get("grossManNo").toString());
            model.setGrossManName(map.get("grossManName").toString());
//            model.setGrossManNo(meterWorkRailwayActualBakService.subStr(map.get("grossManNo").toString(), "0"));
//            model.setGrossManName(meterWorkRailwayActualBakService.subStr(map.get("grossManNo").toString(), "1"));
            model.setGrossTime(grossTime);

            model.setTareManNo(map.get("tareManNo").toString());
            model.setTareManName(map.get("tareManName").toString());
            model.setTareTime(tareTime);
            model.setNetTime(netTime);
            model.setBaseSpot2No(map.get("baseSpot2No").toString());
            model.setBaseSpot2Name(map.get("baseSpot2Name").toString());
//            model.setBaseSpot2No(meterWorkRailwayActualBakService.subStr(map.get("baseSpot2No").toString(), "0"));
//            model.setBaseSpot2Name(meterWorkRailwayActualBakService.subStr(map.get("baseSpot2No").toString(), "1"));
            model.setRailwayNo(map.get("railwayNo").toString());
            model.setGrossWeight(new BigDecimal(map.get("grossWeight").toString()).multiply(new BigDecimal(1000)));
            model.setTareWeight(new BigDecimal(map.get("tareWeight").toString()).multiply(new BigDecimal(1000)));
            model.setRailwayTypeNo(map.get("railwayTypeNo").toString());
            model.setRailwayTypeName(map.get("railwayTypeName").toString());
//            model.setRailwayTypeNo(meterWorkRailwayActualBakService.subStr(map.get("railwayTypeNo").toString(), "0"));
//            model.setRailwayTypeName(meterWorkRailwayActualBakService.subStr(map.get("railwayTypeNo").toString(), "1"));
            rm = meterWorkRailwayActualBakService.supplementaryData(model);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }




    @ApiOperation(value = "根据实绩id获取一次计量信息和委托信息", notes = "根据实绩id获取一次计量信息和委托信息")
    @PostMapping(value = "/firstAndEntrustById")
    public RESTfulResult firstAndEntrustById(@RequestBody HashMap params) {
        RESTfulResult rm = failed();
        try {
            if(params.get("actualNo") == null) {
                return rm;
            }
            String actualNo = params.get("actualNo") == null ? "" : params.get("actualNo").toString();
            rm = meterWorkRailwayActualBakService.firstAndEntrustById(actualNo);
            if (rm.getData() != null) {
                return rm;
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "特殊委托解除结净", notes = "将结净后的数据进行还原")
    @PostMapping(value = "/specialRemove")
    public RESTfulResult specialRemove(@RequestBody HashMap params) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActualBakService.specialRemove(params);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "批量修改静态衡列次编号", notes = "批量修改静态衡列次编号")
    @PostMapping(value = "/batchUpdateLcNo")
    public RESTfulResult batchUpdateLcNo(@RequestBody List<MeterWorkRailwayActualBak> models) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActualBakService.batchUpdateLcNo(models);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "批量修改静态衡列次编号", notes = "净重、毛重、皮重都不能包含一次信息才能进行生成")
    @PostMapping(value = "/batchActualUpdateLcNo")
    public RESTfulResult batchActualUpdateLcNo(@RequestBody List<MeterWorkRailwayActualBak> models) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActualBakService.batchActualUpdateLcNo(models);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "将数据从MeterWorkCarActualBak复制到MeterWorkCarActual")
    @PostMapping(value = "/copyToActual")
    public RESTfulResult copyToActual(@RequestBody HashMap params){
        RESTfulResult rm;
        try {
            List<String> ids = (List<String>) params.get("ids");
            String railwayNo = params.get("railwayNo") == null ? "": params.get("railwayNo").toString();
            rm = meterWorkRailwayActualBakService.CopyToActual(ids,railwayNo);
        } catch (Exception e) {
            e.printStackTrace();
            return failed(null,e.getMessage());
        }
        return rm;
    }

    //======================eason add 2023-04-14 =============================================
    @ApiOperation(value = "创建", notes = "根据MeterWorkRailwayActualBak对象创建")
    @ApiImplicitParam(name = "MeterWorkRailwayActualBak", value = "详细实体MeterWorkRailwayActualBak", required = true, dataType = "MeterWorkRailwayActFirst")
    @PostMapping(value = "/addNetEmergencyList")
    @Transactional
    public RESTfulResult addNetEmergencyList(@RequestBody List<MeterWorkRailwayActualBak> lt) {
        try {
            RESTfulResult rm = meterWorkRailwayActualBakService.addNetEmergencyList(lt);
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }
}
