package com.engine.secret.service.impl;

import cn.hutool.core.convert.Convert;
import com.engine.core.impl.Service;
import com.engine.secret.exception.CustomizeRunTimeException;
import com.engine.secret.instance.AutoGenerateNumberInstance;
import com.engine.secret.service.AutoGenerateNumberService;
import weaver.conn.RecordSet;

import java.util.Map;

/**
 * @author:dxfeng
 * @createTime: 2025/04/16
 * @version: 1.0
 */
public class AutoGenerateNumberServiceImpl extends Service implements AutoGenerateNumberService {

    @Override
    public String getAcceptanceNumber(Map<String, Object> param) {
        Integer secretType = Convert.toInt(param.get("secretType"));
        Integer requestId = Convert.toInt(param.get("requestId"));
        if (null == secretType) {
            throw new CustomizeRunTimeException("未获取到[保密资质（资格）类型]，请检查表单数据");
        }
        // 查询当前请求是否已经生成单号，如已生成过，直接取原来单号，不重新生成
        RecordSet rs = new RecordSet();
        rs.executeQuery("select num from uf_sldh_dt1 where request_id = ? ", requestId);
        if (rs.next()) {
            return rs.getString("num");
        }

        AutoGenerateNumberInstance instance = AutoGenerateNumberInstance.getInstance();
        if (0 == secretType || 1 == secretType) {
            // 集成、印制
            return instance.getAcceptanceNumber(user, param);
        } else {
            // 军工
            return instance.getWarIndustryAcceptanceNumber(user, param);
        }
    }
}
