package com.shzg.project.worn.controller;

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

import com.shzg.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.shzg.framework.aspectj.lang.annotation.Log;
import com.shzg.framework.aspectj.lang.enums.BusinessType;
import com.shzg.project.worn.domain.WornDeclareBill;
import com.shzg.project.worn.service.IWornDeclareBillService;
import com.shzg.framework.web.controller.BaseController;
import com.shzg.framework.web.domain.AjaxResult;
import com.shzg.common.utils.poi.ExcelUtil;
import com.shzg.framework.web.page.TableDataInfo;

/**
 * 申报单查看Controller
 * 
 * @author shzg
 * @date 2026-04-14
 */
@RestController
@RequestMapping("/worn/declareBill")
public class WornDeclareBillController extends BaseController
{
    @Autowired
    private IWornDeclareBillService wornDeclareBillService;

    /**
     * 查询申报单查看列表
     */
    //@PreAuthorize("@ss.hasPermi('worn:declareBill:list')")
    @GetMapping("/list")
    public TableDataInfo list(WornDeclareBill wornDeclareBill)
    {
        startPage();
        if (!SecurityUtils.isAdmin())
        {
            wornDeclareBill.setProjectId(SecurityUtils.getDeptId());
        }
        List<WornDeclareBill> list = wornDeclareBillService.selectWornDeclareBillList(wornDeclareBill);
        return getDataTable(list);
    }

    /**
     * 导出申报单查看列表
     */
    @PreAuthorize("@ss.hasPermi('worn:declareBill:export')")
    @Log(title = "申报单查看", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WornDeclareBill wornDeclareBill)
    {
        List<WornDeclareBill> list = wornDeclareBillService.selectWornDeclareBillList(wornDeclareBill);
        ExcelUtil<WornDeclareBill> util = new ExcelUtil<WornDeclareBill>(WornDeclareBill.class);
        util.exportExcel(response, list, "申报单查看数据");
    }

    /**
     * 获取申报单查看详细信息
     */
    @PreAuthorize("@ss.hasPermi('worn:declareBill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wornDeclareBillService.selectWornDeclareBillById(id));
    }

    /**
     * 新增申报单查看
     */
    /**
     * 新增申报单
     */
    @Log(title = "申报单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WornDeclareBill wornDeclareBill)
    {
        return toAjax(wornDeclareBillService.insertWornDeclareBill(wornDeclareBill));
    }

    /**
     * 修改申报单查看
     */
   // @PreAuthorize("@ss.hasPermi('worn:declareBill:edit')")
    @Log(title = "申报单查看", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody WornDeclareBill wornDeclareBill)
    {
        return toAjax(wornDeclareBillService.updateWornDeclareBill(wornDeclareBill));
    }

    /**
     * 删除申报单查看
     */
    @PreAuthorize("@ss.hasPermi('worn:declareBill:remove')")
    @Log(title = "申报单查看", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wornDeclareBillService.deleteWornDeclareBillByIds(ids));
    }

    /**
     * 根据申报单号查询申报单详情
     */
    @GetMapping("/detail")
    public AjaxResult detail(@RequestParam("billNo") String billNo)
    {
        return AjaxResult.success(wornDeclareBillService.selectWornDeclareBillDetailByBillNo(billNo));
    }

    /**
     * 作废申报单
     */
    @PutMapping("/cancel/{id}")
    public AjaxResult cancel(@PathVariable("id") Long id)
    {
        return toAjax(wornDeclareBillService.cancelWornDeclareBill(id));
    }
}
