package com.mortals.xhx.modules.arameter.service.impl;

import cn.hutool.core.date.DateTime;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.xhx.common.utils.SnowFlakeUtil;
import com.mortals.xhx.modules.arameter.dao.ArameterDao;
import com.mortals.xhx.modules.arameter.model.ArameterEntity;
import com.mortals.xhx.modules.arameter.service.ArameterService;
import org.springframework.stereotype.Service;
import com.mortals.framework.service.impl.AbstractCRUDServiceImpl;

/**
* <p>Title: 表</p>
* <p>Description: ArameterService service接口 </p>
* <p>Copyright: Copyright &reg;  </p>
* @version 1.0.0
*/
@Service("arameterService")
public class ArameterServiceImpl extends AbstractCRUDCacheServiceImpl<ArameterDao, ArameterEntity, Long> implements ArameterService {
    @Override
    protected void saveBefore(ArameterEntity entity, Context context) throws AppException {
        if (entity.newEntity()){
            entity.setId(SnowFlakeUtil.get().nextId());
            entity.setCreatorId(String.valueOf(context.getUser().getId()));
            //固定阈值，先写死
            entity.setThresholdValue("6");
            entity.setCreateTime(DateTime.now());
            entity.setUpdateTime(entity.getUpdateTime());
        }
        super.saveBefore(entity, context);
    }

    @Override
    protected String getExtKey(ArameterEntity data) {

        return "sysCode";
    }

}