import com.sdtool.common.api.BusinessExecutor
import com.sdtool.common.api.ConfigService
import com.sdtool.common.datas.ERPModule
import com.sdtool.common.entity.base.InvokeCallParams
import com.sdtool.common.entity.base.InvokeCallResult
import com.sdtool.common.entity.system.ConfigValue
import com.alibaba.fastjson.JSON
import com.dySweetFishPlugin.sql.dao.OperatorWait
import com.sweetfish.service.RetResult
import org.apache.commons.lang3.StringUtils

import javax.annotation.Resource

class BE_ERP_OrderManager_Read implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {

    @Resource
    private ConfigService configService

    @Override
    String scriptName() {
        return "读取ERP文件管理方式配置"
    }

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

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

    @Override
    boolean needLogin(InvokeCallParams source) {
        return true
    }

    RetResult<InvokeCallResult> execute(InvokeCallParams source) {
        int iManagerKind = configService.getIntRedisConfigValue1("ERPOrderManger", source.supplierCode)
        String orderUploadUrl = ""
        //if (iManagerKind == 1) {
        //样稿文件只用本地模式上传，文件不大，不要去占用七牛空间
        //本地需要一个给前端的上传服务器的地址，通过nginx的配置应该可以借用ERPOrderDownloadCenter
        ConfigValue downloadCenterValue = configService.getRedisConfigValue("ERPOrderDownloadCenter", source.dataSourceId, source.supplierCode)
        if ((downloadCenterValue != null) && (StringUtils.isNotBlank(downloadCenterValue.configValue1))) {
            orderUploadUrl = downloadCenterValue.configValue1
        }
        //}

        def result = [
                managerKind   : iManagerKind,
                orderUploadUrl: orderUploadUrl
        ]
        return RetResult.<InvokeCallResult> successT().result(
                InvokeCallResult.success().data(JSON.toJSONString(result))
        )
    }
}
