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.datas.RedisKeys
import com.sdtool.common.entity.base.InvokeCallParams
import com.sdtool.common.entity.base.InvokeCallResult
import com.sdtool.common.entity.mall.MallUser
import com.sdtool.common.entity.mall.PosterLocation
import com.alibaba.fastjson2.JSON
import com.dySweetFishPlugin.redis.RedisService
import com.dySweetFishPlugin.sql.dao.OperatorWait
import com.google.common.collect.Lists
import com.sweetfish.convert.json.JsonConvert
import com.sweetfish.service.RetResult

import javax.annotation.Resource

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

    @Resource
    JsonConvert jsonConvert

    @Resource
    RedisService redisService

    @Resource
    NoSqlKeysService keysService

    @Resource
    SupplierInitService supplierService

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

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

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

    @Override
    RetResult<InvokeCallResult> execute(InvokeCallParams source) {
        String keyStr = keysService.getRedisKey(RedisKeys.KEY_ERP_MALL_POSTER_LOCATION,source.supplierCode)
        Map<String,String> docMap = redisService.hgetAll(keyStr)
        List<PosterLocation> resultList = new ArrayList<>()
        docMap.each {
            PosterLocation posterLocation = jsonConvert.convertFrom(PosterLocation.class,it.value)
            posterLocation.imageUrl = supplierService.getFileDownloadUrl(posterLocation.posterLocationImage,"",source.dataSourceId,source.getSupplierCode())
            posterLocation.imageWebUrl = supplierService.getFileWebDownloadUrl(posterLocation.posterLocationImage,"",source.dataSourceId,source.supplierCode)
            resultList.add(posterLocation)
        }
        return RetResult.<InvokeCallResult> successT().result(InvokeCallResult.success().data(JSON.toJSONString(resultList)))
    }
}
