package com.huatek.busi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.huatek.busi.dao.BusiSemiAutomaticEvaluateConfigDao;
import com.huatek.busi.dto.BusiSemiAutomaticEvaluateConfigDto;
import com.huatek.busi.entity.BusiSemiAutomaticEvaluateConfig;
import com.huatek.busi.mapper.BusiSemiAutomaticEvaluateConfigMapper;
import com.huatek.busi.service.BusiSemiAutomaticEvaluateConfigService;
import com.huatek.busi.vo.BusiSemiAutomaticEvaluateConfigVo;
import com.huatek.frame.base.util.BeanUtils;
import com.huatek.torch.sql.beans.LocalUser;
import com.huatek.torch.util.tools.UserUtil;
import com.huatek.torch.util.uuid.Uuid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.time.LocalDateTime;

/**
 * @description BusiSemiAutomaticEvaluateConfigServiceImpl
 *
 * @author Kavon
 * @date 2023/11/28 20:52
 */
@Service(interfaceClass = BusiSemiAutomaticEvaluateConfigService.class)
@Transactional(rollbackFor = Exception.class)
public class BusiSemiAutomaticEvaluateConfigServiceImpl implements BusiSemiAutomaticEvaluateConfigService {

    @Autowired
    BusiSemiAutomaticEvaluateConfigMapper busiSemiAutomaticEvaluateConfigMapper;

    @Autowired
    BusiSemiAutomaticEvaluateConfigDao busiSemiAutomaticEvaluateConfigDao;

    @Override
    public BusiSemiAutomaticEvaluateConfigVo findNewestConfig() {
        return busiSemiAutomaticEvaluateConfigMapper.findNewestConfig();
    }

    @Override
    public void updateConfig(String token, BusiSemiAutomaticEvaluateConfigDto dto) {
        BusiSemiAutomaticEvaluateConfig entity = new BusiSemiAutomaticEvaluateConfig();
        BeanUtils.copyPropertiesWithIgnoreNull(dto,entity);
        LocalUser user = UserUtil.getLocalUser(token);
        entity.setUpdateUser(user.getUid());
        entity.setUpdateTime(LocalDateTime.now());
        busiSemiAutomaticEvaluateConfigDao.updateLocal(entity);
    }

    @Override
    public void initConfig(String token) {
        BusiSemiAutomaticEvaluateConfig entity = new BusiSemiAutomaticEvaluateConfig();
        entity.setId(Uuid.getUUID());
        entity.setMark("0");
        LocalUser user = UserUtil.getLocalUser(token);
        entity.setCreateUser(user.getUid());
        entity.setCreateTime(LocalDateTime.now());
        busiSemiAutomaticEvaluateConfigDao.add(entity);
    }
}
