package com.rongwei.bscommon.sys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rongwei.bscommon.sys.dao.ApsConflictLogDao;
import com.rongwei.bscommon.sys.service.ApsConflictLogService;
import com.rongwei.bsentity.domain.ApsConflictLogDo;
import com.rongwei.rwadmincommon.system.vo.SysUserVo;
import com.rongwei.safecommon.utils.CXCommonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Objects;

/**
 * ApsConflictLogServiceImpl class
 *
 * @author XH
 * @date 2024/10/22
 */
@Service
public class ApsConflictLogServiceImpl extends ServiceImpl<ApsConflictLogDao, ApsConflictLogDo> implements ApsConflictLogService {

    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
    @Autowired
    private HttpServletRequest httpServletRequest;

    public void recordLog(String processequid, String aboutid,
                          String conflictname, int conflictstate, SysUserVo sysUserVo) {
        if (sysUserVo == null) {
            sysUserVo = CXCommonUtils.getCurrentUser();
        }
        ApsConflictLogDo apsConflictLogDo = new ApsConflictLogDo();
        apsConflictLogDo.setAboutid(aboutid);
        apsConflictLogDo.setConflictstate(conflictstate == 1 ? "增加" : "删除");
        apsConflictLogDo.setProcessequid(processequid);
        apsConflictLogDo.setConflictname(conflictname);
        apsConflictLogDo.setOperation(httpServletRequest.getRequestURI());
        apsConflictLogDo.setCreatedate(new Date());
        apsConflictLogDo.setCreateuserid(sysUserVo.getId());
        apsConflictLogDo.setCreateusername(sysUserVo.getName());
        asyncSave(apsConflictLogDo);
    }
    @Async("customThreadPool")
    public void asyncSave(ApsConflictLogDo apsConflictLogDo){
        this.save(apsConflictLogDo);
    }
}
