package com.ruoyi.web.controller.oa;

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

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.oa.domain.CmcPartyA;
import com.ruoyi.oa.service.ICmcPartyAService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * cmc业主单位Controller
 * 
 * @author cmc
 * @date 2024-06-12
 */
@RestController
@RequestMapping("/oa/partyA")
public class CmcPartyAController extends BaseController
{
    @Autowired
    private ICmcPartyAService cmcPartyAService;

    /**
     * 查询cmc业主单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcPartyA cmcPartyA)
    {
        startPage();
        List<CmcPartyA> list = cmcPartyAService.selectCmcPartyAList(cmcPartyA);
        return getDataTable(list);
    }

    /**
     * 导出cmc业主单位列表
     */
    @Log(title = "cmc业主单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcPartyA cmcPartyA)
    {
        List<CmcPartyA> list = cmcPartyAService.selectCmcPartyAList(cmcPartyA);
        ExcelUtil<CmcPartyA> util = new ExcelUtil<CmcPartyA>(CmcPartyA.class);
        util.exportExcel(response, list, "cmc业主单位数据");
    }

    /**
     * 获取cmc业主单位详细信息
     */
    @GetMapping(value = "/{partyAId}")
    public AjaxResult getInfo(@PathVariable("partyAId") String partyAId)
    {
        return success(cmcPartyAService.selectCmcPartyAByPartyAId(partyAId));
    }

    /**
     * 新增cmc业主单位
     */
    @Log(title = "cmc业主单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcPartyA cmcPartyA)
    {
        if (cmcPartyAService.selectCmcPartyAList(new CmcPartyA()).size() + 1 < 1000)
            cmcPartyA.setPartyAId("0" + (cmcPartyAService.selectCmcPartyAList(new CmcPartyA()).size() + 1));
        else
            cmcPartyA.setPartyAId(String.valueOf(cmcPartyAService.selectCmcPartyAList(new CmcPartyA()).size() + 1));
        return toAjax(cmcPartyAService.insertCmcPartyA(cmcPartyA));
    }

    /**
     * 修改cmc业主单位
     */
    @Log(title = "cmc业主单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcPartyA cmcPartyA)
    {
        return toAjax(cmcPartyAService.updateCmcPartyA(cmcPartyA));
    }

    /**
     * 删除cmc业主单位
     */
    @Log(title = "cmc业主单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partyAIds}")
    public AjaxResult remove(@PathVariable String[] partyAIds)
    {
        return success(cmcPartyAService.deleteCmcPartyAByPartyAIds(partyAIds));
    }
}
