package com.steerinfo.baseinfo.meterbasevehiclerangeconfig.service.impl;

import com.steerinfo.baseinfo.meterbasevehiclerangeconfig.mapper.MeterBaseVehicleRangeConfigMapper;
import com.steerinfo.baseinfo.meterbasevehiclerangeconfig.model.MeterBaseVehicleRangeConfig;
import com.steerinfo.baseinfo.meterbasevehiclerangeconfig.service.IMeterBaseVehicleRangeConfigService;
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.framework.user.UserPayload;
import com.steerinfo.util.PublicMethod;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

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

    @Resource
    private MeterBaseVehicleRangeConfigMapper meterBaseVehicleRangeConfigMapper;

    @Override
    protected IBaseMapper<MeterBaseVehicleRangeConfig, String> getMapper() {
        return meterBaseVehicleRangeConfigMapper;
    }

    @Override
    public PageList<MeterBaseVehicleRangeConfig> likeByDesc(HashMap<String, Object> params, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<MeterBaseVehicleRangeConfig> rows = meterBaseVehicleRangeConfigMapper.likeByDesc(params);
        PageList pageInfo = new PageList(rows);
        return pageInfo;
    }

    @Override
    public MeterBaseVehicleRangeConfig updateModel(MeterBaseVehicleRangeConfig model) {
        String userId;
        String userName;
        try{
            UserPayload payload = UserPayload.getCurrUser();
            userId = payload.getUserCode();
            userName = payload.getUserName();
        }catch(Exception e) {
            userId = "admin";
            userName = "admins";
        }
        model.setUpdateManNo(userId);
        model.setUpdateManName(userName);
        model.setUpdateTime(new Date());
        meterBaseVehicleRangeConfigMapper.updateByPrimaryKeySelective(model);
        return meterBaseVehicleRangeConfigMapper.selectByPrimaryKey(model.getVehicleRangeId());
    }

    @Override
    public MeterBaseVehicleRangeConfig addModel(MeterBaseVehicleRangeConfig model) {
        model.setVehicleRangeId(PublicMethod.IdCreate(3));
        String userId;
        String userName;
        try{
            UserPayload payload = UserPayload.getCurrUser();
            userId = payload.getUserCode();
            userName = payload.getUserName();
        }catch(Exception e) {
            userId = "admin";
            userName = "admins";
        }
        model.setCreateManNo(userId);
        model.setCreateManName(userName);
        model.setCreateTime(new Date());
        model.setValueFlag("1");
        meterBaseVehicleRangeConfigMapper.insert(model);
        return model;
    }
}
