package com.cyksj.service.error.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.cyksj.mapper.UserRelationChangeErrorRecordMapper;
import com.cyksj.model.entity.UserRelationChangeErrorRecord;
import com.cyksj.model.manage.views.GroupsRelationView;
import com.cyksj.service.error.UserRelationChangeErrorRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/*
 *项目名: netflix
 *文件名: UserRelationChangeErrorRecordServiceImpl
 *创建者: JavaZou
 *创建时间:2023/6/9 10:28
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class UserRelationChangeErrorRecordServiceImpl implements UserRelationChangeErrorRecordService {

	private final UserRelationChangeErrorRecordMapper userRelationChangeErrorRecordMapper;

	@Override
	public void changeTicketErrorRecord(GroupsRelationView relationView, UserRelationChangeErrorRecord.Source source) {
		UserRelationChangeErrorRecord userRelationChangeErrorRecord = new UserRelationChangeErrorRecord();
		BeanUtil.copyProperties(relationView, userRelationChangeErrorRecord);
		userRelationChangeErrorRecord.setSource(source);
		userRelationChangeErrorRecord.setRelationId(relationView.getId());
		if (StrUtil.isNotEmpty(userRelationChangeErrorRecord.getErrorMsg()) && userRelationChangeErrorRecord.getErrorMsg().length() > 1000) {
			userRelationChangeErrorRecord.setErrorMsg(StrUtil.subSufByLength(userRelationChangeErrorRecord.getErrorMsg(), 512));
		}
		userRelationChangeErrorRecordMapper.insert(userRelationChangeErrorRecord);
	}
}
