package com.ruoyi.web.controller.back;

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

import com.ruoyi.web.task.ZyTask;
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.voluntary.domain.BusiScoreLock;
import com.ruoyi.voluntary.service.IBusiScoreLockService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 志愿锁分Controller
 *
 * @author voluntary
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/voluntary/busiScoreLock")
public class BackBusiScoreLockController extends BaseController
{
    @Autowired
    private IBusiScoreLockService busiScoreLockService;
    @Autowired
    private ZyTask zyTask;

    /**
     * 查询志愿锁分列表
     */
    @PreAuthorize("@ss.hasPermi('voluntary:busiScoreLock:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusiScoreLock busiScoreLock)
    {
        startPage();
        List<BusiScoreLock> list = busiScoreLockService.selectBusiScoreLockList(busiScoreLock);
        return getDataTable(list);
    }

    /**
     * 导出志愿锁分列表
     */
    @PreAuthorize("@ss.hasPermi('voluntary:busiScoreLock:export')")
    @Log(title = "志愿锁分", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusiScoreLock busiScoreLock)
    {
        List<BusiScoreLock> list = busiScoreLockService.selectBusiScoreLockList(busiScoreLock);
        ExcelUtil<BusiScoreLock> util = new ExcelUtil<BusiScoreLock>(BusiScoreLock.class);
        util.exportExcel(response, list, "志愿锁分数据");
    }

    /**
     * 获取志愿锁分详细信息
     */
    @PreAuthorize("@ss.hasPermi('voluntary:busiScoreLock:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(busiScoreLockService.selectBusiScoreLockById(id));
    }

    /**
     * 新增志愿锁分
     */
    @PreAuthorize("@ss.hasPermi('voluntary:busiScoreLock:add')")
    @Log(title = "志愿锁分", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusiScoreLock busiScoreLock)
    {
        int count = busiScoreLockService.insertBusiScoreLock(busiScoreLock);
        zyTask.updateUserScoreLock();
        return toAjax(count);
    }

    /**
     * 修改志愿锁分
     */
    @PreAuthorize("@ss.hasPermi('voluntary:busiScoreLock:edit')")
    @Log(title = "志愿锁分", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusiScoreLock busiScoreLock)
    {
        int count = busiScoreLockService.updateBusiScoreLock(busiScoreLock);
        zyTask.updateUserScoreLock();
        return toAjax(count);
    }

    /**
     * 删除志愿锁分
     */
    @PreAuthorize("@ss.hasPermi('voluntary:busiScoreLock:remove')")
    @Log(title = "志愿锁分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busiScoreLockService.deleteBusiScoreLockByIds(ids));
    }
}
