import com.sdtool.business.dao.MallDao
import com.sdtool.common.api.BusinessExecutor
import com.sdtool.common.api.NoSqlKeysService
import com.sdtool.common.api.SupplierInitService
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.mall.PosterLocation
import com.alibaba.fastjson2.JSON
import com.dySweetFishPlugin.redis.RedisService
import com.dySweetFishPlugin.sql.TableIdService
import com.dySweetFishPlugin.sql.dao.OperatorWait
import com.dySweetFishPlugin.sql.dao.TunaService
import com.sweetfish.convert.json.JsonConvert
import com.sweetfish.service.RetResult
import org.rex.RMap

import javax.annotation.Resource

/**
 * @Author: xl Created on 2024-04-01
 * @Content:
 */
class BE_PosterLocation_Search implements BusinessExecutor<InvokeCallParams, InvokeCallResult> {

    @Resource
    TunaService tunaService

    @Resource
    JsonConvert jsonConvert

    @Resource
    TableIdService tableIdService

    @Resource
    RedisService redisService

    @Resource
    NoSqlKeysService keysService

    @Resource
    SupplierInitService supplierService

    private MallDao mallDao

    @Override
    String scriptName() {
        return "商城后台-获取广告位列表"
    }

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

    @Override
    void start(long supplierCode) {
        mallDao = tunaService.generate(MallDao.class)
    }

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

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

    @Override
    RetResult<InvokeCallResult> execute(InvokeCallParams source) {
        RMap params = new RMap<>()
        List<PosterLocation> posterLocationList = mallDao.queryPosterLocation(params, source.page, source.dataSourceId, source.supplierCode)
        posterLocationList.each {
            it.imageUrl = supplierService.getFileDownloadUrl(it.posterLocationImage,"",source.dataSourceId,source.getSupplierCode())
            it.imageWebUrl = supplierService.getFileWebDownloadUrl(it.posterLocationImage,"",source.dataSourceId,source.supplierCode)
        }
        posterLocationList.sort { it.sortIndex }
        return RetResult.<InvokeCallResult> successT().result(InvokeCallResult.success().data(JSON.toJSONString(posterLocationList)).page(source.page))
    }
}
