package com.platform.service.custom;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.platform.entity.ApiTmDealLogVo;
import com.platform.enums.IdStarterEnum;
import com.platform.service.impl.ApiTmDealLogServiceImpl;
import com.platform.utils.UUidGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author abnerhou
 * @date 2020/9/24 18:31
 * @desciption
 */
@Slf4j
@Service
public class MyApiDealLogService extends ApiTmDealLogServiceImpl {

    public int addNew(ApiTmDealLogVo apiTmDealLogVo){
        if(null == apiTmDealLogVo){
            return -1;
        }
        apiTmDealLogVo.setLogId(UUidGenerator.generatorUuid(IdStarterEnum.DEFAULT_ID.getStarter()));
        apiTmDealLogVo.setEnable(1);
        apiTmDealLogVo.setCreateTime(LocalDateTime.now());
        apiTmDealLogVo.setUpdateTime(LocalDateTime.now());
        return getBaseMapper().insert(apiTmDealLogVo);
    }

    public int updateDealLog(ApiTmDealLogVo apiTmDealLogVo){
        if(null == apiTmDealLogVo){
            return -1;
        }
        QueryWrapper<ApiTmDealLogVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("log_id" , apiTmDealLogVo.getLogId());
        queryWrapper.eq("enable" , 1);
        queryWrapper.last("limit 1");
        ApiTmDealLogVo dbTmDealLogVo = getBaseMapper().selectOne(queryWrapper);
        if(null == dbTmDealLogVo){
            log.error("数据不存在");
            return  -1;
        }
        apiTmDealLogVo.setUpdateTime(LocalDateTime.now());
        return getBaseMapper().update(apiTmDealLogVo , queryWrapper);
    }

}
