package com.steerinfo.pretrack.prehookscale.service.impl;

import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.framework.service.pagehelper.PageHelper;
import com.steerinfo.framework.service.pagehelper.PageList;
import com.steerinfo.meterwork.except.MarkerMetException;
import com.steerinfo.pretrack.prehookscale.model.PreHookScale;
import com.steerinfo.pretrack.prehookscale.mapper.PreHookScaleMapper;
import com.steerinfo.pretrack.prehookscale.service.IPreHookScaleService;
import com.steerinfo.pretrack.prerailwayscale.model.PreRailwayScale;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * PreHookScale服务实现：
 * @author generator
 * @version 1.0-SNAPSHORT 2022-01-21 11:24
 * 类描述
 * 修订历史：
 * 日期：2022-01-21
 * 作者：generator
 * 参考：
 * 描述：PreHookScale服务实现
 * @see null
 * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
 */
@Service(value = "preHookScaleService")
public class PreHookScaleServiceImpl extends BaseServiceImpl<PreHookScale, String> implements IPreHookScaleService {

    @Autowired
    private PreHookScaleMapper preHookScaleMapper;

    @Override
    protected IBaseMapper<PreHookScale, String> getMapper() {
        return preHookScaleMapper;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public PageList<PreHookScale> selectlist(String railwayNo, Integer pageNum, Integer pageSize) {
        if (railwayNo == null && "".equals(railwayNo)) {
            throw new MarkerMetException(500, "车号为空!!");
        }
        PageHelper.startPage(pageNum, pageSize);
        List<PreHookScale> list = preHookScaleMapper.selectlist(railwayNo);
        PageList pageInfo = new PageList(list);
        return pageInfo;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public PageList<PreHookScale> selectPre(HashMap map) {
        int pageNum = map.get("pageNum") == null ? 1 : Integer.parseInt(map.get("pageNum").toString());
        int pageSize = map.get("pageSize") == null ? 20 : Integer.parseInt(map.get("pageSize").toString());
        PageHelper.startPage(pageNum, pageSize);
        List<PreHookScale> list = preHookScaleMapper.selectPre(map);
        PageList pageInfo = new PageList(list);
        return pageInfo;
    }

    public PageList<PreHookScale> queryLikeForRailwayNo(Map<String, Object> parameters, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        String railwayNo = (String) parameters.get("railwayNo");
        String valueFlag = (String) parameters.get("valueFlag");
        List<PreHookScale> list = preHookScaleMapper.selectLikeByRailwayNo(railwayNo,valueFlag);
        PageList pageInfo = new PageList(list);
        return pageInfo;
    }
}
