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.SysFactory;
import com.op.wms.service.ISysFactoryService;
import com.op.common.core.web.controller.BaseController;
import com.op.common.core.web.domain.AjaxResult;
import com.op.common.core.utils.poi.ExcelUtil;

/**
 * 工厂模型Controller
 * 
 * @author Open Platform
 * @date 2023-07-03
 */
@RestController
@RequestMapping("/factory")
public class SysFactoryController extends BaseController {
	@Autowired
	private ISysFactoryService sysFactoryService;

	/**
	 * 查询工厂模型列表
	 */
	@RequiresPermissions("wms:factory:list")
	@GetMapping("/list")
	public AjaxResult list(SysFactory sysFactory) {
		List<SysFactory> list = sysFactoryService.selectSysFactoryList(sysFactory);
		return success(list);
	}

	/**
	 * 导出工厂模型列表
	 */
	@RequiresPermissions("wms:factory:export")
	@Log(title = "工厂模型", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, SysFactory sysFactory) {
		List<SysFactory> list = sysFactoryService.selectSysFactoryList(sysFactory);
		ExcelUtil<SysFactory> util = new ExcelUtil<SysFactory>(SysFactory.class);
		util.exportExcel(response, list, "工厂模型数据");
	}

	/**
	 * 获取工厂模型详细信息
	 */
	@RequiresPermissions("wms:factory:query")
	@GetMapping(value = "/{factoryId}")
	public AjaxResult getInfo(@PathVariable("factoryId") Long deptId) {
		return success(sysFactoryService.selectSysFactoryByFactoryId(deptId));
	}

	/**
	 * 新增工厂模型
	 */
	@RequiresPermissions("wms:factory:add")
	@Log(title = "工厂模型", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody SysFactory sysFactory) {
		return toAjax(sysFactoryService.insertSysFactory(sysFactory));
	}

	/**
	 * 修改工厂模型
	 */
	@RequiresPermissions("wms:factory:edit")
	@Log(title = "工厂模型", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody SysFactory sysFactory) {
		return toAjax(sysFactoryService.updateSysFactory(sysFactory));
	}

	/**
	 * 删除工厂模型
	 */
	@RequiresPermissions("wms:factory:remove")
	@Log(title = "工厂模型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{factoryIds}")
	public AjaxResult remove(@PathVariable Long[] factoryIds) {
		return toAjax(sysFactoryService.deleteSysFactoryByFactoryIds(factoryIds));
	}
}
