package com.fuint.module.backendApi.controller;

import com.fuint.common.dto.AccountInfo;
import com.fuint.common.dto.MtPurchaseOrderItemDto;
import com.fuint.common.util.TokenUtil;
import com.fuint.common.vo.MtPurchaseOrderItemVo;
import com.fuint.framework.web.BaseController;
import com.fuint.framework.web.PageResult;
import com.fuint.framework.web.ResponseObject;
import com.fuint.common.Constants;
import com.fuint.common.enums.StatusEnum;
import com.fuint.common.service.PurchaseOrderItemService;
import com.fuint.framework.pagination.PaginationRequest;
import com.fuint.framework.pagination.PaginationResponse;
import com.fuint.framework.exception.BusinessCheckException;
import com.fuint.repository.model.MtPurchaseOrderItem;
import com.fuint.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 材料采购订单项表管理类controller
 *
 * Created by huangwen
 * CopyRight https://www.fuint.cn
 */
@Api(tags="管理端-材料采购订单项表相关接口")
@RestController
@AllArgsConstructor
@RequestMapping(value = "/backendApi/purchase_order_item")
public class BackendPurchaseOrderItemController extends BaseController {

    /**
     * 材料采购订单项表服务接口
     */
    private PurchaseOrderItemService purchaseOrderItemService;

    /**
     * 材料采购订单项表列表查询
     *
     * @param  request HttpServletRequest对象
     * @return 材料采购订单项表列表
     */
    @ApiOperation(value = "材料采购订单项表列表查询")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('purchase_order_item:list')")
    public ResponseObject list(HttpServletRequest request, @RequestBody MtPurchaseOrderItemDto mtPurchaseOrderItemDto) throws BusinessCheckException {

        PageResult<MtPurchaseOrderItemVo> result = purchaseOrderItemService.queryPurchaseOrderItemListByParam(mtPurchaseOrderItemDto);

        return getSuccessResult(result);
    }

    /**
     * 更新材料采购订单项表状态
     *
     * @return
     */
    @ApiOperation(value = "更新材料采购订单项表")
    @RequestMapping(value = "/updateOrderItem", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('purchase_order_item:edit')")
    public ResponseObject updateOrderItem(HttpServletRequest request, @RequestBody MtPurchaseOrderItemDto mtPurchaseOrderItemDto) throws BusinessCheckException {

        purchaseOrderItemService.updateOrderItem(mtPurchaseOrderItemDto);

        return getSuccessResult(true);
    }

    /**
     * 删除材料采购订单项
     *
     * @return
     */
    @ApiOperation(value = "删除材料采购订单项")
    @RequestMapping(value = "/deleteOrderItemById/{id}", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('purchase_order_item:delete')")
    public ResponseObject deleteOrderItemById(HttpServletRequest request,@PathVariable("id") Long id) throws BusinessCheckException {

        purchaseOrderItemService.deleteOrderItemById(id);

        return getSuccessResult(true);
    }

    /**
     * 更新材料采购订单项表状态
     *
     * @return
     */
    @ApiOperation(value = "添加材料采购订单项表")
    @RequestMapping(value = "/updateOrderItem", method = RequestMethod.POST)
    @CrossOrigin
    @PreAuthorize("@pms.hasPermission('purchase_order_item:edit')")
    public ResponseObject addOrderItem(HttpServletRequest request, @RequestBody MtPurchaseOrderItemDto mtPurchaseOrderItemDto) throws BusinessCheckException {

        MtPurchaseOrderItemVo mtPurchaseOrderItemVo = purchaseOrderItemService.addOrderItem(mtPurchaseOrderItemDto);

        return getSuccessResult(mtPurchaseOrderItemVo);
    }



}
