package com.ruoyi.web.controller.dxp.system.customer;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.dxp.dto.AuditDto;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dxp.domain.UserApply;
import com.ruoyi.dxp.service.IUserApplyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业用户申请Controller
 * 
 * @author jy
 * @date 2022-12-05
 */
@RestController
@RequestMapping("/system/audit/customer")
public class UserApplyController extends BaseController
{
    @Autowired
    private IUserApplyService userApplyService;

    /**
     * 查询企业用户申请列表
     */
    @PreAuthorize("@ss.hasPermi('system/audit:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserApply userApply)
    {
        startPage();
        List<UserApply> list = userApplyService.selectUserApplyList(userApply);
        return getDataTable(list);
    }

    /**
     * 导出企业用户申请列表
     */
    @PreAuthorize("@ss.hasPermi('system/audit:customer:export')")
    @Log(title = "企业用户申请", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserApply userApply)
    {
        List<UserApply> list = userApplyService.selectUserApplyList(userApply);
        ExcelUtil<UserApply> util = new ExcelUtil<UserApply>(UserApply.class);
        util.exportExcel(response, list, "企业用户申请数据");
    }

    /**
     * 获取企业用户申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system/audit:customer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userApplyService.selectUserApplyById(id));
    }

    /**
     * 新增企业用户申请
     */
    @PreAuthorize("@ss.hasPermi('system/audit:customer:add')")
    @Log(title = "企业用户申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserApply userApply)
    {
        return toAjax(userApplyService.insertUserApply(userApply));
    }

    /**
     * 修改企业用户申请
     */
    @PreAuthorize("@ss.hasPermi('system/audit:customer:edit')")
    @Log(title = "企业用户申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserApply userApply)
    {
        return toAjax(userApplyService.updateUserApply(userApply));
    }

    /**
     * 删除企业用户申请
     */
    @PreAuthorize("@ss.hasPermi('system/audit:customer:remove')")
    @Log(title = "企业用户申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userApplyService.deleteUserApplyByIds(ids));
    }

    /**
     * 审核用户
     */
    @PreAuthorize("@ss.hasPermi('system/audit:customer:audit')")
    @Log(title = "企业用户申请", businessType = BusinessType.AUDIT)
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody AuditDto auditDto) {
        return userApplyService.audit(auditDto);
    }
}
