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

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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.FloorDTO;
import com.fzm.mall.server.admin.opration.entity.dto.FloorSaveDTO;
import com.fzm.mall.server.admin.opration.mapper.FloorMapper;
import com.fzm.mall.server.admin.opration.model.Floor;
import com.fzm.mall.server.admin.opration.service.IFloorService;
import com.fzm.mall.server.admin.util.CopyUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

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

    @Override
    public void save(FloorSaveDTO floorSaveDTO) {
        Floor floor = CopyUtil.to(floorSaveDTO, Floor.class);
        floor.init();

        this.save(floor);
    }

    @Override
    public List<FloorDTO> listAll() {
        QueryWrapper<Floor> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("display_order").orderByDesc("update_time");
        List<Floor> list = this.list(queryWrapper);

        return CopyUtil.toList(list, FloorDTO.class);
    }
}
