package cn.wise.sc.cement.business.controller;

import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.query.PlanEquipmentPurchaseQuery;
import cn.wise.sc.cement.business.model.query.PlanFinishQuery;
import cn.wise.sc.cement.business.model.query.TeamQuery;
import cn.wise.sc.cement.business.service.IPlanEquipmentPurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ztw
 * @since 2020-09-28
 */
@Api(tags = "计划管理-设备采购计划")
@RestController
@RequestMapping("/business/plan-equipment-purchase")
public class PlanEquipmentPurchaseController {

	private static final Logger log = LoggerFactory.getLogger("PlanEquipmentPurchaseController");

	@Autowired
	private IPlanEquipmentPurchaseService equipmentPurchaseService;

	@ApiOperation(value = "设备采购计划分页列表")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "name", value = "产品名称", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "status", value = "状态：0待采购，1已完成", paramType = "query", dataType = "Integer")
	})
	@GetMapping("/getPage")
	public BaseResponse getPage(PageQuery pageQuery, String name, Integer status) {
		try {
			return equipmentPurchaseService.getPage(pageQuery, name, status);
		} catch (Exception e) {
			log.debug("设备采购计划分页列表{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

	@ApiOperation("设备采购计划列表导出")
	@PostMapping("/export")
	public void export(String name, String fileName, Integer status, HttpServletResponse response) {
		try {
			equipmentPurchaseService.export(name, fileName, status, response);
		} catch (Exception e) {
			log.debug("设备采购计划列表导出{}", e);
		}
	}


	@ApiOperation("设备采购计划列表导出(word)")
	@PostMapping("/export/word")
	public void exportWord(String name, String fileName, Integer status, HttpServletResponse response){
		equipmentPurchaseService.exportWord(name, fileName, status, response);
	}


	@ApiOperation(value = "新增设备采购计划")
	@PostMapping("/create")
	public BaseResponse create(@RequestBody PlanEquipmentPurchaseQuery query) {
		try {
			return equipmentPurchaseService.create(query);
		} catch (Exception e) {
			log.debug("新增设备采购计划{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

	@ApiOperation(value = "更新设备采购计划")
	@PostMapping("/update")
	public BaseResponse update(@RequestBody PlanEquipmentPurchaseQuery query) {
		try {
			return equipmentPurchaseService.update(query);
		} catch (Exception e) {
			log.debug("更新设备采购计划{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

	@ApiOperation(value = "设备采购计划详情")
	@GetMapping("/{id}")
	public BaseResponse getDetail(@PathVariable Integer id) {
		try {
			return equipmentPurchaseService.getDetail(id);
		} catch (Exception e) {
			log.debug("设备采购计划详情{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

	@ApiOperation(value = "采购完成")
	@PostMapping("/finish")
	public BaseResponse finish(PlanFinishQuery query) {
		try {
			return equipmentPurchaseService.finish(query);
		} catch (Exception e) {
			log.debug("采购完成{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

	@ApiOperation(value = "删除")
	@PostMapping("/delete/{id}")
	public BaseResponse delete(@PathVariable Integer id) {
		try {
			return equipmentPurchaseService.delete(id);
		} catch (Exception e) {
			log.debug("删除{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

}

