package com.younike.web.controller.system;

import java.util.List;

import com.younike.common.core.domain.entity.SysUserGroup;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.service.ISysUserGroupService;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 小区管理人员和小区关联Controller
 *
 * @author elev
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/system/group")
public class SysUserGroupController extends BaseController
{
    @Autowired
    private ISysUserGroupService sysUserGroupService;

    /**
     * 查询小区管理人员和小区关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserGroup sysUserGroup)
    {
        startPage();
        List<SysUserGroup> list = sysUserGroupService.selectSysUserGroupList(sysUserGroup);
        return getDataTable(list);
    }

    /**
     * 导出小区管理人员和小区关联列表
     */
    @PreAuthorize("@ss.hasPermi('system:group:export')")
    @Log(title = "小区管理人员和小区关联", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysUserGroup sysUserGroup)
    {
        List<SysUserGroup> list = sysUserGroupService.selectSysUserGroupList(sysUserGroup);
        ExcelUtil<SysUserGroup> util = new ExcelUtil<SysUserGroup>(SysUserGroup.class);
        return util.exportExcel(list, "小区管理人员和小区关联数据");
    }

    /**
     * 获取小区管理人员和小区关联详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:group:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return AjaxResult.success(sysUserGroupService.selectSysUserGroupByUserId(userId));
    }

    /**
     * 新增小区管理人员和小区关联
     */
    @PreAuthorize("@ss.hasPermi('system:group:add')")
    @Log(title = "小区管理人员和小区关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserGroup sysUserGroup)
    {
        return toAjax(sysUserGroupService.insertSysUserGroup(sysUserGroup));
    }

    /**
     * 修改小区管理人员和小区关联
     */
    @PreAuthorize("@ss.hasPermi('system:group:edit')")
    @Log(title = "小区管理人员和小区关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserGroup sysUserGroup)
    {
        return toAjax(sysUserGroupService.updateSysUserGroup(sysUserGroup));
    }

    /**
     * 删除小区管理人员和小区关联
     */
    @PreAuthorize("@ss.hasPermi('system:group:remove')")
    @Log(title = "小区管理人员和小区关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(sysUserGroupService.deleteSysUserGroupByUserIds(userIds));
    }
}
