package com.sptg.gateway.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.sptg.common.core.beans.ResultBean;
import com.sptg.common.core.util.JsonUtils;
import com.sptg.estate.api.dto.CarDto;
import com.sptg.estate.api.dto.EstateRepairDto;
import com.sptg.estate.api.entity.Car;
import com.sptg.estate.api.entity.EstateRepair;
import com.sptg.estate.api.feigns.CarFeign;
import com.sptg.permissions.api.entity.ApiLog;
import com.sptg.permissions.api.feigns.SysApiLogFeign;
import com.sptg.statistics.api.entity.SysOperationLog;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * Created By lidexi in 2021/3/18
 * 车辆管理控制层
 **/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/app/car")
public class CarController {

    private final CarFeign carFeign;

    @PostMapping(value = "/saveOrUpdate")
    public Map<String,Object> saveOrUpdate(@RequestBody CarDto carDto){
        Map<String,Object> map = new HashMap<>();
        log.warn("============================APP住户车辆登记或修改车辆信息(/app/car/saveOrUpdate)请求数据===============================");
        log.warn(JsonUtils.objectToJson(carDto));

        carDto.setAuditStatus(0);//新增或者重新编辑都需要重新审核

        if(carDto.getId() == null){//新增
            ResultBean<Boolean> addResultBean = carFeign.addByApp(carDto);
            map.put("result",addResultBean.getData());
        }else{//修改
//            carDto.set
            ResultBean<Boolean> editResultBean = carFeign.edit(carDto);
            map.put("result",editResultBean.getData());
        }

        return map;
    }


    @PostMapping(value = "/page")
    private Map<String,Object> getPage(@RequestBody CarDto carDto){
        Map<String,Object> map = new HashMap<>();
//        EstateRepairDto
        ResultBean<Page<Car>> page = this.carFeign.page(carDto);
        if(page != null){
            map.put("carPage",page.getData());
        }
        return map;
    }
}
