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

import com.steerinfo.baseinfo.meterbaserfidinfo.mapper.MeterBaseRfidInfoMapper;
import com.steerinfo.baseinfo.meterbaserfidinfo.model.MeterBaseRfidInfo;
import com.steerinfo.baseinfo.meterbaserfidinfo.service.IMeterBaseRfidInfoService;
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 org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

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

    @Autowired(required = false)
    private MeterBaseRfidInfoMapper meterBaseRfidInfoMapper;

    @Override
    protected IBaseMapper<MeterBaseRfidInfo, String> getMapper() {
        return meterBaseRfidInfoMapper;
    }

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

    @Override
    public List<String> carNoByNoPage(HashMap<String, Object> parmas) {
        return meterBaseRfidInfoMapper.carNoByNoPage(parmas);
    }

    @Override
    public MeterBaseRfidInfo checkAndAdd(HashMap<String, Object> map) {
        MeterBaseRfidInfo model = new MeterBaseRfidInfo();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String no = meterBaseRfidInfoMapper.getNewID(sdf.format(new Date()));
        model.setRfidId(sdf.format(new Date()) + no);
        model.setRfidCode(map.get("rfidCode").toString());
        model.setCarNo(map.get("carNo").toString());
        model.setCreateTime(new Date());
        UserPayload payload = UserPayload.getCurrUser();
        String userId = payload.getUserCode();
        String userName = payload.getUserName();
        model.setCreateManNo(userId);
        model.setCreateManName(userName);
        model.setValueFlag("0");
        int i = meterBaseRfidInfoMapper.insertSelective(model);
        if(i >= 1) {
            return model;
        }else {
            return null;
        }
    }
}
