package com.cool.store.dao;

import com.alibaba.fastjson.JSONObject;
import com.cool.store.dto.log.LineLogInfo;
import com.cool.store.entity.HyPartnerTaskInfoLogDO;
import com.cool.store.enums.OperateTypeEnum;
import com.cool.store.mapper.HyPartnerTaskInfoLogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @Author wxp
 * @Date 2023/6/25 19:41
 * @Version 1.0
 */
@Repository
@Slf4j
public class HyPartnerTaskInfoLogDAO {


    @Resource
    HyPartnerTaskInfoLogMapper hyPartnerTaskInfoLogMapper;


    public int updateByPrimaryKeySelective(HyPartnerTaskInfoLogDO hyPartnerTaskInfoLogDO){
        return hyPartnerTaskInfoLogMapper.updateByPrimaryKeySelective(hyPartnerTaskInfoLogDO);
    }

    public int insertSelective( HyPartnerTaskInfoLogDO record){
        return hyPartnerTaskInfoLogMapper.insertSelective(record);
    }

    /**
     * 新增操作日志
     * @param lineLogInfo
     */
   public void addOperateLog(LineLogInfo lineLogInfo){
        if(!LineLogInfo.checkParams(lineLogInfo)){
            return;
        }
        HyPartnerTaskInfoLogDO logInfo = LineLogInfo.convertDO(lineLogInfo);
        log.info("logInfo:{}", JSONObject.toJSON(lineLogInfo));
        insertSelective(logInfo);
   }

    public  int updateLineId(String newPartnerId,Long newLineId,Long oldLineId){
        if (newLineId==null || Objects.isNull(oldLineId)){
            return 0;
        }
        return hyPartnerTaskInfoLogMapper.updateLineId(newPartnerId,newLineId, oldLineId);
    }

}
