package com.brilliance.isc.common.bopset.counter.service.impl;

import com.brilliance.isc.common.bopset.counter.mapper.CounterBopdecMapper;
import com.brilliance.isc.common.bopset.counter.service.CounterBopdecService;
import com.brilliance.isc.counter.service.SerialCounterService;
import com.brilliance.mda.runtime.mda.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class CounterBopdecServiceImpl implements CounterBopdecService {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private CounterBopdecMapper counterBopdecMapper;

    @Value("${counter.step:1}")
    private Integer step;

    @Value("${counter.start:1}")
    private Integer start;

    @Autowired
    private SerialCounterService serialCounterService;

    @Override
    public int dbBopdecCounter(String couNam, Date dat) {
        //处理并发场景，替换原有发号逻辑
        String vcounam = Strings.trim(couNam);
        return (int) serialCounterService.genSerialNumberByDb("bopcou",vcounam,dat);
        /*
        Integer couval = counterBopdecMapper.getCountValWithUpdate(couNam,dat);
        if(couval != null)
        {
            try {
                couval = counterBopdecMapper.getCountValWithUpdate(couNam,dat);
                if(couval != null) {
                    counterBopdecMapper.updateCounter(couNam,dat); //计算器增加
                }
            }catch (Exception e){
                logger.debug("主键生成异常:{}",e);
                throw(new CommonServiceException("主键生成异常"));
            }finally {
            }
        }else{
            counterBopdecMapper.insertCounter(couNam,start,step,dat); //插入新数
        }
        couval = counterBopdecMapper.getCountValWithUpdate(couNam,dat);
        return couval;
         */
    }
}
