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

import com.alibaba.druid.pool.ha.selector.RandomDataSourceRecoverThread;
import com.steerinfo.baseinfo.meterbasespotinfo.model.MeterBaseSpotInfo;
import com.steerinfo.baseinfo.meterbaseuserspot.mapper.MeterBaseUserSpotMapper;
import com.steerinfo.baseinfo.meterbaseuserspot.model.MeterBaseUserSpot;
import com.steerinfo.baseinfo.meterbaseuserspot.service.IMeterBaseUserSpotService;
import com.steerinfo.framework.controller.RESTfulResult;
import com.steerinfo.framework.mapper.IBaseMapper;
import com.steerinfo.framework.service.impl.BaseServiceImpl;
import com.steerinfo.util.SSOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

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

    @Autowired
    private MeterBaseUserSpotMapper meterBaseUserSpotMapper;

    @Override
    protected IBaseMapper<MeterBaseUserSpot, String> getMapper() {
        return meterBaseUserSpotMapper;
    }

    @Override
    public RESTfulResult checkAdd(List<MeterBaseUserSpot> models) {
        RESTfulResult rm = new RESTfulResult();
        rm.setCode("200");
        try{
            int num = 0;
            for(MeterBaseUserSpot model: models) {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
                String afl = sdf.format(new Date());
                String userSpotNo = sdf.format(new Date()) + meterBaseUserSpotMapper.getNewID(afl);
                model.setId(userSpotNo);
                model.setCreateTime(new Date());
                meterBaseUserSpotMapper.insertSelective(model);
                num++;
            }
            rm.setData(num);
            rm.setMessage("");
        }
        catch (Exception e){
            e.printStackTrace();
            rm.setCode("500");
            rm.setMessage(e.getMessage());
        }
        return rm;
    }

    @Override
    public List<MeterBaseUserSpot> queryall(Map<String,Object> parmas)
    {
        return meterBaseUserSpotMapper.selectByParameters(parmas);
    }
}
