package com.zcloud.controller.corp;

import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.service.corp.CorpStopService;
import com.zcloud.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 说明：十小停用管理
 * 作者：yangming
 * 时间：2023-2-13
 * 官网：www.zcloudchina.com
 */
@Controller
@RequestMapping("/app/corpstop")
public class AppCorpStopController extends BaseController {

	@Autowired
	private CorpStopService corpStopService;



	/**新增
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/save")
	@ResponseBody
	public Object save() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("STOPUSE_ID",this.get32UUID());
		pd.put("TYPE","0");
		pd.put("ISDELETE", "0");	//是否删除 0 未删除  1已删除
		pd.put("ISHANDLE","0");   //默认监管端未处理
		pd.put("OPERATOR", pd.getString("USERNAME"));	//操作人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//操作时间
		pd.put("CREATOR", pd.getString("USERNAME"));	//创建人
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));	//创建时间
		PageData handle = corpStopService.isHandle(pd); //查询此企业是否有未处理的数据
		if(handle == null){
			corpStopService.save(pd);
		} else {
			map.put("message","1");
		}
		map.put("result", errInfo);
		return map;
	}


	/**列表
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/list")
	@ResponseBody
	public Object list(Page page) throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		page.setPd(pd);
		List<PageData> varList =  corpStopService.list(page);
		map.put("varList",varList);
		map.put("page",page);
		map.put("result", errInfo);
		return map;
	}


	/**列表
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/goEdit")
	@ResponseBody
	public Object goEdit() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		PageData corp =  corpStopService.findById(pd);
		map.put("corp",corp);
		map.put("result", errInfo);
		return map;
	}


	/**启用
	 * @param
	 * @throws Exception
	 */
	@RequestMapping(value="/enable")
	@ResponseBody
	public Object enable() throws Exception{
		Map<String,Object> map = new HashMap<String,Object>();
		String errInfo = "success";
		PageData pd = new PageData();
		pd = this.getPageData();
		pd.put("STOPUSE_ID",this.get32UUID());
		pd.put("TYPE","1"); //申请启用
		pd.put("ISDELETE", "0");	//是否删除 0 未删除  1已删除
		pd.put("ISHANDLE","0");   //默认监管端未处理
		pd.put("OPERATOR", pd.getString("USERNAME"));	//操作人
		pd.put("OPERATTIME", DateUtil.date2Str(new Date()));	//操作时间
		pd.put("CREATOR", pd.getString("USERNAME"));	//创建人
		pd.put("CREATTIME", DateUtil.date2Str(new Date()));	//创建时间

		PageData handle = corpStopService.isHandle(pd); //查询此企业是否有未处理的数据
		if(handle == null){
			corpStopService.save(pd);
		} else {
			map.put("message","1");
		}
		map.put("result", errInfo);
		return map;
	}


}
