package com.steerinfo.meterwork.meterworkcaractualfirstbak.controller;

import com.alibaba.fastjson.JSONObject;
import com.jisco.dynamicweight.dynamicbasecamera.factories.ConverterFactories;
import com.jisco.dynamicweight.util.UserUtil;
import com.steerinfo.baseinfo.meterbasecar.mapper.MeterBaseCarMapper;
import com.steerinfo.baseinfo.meterbasecar.model.MeterBaseCar;
import com.steerinfo.baseinfo.meterbaseoperationlog.mapper.MeterBaseOperationLogMapper;
import com.steerinfo.baseinfo.meterbaseoperationlog.model.MeterBaseOperationLog;
import com.steerinfo.meterwork.meterworkcaractualfirstbak.mapper.MeterWorkCarActualFirstBakMapper;
import com.steerinfo.meterwork.meterworkcaractualfirstbak.model.MeterWorkCarActualFirstBak;
import com.steerinfo.meterwork.meterworkcaractualfirstbak.service.IMeterWorkCarActualFirstBakService;
import com.steerinfo.baseinfo.meterbasespotinfo.mapper.MeterBaseSpotInfoMapper;
import com.steerinfo.baseinfo.meterbasespotinfo.model.MeterBaseSpotInfo;
import com.steerinfo.framework.controller.BaseRESTfulController;
import com.steerinfo.framework.controller.RESTfulResult;
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.*;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.meterworkcaractualbak.model.MeterWorkCarActualBak;
import com.steerinfo.meterwork.meterworkprelink.model.MeterWorkPreLink;
import com.steerinfo.pretrack.pretrackscale.model.PreTrackScale;
import com.steerinfo.util.PublicMethod;
import com.steerinfo.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.*;

/**
 * MeterWorkCarActualFirstBak RESTful接口：
 *
 * @author generator
 * @version 1.0-SNAPSHORT 2020-09-17 11:28
 * 类描述
 * 修订历史：
 * 日期：2020-09-17
 * 作者：generator
 * 参考：
 * 描述：MeterWorkCarActualFirstBak RESTful接口
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 * @see null
 */
@RestController
@RequestMapping("/${api.version}/meterworkcaractualfirstbaks")
@Api(value = "/${api.version}/meterworkcaractualfirstbaks", tags = "计量汽车衡一次数据 - MeterWorkCarActualFirstBakController")
public class MeterWorkCarActualFirstBakController extends BaseRESTfulController {

    private static Logger logger	= LoggerFactory.getLogger( MeterWorkCarActualFirstBakController.class );

    @Resource
    MeterWorkCarActualFirstBakMapper meterWorkCarActualFirstBakMapper;

    @Resource
    MeterBaseSpotInfoMapper meterBaseSpotInfoMapper;

    @Autowired
    IMeterWorkCarActualFirstBakService meterWorkCarActualFirstBakService;

    @Resource
    MeterBaseCarMapper meterBaseCarMapper;

    @Resource
    MeterBaseOperationLogMapper meterBaseOperationLogMapper;

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

    @ApiOperation(value = "创建", notes = "根据MeterWorkCarActualFirst对象创建")
    @ApiImplicitParam(name = "meterWorkCarActualFirst", value = "详细实体meterWorkCarActualFirst", required = true, dataType = "MeterWorkCarActualFirst")
    @PostMapping(value = "/")
    public RESTfulResult add(@RequestBody MeterWorkCarActualFirstBak model) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String afl = sdf.format(new Date());
//            String no = meterWorkCarActualFirstBakMapper.getNewID(afl);
//            model.setActualFirstNo(sdf.format(new Date()) + no);
            String no = PublicMethod.IdCreate(3);
            model.setActualFirstNo(no);
            model.setValueFlag("1");
            model.setMeterWeight(model.getMeterWeight().multiply(new BigDecimal(1000)));
            if(model.getCreateTime() == null || StringUtils.isEmpty(model.getCreateTime().toString())){
                model.setCreateTime(new Date());
            }
            String userId = null;
            String userName = null;
            try{
                if((model.getCreateManNo() == null || StringUtils.isEmpty(model.getCreateManNo()))
                        || (model.getCreateManName() == null || StringUtils.isEmpty(model.getCreateManName()))) {
                    UserPayload payload = UserPayload.getCurrUser();
                    userId = payload.getUserCode();
                    userName = payload.getUserName();
                }else {
                    userId = model.getCreateManNo();
                    userName = model.getCreateManName();
                }
            }catch(Exception e) {
                userId = "admin";
                userName = "admins";
            }
            model.setCreateManNo(userId);
            model.setCreateManName(userName);
            model.setIsPreScale("0");
            HashMap<String, Object> obj = new HashMap<>();
            obj.put("baseSpotNo", model.getBaseSpotNo());
            List<MeterBaseSpotInfo> spotModel = meterBaseSpotInfoMapper.selectByParameters(obj);
            if(spotModel.size() >= 1) {
                model.setBaseSpotName(spotModel.get(0).getBaseSpotName());
            }else {
                throw new MarkerMetException(500, "计量点配置表未找到相应的计量点！！");
            }
            MeterWorkCarActualFirstBak meterWorkCarActualFirstBak = meterWorkCarActualFirstBakService.add(model);
            return success(meterWorkCarActualFirstBak);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "创建", notes = "根据MeterWorkCarActualFirst对象创建")
    @ApiImplicitParam(name = "meterWorkCarActualFirst", value = "详细实体meterWorkCarActualFirst", required = true, dataType = "MeterWorkCarActualFirst")
    @PostMapping(value = "/addExport")
    @Transactional
    public RESTfulResult addExport(@RequestBody List<MeterWorkCarActualFirstBak> models) {
        try {
            for (MeterWorkCarActualFirstBak model : models) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                String afl = sdf.format(new Date());
//            String no = meterWorkCarActualFirstBakMapper.getNewID(afl);
//            model.setActualFirstNo(sdf.format(new Date()) + no);
                String no = PublicMethod.IdCreate(3);
                model.setActualFirstNo(no);
                model.setValueFlag("1");
                model.setMeterWeight(model.getMeterWeight().multiply(new BigDecimal(1000)));
                if(model.getCreateTime() == null || StringUtils.isEmpty(model.getCreateTime().toString())){
                    model.setCreateTime(new Date());
                }
                String userId = null;
                String userName = null;
                try{
                    if((model.getCreateManNo() == null || StringUtils.isEmpty(model.getCreateManNo()))
                            || (model.getCreateManName() == null || StringUtils.isEmpty(model.getCreateManName()))) {
                        UserPayload payload = UserPayload.getCurrUser();
                        userId = payload.getUserCode();
                        userName = payload.getUserName();
                    }else {
                        userId = model.getCreateManNo();
                        userName = model.getCreateManName();
                    }
                }catch(Exception e) {
                    userId = "admin";
                    userName = "admins";
                }
                model.setCreateManNo(userId);
                model.setCreateManName(userName);
                model.setIsPreScale("0");
                HashMap<String, Object> obj = new HashMap<>();
                obj.put("baseSpotNo", model.getBaseSpotNo());
                List<MeterBaseSpotInfo> spotModel = meterBaseSpotInfoMapper.selectByParameters(obj);
                if(spotModel.size() >= 1) {
                    model.setBaseSpotName(spotModel.get(0).getBaseSpotName());
                }else {
                    throw new MarkerMetException(500, "计量点配置表未找到相应的计量点！！");
                }
                MeterWorkCarActualFirstBak meterWorkCarActualFirstBak = meterWorkCarActualFirstBakService.add(model);
            }
            return success();
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "一次数据补入", notes = "根据MeterWorkCarActualFirstBak对象创建")
    @ApiImplicitParam(name = "meterWorkCarActualFirstBak", value = "详细实体meterWorkCarActualFirstBak", required = true, dataType = "MeterWorkCarActualFirstBak")
    @PostMapping(value = "/firstDataSupplement")
    public RESTfulResult firstDataSupplement(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = new RESTfulResult();
        rm.setFailed();
        try {
            rm = meterWorkCarActualFirstBakService.firstDataSupplement(model);
        } catch (Exception ex) {
            ex.printStackTrace();
            rm.setMessage("操作异常，请确认！！！>>>>" + ex.getMessage());
        }
        return rm;
    }

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

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

    @ApiOperation(value = "新增数据", notes = "根据MeterWorkCarActualFirst对象创建")
    @ApiImplicitParam(name = "meterWorkCarActualFirst", value = "详细实体meterWorkCarActualFirst", required = true, dataType = "MeterWorkCarActualFirst")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/add")
    public RESTfulResult chechandadd(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterMonitorNote, MeterWorkCarActualBak, MeterMonitorNote> com) {
        RESTfulResult rm = failed();
        try {
            MeterMonitorNote note = com.getTwo();
            MeterWorkCarActualFirstBak first = com.getOne();
            RESTfulResult res = meterWorkCarActualFirstBakService.checkandadd(first, note);
            return res;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }


    @ApiOperation(value = "修改数据", notes = "根据MeterWorkCarActualFirst对象创建")
    @PostMapping(value = "/update")
    public RESTfulResult chechandupdate(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualFirstBakService.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 = "根据MeterWorkCarActualFirst对象创建")
    @PostMapping(value = "/updateCar")
    public RESTfulResult updateCar(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualFirstBakService.checkcarandupdate(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 = "根据MeterWorkCarActualFirst对象创建")
    @PostMapping(value = "/audit")
    public RESTfulResult audit(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualFirstBakService.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 = "根据MeterWorkCarActualFirst对象创建")
    @PostMapping(value = "/unaudit")
    public RESTfulResult unaudit(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualFirstBakService.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;
    }

    /*
    // By BourneCao 20211222 和杨秀东确认，不再需要一次计量历史查询表和相关视图

    @ApiOperation(value = "历史查询", notes = "根据传入参数进行查询")
    @GetMapping(value = "/selectView")
    public RESTfulResult selectView(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkCarActualFirst> pageInfo = meterWorkCarActualFirstService.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 = "根据MeterWorkCarActualFirst对象创建")
    @PostMapping(value = "/abolish")
    public RESTfulResult abolish(@RequestBody List<MeterWorkCarActualFirstBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualFirstBakService.abolish(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 = "查询一次计量-C#", notes = "根据车号查询未使用和使用中的预报")
    @PostMapping(value = "/queryByFlag")
    public RESTfulResult queryFirst(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = failed();
        if (model.getCarNo() == null || "".equals(model.getCarNo())) {
            rm.setMessage("请传入车号参数");
            return rm;
        }
        try {
            String carNo = model.getCarNo();
            rm = meterWorkCarActualFirstBakService.queryFirst(carNo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "启用", notes = "根据MeterWorkCarActualFirst对象创建")
    @PostMapping(value = "/recover")
    public RESTfulResult recover(@RequestBody List<MeterWorkCarActualFirstBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualFirstBakService.recover(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("操作异常，请确认！");
        }
        return rm;
    }

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

    @ApiOperation(value = "匹配", notes = "根据MeterWorkCarActualFirst对象创建")
    @PostMapping(value = "/match")
    public RESTfulResult match(@RequestBody MeterWorkCarActualFirstDto model) {
        RESTfulResult rm = new RESTfulResult();
        try {
            rm = meterWorkCarActualFirstBakService.match(model.getActualFirstNo(), model.getPredictionNo());
//            if (mwcaf != null) {
//                return success(mwcaf);
//            } else {
//                return failed("匹配失败");
//            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            return failed("操作异常");
        } catch (Exception e) {
            e.printStackTrace();
            return failed("操作异常");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "查询毛重数据", notes = "根据传入参数进行查询")
    @GetMapping(value = "/selectTa")
    public RESTfulResult selectTa(@RequestParam HashMap parmas, String weightType, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkCarActualFirstBak> pageInfo = meterWorkCarActualFirstBakService.selectTa(parmas, weightType, 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 carNo, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkCarActualFirstBak> pageInfo = meterWorkCarActualFirstBakService.selectNet(weightType, carNo, 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 = "/analysis")
    public RESTfulResult analysis(@RequestParam String startTime, String endTime, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<StaffPerformanceAnalysis> pageInfo = meterWorkCarActualFirstBakService.analysis(startTime, endTime, 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 = "/utensil")
    public RESTfulResult utensil(@RequestParam String startTime, String endTime, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<UtensilDto> pageInfo = meterWorkCarActualFirstBakService.utensil(startTime, endTime, 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 = "/meterType")
    public RESTfulResult meterType(@RequestParam String baseSpotNo, String startTime, String endTime) {
        RESTfulResult rm = failed();
        try {
            List<MeterTypeDto> rows = meterWorkCarActualFirstBakService.meterType(baseSpotNo, startTime, endTime);
            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 = "/daily")
    public RESTfulResult daily(@RequestParam String baseSpotNo, String startTime, String endTime) {
        RESTfulResult rm = failed();
        try {
            List<TimesDto> rows = meterWorkCarActualFirstBakService.daily(baseSpotNo, startTime, endTime);
            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 = "/period")
    public RESTfulResult period(@RequestParam String baseSpotNo, String startTime, String endTime) {
        RESTfulResult rm = failed();
        try {
            List<TimesDto> rows = meterWorkCarActualFirstBakService.period(baseSpotNo, startTime, endTime);
            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 = "/detailed")
    public RESTfulResult detailed(@RequestParam String times, String num) {
        RESTfulResult rm = failed();
        try {
            List<MeterWorkCarActualFirstBak> rows = meterWorkCarActualFirstBakService.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 = "/abnormal")
    public RESTfulResult abnormal(@RequestParam String startTime, String endTime, String baseSpotNo, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<AbnormalDto> pageInfo = meterWorkCarActualFirstBakService.abnormal(baseSpotNo, startTime, endTime, 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 = "/getByAbnormal")
    public RESTfulResult getByAbnormal(@RequestParam String meterReasonNo, String meterReasonName, Integer pageNum, Integer pageSize) {
        RESTfulResult rm = failed();
        try {
            PageList<MeterWorkCarActualFirstBak> pageInfo = meterWorkCarActualFirstBakService.getByAbnormal(meterReasonNo, meterReasonName, 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 = "C#端查询")
    @ApiImplicitParam(name = "meterWorkCarActualFirst", value = "详细实体meterWorkCarActualFirst", required = true, dataType = "MeterWorkCarActualFirst")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/doQueryWf")
    public RESTfulResult doQueryWf(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = meterWorkCarActualFirstBakService.doQueryWf(model);
        return rm;
    }

    @ApiOperation(value = "C#端修改")
    @ApiImplicitParam(name = "meterWorkCarActualFirst", value = "详细实体meterWorkCarActualFirst", required = true, dataType = "MeterWorkCarActualFirst")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/doUpdateWf")
    public RESTfulResult doUpdateWf(@RequestBody MeterWorkCarActualFirstBak model) {
        RESTfulResult rm = meterWorkCarActualFirstBakService.doUpdateWf(model);
        return rm;
    }

    @ApiOperation(value = "内倒车辆存储一次计量数据")
    @Transactional
    @PostMapping(value = "/doAddInnerWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddInnerWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterWorkPreLink, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doAddInnerWf(com.getOne(), com.getSOne(), com.getFour());
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "内倒车辆结净")
    @Transactional
    @PostMapping(value = "/doAddNetInnerWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetInnerWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterWorkPreLink, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doAddNetInnerWf(com.getOne(), com.getTwo(), com.getSOne(), com.getFour());
            if(!rm.isSucceed()){
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "内倒车辆结净")
    @Transactional
    @PostMapping(value = "/doAddNetNewHZHX", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetNewHZHX(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doAddNetNewHZHX(com.getOne(), com.getThree(),com.getTwo(), com.getSOne(), com.getFour());
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "非内倒车辆存储一次计量数据")
    @PostMapping(value = "/doAddWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkPreLink, MeterWorkCarActualBak, MeterMonitorNote> com) {
        RESTfulResult rm = failed();
        try {
            RESTfulResult rr = meterWorkCarActualFirstBakService.doAddWf(com.getOne(), com.getTwo(), com.getSOne(), com.getSTwo(), com.getFour());
            return rr;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "非内倒车辆结净")
    @PostMapping(value = "/doAddNetWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterWorkPreLink, MeterMonitorNote> com) {
        RESTfulResult rm = failed();
        try {
            RESTfulResult rr = meterWorkCarActualFirstBakService.doAddNetWf(com.getOne(), com.getTwo(), com.getFour(), com.getThree(), com.getSOne(), com.getSTwo());
            return rr;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "web端补打二维码加密")
    @PostMapping(value = "/encryptionForWeb", produces = "application/json;charset=UTF-8")
    public RESTfulResult encryptionForWeb(@RequestBody String str) throws Exception {
        try {
            JSONObject json = JSONObject.parseObject(str);
            String a = (String) json.get("str");
            String enStr = meterWorkCarActualFirstBakService.encryption(a);
            return success(enStr);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "终端补打二维码加密")
    @PostMapping(value = "/encryptionForWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult encryptionForWf(@RequestBody MeterWorkCarActualFirstBak str) throws Exception {
        try {
            String a = str.getActualFirstNo();
            String enStr = meterWorkCarActualFirstBakService.encryption(a);
            return success(enStr);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "终端补打二维码加密")
    @PostMapping(value = "/encryptionForWfTest", produces = "application/json;charset=UTF-8")
    public RESTfulResult encryptionForWfTest(@RequestBody HashMap param) throws Exception {
        try {
            String carNo = param.get("carNo") == null ? "": param.get("carNo").toString();
            if(StringUtils.isEmpty(carNo)) {
                return failed("车号为空");
            }
            String enStr = meterWorkCarActualFirstBakService.encryptionTest(carNo);
            return success(enStr);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "终端补打二维码解密")
    @PostMapping(value = "/DecryptionForWfTest", produces = "application/json;charset=UTF-8")
    public RESTfulResult DecryptionForWfTest(@RequestBody HashMap param) throws Exception {
        try {
            String message = param.get("message") == null ? "": param.get("message").toString();
            if(StringUtils.isEmpty(message)) {
                return failed("密文为空");
            }
            RESTfulResult rm  = meterWorkCarActualFirstBakService.decryptionTest(message);
            return rm;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "非内倒车辆使用期限皮重结净")
    @PostMapping(value = "/doAddNetByTermWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetByTermWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterMonitorNote, MeterWorkPreLink> com) {
        RESTfulResult rm = failed();
        try {
            RESTfulResult rr = meterWorkCarActualFirstBakService.doAddNetByTermWf(com.getOne(), com.getTwo(), com.getThree());
            return rr;
        } 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("meterworkcaractualfirst:view")
    @GetMapping(value = "/queryOrderByTime")
    public RESTfulResult queryOrderByTime(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkCarActualFirstBak> list = meterWorkCarActualFirstBakService.queryOrderByTime(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }


    @ApiOperation(value = "联达车辆存储一次计量数据")
    @PostMapping(value = "/doAddLianDaWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddLianDaWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterMonitorNote, MeterMonitorNote, MeterMonitorNote> com) {
        RESTfulResult rm = failed();
        try {
            RESTfulResult rr = meterWorkCarActualFirstBakService.doAddLianDaWf(com.getOne(), com.getTwo());
            return rr;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "联达车辆结净")
    @PostMapping(value = "/doAddNetLianDaWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetLianDaWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterMonitorNote, MeterMonitorNote> com) {
        RESTfulResult rm = failed();
        try {
            RESTfulResult rr = meterWorkCarActualFirstBakService.doAddNetLianDaWf(com.getOne(), com.getTwo(), com.getThree());
            return rr;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "吊钩秤数据生成")
    @PostMapping(value = "/doCraneDbWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doCraneDbWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterMonitorNote, MeterMonitorNote, MeterMonitorNote> com) {
        RESTfulResult rm = failed();
        try {
            RESTfulResult rr = meterWorkCarActualFirstBakService.doCraneDbWf(com.getOne(), com.getTwo());
            return rr;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "吊钩秤数据生成")
    @PostMapping(value = "/doCraneNetDbWf", produces = "application/json;charset=UTF-8")
    public RESTfulResult doCraneNetDbWf(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterMonitorNote, MeterMonitorNote> com) {
        RESTfulResult rm = failed();
        try {
            RESTfulResult rr = meterWorkCarActualFirstBakService.doCraneNetDbWf(com.getOne(), com.getTwo(), com.getThree());
            return rr;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "车号汇总统计汇总-网页", notes = "根据传入时间和车号，查询给定时间段去重车号")
    @GetMapping(value = "/distinctCarNo")
    public RESTfulResult distinctCarNo(@RequestParam HashMap param) {
        RESTfulResult rm = failed();
        try {
//            String carNo = param.get("carNo") == null ? "":param.get("carNo").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 = meterWorkCarActualFirstService.distinctCarNo(carNo, startTime, endTime, baseSpotNo, matterName, predictionNo, forwardingUnitName,receivingUintName,valueFlag);
            List<String> rows = meterWorkCarActualFirstBakService.distinctCarNo(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 = "/distinctCarNo")
    public RESTfulResult distinctCarNoPost(@RequestBody(required = false) HashMap param) {
        RESTfulResult rm = failed();
        try {
//            String carNo = param.get("carNo") == null ? "":param.get("carNo").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 = meterWorkCarActualFirstService.distinctCarNo(carNo, startTime, endTime, baseSpotNo, matterName, predictionNo, forwardingUnitName,receivingUintName,valueFlag);
            List<String> rows = meterWorkCarActualFirstBakService.distinctCarNo(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 = "智能终端混装混卸--远程计量")
    @Transactional
    @PostMapping(value = "/doAddNetHZHX", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetHZHX(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterWorkCarActualFirstBak, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.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 = "/doNetAddTwo", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetAddTwo(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, PreTrackScale, PreTrackScale> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doNetAddTwo(com.getOne(), com.getTwo(), com.getThree(), com.getFour());
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @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 = meterWorkCarActualFirstBakService.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 = meterWorkCarActualFirstBakService.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 = "/doubleEntrustmentMatch")
    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();

            rm = meterWorkCarActualFirstBakService.doubleEntrustmentMatch(actualNo1, actualNo2,predictionNo1,predictionNo2);
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "期限皮重结净")
    @Transactional
    @PostMapping(value = "/doNetTermTare", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetTermTare(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak,MeterWorkPreLink, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doNetTermTare(com.getOne(), com.getTwo(), com.getSOne());
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "应急计量批量新增")
    @Transactional
    @PostMapping(value = "/addEmergency", produces = "application/json;charset=UTF-8")
    public RESTfulResult addEmergency(@RequestBody List<MeterWorkCarActualFirstBak> model) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.addEmergency(model);
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "应急计量单个新增")
    @Transactional
    @PostMapping(value = "/addFirstEmergency", produces = "application/json;charset=UTF-8")
    public RESTfulResult addFirstEmergency(@RequestBody MeterWorkCarActualFirstBak model) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.addFirstEmergency(model);
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "应急计量-两个一次数据编号结净")
    @Transactional
    @PostMapping(value = "/doNetEmergency", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetEmergency(@RequestBody MeterWorkCarActualBak model) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doNetEmergency(model);
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "多毛一皮结净")
    @Transactional
    @PostMapping(value = "/doNetAddMuch", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetAddMuch(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak,MeterWorkPreLink, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doNetAddMuch(com.getOne());
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "内倒车辆错误结净")
    @Transactional
    @PostMapping(value = "/doAddNetInnerWfError", produces = "application/json;charset=UTF-8")
    public RESTfulResult doAddNetInnerWfError(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterWorkPreLink, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doAddNetInnerWfError(com.getOne(), com.getTwo(), com.getSOne(), com.getFour());
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "期限皮结净")
    @Transactional
    @PostMapping(value = "/doNetByFirst", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetByFirst(@RequestBody CommonCombination<MeterWorkCarActualFirstBak, MeterWorkCarActualFirstBak,PreTrackScale, MeterMonitorNote> com) {
        try {
            MeterWorkCarActualFirstBak grossModel = com.getOne();
            MeterWorkCarActualFirstBak tareModel = com.getTwo();
            PreTrackScale scale = com.getThree();
            RESTfulResult rm = meterWorkCarActualFirstBakService.doNetByFirst(grossModel, tareModel, scale);
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "web端-期限皮结净（可带委托）")
    @Transactional
    @PostMapping(value = "/doNetByTermData", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetByTermData(@RequestBody HashMap<String, Object> params) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doNetByTermData(params);
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "毛皮转换")
    @Transactional
    @PostMapping(value = "/furConversion")
    public RESTfulResult furConversion(@RequestBody HashMap params) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.furConversion(params);
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value = "多毛一皮结净")
    @Transactional
    @PostMapping(value = "/doNetAddMuchGross", produces = "application/json;charset=UTF-8")
    public RESTfulResult doNetAddMuchGross(@RequestBody CommonCombination<List<MeterWorkCarActualFirstBak>, MeterWorkCarActualFirstBak,MeterWorkPreLink, MeterMonitorNote> com) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.doNetAddMuchGross(com.getOne(),com.getTwo(),com.getFour());
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }

    @ApiOperation(value="批量创建", notes="根据List<MeterWorkCarActFirstBak>对象创建")
    @PostMapping(value = "/batchCheckAdd")
    public RESTfulResult batchCheckAdd(@RequestBody List<MeterWorkCarActualFirstBak> models){
        RESTfulResult rm = meterWorkCarActualFirstBakService.batchCheckAdd(models);
        return rm;
    }

    @ApiOperation(value = "将数据从MeterWorkCarActualFirstBak复制到MeterWorkCarActualFirst")
    @PostMapping(value = "/copyToFirst")
    public RESTfulResult copyToFirst(@RequestBody HashMap params){
        List<String> ids = (List<String>) params.get("ids");
        String carNo = params.get("carNo") == null ? "": params.get("carNo").toString();
        HashMap<String, Object> carMap = new HashMap<>();
        carMap.put("carNo", carNo);
        List<MeterBaseCar> carModels = meterBaseCarMapper.selectByParameters(carMap);


        if(carModels.size() >= 1) {
            MeterBaseCar meterBaseCar = carModels.get(0);
            String carTypeNo = null;
            if (meterBaseCar.getCarTypeNo() != null){
                carTypeNo = meterBaseCar.getCarTypeNo();
            }else{
                return failed(null,"车型为空");
            }
            //内倒
            if ("001004003".equals(carTypeNo)){
                try {
                    meterWorkCarActualFirstBakService.ndCopyToFirst(ids,carNo);
                } catch (Exception e) {
                    e.printStackTrace();
                    return failed(null,e.getMessage());
                }
            }else if ("001004002".equals(carTypeNo)){//外进外发
                try {
                    meterWorkCarActualFirstBakService.wwCopyToFirst(ids,carNo);
                } catch (Exception e) {
                    e.printStackTrace();
                    return failed(null,e.getMessage());
                }
            }else{
                return failed(null,"车型编号错误，不存在对应车型");
            }
        }else {
            try {
                meterWorkCarActualFirstBakService.wwCopyToFirst(ids,carNo);
            } catch (Exception e) {
                e.printStackTrace();
                return failed(null,e.getMessage());
            }
        }
        return success(null,"复制成功");
    }


    @ApiOperation(value = "单机计量数据上传")
    @Transactional
    @PostMapping(value = "/addFirstEmergencyList", produces = "application/json;charset=UTF-8")
    public RESTfulResult addFirstEmergencyList(@RequestBody List<MeterWorkCarActualFirstBak> model) {
        try {
            RESTfulResult rm = meterWorkCarActualFirstBakService.addFirstEmergencyList(model);
            if(!rm.isSucceed()) {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            }
            return rm;
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return failed(null, "操作异常，请确认！");
        }
    }
}
