package com.gic.haoban.manage.service.service.out.impl.hm;

import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.dto.hm.HmLinkVisitLogDTO;
import com.gic.haoban.manage.api.service.hm.HmLinkVisitLogApiService;
import com.gic.haoban.manage.service.errorcode.HaoBanErrCode;
import com.gic.haoban.manage.service.pojo.bo.hm.HmLinkBO;
import com.gic.haoban.manage.service.service.hm.HmLinkService;
import com.gic.haoban.manage.service.service.hm.HmLinkVisitLogService;

@Service("hmLinkVisitLogApiService")
public class HmLinkVisitLogApiServiceImpl implements HmLinkVisitLogApiService {

    private static org.apache.logging.log4j.Logger log = LogManager.getLogger(HmLinkVisitLogApiService.class);
    
    @Autowired
    private HmLinkVisitLogService hmLinkVisitLogService;
    
    @Autowired
    private HmLinkService hmLinkService;

    @Override
    public ServiceResponse<Void> save(String enterpriseId ,String unionid, String linkShortCode) {
        HmLinkVisitLogDTO dto = new HmLinkVisitLogDTO();
        HmLinkBO link = this.hmLinkService.getByLinkShortCode(linkShortCode);
        if (null == link) {
            log.info("链接不存在,linkShortCode={}", linkShortCode);
            return ServiceResponse.failure(HaoBanErrCode.ERR_OTHER.getCode(), "链接不存在");
        }
        dto.setLinkId(link.getLinkId());
        dto.setUnionId(unionid);
        dto.setWxEnterpriseId(link.getWxEnterpriseId());
        dto.setEnterpriseId(enterpriseId);
        this.hmLinkVisitLogService.save(dto);
        return ServiceResponse.success();
    }
}
