package com.sifang.modules.sunshine.SystemSetting.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.sifang.modules.sys.common.UserUtils;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.util.CrmUtils;
import com.sifang.modules.sys.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sifang.modules.sunshine.SystemSetting.service.OrderMarkSettingService;
import com.sifang.modules.sunshine.SystemSetting.utils.OrderCommonUtils;
import com.sifang.modules.sys.util.LayuiPage;


/**
 * @author lzp
 * @date 2019/10/11 14:28
 * g工单标记设置Controller
 */
@Controller
@RequestMapping(value = "${adminPath}/yangguang/orderMarkSet")
public class OrderMarkController extends BaseController {

	@Autowired
	private OrderMarkSettingService markSettingService;

	@RequestMapping(value = "toMarkSetPage")
	public String toMarkSetPage(String userType,Model model) {
		model.addAttribute("userType",userType);
		return "modules/yangguang/systemSetting/ordersetting/markSet/orderMarkSetting";
	}

	/**
	 * 获取工单加急设置数据
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("getMarkSetData")
	public Object getMarkSetData(HttpServletRequest request) {
		LayuiPage page = new LayuiPage(request);
		markSettingService.getAllMarkData(page,"1");
		return page.renderJson();
	}

	/**
	 * 项目标记
	*/

	@RequestMapping(value = "projectMarkSetList")
	public String projectMarkSetList(Model model) {
		return "modules/yangguang/systemSetting/ordersetting/markSet/projectMarkSetting";
	}

	/**
	 * 获取项目标记设置数据
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("projectMarkSetPage")
	public Object projectMarkSetPage(HttpServletRequest request) {
		LayuiPage page = new LayuiPage(request);
		markSettingService.getAllMarkData(page,"2");
		return page.renderJson();
	}




	/**
	 * 添加标记页面
	 * @return
	 */
	@RequestMapping("addMarkPage")
	public String addExigencyPage(Model model,HttpServletRequest request){
		String useType= request.getParameter("useType");
		model.addAttribute("useType", useType);
		model.addAttribute("totalColors", OrderCommonUtils.getAllMarkColor());
		model.addAttribute("typeList", markSettingService.getAllMarkType(useType));
		return "modules/yangguang/systemSetting/ordersetting/markSet/addMark";
	}

	/**
	 * 添加标记
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("addMark")
	public String addMark(HttpServletRequest request){
		Map<String, String> map = getParams(request);
		try {
			return markSettingService.addMark(map);
		} catch (Exception e) {
			e.printStackTrace();
			return "201";
		}
	}


	@RequestMapping("toEditMarkPage")
	public String toEditMarkPage(HttpServletRequest request,Model model){
		String id = request.getParameter("id");
		String useType= request.getParameter("useType");
		model.addAttribute("useType", useType);
		model.addAttribute("totalColors", OrderCommonUtils.getAllMarkColor());
		model.addAttribute("record", markSettingService.getMarkDetail(id));
		return "modules/yangguang/systemSetting/ordersetting/markSet/editMark";
	}

	/**
	 * 修改标记
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("updateMark")
	public String updateMark(HttpServletRequest request){
		Map<String, String> map = getParams(request);
		try {
			return markSettingService.editMark(map);
		} catch (Exception e) {
			e.printStackTrace();
			return "201";
		}
	}

	/**
	 * 删除标记
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping("delMark")
	public String delMark(HttpServletRequest request){
		String ids = request.getParameter("ids");
		try {
			markSettingService.delMark(ids);
			return "200";
		} catch (Exception e) {
			e.printStackTrace();
			return "201";
		}

	}

}
