package com.xinelu.manage.controller.crowdinfo;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.domain.R;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.crowdinfo.CrowdInfo;
import com.xinelu.manage.service.crowdinfo.ICrowdInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 人群信息Controller
 *
 * @author xinelu
 * @date 2024-03-04
 */
@Api(tags = "人群信息控制器")
@RestController
@RequestMapping("/manage/crowdInfo")
public class CrowdInfoController extends BaseController {
    @Resource
    private ICrowdInfoService crowdInfoService;

	/**
	 * 分页查询人群信息列表
	 */
	@PreAuthorize("@ss.hasPermi('manage:crowdInfo:list')")
	@GetMapping("/list")
    public TableDataInfo list(CrowdInfo crowdInfo) {
        startPage();
        List<CrowdInfo> list = crowdInfoService.selectCrowdInfoList(crowdInfo);
        return getDataTable(list);
    }

	/**
	 * 查询人群信息列表
	 */
	@ApiOperation("查询人群信息列表")
	@GetMapping("/getList")
	public R<List<CrowdInfo>> getList(CrowdInfo crowdInfo) {
		List<CrowdInfo> list = crowdInfoService.selectCrowdInfoList(crowdInfo);
		return R.ok(list);
	}

    /**
     * 导出人群信息列表
     */
    @PreAuthorize("@ss.hasPermi('manage:crowdInfo:export')")
    @Log(title = "人群信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrowdInfo crowdInfo) {
        List<CrowdInfo> list = crowdInfoService.selectCrowdInfoList(crowdInfo);
        ExcelUtil<CrowdInfo> util = new ExcelUtil<CrowdInfo>(CrowdInfo. class);
        util.exportExcel(response, list, "人群信息数据");
    }

    /**
     * 获取人群信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:crowdInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(crowdInfoService.selectCrowdInfoById(id));
    }

    /**
     * 新增人群信息
     */
    @PreAuthorize("@ss.hasPermi('manage:crowdInfo:add')")
    @Log(title = "人群信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrowdInfo crowdInfo) {
        return toAjax(crowdInfoService.insertCrowdInfo(crowdInfo));
    }

    /**
     * 修改人群信息
     */
    @PreAuthorize("@ss.hasPermi('manage:crowdInfo:edit')")
    @Log(title = "人群信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrowdInfo crowdInfo) {
        return toAjax(crowdInfoService.updateCrowdInfo(crowdInfo));
    }

    /**
     * 删除人群信息
     */
    @PreAuthorize("@ss.hasPermi('manage:crowdInfo:remove')")
    @Log(title = "人群信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(crowdInfoService.deleteCrowdInfoByIds(ids));
    }
}
