import com.sdtool.business.dao.MallDao
import com.sdtool.common.api.BusinessExecutor
import com.sdtool.common.api.NoSqlKeysService
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.PosterLocation
import com.sdtool.common.entity.site.ERPTokenUser
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 javax.annotation.Resource

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

    @Resource
    TunaService tunaService

    @Resource
    JsonConvert jsonConvert

    @Resource
    TableIdService tableIdService

    @Resource
    RedisService redisService

    @Resource
    NoSqlKeysService keysService

    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.ASNYC
    }

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

    @Override
    RetResult<InvokeCallResult> execute(InvokeCallParams source) {
        PosterLocation posterLocation = jsonConvert.convertFromO(PosterLocation.class,source.params)
        PosterLocation.update(posterLocation,source.currentUser.id)

        int iData = mallDao.editPosterLocation(posterLocation,source.dataSourceId,source.supplierCode)
        if (iData > 0) {
            redisService.hset(keysService.getRedisKey(RedisKeys.KEY_ERP_MALL_POSTER_LOCATION,source.supplierCode),
            String.valueOf(posterLocation.id),jsonConvert.convertTo(posterLocation))
            return RetResult.successT()
        } else return RetResult.error().retinfo(" 修改广告位失败")
    }
}
