package com.aucma.production.controller;

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

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.aucma.common.annotation.Log;
import com.aucma.common.core.controller.BaseController;
import com.aucma.common.core.domain.AjaxResult;
import com.aucma.common.enums.BusinessType;
import com.aucma.production.domain.ProdTaskPool;
import com.aucma.production.service.IProdTaskPoolService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

@RestController
@RequestMapping("/production/taskPool")
public class ProdTaskPoolController extends BaseController {
    @Autowired
    private IProdTaskPoolService prodTaskPoolService;

    @PreAuthorize("@ss.hasPermi('production:taskPool:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProdTaskPool prodTaskPool) {
        startPage();
        List<ProdTaskPool> list = prodTaskPoolService.selectProdTaskPoolList(prodTaskPool);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('production:taskPool:export')")
    @Log(title = "生产任务池", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProdTaskPool prodTaskPool) {
        List<ProdTaskPool> list = prodTaskPoolService.selectProdTaskPoolList(prodTaskPool);
        ExcelUtil<ProdTaskPool> util = new ExcelUtil<ProdTaskPool>(ProdTaskPool.class);
        util.exportExcel(response, list, "生产任务池数据");
    }

    @PreAuthorize("@ss.hasPermi('production:taskPool:query')")
    @GetMapping(value = "/{orderCode}")
    public AjaxResult getInfo(@PathVariable("orderCode") String orderCode) {
        return success(prodTaskPoolService.selectProdTaskPoolByOrderCode(orderCode));
    }

    @PreAuthorize("@ss.hasPermi('production:taskPool:add')")
    @Log(title = "生产任务池", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProdTaskPool prodTaskPool) {
        prodTaskPool.setCreatedBy(getUsername());
        return toAjax(prodTaskPoolService.insertProdTaskPool(prodTaskPool));
    }

    @PreAuthorize("@ss.hasPermi('production:taskPool:edit')")
    @Log(title = "生产任务池", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProdTaskPool prodTaskPool) {
        prodTaskPool.setUpdatedBy(getUsername());
        return toAjax(prodTaskPoolService.updateProdTaskPool(prodTaskPool));
    }

    @PreAuthorize("@ss.hasPermi('production:taskPool:edit')")
    @Log(title = "生产任务池状态切换", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody ProdTaskPool prodTaskPool) {
        return toAjax(prodTaskPoolService.changeTaskStatus(prodTaskPool));
    }

    @PreAuthorize("@ss.hasPermi('production:taskPool:remove')")
    @Log(title = "生产任务池", businessType = BusinessType.DELETE)
    @DeleteMapping("/{orderCodes}")
    public AjaxResult remove(@PathVariable String[] orderCodes) {
        return toAjax(prodTaskPoolService.deleteProdTaskPoolByOrderCodes(orderCodes));
    }
}
