package com.ruoyi.web.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.web.domain.ZdUser;
import com.ruoyi.web.service.IZdUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 账单信息-用户Controller
 * 
 * @author shenzx
 * @date 2025-09-17
 */
@RestController
@RequestMapping("/zd/user")
public class ZdUserController extends BaseController
{
    private IZdUserService zdUserService;
    @Autowired
    public void setZdUserService(IZdUserService zdUserService) {
        this.zdUserService = zdUserService;
    }

    /**
     * 查询账单信息-用户列表
     */
    @PreAuthorize("@ss.hasPermi('zd:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZdUser zdUser)
    {
        startPage();
        QueryWrapper<ZdUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(zdUser);
        List<ZdUser> zdUserList = zdUserService.list(queryWrapper);
        return getDataTable(zdUserList);
    }

    /**
     * 导出账单信息-用户列表
     */
    @PreAuthorize("@ss.hasPermi('zd:user:export')")
    @Log(title = "账单信息-用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZdUser zdUser)
    {
        QueryWrapper<ZdUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(zdUser);
        List<ZdUser> list = zdUserService.list(queryWrapper);
        ExcelUtil<ZdUser> util = new ExcelUtil<>(ZdUser.class);
        util.exportExcel(response, list, "账单信息-用户数据");
    }

    /**
     * 获取账单信息-用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('zd:user:query')")
    @GetMapping(value = "/{zdId}")
    public AjaxResult getInfo(@PathVariable("zdId") Long zdId)
    {
        return success(zdUserService.getById(zdId));
    }

    /**
     * 新增账单信息-用户
     */
    @PreAuthorize("@ss.hasPermi('zd:user:add')")
    @Log(title = "账单信息-用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZdUser zdUser)
    {
        zdUserService.save(zdUser);
        return success(zdUser);
    }

    /**
     * 修改账单信息-用户
     */
    @PreAuthorize("@ss.hasPermi('zd:user:edit')")
    @Log(title = "账单信息-用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZdUser zdUser)
    {
        zdUserService.updateById(zdUser);
        return success(zdUser);
    }

    /**
     * 删除账单信息-用户
     */
    @PreAuthorize("@ss.hasPermi('zd:user:remove')")
    @Log(title = "账单信息-用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{zdIds}")
    public AjaxResult remove(@PathVariable Long[] zdIds)
    {
        return toAjax(zdUserService.removeByIds(Arrays.asList(zdIds)));
    }
}
