package org.springblade.estate.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.expand.feign.IOrgPositionClient;
import org.springblade.system.expand.util.QueryWrapperUtil;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.estate.entity.ParkingSpace;
import org.springblade.estate.vo.ParkingSpaceVO;
import org.springblade.estate.wrapper.ParkingSpaceWrapper;
import org.springblade.estate.service.IParkingSpaceService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 * 车位信息 client
 *
 * @author lianghanqiang
 * @since 2021-03-30
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/parkingspace")

public class ParkingSpaceClient implements IParkingSpaceClient {

    private final IParkingSpaceService parkingSpaceService;
    private final IOrgPositionClient orgPositionClient;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public ParkingSpaceVO detail(@SpringQueryMap ParkingSpace parkingSpace) {
        ParkingSpace detail = parkingSpaceService.getOne(Condition.getQueryWrapper(parkingSpace));
        return ParkingSpaceWrapper.build().entityVO(detail);
        }

    /**
     * 查询 车位信息
     */
    @Override
    @GetMapping("/list")
    public List<ParkingSpaceVO> list(@SpringQueryMap ParkingSpace parkingSpace) {
		LambdaQueryWrapper<ParkingSpace> queryWrapper = new QueryWrapperUtil<ParkingSpace>().getBasicQueryWrapper(ParkingSpace::getOrgPosition, parkingSpace, AuthUtil.getUser(), orgPositionClient);
		return ParkingSpaceWrapper.build().listVO(parkingSpaceService.list(queryWrapper));
        }



    /**
     * 新增 车位信息
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody ParkingSpace parkingSpace) {
        return parkingSpaceService.save(parkingSpace);
        }

    /**
     * 修改 车位信息
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody ParkingSpace parkingSpace) {
        return parkingSpaceService.updateById(parkingSpace);
        }

    /**
     * 新增或修改 车位信息
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody ParkingSpace parkingSpace) {
        return parkingSpaceService.saveOrUpdate(parkingSpace);
        }


    /**
     * 删除 车位信息
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return parkingSpaceService.deleteLogic(Func.toLongList(ids));
        }


}
