import com.sdtool.common.api.BusinessExecutor
import com.sdtool.common.datas.ERPModule
import com.sdtool.common.entity.base.InvokeCallParams
import com.sdtool.common.entity.base.InvokeCallResult
import com.alibaba.fastjson2.JSON
import com.dySweetFishPlugin.sql.dao.OperatorWait
import com.sweetfish.service.RetResult
import groovy.io.FileType

import javax.annotation.Resource

class BE_SiteConfig_List implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {

    @Resource(name = "APP_HOME")
    private String appHome

    @Override
    String scriptName() {
        return "读取网站配置列表"
    }

    @Override
    ERPModule module() {
        return ERPModule.CONFIG
    }

    @Override
    OperatorWait getAWait(InvokeCallParams s) {
        return OperatorWait.SYNC
    }

    RetResult<InvokeCallResult> execute(InvokeCallParams source) {
        def siteConfigFile = new File(appHome + File.separator +
                "conf" + File.separator +
                "script" + File.separator +
                source.supplierCode + File.separator +
                "config" + File.separator)

        def jsonFiles = []
        siteConfigFile.eachFile(FileType.FILES) { file ->
            if (file.name.endsWith('_SiteConfig.json')) {
                jsonFiles << file.name - '_SiteConfig.json'
            }
        }

        return RetResult.<InvokeCallResult> successT().result(
                InvokeCallResult.success().data(JSON.toJSONString(jsonFiles))
        )
    }
}



