package com.xinyilu.web.controller.kindergarteninfo;

import com.xinyilu.common.annotation.Log;
import com.xinyilu.common.core.controller.BaseController;
import com.xinyilu.common.core.domain.AjaxResult;
import com.xinyilu.common.core.page.TableDataInfo;
import com.xinyilu.common.custominterface.Insert;
import com.xinyilu.common.custominterface.Update;
import com.xinyilu.common.enums.BusinessType;
import com.xinyilu.system.domain.dto.KindergartenInfoDTO;
import com.xinyilu.system.domain.kindergarteninfo.KindergartenInfo;
import com.xinyilu.system.service.kindergarteninfo.IKindergartenInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 幼儿园信息管理Controller
 *
 * @author jihan
 * @date 2022-07-28
 */
@RestController
@RequestMapping("/system/kindergartenInfo")
public class KindergartenInfoController extends BaseController {

    @Autowired
    private IKindergartenInfoService kindergartenInfoService;

    /**
     * 查询幼儿园信息管理列表
     */
//    @PreAuthorize("@ss.hasPermi('system:kindergartenInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(KindergartenInfoDTO kindergartenInfo) {
        return kindergartenInfoService.selectKindergartenInfoList(kindergartenInfo);
    }

    /**
     * 获取幼儿园信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:kindergartenInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(kindergartenInfoService.selectKindergartenInfoById(id));
    }

    /**
     * 新增幼儿园信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:kindergartenInfo:add')")
    @Log(title = "幼儿园信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody KindergartenInfo kindergartenInfo) {
        //创建人
        kindergartenInfo.setCreateBy(getUsername());
        return kindergartenInfoService.insertKindergartenInfo(kindergartenInfo);
    }

    /**
     * 修改幼儿园信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:kindergartenInfo:edit')")
    @Log(title = "幼儿园信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody KindergartenInfo kindergartenInfo) {
        //修改人
        kindergartenInfo.setUpdateBy(getUsername());
        return kindergartenInfoService.updateKindergartenInfo(kindergartenInfo);
    }

    /**
     * 删除幼儿园信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:kindergartenInfo:remove')")
    @Log(title = "幼儿园信息管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(kindergartenInfoService.updateKindergartenInfoById(ids));
    }

}
