package com.steerinfo.meterwork.meterworkcaractual.controller;

import com.steerinfo.baseinfo.meterbasecar.model.MeterBaseCar;
import com.steerinfo.baseinfo.meterbasematterinfoold.mapper.MeterBaseMatterInfoOldMapper;
import com.steerinfo.baseinfo.meterbasespecialunit.model.MeterBaseSpecialUnit;
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.utils.collection.ListUtils;
import com.steerinfo.metermonitor.metermonitornote.model.MeterMonitorNote;
import com.steerinfo.meterwork.dto.CommonCombination;
import com.steerinfo.meterwork.dto.MeterWorkCarActualFirstDto;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.metertolimsold.mapper.MeterToLimsOldMapper;
import com.steerinfo.meterwork.meterworkcaractual.mapper.MeterWorkCarActualMapper;
import com.steerinfo.meterwork.meterworkcaractual.model.MeterWorkCarActual;
import com.steerinfo.meterwork.meterworkcaractual.model.MeterWorkCarActualTHJCompare;
import com.steerinfo.meterwork.meterworkcaractual.service.IMeterWorkCarActualService;
import com.steerinfo.meterwork.meterworkcaractualfirst.model.MeterWorkCarActualFirst;
import com.steerinfo.meterwork.meterworkrailwayactfirst.model.MeterWorkRailwayActFirst;
import com.steerinfo.meterwork.meterworkrailwayactual.model.MeterWorkRailwayActual;
import com.steerinfo.util.CommonPage;
import com.steerinfo.util.FieldsCollector;
import com.steerinfo.util.StringUtils;
import io.micrometer.core.instrument.Meter;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import oracle.jdbc.proxy.annotation.Post;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
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.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

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

    @Autowired
    IMeterWorkCarActualService meterWorkCarActualService;
    @Resource
    MeterWorkCarActualMapper meterWorkCarActualMapper;
    @Resource
    MeterBaseMatterInfoOldMapper meterBaseMatterInfoOldMapper;
    @Resource
    MeterToLimsOldMapper meterToLimsOldMapper;

    @ApiOperation(value = "获取列表", notes = "分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    //@RequiresPermissions("meterworkcaractual:view")
    @GetMapping(value = "/")
    public RESTfulResult list(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.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("meterworkcaractual:view")
    @GetMapping(value = "/like/")
    public RESTfulResult listLike(@RequestParam HashMap parmas, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.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 params, Integer pageNum, Integer pageSize) {
        try {
            int pageNum01 = params.get("pageNum") == null ? 1 : Integer.parseInt(params.get("pageNum").toString());
            int pageSize01 = params.get("pagesize") == null ? 20 : Integer.parseInt(params.get("pagesize").toString());
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.likeByDesc(params, pageNum01, pageSize01);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "APP获取列表", notes = "分页模糊查询")
    @PostMapping(value = "/ApplikeByDesc")
    public RESTfulResult ApplikeByDesc(@RequestBody HashMap params) {
        RESTfulResult rm = failed();
        rm.setCode("500");
        try {
            int pageNum01 = params.get("pageNum") == null ? 1 : Integer.parseInt(params.get("pageNum").toString());
            int pageSize01 = params.get("pagesize") == null ? 20 : Integer.parseInt(params.get("pagesize").toString());
            if(params.get("carNo")==null || params.get("carNo") != null && StringUtils.isEmpty(params.get("carNo").toString())) {
                rm.setMessage("车号参数为空，不能进行查询！！");
                return rm;
            }
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.likeByDesc(params, pageNum01, pageSize01);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "远程-获取列表", notes = "分页模糊查询")
    @PostMapping(value = "/likeByDesc/")
    public RESTfulResult likeByDesc01(@RequestBody CommonPage<HashMap> oci) {
        try {
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.likeByDesc(oci.getParam(), oci.getPageNum(), oci.getPageSize());
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }
    @ApiOperation(value = "web端分页降序获取列表", notes = "分页模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    @GetMapping(value = "/likeDesc/")
    public RESTfulResult likeDesc(@RequestParam HashMap params, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.likeByDesc(params, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "web端分页降序获取列表", notes = "分页模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer")
    })
    @PostMapping(value = "/likeDesc/")
    public RESTfulResult likeDescPost(@RequestBody(required = false) HashMap params) {
        try {
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.likeByDesc(params,
                    Integer.parseInt(params.get("pageNum").toString()),
                    Integer.parseInt(params.get("pageSize").toString()));
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "获取列表", notes = "不分页分页模糊查询")
    @PostMapping(value = "/likeByValueFlag/")
    public RESTfulResult likeByValueFlag(@RequestBody HashMap params) {
        try {
            List<MeterWorkCarActual> list = meterWorkCarActualService.likeByValueFlag(params);
            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("meterworkcaractual:view")
    @PostMapping(value = "/like/")
    public RESTfulResult listLikePost(@RequestBody HashMap parmas) {
        try {
            Integer pageNum = parmas.get("pageNum") == null ? 1 : Integer.parseInt(parmas.get("pageNum").toString());
            Integer pageSize =parmas.get("pageSize") == null ? 20 : Integer.parseInt(parmas.get("pageSize").toString());
            PageList<MeterWorkCarActual> list = meterWorkCarActualService.queryLikeForPage(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

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

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

    @ApiOperation(value = "未匹配委托的数据修改车号", notes = "根据传过来的meterWorkCarActual信息来更新车号信息")
    @PostMapping(value = "/updateCar", produces = "application/json;charset=UTF-8")
    public RESTfulResult updateCar(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.updateCar(model);
            if (num >= 1) {
                return success(num);
            } else {
                return failed("修改失败");
            }
        } 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("meterworkcaractual: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);
                meterWorkCarActualService.delete(ids);
            }
            return success();
        } catch (Exception ex) {
           ex.printStackTrace();
throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "新增数据", notes = "根据MeterWorkCarActual对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActual", value = "详细实体MeterWorkCarActual", required = true, dataType = "MeterWorkCarActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/add")
    public RESTfulResult checkandadd(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.checkandadd(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 = "根据MeterWorkCarActual对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActual", value = "详细实体MeterWorkCarActual", required = true, dataType = "MeterWorkCarActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/audit")
    public RESTfulResult audit(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.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 = "根据MeterWorkCarActual对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActual", value = "详细实体MeterWorkCarActual", required = true, dataType = "MeterWorkCarActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/unaudit")
    public RESTfulResult unaudit(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.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 = "根据MeterWorkCarActual对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActual", value = "详细实体MeterWorkCarActual", required = true, dataType = "MeterWorkCarActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/publish")
    public RESTfulResult publish(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.publish(model);
            if (num >= 1) {
                return success(num);
            } else {
                return failed("操作失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "数据撤销发布", notes = "根据MeterWorkCarActual对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActual", value = "详细实体MeterWorkCarActual", required = true, dataType = "MeterWorkCarActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/revocation")
    public RESTfulResult revocation(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.revocation(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<MeterWorkCarActual> pageInfo = meterWorkCarActualService.selectView(parmas, pageNum, pageSize);
            return success(pageInfo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

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

        }
        return rm;
    }

    @ApiOperation(value = "手工录入数据")
    @PostMapping(value = "/manualInput")
    public RESTfulResult manualInput(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.manualInput(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 = "数据结净-C#端")
    @PostMapping(value = "/clientClean")
    public RESTfulResult clientClean(@RequestBody CommonCombination<MeterWorkCarActualFirst, MeterWorkCarActual, MeterWorkCarActualFirst, MeterWorkCarActual> model) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActual num = meterWorkCarActualService.clientClean(model.getOne(), model.getTwo());
            return success(num);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

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

        }
        return rm;
    }

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

        }
        return rm;
    }

    @ApiOperation(value = "解除", notes = "将结净后的数据进行还原且清除委托信息")
    @PostMapping(value = "/remove")
    public RESTfulResult remove(@RequestBody List<MeterWorkCarActual> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.remove(models);
            if (num >= 1) {
                return success(num);
            } else {
                return failed("操作失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }
    @ApiOperation(value = "解除", notes = "将结净后的数据进行还原但不清除委托信息")
    @PostMapping(value = "/removeButNotEntrust")
    public RESTfulResult removeButNotEntrust(@RequestBody List<MeterWorkCarActual> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.removeButNotEntrust(models);
            if (num >= 1) {
                return success(num);
            } else {
                return failed("操作失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

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

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

    // test,后台批处理
    @PostMapping(value = "/testBatchcommonRemove")
    public RESTfulResult testBatchcommonRemove(@RequestBody HashMap params) {

        try {
            int rm = meterWorkCarActualService.batchCommonRemove();
                if (rm >= 1) {
                    return success(rm);
                } else {
                    return failed("操作失败");
                }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            return failed("操作失败");

        } catch (Exception e) {
            e.printStackTrace();
            return failed("操作失败");

        }
    }

    @ApiOperation(value = "查询计量票据录入数据")
    @PostMapping(value = "/selectManualData")
    @Transactional(rollbackFor = Exception.class)
    public RESTfulResult selectManualData(@RequestBody CommonPage<MeterWorkCarActual> oci) throws IOException, ParseException {
        RESTfulResult rm = failed();
        Map<String, Object> map = FieldsCollector.beanToMap(oci.getParam());

        try {
            if (StringUtils.isNotEmpty(oci.getStartTime()) && StringUtils.isNotEmpty(oci.getEndTime())) {
                map.put("startTime", oci.getStartTime());
                map.put("endTime", oci.getEndTime());
            }
            map.put("dataSource", "4");
            PageHelper.startPage(oci.getPageNum(), oci.getPageSize());
            List<MeterWorkCarActual> rows = meterWorkCarActualMapper.selectManualData(map);
            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 = "期限结净")
    @PostMapping(value = "/termclean")
    public RESTfulResult termclean(@RequestParam String actualFirstNo, String dataNo) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActual mwca = meterWorkCarActualService.termclean(actualFirstNo, dataNo);
            return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

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

    @ApiOperation(value = "导出access文件")
    @PostMapping(value = "/doQueryAccessWf")
    @Transactional(rollbackFor = Exception.class)
    public RESTfulResult doQueryAccessWf(@RequestBody CommonPage<MeterWorkCarActual> oci) throws IOException, ParseException {
        RESTfulResult rm = failed();
        Map<String, Object> map = FieldsCollector.beanToMap(oci.getParam());

        try {
            if (StringUtils.isNotEmpty(oci.getStartTime()) && StringUtils.isNotEmpty(oci.getEndTime())) {
                map.put("startTime", oci.getStartTime());
                map.put("endTime", oci.getEndTime());
            }
            map.put("valueFlag", "0");
            PageHelper.startPage(oci.getPageNum(), oci.getPageSize());
            List<MeterWorkCarActual> rows = meterWorkCarActualMapper.selectParameters(map);
            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 = "合同号，业务类型，毛重，皮重，净重")
    @Transactional
    @PostMapping(value = "/insertByNotice")
    public RESTfulResult insertByNotice(@RequestBody MeterWorkCarActual actual) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActual mwca = meterWorkCarActualService.insertByNotice(actual);
            if(mwca!=null )
                return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "按合预报编号,添加计量实绩数据（单包计量）", notes = "合同号，业务类型，毛重，皮重，净重")
    @Transactional
    @PostMapping(value = "/insertByScale")
    public RESTfulResult insertByScale(@RequestBody MeterWorkCarActual actual) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActual mwca = meterWorkCarActualService.insertByScale(actual);
            if(mwca!=null )
                return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "批量修改单包计量的数据", notes = "全校验通过后，才进行修改")
    @Transactional
    @PostMapping(value = "/updateByDanBao")
    public RESTfulResult updateByDanBao(@RequestBody List<MeterWorkCarActual> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.updateByDanBao(models);
            if (num >= 1) {
                return success(num);
            } else {
                return failed("操作失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "批量修改单包计量的数据", notes = "全校验通过后，才进行修改")
    @Transactional
    @PostMapping(value = "/updateByZhuWai")
    public RESTfulResult updateByZhuWai(@RequestBody List<MeterWorkCarActual> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.updateByZhuWai(models);
            if (num >= 1) {
                return success(num);
            } else {
                return failed("操作失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "转换火车实绩到汽车实绩表中", notes = "预报编号，火车实绩编号")
    @Transactional
    @PostMapping(value = "/conversionTrainToCar")
    public RESTfulResult conversionTrainToCar(@RequestParam String predictionNo,String actualNo) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActual carActual = meterWorkCarActualService.conversionTrainToCar(predictionNo, actualNo);
            return success(carActual);
        } 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<String, Object> params) {
        RESTfulResult rm = failed();
        try {
            List<String> rows = meterWorkCarActualService.distinctCarNo(params);
            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<String, Object> params) {
        RESTfulResult rm = failed();
        try {
            List<String> rows = meterWorkCarActualService.distinctCarNo(params);
            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 = "根据MeterWorkCarActual对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActual", value = "详细实体MeterWorkCarActual", required = true, dataType = "MeterWorkCarActual")
    //@RequiresPermissions("meterworkcaractualfirst:create")
    @PostMapping(value = "/checkandadditional")
    public RESTfulResult checkandadditional(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualService.checkandadditional(model);
            if (num == 1) {
                return success(num);
            } else {
                return failed("新增失败");
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "汽车衡净重数据补录", notes = "根据MeterWorkCarActual对象创建")
    @PostMapping(value = "/supplementaryData")
    public RESTfulResult supplementaryData(@RequestBody HashMap map) {
        RESTfulResult rm = failed();
        try {
            SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
            String grossTimeTemp = map.get("grossTime").toString().replaceAll("-", "/");
            String tareTimeTemp = map.get("tareTime").toString().replaceAll("-", "/");
            String netTimeTemp = map.get("netTime").toString().replaceAll("-", "/");

            Date grossTime = simpleFormat.parse(grossTimeTemp);
            Date tareTime = simpleFormat.parse(tareTimeTemp);
            Date netTime = simpleFormat.parse(netTimeTemp);

            MeterWorkCarActual model = new MeterWorkCarActual();
            if(map.get("predictionNo") != null) {
                model.setPredictionNo(map.get("predictionNo").toString());
            }
            model.setBaseSpot1No(map.get("baseSpot1No").toString());
            model.setBaseSpot1Name(map.get("baseSpot1Name").toString());
            model.setGrossManNo(map.get("grossManNo").toString());
            model.setGrossManName(map.get("grossManName").toString());
            model.setGrossTime(grossTime);
            model.setTareTime(tareTime);
            model.setNetTime(netTime);
            model.setBaseSpot2No(map.get("baseSpot2No").toString());
            model.setBaseSpot2Name(map.get("baseSpot2Name").toString());
            model.setCarNo(map.get("carNo").toString());
            model.setGrossWeight(new BigDecimal(map.get("grossWeight").toString()));
            model.setTareWeight(new BigDecimal(map.get("tareWeight").toString()));
            rm = meterWorkCarActualService.supplementaryData(model);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

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

        }
        return rm;
    }

    @ApiOperation(value = "废除标识", notes = "根据List对象，更新valueFlag状态")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"),
            @ApiImplicitParam(name = "meterWorkCarActual", value = "详细实体meterWorkCarActual", required = true, dataType = "MeterWorkCarActual")
    })
    @PutMapping(value = "/abolish", produces = "application/json;charset=UTF-8")
    public RESTfulResult abolish(@RequestBody List<MeterWorkCarActual> models) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkCarActualService.abolish(models);
            return success(rm);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "根据HashMap查询最新的结净信息", notes = "根据HashMap查询最新的结净信息")
    @PostMapping(value = "/selectByMap")
    public RESTfulResult selectByMap(@RequestBody HashMap params) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkCarActualService.selectByMap(params);
            if (rm.getData() != null) {
                return rm;
            }
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "根据实绩编号查询一次计量图片", notes = "实绩编号的两个一次计量编号")
    @GetMapping(value = "/findPictureByActualNo")
    public RESTfulResult findPictureByActualNo(@RequestParam String actualNo) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkCarActualService.findPictureByActualNo(actualNo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "根据时间查询所有秤点的结净已匹配、结净未匹配、结净已上传、结净未上传", notes = "实绩编号的两个一次计量编号")
    @PostMapping(value = "/countAllSpotSate")
    public RESTfulResult countAllSpotSate(@RequestBody HashMap params) {
        try {
            List<HashMap> list = meterWorkCarActualService.countAllSpotSate(params);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "计量统计明细-获取列表", notes = "不分页模糊查询")
    //@RequiresPermissions("meterworkcaractualfirst:view")
    @PostMapping(value = "/carActualDataDetail")
    public RESTfulResult carActualDataDetail(@RequestBody HashMap parmas) {
        try {
            List<MeterWorkCarActual> list = meterWorkCarActualService.carActualDataDetail(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "钢材产品理论量与计量数据对比-获取列表", notes = "分页模糊查询")
    //@RequiresPermissions("meterworkcaractualfirst:view")
    @PostMapping(value = "/netWeightAndTheoryAmount")
    public RESTfulResult netWeightAndTheoryAmount(@RequestBody HashMap parmas) {
        try {
            PageList<HashMap> list = meterWorkCarActualService.netWeightAndTheoryAmount(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "同一辆车找出12小时以内的内倒双委托数据-获取列表", notes = "分页模糊查询")
    //@RequiresPermissions("meterworkcaractualfirst:view")
    @PostMapping(value = "/findCommonAndInnerDouble")
    public RESTfulResult findCommonAndInnerDouble(@RequestBody(required = false) HashMap parmas) {
        try {
            List<MeterWorkCarActualTHJCompare> list = meterWorkCarActualService.findCommonAndInnerDouble(parmas);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

    @ApiOperation(value = "小洁净和负洁净重量比对核查-获取列表", notes = "分页模糊查询")
    //@RequiresPermissions("meterworkcaractualfirst:view")
    @PostMapping(value = "/smallAndNegativeNetWeightRatio")
    public RESTfulResult smallAndNegativeNetWeightRatio(@RequestBody(required = false) HashMap parmas) {
        try {
            PageList<MeterWorkCarActualTHJCompare> list = meterWorkCarActualService.smallAndNegativeNetWeightRatio(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 = "将结净后的数据进行还原;关键词：updateManNo、updateManName、actualNo")
    @PostMapping(value = "/localCommonRemove")
    public RESTfulResult localCommonRemove(@RequestBody HashMap params) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkCarActualService.localCommonRemove(params);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "本地计量-匹配委托", notes = "将结净后的数据进行还原;关键词：updateManNo、updateManName、actualNo、predictionNo、note")
    @PostMapping(value = "/localMatchPrediction")
    public RESTfulResult localMatchPrediction(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkCarActualService.localMatchPrediction(model.getActualNo(), model.getPredictionNo(), model.getUpdateManNo(), model.getPredictionNo(), model.getNote());
            return rm;
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "本地计量-解除委托", notes = "将结净后的数据进行还原;关键词：updateManNo、updateManName、actualNo")
    @PostMapping(value = "/localRemovePrediction")
    public RESTfulResult localRemovePrediction(@RequestBody MeterWorkCarActual model) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActual mwca = meterWorkCarActualService.localRemovePrediction(model);
            return success(mwca);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "修改报表操作原因", notes = "将净重数据进行操作员修改,参数：List<MeterWorkCarActual>")
    @PostMapping(value = "/updateNote")
    public RESTfulResult updateNote(@RequestBody List<MeterWorkCarActual> models) {
        return meterWorkCarActualService.updateNote(models);
    }

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

}
