package com.op.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.op.common.log.annotation.Log;
import com.op.common.log.enums.BusinessType;
import com.op.common.security.annotation.RequiresPermissions;
import com.op.wms.domain.BaseProductGroupsT;
import com.op.wms.service.IBaseProductGroupsTService;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.utils.poi.ExcelUtil;
import com.op.common.core.web.page.TableDataInfo;

/**
 * 物料分组Controller
 * 
 * @author Open Platform
 * @date 2023-07-18
 */
@RestController
@RequestMapping("/productGroups")
public class BaseProductGroupsTController extends BaseController {
	@Autowired
	private IBaseProductGroupsTService baseProductGroupsTService;

	/**
	 * 查询物料分组列表
	 */
	@RequiresPermissions("wms:productGroups:list")
	@GetMapping("/list")
	public TableDataInfo list(BaseProductGroupsT baseProductGroupsT) {
		startPage();
		List<BaseProductGroupsT> list = baseProductGroupsTService.selectBaseProductGroupsTList(baseProductGroupsT);
		return getDataTable(list);
	}

	/**
	 * 导出物料分组列表
	 */
	@RequiresPermissions("wms:productGroups:export")
	@Log(title = "物料分组", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, BaseProductGroupsT baseProductGroupsT) {
		List<BaseProductGroupsT> list = baseProductGroupsTService.selectBaseProductGroupsTList(baseProductGroupsT);
		ExcelUtil<BaseProductGroupsT> util = new ExcelUtil<BaseProductGroupsT>(BaseProductGroupsT.class);
		util.exportExcel(response, list, "物料分组数据");
	}

	/**
	 * 获取物料分组详细信息
	 */
	@RequiresPermissions("wms:productGroups:query")
	@GetMapping(value = "/{pgId}")
	public AjaxResult getInfo(@PathVariable("pgId") String pgId) {
		return success(baseProductGroupsTService.selectBaseProductGroupsTByPgId(pgId));
	}

	/**
	 * 新增物料分组
	 */
	@RequiresPermissions("wms:productGroups:add")
	@Log(title = "物料分组", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody BaseProductGroupsT baseProductGroupsT) {
		return toAjax(baseProductGroupsTService.insertBaseProductGroupsT(baseProductGroupsT));
	}

	/**
	 * 修改物料分组
	 */
	@RequiresPermissions("wms:productGroups:edit")
	@Log(title = "物料分组", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody BaseProductGroupsT baseProductGroupsT) {
		return toAjax(baseProductGroupsTService.updateBaseProductGroupsT(baseProductGroupsT));
	}

	/**
	 * 删除物料分组
	 */
	@RequiresPermissions("wms:productGroups:remove")
	@Log(title = "物料分组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pgIds}")
	public AjaxResult remove(@PathVariable String[] pgIds) {
		return toAjax(baseProductGroupsTService.deleteBaseProductGroupsTByPgIds(pgIds));
	}
}
