package com.steerinfo.meterwork.meterworkrailwayactfirst.controller;

import com.steerinfo.baseinfo.meterbaserailwayaiweight.model.MeterBaseRailwayAiweight;
import com.steerinfo.baseinfo.meterbaserailwayweight.mapper.MeterBaseRailwayWeightMapper;
import com.steerinfo.baseinfo.meterbaserailwayweight.model.MeterBaseRailwayWeight;
import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.framework.user.UserPayload;
import com.steerinfo.framework.utils.collection.ListUtils;
import com.steerinfo.metermonitor.metermonitornote.model.MeterMonitorNote;
import com.steerinfo.meterwork.dto.CommonCombination;
import com.steerinfo.meterwork.dto.MeterWorkRailwayActFirstDto;
import com.steerinfo.meterwork.dto.StaffPerformanceAnalysis;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkcaractual.model.MeterWorkCarActual;
import com.steerinfo.meterwork.meterworkcaractualfirst.model.MeterWorkCarActualFirst;
import com.steerinfo.meterwork.meterworkrailwayactfirst.mapper.MeterWorkRailwayActFirstMapper;
import com.steerinfo.meterwork.meterworkrailwayactfirst.model.MeterWorkRailwayActFirst;
import com.steerinfo.meterwork.meterworkrailwayactfirst.service.IMeterWorkRailwayActFirstService;
import com.steerinfo.meterwork.meterworkrailwayactual.mapper.MeterWorkRailwayActualMapper;
import com.steerinfo.meterwork.meterworkrailwayactual.model.MeterWorkRailwayActual;
import com.steerinfo.meterwork.meterworkrailwaymotorialreceived.model.MeterWorkRailwayMotorialReceived;
import com.steerinfo.meterwork.meterworkrailwayreceived.model.MeterWorkRailwayReceived;
import com.steerinfo.pretrack.prerailwayscale.model.PreRailwayScale;
import com.steerinfo.pretrack.pretrackscale.model.PreTrackScale;
import com.steerinfo.util.StringUtils;
import io.micrometer.core.instrument.Meter;
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.*;

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

    @Autowired
    IMeterWorkRailwayActFirstService meterWorkRailwayActFirstService;

    @Resource
    MeterWorkRailwayActualMapper actualMapper;
    @Resource
    MeterWorkRailwayActFirstMapper actFirstMapper;
    @Resource
    MeterBaseRailwayWeightMapper baseRailwayWeightMapper;

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

    @ApiOperation(value = "创建", notes = "根据MeterWorkRailwayActFirst对象创建")
    @ApiImplicitParam(name = "meterWorkRailwayActFirst", value = "详细实体meterWorkRailwayActFirst", required = true, dataType = "MeterWorkRailwayActFirst")
    //@RequiresPermissions("meterworkrailwayactfirst:create")
    @PostMapping(value = "/")
    public RESTfulResult add(@ModelAttribute MeterWorkRailwayActFirst model) {
        try {
            MeterWorkRailwayActFirst meterWorkRailwayActFirst = meterWorkRailwayActFirstService.add(model);
            return success(meterWorkRailwayActFirst);
        } 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("meterworkrailwayactfirst:view")
    @GetMapping(value = "/{id}")
    public RESTfulResult get(@PathVariable String id) {
        try {
            MeterWorkRailwayActFirst meterWorkRailwayActFirst = meterWorkRailwayActFirstService.getById(id);
            return success(meterWorkRailwayActFirst);
        } catch (Exception ex) {
           ex.printStackTrace();
throw new MarkerMetException(500, "操作异常！！");
        }
    }

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

    @ApiOperation(value = "新增数据", notes = "根据MeterWorkRailwayActFirst对象创建")
    @ApiImplicitParam(name = "MeterWorkRailwayActFirst", value = "详细实体MeterWorkRailwayActFirst", required = true, dataType = "MeterWorkRailwayActFirst")
    @PostMapping(value = "/add")
    public RESTfulResult chechandadd(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActFirstService.checkandadd(model);
            return rm;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }


    @ApiOperation(value = "修改数据", notes = "根据MeterWorkRailwayActFirst对象创建")
    @PostMapping(value = "/update")
    public RESTfulResult chechandupdate(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActFirstService.checkandupdate(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 = "根据MeterWorkRailwayActFirst对象创建")
    @PostMapping(value = "/audit")
    public RESTfulResult audit(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActFirstService.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 = "根据MeterWorkRailwayActFirst对象创建")
    @PostMapping(value = "/unaudit")
    public RESTfulResult unaudit(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActFirstService.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 = "根据传入参数进行查询")
    @GetMapping(value = "/selectView")
    public RESTfulResult selectView(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkRailwayActFirst> pageInfo = meterWorkRailwayActFirstService.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 = "修改车号-网页", notes = "根据MeterWorkRailwayActFirst对象修改车号")
    @PostMapping(value = "/updateCar")
    public RESTfulResult updateCar(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActFirstService.updateCar(model);
                return success(num);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "停用-网页", notes = "根据MeterWorkRailwayActFirst对象修改状态")
    @PostMapping(value = "/abolish")
    public RESTfulResult abolish(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActFirstService.abolish(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 = "根据MeterWorkRailwayActFirst对象创建")
    @PostMapping(value = "/recover")
    public RESTfulResult recover(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActFirstService.recover(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("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "解除委托-网页", notes = "根据MeterWorkRailwayActFirst对象创建")
    @PostMapping(value = "/remove")
    public RESTfulResult remove(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkRailwayActFirstService.remove(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("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "一次数据维护-网页", notes = "根据传入时间和火车号，查询给定时间段去重车号")
    @GetMapping(value = "/distinctRailwayNo")
    public RESTfulResult distinctRailwayNo(@RequestParam HashMap param) {
        RESTfulResult rm = failed();
        try {
            String railwayTypeNo = param.get("railwayTypeNo") == null ? "":param.get("railwayTypeNo").toString();
            String lcNo = param.get("lcNo") == null ? "" : param.get("lcNo").toString();
            String railwayNo = param.get("railwayNo") == null ? "":param.get("railwayNo").toString();
            String startTime = param.get("startTime") == null ? "":param.get("startTime").toString();
            String endTime = param.get("endTime") == null ? "":param.get("endTime").toString();
            String baseSpotNo = param.get("baseSpotNo") == null ? "": param.get("baseSpotNo").toString();
            String matterName = param.get("matterName") == null ? "": param.get("matterName").toString();
            String predictionNo = param.get("predictionNo") == null ? "": param.get("predictionNo").toString();
            String forwardingUnitName = param.get("forwardingUnitName") == null ? "": param.get("forwardingUnitName").toString();
            String receivingUintName = param.get("receivingUintName") == null ? "": param.get("receivingUintName").toString();
            String valueFlag = param.get("valueFlag") == null ? "":param.get("valueFlag").toString();
            List<String> rows = meterWorkRailwayActFirstService.distinctRailwayNo(railwayTypeNo, lcNo, railwayNo, startTime, endTime, baseSpotNo, matterName, predictionNo, forwardingUnitName,receivingUintName,valueFlag);
            return success(rows);
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>" + e.getMessage());
        }
        return rm;
    }

    @ApiOperation(value = "一次数据维护-网页", notes = "根据传入时间查询去重列次编号")
    @PostMapping(value = "/distinctLcNo")
    public RESTfulResult distinctLcNo(@RequestBody HashMap param) {
        RESTfulResult rm = failed();
        try {
            String railwayTypeNo = param.get("railwayTypeNo") == null ? "":param.get("railwayTypeNo").toString();
            String startTime = param.get("startTime") == null ? "":param.get("startTime").toString();
            String endTime = param.get("endTime") == null ? "":param.get("endTime").toString();
            List<String> rows = meterWorkRailwayActFirstService.distinctLcNo(railwayTypeNo, startTime, endTime);
            return success(rows);
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>" + e.getMessage());
        }
        return rm;
    }

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

    @ApiOperation(value = "匹配委托-网页", notes = "根据MeterWorkRailwayActFirst对象创建")
    @PostMapping(value = "/match")
    public RESTfulResult match(@RequestBody MeterWorkRailwayActFirstDto model) {
        RESTfulResult rm = failed();
        try {
            MeterWorkRailwayActFirst mwraf = meterWorkRailwayActFirstService.match(model.getActualFirstNo(), model.getPredictionNo());
            if (mwraf != null) {
                return success(mwraf);
            } 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 Integer pageNum, Integer pageSize, String flag) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkRailwayActFirst> pageInfo = meterWorkRailwayActFirstService.selectDiff(flag, 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 = "查询毛重数据", notes = "根据传入参数进行查询")
    @GetMapping(value = "/selectTa")
    public RESTfulResult selectTa(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkRailwayActFirst> pageInfo = meterWorkRailwayActFirstService.selectTa(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 = "查询皮重数据", notes = "根据传入参数进行查询")
    @GetMapping(value = "/selectNet")
    public RESTfulResult selectNet(@RequestParam String weightType, String railwayNo, String flag, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<MeterWorkRailwayActFirst> rows = meterWorkRailwayActFirstService.selectNet(weightType, railwayNo, flag);
            PageList pageInfo = new PageList(rows);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "获取动态列表", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterworkrailwayactfirst:view")
    @GetMapping(value = "/selectAct")
    public RESTfulResult listAct(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<MeterWorkRailwayActFirst> rows = meterWorkRailwayActFirstService.selectAct(parmas, pageNum, pageSize);
            PageList pageInfo = new PageList(rows);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "获取静态列表", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterworkrailwayactfirst:view")
    @GetMapping(value = "/selectSta")
    public RESTfulResult listSta(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<MeterWorkRailwayActFirst> rows = meterWorkRailwayActFirstService.selectSta(parmas);
            PageList pageInfo = new PageList(rows);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "获取计量效率具体信息", notes = "根据传入参数进行查询")
    @GetMapping(value = "/detailed")
    public RESTfulResult detailed(@RequestParam String times, String num) {
        RESTfulResult rm = failed();
        try {
            List<MeterWorkRailwayActFirst> rows = meterWorkRailwayActFirstService.detailed(times, num);
            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 = "根据传入参数进行查询")
    @GetMapping(value = "/analysis")
    public RESTfulResult analysis(@RequestParam String startTime, String endTime, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageHelper.startPage(pageNum, pageSize);
            List<StaffPerformanceAnalysis> rows = meterWorkRailwayActFirstService.analysis(startTime, endTime);
            PageList pageInfo = new PageList(rows);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "C#端入库秤实绩静轨使用固重洁净", notes = "根据MeterWorkStorageActual对象创建")
    @ApiImplicitParam(name = "meterWorkStorageActual", value = "详细实体meterWorkStorageActual", required = true, dataType = "MeterWorkStorageActual")
    //@RequiresPermissions("meterworkstorageactual:create")
    @PostMapping(value = "/doAddWf")
    public RESTfulResult doAddWf(@RequestBody CommonCombination<MeterWorkRailwayActFirst, MeterWorkRailwayActual, MeterWorkRailwayActFirst, MeterMonitorNote> model) {
        RESTfulResult rm = failed();
        try {
            String no = meterWorkRailwayActFirstService.doAddWf(model.getOne(), model.getTwo());
            if (StringUtils.isEmpty(no)) {
                return failed(null, "新增数据失败");
            }
            return success(no);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "C#端轨道衡实绩动轨", notes = "根据MeterWorkStorageActual对象创建")
    @ApiImplicitParam(name = "meterWorkStorageActual", value = "详细实体meterWorkStorageActual", required = true, dataType = "MeterWorkStorageActual")
    //@RequiresPermissions("meterworkstorageactual:create")
    @PostMapping(value = "/doAddMotoriaWf")
    public RESTfulResult doAddWfAct(@RequestBody CommonCombination<PreRailwayScale, List<MeterWorkRailwayActFirst>, MeterBaseRailwayWeight, MeterMonitorNote> model) {
        RESTfulResult rm = failed();
        try {
            String userId = "";
            String userName = "";
            if(StringUtils.isEmpty(model.getTwo().get(0).getCreateManNo())){
                UserPayload payload = UserPayload.getCurrUser();
                userId = payload.getId();
                userName = payload.getUserName();
            }

            String no = "";
            MeterBaseRailwayWeight mbr = baseRailwayWeightMapper.selectByPrimaryKey(model.getThree().getRailwayPk());
            for (MeterWorkRailwayActFirst first : model.getTwo()) {
                if(StringUtils.isEmpty(first.getCreateManNo())){
                    first.setCreateManNo(userId);
                    first.setCreateManName(userName);
                }
                if(first.getCreateTime()==null){
                    first.setCreateTime(new Date());
                }
                if(StringUtils.isEmpty(first.getActualFirstNo())) {
                    //此为第一次计量的数据
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                    String afl = sdf.format(new Date());
                    //一次数据
                    String firstNo = actFirstMapper.getNewID(afl);
                    first.setActualFirstNo(afl + firstNo);
                }else if(first.getActualFirstNo().length()>14){
                    first.setActualFirstNo(first.getActualFirstNo().substring(2));
                }
                no += meterWorkRailwayActFirstService.doAddWfAct(model.getOne(), first, mbr) + ",";
            }

            if (StringUtils.isEmpty(no)) {
                return failed(null, "新增数据失败");
            }
            return success(no.substring(0, no.length() - 1));
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "C#端轨道衡实绩静轨需二次洁净", notes = "根据MeterWorkStorageActual对象创建")
    @PostMapping(value = "/doAddWfStatic")
    public RESTfulResult doAddWfStatic(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActFirstService.doAddWfStatic(model);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "C#端轨道衡实绩静轨洁净--两条数据", notes = "根据两个MeterWorkStorageActual对象创建")
    @PostMapping(value = "/doAddWfStaticTwo")
    public RESTfulResult doAddWfStaticTwo(@RequestBody CommonCombination<PreRailwayScale, MeterWorkRailwayActFirst, MeterWorkRailwayActFirst, MeterWorkRailwayActFirst> com) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkRailwayActFirstService.doAddWfStaticTwo(com.getOne(), com.getTwo(), com.getThree());
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>" + e.getMessage());
        }
        return rm;
    }

    @ApiOperation(value = "C#端轨道衡实绩静轨复磅", notes = "根据MeterWorkStorageActual对象创建")
    @PostMapping(value = "/doAddWfRecover")
    public RESTfulResult doAddWfRecover(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            String no = meterWorkRailwayActFirstService.doAddWfRecover(model);
            if (StringUtils.isEmpty(no)) {
                return failed(null, "复磅数据保存失败");
            }
            return success(no);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "C#端轨道衡实绩静轨-复磅-更新自重", notes = "根据MeterWorkStorageActual对象创建")
    @PostMapping(value = "/doUpdateSelfWeight")
    public RESTfulResult doUpdateSelfWeight(@RequestBody MeterWorkRailwayActFirst model) {
        RESTfulResult rm = failed();
        try {
            String no = meterWorkRailwayActFirstService.doUpdateSelfWeight(model);
            if (StringUtils.isEmpty(no)) {
                return failed(null, "复磅数据保存失败");
            }
            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 = "分页查询")
    @GetMapping(value = "/doQueryWf")
    public RESTfulResult doQueryWf(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkRailwayActFirst> list = meterWorkRailwayActFirstService.doQueryWf(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
           ex.printStackTrace();
throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "水分数据操作", notes = "水分数据操作")
    @PostMapping(value = "/doEditMotoriaWf")
    public RESTfulResult doEditMotoriaWf(@RequestBody List<MeterWorkRailwayActual> lma) {
        try {
            if (lma != null && lma.size() > 0) {
                for (MeterWorkRailwayActual ma : lma) {
                    MeterWorkRailwayActual m = new MeterWorkRailwayActual();
                    m.setActualNo(ma.getActualNo());
                    m.setWaterNum(ma.getWaterNum());
                    actualMapper.updateByPrimaryKeySelective(m);

                    MeterWorkRailwayActFirst first = new MeterWorkRailwayActFirst();
                    first.setActualFirstNo(ma.getActualFirst1No());
                    first.setWaterNum(ma.getWaterNum());
                    actFirstMapper.updateByPrimaryKeySelective(first);
                }
            }
            return success();
        } catch (Exception ex) {
           ex.printStackTrace();
throw new MarkerMetException(500, "操作异常！！");
        }
    }
    @ApiOperation(value = "智能终端混装混卸--远程计量")
    @Transactional
    @PostMapping(value = "/doAddNetHZHX", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetHZHX(@RequestBody CommonCombination<MeterWorkRailwayActFirst, MeterWorkRailwayActual,MeterWorkRailwayActFirst, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkRailwayActFirstService.doAddNetHZHX(com.getOne(), com.getTwo(), com.getThree(), com.getFour());
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "智能终端混装混卸--智能计量(记录)")
    @Transactional
    @PostMapping(value = "/doAddNetHZHXTwo", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetHZHXTwo(@RequestBody CommonCombination<PreRailwayScale, MeterWorkRailwayActFirst,MeterWorkRailwayActFirst, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkRailwayActFirstService.doAddNetHZHXTwo(com.getOne(), com.getTwo(), com.getThree(), com.getFour(), com.getSOne());
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "双委托洁净--远程计量")
    @Transactional
    @PostMapping(value = "/doNetAddTwo", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetAddTwo(@RequestBody CommonCombination<MeterWorkRailwayActFirst, MeterWorkRailwayActual, PreRailwayScale, PreRailwayScale> com) {
        try {
            RESTfulResult rm = meterWorkRailwayActFirstService.doNetAddTwo(com.getOne(), com.getTwo(), com.getThree(), com.getFour());
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "双委托洁净--智能计量(记录)")
    @Transactional
    @PostMapping(value = "/doNetAddTwoDouble", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetAddTwoDouble(@RequestBody CommonCombination<PreRailwayScale, PreRailwayScale, MeterWorkRailwayActFirst, MeterWorkRailwayActFirst> com) {
        try {
            RESTfulResult rm = meterWorkRailwayActFirstService.doNetAddTwoDouble(com.getOne(), com.getTwo(), com.getThree(), com.getFour());
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "轨道衡双委托匹配洁净", notes = "轨道衡双委托匹配洁净")
    //@RequiresPermissions("meterworkcaractual:view")
    @PostMapping(value = "/doubleEntrustMatch")
    public RESTfulResult doubleEntrustmentMatch(@RequestBody HashMap parmas) {
        RESTfulResult rm = failed();
        try {
            String actualNo1 = parmas.get("actualNo1").toString();
            String actualNo2 = parmas.get("actualNo2").toString();
            String predictionNo1 = parmas.get("predictionNo1").toString();
            String predictionNo2 = parmas.get("predictionNo2").toString();

            String msg = meterWorkRailwayActFirstService.doubleEntrustMatch(actualNo1, actualNo2,predictionNo1,predictionNo2);
            rm.setMessage(msg);
            if (rm.getMessage() != "" || !rm.getMessage().equals("")){
                return rm;
            }
            return success();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "混装", notes = "混装")
    //@RequiresPermissions("meterworkcaractual:view")
    @PostMapping(value = "/mixedLoading")
    public RESTfulResult mixedLoading(@RequestBody HashMap parmas) {
        try {
            String actualNo1 = parmas.get("actualNo1").toString();
            String actualNo2 = parmas.get("actualNo2").toString();
            String actualNo3 = parmas.get("actualNo3").toString();
            String predictionNo1 = parmas.get("predictionNo1").toString();
            String predictionNo2 = parmas.get("predictionNo2").toString();
            String msg = meterWorkRailwayActFirstService.mixedLoading(actualNo1, actualNo2,actualNo3,predictionNo1,predictionNo2);
            if (msg != "" || !msg.equals("")){
                return failed(null,msg);
            }
            return success();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "混卸", notes = "混卸")
    //@RequiresPermissions("meterworkcaractual:view")
    @PostMapping(value = "/mixedDischarge")
    public RESTfulResult mixedDischarge(@RequestBody HashMap parmas) {
        try {
            String actualNo1 = parmas.get("actualNo1").toString();
            String actualNo2 = parmas.get("actualNo2").toString();
            String actualNo3 = parmas.get("actualNo3").toString();
            String predictionNo1 = parmas.get("predictionNo1").toString();
            String predictionNo2 = parmas.get("predictionNo2").toString();

            String msg = meterWorkRailwayActFirstService.mixedDischarge(actualNo1, actualNo2,actualNo3,predictionNo1,predictionNo2);
            if (msg != "" || !msg.equals("")){
                return failed(null,msg);
            }
            return success();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "标识皮重洁净", notes = "标识皮重洁净")
    //@RequiresPermissions("meterworkcaractual:view")
    @PostMapping(value = "/fixedTare")
    public RESTfulResult fixedTare(@RequestBody HashMap parmas) {
        RESTfulResult rm = failed();
        try {
            String actualNo = parmas.get("actualNo") == null ? "" : parmas.get("actualNo").toString();
            String predictionNo = parmas.get("predictionNo") == null ? "" : parmas.get("predictionNo").toString();
            String tareWeight = parmas.get("tareWeight") == null ? "" : parmas.get("tareWeight").toString();

            String msg = meterWorkRailwayActFirstService.fixedTare(actualNo, tareWeight, predictionNo);
            if (msg.equals("")){
                return rm;
            }
            rm.setSucceed();
            rm.setCode("200");
            rm.setMessage(msg);
            return rm;


        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "历史皮重洁净", notes = "历史皮重洁净")
    //@RequiresPermissions("meterworkcaractual:view")
    @PostMapping(value = "/HistoricalTare")
    public RESTfulResult HistoricalTare(@RequestBody HashMap parmas) {
        RESTfulResult rm = failed();
        try {
            String actualNo = parmas.get("actualNo") == null ? "" : parmas.get("actualNo").toString();
            String predictionNo = parmas.get("predictionNo") == null ? "" : parmas.get("predictionNo").toString();

            rm = meterWorkRailwayActFirstService.HistoricalTare(actualNo, predictionNo);
            return rm;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "轨道衡衡一次数据补录", notes = "根据MeterWorkRailwayActFirst对象创建")
    @PostMapping(value = "/supplementaryData")
    public RESTfulResult supplementaryData(@RequestBody HashMap map) {
        RESTfulResult rm = failed();
        try {
            MeterWorkRailwayActFirst model = new MeterWorkRailwayActFirst();
            //model.setPredictionNo(map.get("predictionNo").toString());
            model.setBaseSpotNo(map.get("baseSpotNo").toString());
            model.setBaseSpotName(map.get("baseSpotName").toString());
            model.setCreateManNo(map.get("createManNo").toString());
            model.setCreateManName(map.get("createManName").toString());
            /*SimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd HH24:mm:ss" );
            Date date = sdf.parse(map.get("createTime").toString());*/
            model.setMeterWeight(new BigDecimal(map.get("meterWeight").toString()));

            model.setWeightType(map.get("weightType").toString());
            model.setRailwayNo(map.get("railwayNo").toString());
            model.setRailwayModelNo(map.get("railwayModelNo").toString());
            model.setRailwayModelName(map.get("railwayModelName").toString());
            model.setRailwayTypeNo(map.get("railwayTypeNo").toString());
            model.setRailwayTypeName(map.get("railwayTypeName").toString());
            rm = meterWorkRailwayActFirstService.supplementaryData(model);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "动态衡维护界面--皮重保存", notes = "根据List<MeterWorkRailwayActFirst>对象进行批量修改重量类型")
    @PostMapping(value = "/doAddRailWf")
    public RESTfulResult doAddRailWf(@RequestBody List<MeterWorkRailwayActFirst> models) {
        RESTfulResult rm = failed();
        try {
            if(models.size() >= 1) {
                rm = meterWorkRailwayActFirstService.doAddRailWf(models);
            }else {
                rm.setMessage("至少需要选择一条数据进行皮重保存，请确认！！！！");
            }
            return rm;
        }catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>>" + e.getMessage());
            return rm;
        }
    }

    @ApiOperation(value = "动态衡维护界面--毛皮匹配洁净保存", notes = "根据毛皮的List<MeterWorkRailwayActFirst>对象进行批量匹配洁净保存")
    @PostMapping(value = "/doAddRailNetWf")
    public RESTfulResult doAddRailNetWf(@RequestBody CommonCombination<List<MeterWorkRailwayMotorialReceived>, List<MeterWorkRailwayActFirst>, MeterBaseRailwayWeight,MeterBaseRailwayWeight> com) {
        RESTfulResult rm = failed();
        try {

            if(com.getOne().size() >= 1 && com.getTwo().size() >= 1) {
                rm = meterWorkRailwayActFirstService.doAddRailNetWf(com.getOne(), com.getTwo());
            }else if(com.getOne().size() < 1){
                rm.setMessage("至少需要选择一条毛重数据进行匹配洁净保存，请确认！！！！");
            }else if(com.getTwo().size() < 1) {
                rm.setMessage("至少需要选择一条皮重数据进行匹配洁净保存，请确认！！！！");
            }
            return rm;
        }catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>>" + e.getMessage());
            return rm;
        }
    }

    @ApiOperation(value = "动态衡维护界面--毛皮匹配洁净保存", notes = "根据毛皮的List<MeterWorkRailwayActFirst>对象进行批量匹配洁净保存")
    @PostMapping(value = "/doAddRailAINetWf")
    public RESTfulResult doAddRailAINetWf(@RequestBody CommonCombination<List<MeterWorkRailwayMotorialReceived>, List<MeterBaseRailwayAiweight>, MeterBaseRailwayWeight,MeterBaseRailwayWeight> com) {
        RESTfulResult rm = failed();
        try {

            if(com.getOne().size() >= 1 && com.getTwo().size() >= 1) {
                rm = meterWorkRailwayActFirstService.doAddRailAINetWf(com.getOne(), com.getTwo());
            }else if(com.getOne().size() < 1){
                rm.setMessage("至少需要选择一条毛重数据进行匹配洁净保存，请确认！！！！");
            }else if(com.getTwo().size() < 1) {
                rm.setMessage("至少需要选择一条AI标志皮重数据进行匹配洁净保存，请确认！！！！");
            }
            return rm;
        }catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>>" + e.getMessage());
            return rm;
        }
    }

    @ApiOperation(value = "动态衡维护界面--毛皮匹配洁净保存", notes = "根据毛皮的List<MeterWorkRailwayActFirst>对象进行批量匹配洁净保存")
    @PostMapping(value = "/selfServiceMeasurement")
    public RESTfulResult selfServiceMeasurement(@RequestBody MeterWorkRailwayActFirst first) {
        RESTfulResult rm = failed();
        try {

            if(first != null) {
                rm = meterWorkRailwayActFirstService.selfServiceMeasurement(first);
            }else {
                rm.setMessage("至少需要穿一条一次数据进行匹配洁净保存，请确认！！！！");
            }
            return rm;
        }catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！>>>>" + e.getMessage());
            return rm;
        }
    }

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

        }
        return rm;
    }

}
