package com.ics.controller.mobile;

import com.ics.admin.domain.ApplyPark;
import com.ics.admin.domain.ApplySettle;
import com.ics.common.utils.ValidatorUtils;
import com.ics.service.IApplyParkService;
import com.ics.admin.service.IParkService;
import com.ics.common.core.controller.BaseController;
import com.ics.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wf.jwtp.annotation.RequiresPermissions;

/**
 * 入园申请 提供者
 *
 * @author zzm
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/applyPark")
public class ApplyParkAPIController extends BaseController {

    @Autowired
    private IApplyParkService applyParkService;

    @Autowired
    private IParkService parkService;


    @RequiresPermissions("member:center:view")
    @GetMapping("get/{id}")
    public R get(@PathVariable("id") Long id) {
        return R.data(applyParkService.selectApplyParkById(id));
    }

    /**
     * 查询入园申请
     */
    @RequiresPermissions("member:center:view")
    @GetMapping("getByCurrentUser")
    public R getByCurrentUser() {
        return R.data(applyParkService.selectApplyParkByCurrentUser(getCurrentUserId()));
    }


    /**
     * 新增保存入园申请
     */
    @RequiresPermissions("member:center:view")
    @PostMapping("save")
    public R addSave(@RequestBody ApplyPark applyPark) {
        ValidatorUtils.validateEntity(applyPark);
        if (applyPark.getParkId() == null) {
            return R.error("请选择园区!");
        }
        applyPark.setStatus(ApplySettle.Status.APPROVING);
        applyPark.setCreateUserId(getCurrentUserId());
        applyPark.setTenantId(parkService.selectParkById(applyPark.getParkId()).getTenantId());
        return toAjax(applyParkService.insertApplyPark(applyPark));
    }

    /**
     * 修改保存入园申请
     */
    @RequiresPermissions("member:center:view")
    @PostMapping("update")
    public R editSave(@RequestBody ApplyPark applyPark) {
        return toAjax(applyParkService.updateApplyPark(applyPark));
    }



}