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

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.enumation.FileExt;
import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.model.PageQuery;
import cn.wise.sc.cement.business.model.query.PlanEquipmentMaintainQuery;
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.vo.PlanEquipmentPurchaseVo;
import cn.wise.sc.cement.business.service.IPlanEquipmentMaintainService;
import cn.wise.sc.cement.business.util.WordUtil;
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;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

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

	@Autowired
	private IPlanEquipmentMaintainService equipmentMaintainService;

	@ApiOperation(value = "设备维护计划分页列表")
	@ApiImplicitParams(value = {
			@ApiImplicitParam(name = "name", value = "产品名称", paramType = "query", dataType = "String")
	})
	@GetMapping("/getPage")
	public BaseResponse getPage(PageQuery pageQuery, String name) {
		try {
			return equipmentMaintainService.getPage(pageQuery, name);
		} catch (Exception e) {
			log.debug("设备维护计划分页列表{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

	@ApiOperation("设备维护计划分列表导出")
	@PostMapping("/export")
	public void export(String name, String fileName, HttpServletResponse response) {
		try {
			equipmentMaintainService.export(name, fileName, response);
		} catch (Exception e) {
			log.debug("设备维护计划分列表导出{}", e);
		}
	}

	@ApiOperation("设备维护计划列表导出(word)")
	@PostMapping("/export/word")
	public void exportWord(String name, String fileName, HttpServletResponse response){
		equipmentMaintainService.exportWord(name, fileName, response);
	}



	@ApiOperation(value = "新增设设备维护计划分页列表")
	@PostMapping("/create")
	public BaseResponse create(@RequestBody PlanEquipmentMaintainQuery query) {
		try {
			return equipmentMaintainService.create(query);
		} catch (Exception e) {
			log.debug("新增设备维护计划分页列表{}", e);
		}
		return BaseResponse.errorMsg("失败!");
	}

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

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

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

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










}

