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

/**
 * cmc合作单位Controller
 * 
 * @author cmc
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/oa/partner")
public class CmcPartnerController extends BaseController
{
    @Autowired
    private ICmcPartnerService cmcPartnerService;

    /**
     * 查询cmc合作单位列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmcPartner cmcPartner)
    {
        startPage();
        List<CmcPartner> list = cmcPartnerService.selectCmcPartnerList(cmcPartner);
        return getDataTable(list);
    }

    /**
     * 导出cmc合作单位列表
     */
    @Log(title = "cmc合作单位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmcPartner cmcPartner)
    {
        List<CmcPartner> list = cmcPartnerService.selectCmcPartnerList(cmcPartner);
        ExcelUtil<CmcPartner> util = new ExcelUtil<CmcPartner>(CmcPartner.class);
        util.exportExcel(response, list, "cmc合作单位数据");
    }

    /**
     * 获取cmc合作单位详细信息
     */
    @GetMapping(value = "/{partnerId}")
    public AjaxResult getInfo(@PathVariable("partnerId") String partnerId)
    {
        return success(cmcPartnerService.selectCmcPartnerByPartnerId(partnerId));
    }

    /**
     * 新增cmc合作单位
     */
    @Log(title = "cmc合作单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmcPartner cmcPartner)
    {
        if (cmcPartnerService.selectCmcPartnerList(new CmcPartner()).size() + 1 < 1000)
            cmcPartner.setPartnerId("0" + (cmcPartnerService.selectCmcPartnerList(new CmcPartner()).size() + 1));
        else
            cmcPartner.setPartnerId(String.valueOf(cmcPartnerService.selectCmcPartnerList(new CmcPartner()).size() + 1));
        return toAjax(cmcPartnerService.insertCmcPartner(cmcPartner));
    }

    /**
     * 修改cmc合作单位
     */
    @Log(title = "cmc合作单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmcPartner cmcPartner)
    {
        return toAjax(cmcPartnerService.updateCmcPartner(cmcPartner));
    }

    /**
     * 删除cmc合作单位
     */
    @Log(title = "cmc合作单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partnerIds}")
    public AjaxResult remove(@PathVariable String[] partnerIds)
    {
        return success(cmcPartnerService.deleteCmcPartnerByPartnerIds(partnerIds));
    }
}
