package org.springblade.estate.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;

import javax.validation.Valid;

import org.springblade.common.utils.BeanMapUtil;
import org.springblade.core.mp.support.BladePage;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.estate.dto.CarDTO;
import org.springblade.core.mp.support.Query;
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.Car;
import org.springblade.estate.vo.CarVO;
import org.springblade.estate.wrapper.CarWrapper;
import org.springblade.estate.service.ICarService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
import java.util.Map;

/**
 * 车辆信息 client
 *
 * @author lianghanqiang
 * @since 2021-03-30
 */

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

public class CarClient implements ICarClient {

    private final ICarService carService;
    private final IOrgPositionClient orgPositionClient;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public CarVO detail(@SpringQueryMap Car car) {
        Car detail = carService.getOne(Condition.getQueryWrapper(car));
        return CarWrapper.build().entityVO(detail);
        }

    /**
     * 查询 车辆信息
     */
    @Override
    @GetMapping("/list")
    public List<CarVO> list(@SpringQueryMap Car car) {
        return CarWrapper.build().listVO(carService.list(Condition.getQueryWrapper(car)));
        }



    /**
     * 新增 车辆信息
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Car car) {
        return carService.save(car);
        }

    /**
     * 修改 车辆信息
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Car car) {
        return carService.updateById(car);
        }

    /**
     * 新增或修改 车辆信息
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody Car car) {
        return carService.saveOrUpdate(car);
        }


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

	@Override
	@PostMapping("/page")
	public R<BladePage<CarVO>> page(@RequestBody CarDTO carDto) {
		IPage<Car> carIPage = this.carService.page(Condition.getPage(carDto.getQuery()), Condition.getQueryWrapper(carDto));
		IPage<CarVO> pageVO = CarWrapper.build().pageVO(carIPage);
		return R.data(BladePage.of(pageVO));
	}



}
