package com.iformall.controller.basic;

import com.iformall.annotation.SystemControllerLog;
import com.iformall.common.ErrorCode;
import com.iformall.common.ResultData;
import com.iformall.controller.base.BaseController;
import com.iformall.domain.po.WxMallFloor;
import com.iformall.service.WxMallBuildingService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("wxMallBuilding")
public class WxMallBuildingController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WxMallBuildingService wxMallBuildingService;

    @ApiOperation("获取楼层楼座数据")
    @GetMapping("getbuildingfloorlist")
    @SystemControllerLog(description = "商城-楼座-获取楼层楼座数据")
    public ResultData getbuildingfloorlist() {
        logger.debug("[" + getIpAddr() + "] WxMallBuildingController::getbuildingfloorlist");
        return wxMallBuildingService.getbuildingfloorlist(getTenantId());
    }

    @ApiOperation("保存楼层楼座面积")
    @PostMapping("saveFloorArea")
    @SystemControllerLog(description = "商城-楼座/楼层-保存面积")
    public ResultData saveFloorArea(@RequestBody WxMallFloor record) {
        logger.debug("[" + getIpAddr() + "] WxMallBuildingController::addBuildingAndFloor");
        if(record == null) {
            return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
        }
        if (record.getId() == null) {
            return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
        }
        if (record.getTotalArea() == null && record.getOperatingArea() == null) {
            return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL);
        }
        record.setTenantId(getTenantId());
        wxMallBuildingService.saveFloorArea(record);
        return new ResultData();
    }

}
