package com.docus.server.collect.basic.ws.impl;

import com.docus.core.util.json.JSON;
import com.docus.log.annotation.TrackGroup;
import com.docus.log.context.TrackHelper;
import com.docus.server.collect.IConverter;
import com.docus.server.collect.IWsResult;
import com.docus.server.collect.basic.ws.IBasicServer;
import com.docus.server.enums.CollectTypeEnum;
import com.docus.server.collect.web.process.VisitorProcessor;
import com.docus.server.collect.web.service.CollectService;
import com.docus.server.record.common.pojo.dto.TBasicDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author wen yongbin
 * @date 2023年2月25日21:56:33
 * @see CollectTypeEnum 枚举
 * @see IConverter 通用转化器
 * @see IWsResult 通用返回结果
 * @see VisitorProcessor 通用处理器
 */
@Service
@Slf4j
public class BasicServerImpl implements IBasicServer {
    @Resource
    private CollectService collectService;

    @Override
    @TrackGroup(
        group = "WEBSERVICE_XML_INSERT_BASIC", retryKey = "basic",
        beanNames = {"wsTBasicConverter", "wsBasicResultImpl"},
        processor = VisitorProcessor.class)
    public String setTBasic(String message) {
        log.info("新增基础数据：{}", message);
        collectService.insertOrUpdateBasic(getValue());
        return null;
    }

    @Override
    @TrackGroup(
        group = "WEBSERVICE_XML_UPDATE_BASIC", retryKey = "basic",
        beanNames = {"wsTBasicConverter", "wsBasicResultImpl"},
        processor = VisitorProcessor.class)
    public String updateTBasic(String message) {
        log.info("修改基础数据：{}", message);
        collectService.insertOrUpdateBasic(getValue());
        return null;
    }

    public TBasicDTO getValue() {
        return JSON.fromJSON((String) TrackHelper.getValue("jsonStr"), TBasicDTO.class);
    }
}

