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

import com.steerinfo.baseinfo.meterbasevehiclerangeconfig.model.MeterBaseVehicleRangeConfig;
import com.steerinfo.baseinfo.meterbasevehiclerangeprintconfig.mapper.MeterBaseVehicleRangePrintConfigMapper;
import com.steerinfo.baseinfo.meterbasevehiclerangeprintconfig.model.MeterBaseVehicleRangePrintConfig;
import com.steerinfo.baseinfo.meterbasevehiclerangeprintconfig.service.IMeterBaseVehicleRangePrintConfigService;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

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

    @Autowired(required = false)
    private MeterBaseVehicleRangePrintConfigMapper meterBaseVehicleRangePrintConfigMapper;

    @Override
    protected IBaseMapper<MeterBaseVehicleRangePrintConfig, String> getMapper() {
        return meterBaseVehicleRangePrintConfigMapper;
    }

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

    @Override
    public MeterBaseVehicleRangePrintConfig updateModel(MeterBaseVehicleRangePrintConfig model) {
        String userId;
        String userName;
        try{
            UserPayload payload = UserPayload.getCurrUser();
            userId = payload.getUserCode();
            userName = payload.getUserName();
        }catch(Exception e) {
            userId = "admin";
            userName = "admins";
        }
        model.setNetWeightUpper(model.getNetWeightUpper()*1000);
        model.setNetWeightLower(model.getNetWeightLower()*1000);
        model.setLoadWeight(model.getLoadWeight()*1000);
        model.setUpdateManNo(userId);
        model.setUpdateManName(userName);
        model.setUpdateTime(new Date());
        meterBaseVehicleRangePrintConfigMapper.updateByPrimaryKeySelective(model);
        return meterBaseVehicleRangePrintConfigMapper.selectByPrimaryKey(model.getVehicleRangeId());
    }

    @Override
    public MeterBaseVehicleRangePrintConfig addModel(MeterBaseVehicleRangePrintConfig 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.setNetWeightUpper(model.getNetWeightUpper()*1000);
        model.setNetWeightLower(model.getNetWeightLower()*1000);
        model.setLoadWeight(model.getLoadWeight()*1000);
        model.setCreateManNo(userId);
        model.setCreateManName(userName);
        model.setCreateTime(new Date());
        model.setValueFlag("1");
        meterBaseVehicleRangePrintConfigMapper.insert(model);
        return model;
    }
}
