package com.ruoyi.system.controller;

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

import com.ruoyi.system.domain.Users;
import com.ruoyi.system.domain.WorkerApply;
import com.ruoyi.system.service.IUsersService;
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.system.domain.Cooperate;
import com.ruoyi.system.service.ICooperateService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业合作Controller
 * 
 * @author ruoyi
 * @date 2025-05-13
 */
@RestController
@RequestMapping("/system/Cooperate")
public class CooperateController extends BaseController
{
    @Autowired
    private ICooperateService cooperateService;
    @Autowired
    private IUsersService usersService;
    /**
     * 查询企业合作列表
     */
    @PreAuthorize("@ss.hasPermi('system:Cooperate:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cooperate cooperate)
    {
        startPage();
        List<Cooperate> list = cooperateService.selectCooperateList(cooperate);
        for(Cooperate data:list){
            Users users = usersService.selectUsersById(data.getUid());
            if (users!=null){
                data.setUname(users.getName());
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出企业合作列表
     */
    @PreAuthorize("@ss.hasPermi('system:Cooperate:export')")
    @Log(title = "企业合作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cooperate cooperate)
    {
        List<Cooperate> list = cooperateService.selectCooperateList(cooperate);
        ExcelUtil<Cooperate> util = new ExcelUtil<Cooperate>(Cooperate.class);
        util.exportExcel(response, list, "企业合作数据");
    }

    /**
     * 获取企业合作详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:Cooperate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cooperateService.selectCooperateById(id));
    }

    /**
     * 新增企业合作
     */
    @PreAuthorize("@ss.hasPermi('system:Cooperate:add')")
    @Log(title = "企业合作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Cooperate cooperate)
    {
        return toAjax(cooperateService.insertCooperate(cooperate));
    }

    /**
     * 修改企业合作
     */
    @PreAuthorize("@ss.hasPermi('system:Cooperate:edit')")
    @Log(title = "企业合作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cooperate cooperate)
    {
        return toAjax(cooperateService.updateCooperate(cooperate));
    }

    /**
     * 删除企业合作
     */
    @PreAuthorize("@ss.hasPermi('system:Cooperate:remove')")
    @Log(title = "企业合作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cooperateService.deleteCooperateByIds(ids));
    }
}
