package com.aucma.production.controller;

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

import com.aucma.base.domain.BaseOrderInfo;
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.ProductPlanInfo;
import com.aucma.production.service.IProductPlanInfoService;
import com.aucma.common.utils.poi.ExcelUtil;
import com.aucma.common.core.page.TableDataInfo;

/**
 * 生产计划Controller
 *
 * @author Yinq
 * @date 2023-10-07
 */
@RestController
@RequestMapping("/production/planInfo" )
public class ProductPlanInfoController extends BaseController {
    @Autowired
    private IProductPlanInfoService productPlanInfoService;

    /**
     * 查询生产计划列表
     */
    @PreAuthorize("@ss.hasPermi('production:planInfo:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(ProductPlanInfo productPlanInfo) {
        startPage();
        List<ProductPlanInfo> list = productPlanInfoService.selectProductPlanInfoList(productPlanInfo);
        return getDataTable(list);
    }

    /**
     * 导出生产计划列表
     */
    @PreAuthorize("@ss.hasPermi('production:planInfo:export')" )
    @Log(title = "生产计划" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ProductPlanInfo productPlanInfo) {
        List<ProductPlanInfo> list = productPlanInfoService.selectProductPlanInfoList(productPlanInfo);
        ExcelUtil<ProductPlanInfo> util = new ExcelUtil<ProductPlanInfo>(ProductPlanInfo. class);
        util.exportExcel(response, list, "生产计划数据" );
    }

    /**
     * 获取生产计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:planInfo:query')" )
    @GetMapping(value = "/{objId}" )
    public AjaxResult getInfo(@PathVariable("objId" ) Long objId) {
        return success(productPlanInfoService.selectProductPlanInfoByObjId(objId));
    }

    /**
     * 新增生产计划
     */
    @PreAuthorize("@ss.hasPermi('production:planInfo:add')" )
    @Log(title = "生产计划" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductPlanInfo productPlanInfo) {
        productPlanInfo.setCreatedBy(getUsername());
        return toAjax(productPlanInfoService.insertProductPlanInfo(productPlanInfo));
    }

    /**
     * 修改生产计划
     */
    @PreAuthorize("@ss.hasPermi('production:planInfo:edit')" )
    @Log(title = "生产计划" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductPlanInfo productPlanInfo) {
        productPlanInfo.setUpdatedBy(getUsername());
        return toAjax(productPlanInfoService.updateProductPlanInfo(productPlanInfo));
    }

    /**
     * 删除生产计划
     */
    @PreAuthorize("@ss.hasPermi('production:planInfo:remove')" )
    @Log(title = "生产计划" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{objIds}" )
    public AjaxResult remove(@PathVariable Long[] objIds) {
        return toAjax(productPlanInfoService.deleteProductPlanInfoByObjIds(objIds));
    }

    /**
     * 工单计划下达
     * @param baseOrderInfo
     * @return
     */
    @PostMapping("/releaseOrderPlan")
    public AjaxResult releaseOrderPlan(@RequestBody BaseOrderInfo baseOrderInfo) {
        return success(productPlanInfoService.releaseOrderPlan(baseOrderInfo));
    }

}
