package com.xinyilu.web.controller.parentInfo;

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.parentInfo.ParentInfo;
import com.xinyilu.system.domain.vo.ParentInfoVO;
import com.xinyilu.system.service.parentInfo.IParentInfoService;
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 xinyilu
 * @date 2022-07-29
 */
@RestController
@RequestMapping("/system/parentInfo")
public class ParentInfoController extends BaseController {
    @Autowired
    private IParentInfoService parentInfoService;

    /**
     * 查询家长信息列表
     */
//    @PreAuthorize("@ss.hasPermi('system:parentInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParentInfoVO parentInfo) {
        return parentInfoService.selectParentInfoList(parentInfo);
    }

    /**
     * 获取家长信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:parentInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(parentInfoService.selectParentInfoById(id));
    }

    /**
     * 新增家长信息
     */
    @PreAuthorize("@ss.hasPermi('system:parentInfo:add')")
    @Log(title = "家长信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@Validated(Insert.class) @RequestBody ParentInfo parentInfo) {
        parentInfo.setCreateBy(getUsername());
        return parentInfoService.insertParentInfo(parentInfo);
    }

    /**
     * 修改家长信息
     */
    @PreAuthorize("@ss.hasPermi('system:parentInfo:edit')")
    @Log(title = "家长信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@Validated(Update.class) @RequestBody ParentInfo parentInfo) {
        parentInfo.setUpdateBy(getUsername());
        return parentInfoService.updateParentInfo(parentInfo);
    }

    /**
     * 删除家长信息
     */
    @PreAuthorize("@ss.hasPermi('system:parentInfo:remove')")
    @Log(title = "家长信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(parentInfoService.updateParentInfoByIds(ids));
    }
}
