package com.ym.mec.web.controller;

import com.ym.mec.biz.dal.entity.CooperationOrgan;
import com.ym.mec.biz.service.CooperationOrganService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.page.QueryInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RequestMapping("cooperationOrgan")
@Api(tags = "合作单位(教学点)服务")
@RestController
public class CooperationOrganController extends BaseController {

    @Autowired
    private CooperationOrganService cooperationOrganService;

    @ApiOperation(value = "新增合作单位(教学点)")
    @PostMapping("/add")
    public Object add(CooperationOrgan cooperationOrgan) {
        cooperationOrganService.insert(cooperationOrgan);
        return succeed();
    }

    @ApiOperation(value = "删除合作单位(教学点)")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "合作单位(教学点)编号", required = true) @PathVariable("id") Integer id) {
        cooperationOrganService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "修改合作单位(教学点)")
    @PutMapping("/update")
    public Object update(CooperationOrgan cooperationOrgan) {
        cooperationOrgan.setUpdateTime(new Date());
        cooperationOrganService.update(cooperationOrgan);
        return succeed();
    }

    @ApiOperation(value = "分页查询合作单位(教学点)列表")
    @GetMapping("/queryPage")
    public Object queryPage(QueryInfo queryInfo) {
        return succeed(cooperationOrganService.queryPage(queryInfo));
    }

    @ApiOperation(value = "根据机构编号获取合作单位(教学点)列表")
    @GetMapping("/queryByOrganId")
    public Object queryByOrganId(Integer organId){
        return succeed(cooperationOrganService.queryByOrganId(organId));
    }
}
