package com.steerinfo.meterwork.meterworkcaractualbak.controller;

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.meterworkcaractualbak.mapper.MeterWorkCarActualBakMapper;
import com.steerinfo.meterwork.meterworkcaractualbak.model.MeterWorkCarActualBak;
import com.steerinfo.meterwork.meterworkcaractualbak.service.IMeterWorkCarActualBakService;
import com.steerinfo.baseinfo.meterbasematterinfoold.mapper.MeterBaseMatterInfoOldMapper;
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.meterwork.dto.CommonCombination;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.meterwork.metertolimsold.mapper.MeterToLimsOldMapper;
import com.steerinfo.meterwork.meterworkcaractualfirstbak.controller.MeterWorkCarActualFirstBakController;
import com.steerinfo.meterwork.meterworkcaractualfirstbak.model.MeterWorkCarActualFirstBak;
import com.steerinfo.util.CommonPage;
import com.steerinfo.util.FieldsCollector;
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.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.*;

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

    @Autowired
    IMeterWorkCarActualBakService meterWorkCarActualBakService;

    @Resource
    MeterWorkCarActualBakMapper meterWorkCarActualBakMapper;

    @Resource
    MeterBaseCarMapper meterBaseCarMapper;

    @Resource
    MeterBaseMatterInfoOldMapper meterBaseMatterInfoOldMapper;

    @Resource
    MeterBaseOperationLogMapper meterBaseOperationLogMapper;

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


    @Resource
    MeterToLimsOldMapper meterToLimsOldMapper;

    @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<MeterWorkCarActualBak> list = meterWorkCarActualBakService.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<MeterWorkCarActualBak> list = meterWorkCarActualBakService.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<MeterWorkCarActualBak> list = meterWorkCarActualBakService.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<MeterWorkCarActualBak> list = meterWorkCarActualBakService.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<MeterWorkCarActualBak> list = meterWorkCarActualBakService.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<MeterWorkCarActualBak> list = meterWorkCarActualBakService.likeByDesc(params, 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 = "/likeByValueFlag/")
    public RESTfulResult likeByValueFlag(@RequestBody HashMap params, Integer pageNum, Integer pageSize) {
        try {
            PageList<MeterWorkCarActualBak> list = meterWorkCarActualBakService.likeByDesc(params, 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 = "/likeByValueFlagNoPage/")
    public RESTfulResult likeByValueFlagNoPage(@RequestBody HashMap params) {
        try {
            List<MeterWorkCarActualBak> list = meterWorkCarActualBakService.likeByDescNoPage(params);
            return 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 = "/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<MeterWorkCarActualBak> list = meterWorkCarActualBakService.queryLikeForPage(parmas, pageNum, pageSize);
            return success(list);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new MarkerMetException(500, "操作异常！！");
        }
    }

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

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

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

    @ApiOperation(value = "新增数据", notes = "根据MeterWorkCarActualBak对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActualBak", value = "详细实体MeterWorkCarActualBak", required = true, dataType = "MeterWorkCarActualBak")
    @PostMapping(value = "/add")
    public RESTfulResult checkandadd(@RequestBody MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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 = "根据MeterWorkCarActualBak对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActualBak", value = "详细实体MeterWorkCarActualBak", required = true, dataType = "MeterWorkCarActualBak")
    @PostMapping(value = "/audit")
    public RESTfulResult audit(@RequestBody MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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 = "根据MeterWorkCarActualBak对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActualBak", value = "详细实体MeterWorkCarActualBak", required = true, dataType = "MeterWorkCarActualBak")
    @PostMapping(value = "/unaudit")
    public RESTfulResult unaudit(@RequestBody MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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 = "根据MeterWorkCarActualBak对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActualBak", value = "详细实体MeterWorkCarActualBak", required = true, dataType = "MeterWorkCarActualBak")
    @PostMapping(value = "/publish")
    public RESTfulResult publish(@RequestBody MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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 = "根据MeterWorkCarActualBak对象创建")
    @ApiImplicitParam(name = "MeterWorkCarActualBak", value = "详细实体MeterWorkCarActualBak", required = true, dataType = "MeterWorkCarActualBak")
    @PostMapping(value = "/revocation")
    public RESTfulResult revocation(@RequestBody MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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<MeterWorkCarActualBak> pageInfo = meterWorkCarActualBakService.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 {
            MeterWorkCarActualBak mwca = meterWorkCarActualBakService.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 MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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<MeterWorkCarActualFirstBak, MeterWorkCarActualBak, MeterWorkCarActualFirstBak, MeterWorkCarActualBak> model) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActualBak num = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.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 MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActualBak mwca = meterWorkCarActualBakService.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<MeterWorkCarActualBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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<MeterWorkCarActualBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.commonRemove(params);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        }
        return rm;
    }

    @ApiOperation(value = "查询计量票据录入数据")
    @PostMapping(value = "/selectManualData")
    @Transactional(rollbackFor = Exception.class)
    public RESTfulResult selectManualData(@RequestBody CommonPage<MeterWorkCarActualBak> 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<MeterWorkCarActualBak> rows = meterWorkCarActualBakMapper.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 {
            MeterWorkCarActualBak mwca = meterWorkCarActualBakService.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<MeterWorkCarActualBak> oci) {
        try {
            RESTfulResult rm = meterWorkCarActualBakService.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<MeterWorkCarActualBak> 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<MeterWorkCarActualBak> rows = meterWorkCarActualBakMapper.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 MeterWorkCarActualBak actual) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActualBak mwca = meterWorkCarActualBakService.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 MeterWorkCarActualBak actual) {
        RESTfulResult rm = failed();
        try {
            MeterWorkCarActualBak mwca = meterWorkCarActualBakService.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<MeterWorkCarActualBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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<MeterWorkCarActualBak> models) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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 {
            MeterWorkCarActualBak carActual = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.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")
    @PostMapping(value = "/checkandadditional")
    public RESTfulResult checkandadditional(@RequestBody MeterWorkCarActualBak model) {
        RESTfulResult rm = failed();
        try {
            int num = meterWorkCarActualBakService.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);

            MeterWorkCarActualBak model = new MeterWorkCarActualBak();
            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 = meterWorkCarActualBakService.supplementaryData(model);
        } 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 = "/supplementaryDataExport")
    @Transactional
    public RESTfulResult supplementaryDataExport(@RequestBody List<HashMap> list) {
        RESTfulResult rm = failed();
        try {
            for (HashMap map : list) {
                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);

                MeterWorkCarActualBak model = new MeterWorkCarActualBak();
                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 = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.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<MeterWorkCarActualBak> models) {
        RESTfulResult rm = failed();
        try {
            rm = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.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 = meterWorkCarActualBakService.findPictureByActualNo(actualNo);
        } catch (MarkerMetException e) {
            e.printStackTrace();
            rm.setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            rm.setMessage("操作异常，请确认！");
        } finally {

        }
        return rm;
    }

    @ApiOperation(value = "将数据从MeterWorkCarActualBak复制到MeterWorkCarActual")
    @PostMapping(value = "/copyToActual")
    public RESTfulResult copyToActual(@RequestBody HashMap params){
        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 {
                    meterWorkCarActualBakService.ndCopyToActual(ids,carNo);
                } catch (Exception e) {
                    e.printStackTrace();
                    return failed(null,"复制失败");
                }
            }else if ("001004002".equals(carTypeNo)){//外进外发
                try {
                    meterWorkCarActualBakService.wwCopyToActual(ids,carNo);
                } catch (Exception e) {
                    e.printStackTrace();
                    return failed(null,"复制失败");
                }
            }else{
                return failed(null,"车型编号错误，不存在对应车型");
            }
        }else {
            try {
                meterWorkCarActualBakService.wwCopyToActual(ids,carNo);
            } catch (Exception e) {
                e.printStackTrace();
                return failed(null,"复制失败");
            }
        }
        return success(null,"复制成功");
    }

}
