package com.liquidnet.client.admin.zhengzai.goblin.service.imp;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.liquidnet.client.admin.zhengzai.goblin.service.IGoblinZhengzaiMarketService;
import com.liquidnet.client.admin.zhengzai.goblin.utils.GoblinMongoUtils;
import com.liquidnet.client.admin.zhengzai.goblin.utils.GoblinRedisUtils;
import com.liquidnet.commons.lang.util.IDGenerator;
import com.liquidnet.service.base.ResponseDto;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.GoblinZhengzaiStoreListVo;
import com.liquidnet.service.goblin.dto.vo.GoblinZhengzaiVo;
import com.liquidnet.service.goblin.entity.GoblinSelfMarketing;
import com.liquidnet.service.goblin.mapper.GoblinSelfMarketingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

import static com.liquidnet.commons.lang.util.DateUtil.DTF_YMD_HMS;

/**
 * 正在下单相关
 */
@Service
public class GoblinZhengzaiMarketServiceImpl implements IGoblinZhengzaiMarketService {

    @Autowired
    GoblinRedisUtils goblinRedisUtils;
    @Autowired
    GoblinMongoUtils goblinMongoUtils;
    @Autowired
    GoblinSelfMarketingMapper goblinSelfMarketingMapper;

    @Override
    public ResponseDto<List<GoblinZhengzaiVo>> zhengzaiList(int page, String purchaseName, int status, String st, String et, String ct) {
        return null;
    }

    @Override
    public ResponseDto<Boolean> zhengzaiStatus(String marketId, int status) {
        return null;
    }

    @Override
    public ResponseDto<Boolean> zhengzaiInsert(String purchaseName, String st, String et) {
        GoblinSelfMarketing selfMarketing = GoblinSelfMarketing.getNew();
        String SelfMarketId = IDGenerator.nextTimeId2();
        selfMarketing.setSelfMarketId(SelfMarketId);
        selfMarketing.setName(purchaseName);
        selfMarketing.setType(GoblinStatusConst.MarketingStatus.SELF_TYPE_ZHENGZAI.getValue());
        selfMarketing.setStartTime(LocalDateTime.parse(st, DTF_YMD_HMS));
        selfMarketing.setEndTime(LocalDateTime.parse(et, DTF_YMD_HMS));
        //mysql
        goblinSelfMarketingMapper.insert(selfMarketing);
        //mongo
        goblinMongoUtils.insertSelfMarket(selfMarketing);
        //redis
        goblinRedisUtils.setSelfMarket(SelfMarketId, selfMarketing);
        return ResponseDto.success();
    }

    @Override
    public ResponseDto<Boolean> zhengzaiUpdate(String marketId, String purchaseName, String st, String et) {
        GoblinSelfMarketing selfMarketing = GoblinSelfMarketing.getNew();
        selfMarketing.setName(purchaseName);
        selfMarketing.setType(GoblinStatusConst.MarketingStatus.SELF_TYPE_ZHENGZAI.getValue());
        selfMarketing.setStartTime(LocalDateTime.parse(st, DTF_YMD_HMS));
        selfMarketing.setEndTime(LocalDateTime.parse(et, DTF_YMD_HMS));
        //mysql
        goblinSelfMarketingMapper.update(selfMarketing, Wrappers.lambdaUpdate(GoblinSelfMarketing.getNew()).eq(GoblinSelfMarketing::getSelfMarketId, marketId));
        //mongo
        goblinMongoUtils.updateSelfMarket(marketId, selfMarketing);
        //redis
        goblinRedisUtils.setSelfMarket(marketId, selfMarketing);
        return ResponseDto.success();
    }

    @Override
    public ResponseDto<GoblinZhengzaiVo> zhengzaiDetails(String marketId) {
        return null;
    }

    @Override
    public ResponseDto<String> zhengzaiSkuList(String marketId, String storeId) {
        return null;
    }

    @Override
    public ResponseDto<Boolean> zhengzaiStoreList(String marketId) {
        return null;
    }

    @Override
    public ResponseDto<Boolean> zhengzaiSkuDel(String marketId, String skuId) {
        return null;
    }

    @Override
    public ResponseDto<List<GoblinZhengzaiStoreListVo>> zhengzaiStore(String marketId, String storeId, Integer delTag) {
        return null;
    }
}
