import com.sdtool.common.api.BusinessExecutor
import com.sdtool.common.datas.ERPModule
import com.sdtool.common.entity.base.ProcessStringItem
import com.sweetfish.service.RetResult
import groovy.json.JsonSlurper
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger

import javax.annotation.Resource

@SuppressWarnings("unused")
class BE_System_TestListExt implements BusinessExecutor<ProcessStringItem, ProcessStringItem> {

    protected final Logger logger = LogManager.getLogger(this.getClass().getSimpleName())

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

    @Override
    String scriptName() {
        return "测试Groovy扩展方法是否成功"
    }

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

    void start(long supplierCode) {
        def jsonSlurper = new JsonSlurper()

        def testTableJsonFile = new File(appHome + File.separator +
                "conf" + File.separator +
                "script" + File.separator +
                "1000" + File.separator +
                "quoteFiles" + File.separator +
                "testTable.json")
        def testTableJsonArray = jsonSlurper.parse(testTableJsonFile)

        logger.info(testTableJsonArray.findQuotedElement(["规格": "正度", "开数": "16开"]))
        logger.info(testTableJsonArray.findQuotedElements(["规格": "大度", "开数": "8开"]))
    }

    RetResult<ProcessStringItem> execute(ProcessStringItem source) {
        return RetResult.<ProcessStringItem> successT().result(
                ProcessStringItem.newBuilder()
                        .itemValue("此代码无需执行，主要用于扩展Groovy方法，简化书写")
                        .build()
        )
    }
}
