package com.fs.hisStore.service.categoryVal;

import cn.hutool.core.util.ObjectUtil;
import com.fs.common.utils.StringUtils;
import com.fs.common.utils.txocr.ContainsResult;
import com.fs.common.utils.txocr.TxOcrClient;
import com.fs.hisStore.domain.FsStoreScrm;
import com.fs.hisStore.service.impl.FsStoreScrmServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: Guos
 * @time: 2025/11/28 下午2:21
 */
@Slf4j
@Component
public class IIIMedicalDeviceCheck extends AbstractHandler{

    @Lazy
    @Autowired
    private FsStoreScrmServiceImpl fsStoreScrmService;

    @Override
    public void afterPropertiesSet() throws Exception {
        ProductCategoryCheckFactory.register("233", this);
    }

    /**
     * 校验
     * @param cateName
     * @param storeId
     * @param medicalDeviceCode 器械编码
     */
    public ContainsResult check(String cateName, Long storeId, String medicalDeviceCode){
        log.info("3类器械验证");
        FsStoreScrm fsStoreScrm = fsStoreScrmService.selectFsStoreByStoreId(storeId);
        ContainsResult result = new ContainsResult();
        if(ObjectUtil.isEmpty(fsStoreScrm)){
            result.setFlag(false);
            result.setMessage("店铺不存在！");
            return result;
        }
        if(StringUtils.isEmpty(fsStoreScrm.getMedicalDevice3())){
            result.setFlag(false);
            result.setMessage("没有上传3类证书不允许选择该分类！");
            return result;
        }
        String medicalDevice3 = fsStoreScrm.getMedicalDevice3();
        String ocrStr = TxOcrClient.ExtractDocBasic(medicalDevice3);
        boolean contains = ocrStr.contains(medicalDeviceCode);
        result.setFlag(contains);
        result.setMessage(contains ? "器械编号符合所选商品分类3类器械标准" : "器械编号不符合所选商品分类3类器械标准");
        return result;
    }

}
