Newer
Older
newfiber-data-adapter / src / main / java / org / springnewfiber / dataadapter / xf / service / DataAccessRecordService.java
package org.springnewfiber.dataadapter.xf.service;

import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springnewfiber.dataadapter.config.RequestDataHelper;
import org.springnewfiber.dataadapter.xf.entity.DataAccessRecord;
import org.springnewfiber.dataadapter.xf.enums.EDataAccessType;
import org.springnewfiber.dataadapter.xf.mapper.DataAccessRecordMapper;

/**
 * 数据接入记录 服务实现类
 * @since 2022-06-28 15:06:03
 * @author admin
 */
@Service
@DS("access")
public class DataAccessRecordService extends ServiceImpl<DataAccessRecordMapper, DataAccessRecord> {
	@Async
	public Integer save(EDataAccessType accessType, String dataType, String content){
		RequestDataHelper.setRequestData(new HashMap<String,Object>() {{
			int year=DateUtil.thisYear();
			int month=DateUtil.thisMonth();
			put("t_data_access_record", "t_data_access_record".concat("_").concat(String.valueOf(year)).concat(String.valueOf(month+1)));
		}});
		DataAccessRecord dataAccessRecord = new DataAccessRecord();
		dataAccessRecord.setAccessType(accessType.getCode());
		dataAccessRecord.setDataType(dataType);
		dataAccessRecord.setContent(content);
        dataAccessRecord.setContentHash(DigestUtil.md5Hex(content));
		dataAccessRecord.setCreateDatetime(new Date());
		save(dataAccessRecord);

		return dataAccessRecord.getId();
	}

	public void refreshResult(Integer id, Integer timeConsume, String result){
		DataAccessRecord dataAccessRecord = new DataAccessRecord();
		dataAccessRecord.setId(id);
		dataAccessRecord.setTimeConsume(timeConsume);
		dataAccessRecord.setResult(result);
		updateById(dataAccessRecord);
	}
}