package com.fzm.mall.server.admin.opration.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.fzm.mall.server.admin.constant.MallResponseError;
import com.fzm.mall.server.admin.exception.MyException;
import com.fzm.mall.server.admin.opration.entity.dto.FloorGoodsDTO;
import com.fzm.mall.server.admin.opration.entity.dto.FloorGoodsSaveDTO;
import com.fzm.mall.server.admin.opration.model.FloorGoods;
import com.fzm.mall.server.admin.opration.mapper.FloorGoodsMapper;
import com.fzm.mall.server.admin.opration.model.Keyword;
import com.fzm.mall.server.admin.opration.service.IFloorGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzm.mall.server.admin.util.CopyUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 运营中心-首页楼层 服务实现类
 * </p>
 *
 * @author fzm
 * @since 2021-03-23
 */
@Service
@Transactional
public class FloorGoodsServiceImpl extends ServiceImpl<FloorGoodsMapper, FloorGoods> implements IFloorGoodsService {

    @Resource
    private FloorGoodsMapper floorGoodsMapper;

    @Override
    public void save(FloorGoodsSaveDTO floorGoodsSaveDTO) {
        FloorGoods floorGoods = CopyUtil.to(floorGoodsSaveDTO, FloorGoods.class);
        floorGoods.init();
        floorGoodsMapper.insert(floorGoods);
    }

    @Override
    public void delete(String operationFloorId, String goodsId) {
        UpdateWrapper<FloorGoods> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("operation_floor_id", operationFloorId)
                .eq("goods_id", goodsId)
                .set("status", true);
        floorGoodsMapper.update(null, updateWrapper);
    }

    @Override
    public List<FloorGoodsDTO> listAll(String operationFloorId) {
        List<FloorGoods> result = floorGoodsMapper.listAll(operationFloorId);
        return CopyUtil.toList(result, FloorGoodsDTO.class);
    }
}
