package com.bcxin.ins.coninsweb.product.controller;

import com.bcxin.ins.service.order.PolicyService;
import com.bcxin.ins.service.product.ProductService;
import com.bcxin.ins.rest.UserSupportUtil;
import com.bcxin.ins.core.base.web.BaseController;
import com.bcxin.ins.spring.annotation.LoginRequired;
import com.bcxin.ins.util.Constant;
import com.bcxin.ins.util.DSUtil;
import com.bcxin.ins.vo.ClientUserVo;
import com.bcxin.ins.vo.ConstProp;
import com.bcxin.ins.vo.OrderFormVo;
import com.bcxin.ins.vo.ProductVo;
import com.bcxin.mybatisplus.toolkit.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * 团意险产品相关业务逻辑处理（不包括后台产品配置）
 * @author zxf
 *
 */
@Controller
public class InsuranceProduct_TYX_Controller extends BaseController {

	@Autowired
	private ProductService productService;
	@Autowired
	private PolicyService policyService;


	/**
	 *
	 * <b>产品中心，各分类产品列表 </b>
	 *
	 * @param request
	 * @return
	 * @author ZXF
	 * @date 2016年12月14日 下午5:22:29
	 * @注意事项 </b>
	 * <b>
	 */
	@RequestMapping("/insurance/gmr/product/productAllView")
	public ModelAndView productAll(HttpServletRequest request) {
		ModelAndView view = new ModelAndView("/coninsweb/insurance/gmr/productAll");
		String user_id = request.getParameter("user_id");

		ClientUserVo userdetail = UserSupportUtil.getSessionUser();
		if (  userdetail == null ) {
			return new ModelAndView("redirect:/");
		}
		view.addObject(ConstProp.USERDETAIL,userdetail);
		view.addObject("ctxStatic", policyService.getArsPathWeb(userdetail.getWeb_type()));
		setTokenByApi(view);
		return view;
	}

	/**
	 *
	 * <b>产品中心，各分类产品列表 </b>
	 *
	 * @param oid
	 * @return
	 * @author ZXF
	 * @date 2016年12月14日 下午5:22:29
	 * @注意事项 </b>
	 * <b>
	 */
	@RequestMapping("/insurance/gmr/product/productInfo_iframe/{oid}")
	public ModelAndView productInfo_iframe(HttpServletRequest request,@PathVariable long oid) {
		ModelAndView view = new ModelAndView("/coninsweb/api/gmr/gmr_pro_index");
		ClientUserVo userdetail = UserSupportUtil.getSessionUser();
		view.addObject(ConstProp.USERDETAIL,userdetail);
		view.addObject("product_id", String.valueOf(oid));
		setTokenByApi(view);
		return view;
	}

	/**
	 *
	 * <b>跳转到投保界面 </b>
	 *
	 * @param oid
	 * @return
	 * @author ZXF
	 * @date 2016年12月14日 下午5:22:29
	 * @注意事项 </b>
	 * <b>
	 */
	@RequestMapping("/insurance/gmr/policy/policy_iframe/{oid}")
	public ModelAndView policy_iframe(@PathVariable long oid) {
		ModelAndView view = new ModelAndView("/coninsweb/api/gmr/gmr_order_index");
		ClientUserVo userdetail = UserSupportUtil.getSessionUser();
		if (  userdetail == null ) {
			return new ModelAndView(DSUtil.operation()+"/insurance/gmr/policy/policy_iframe/"+oid);
		}
		view.addObject(ConstProp.USERDETAIL,userdetail);
		view.addObject(ConstProp.ORDER_ID, String.valueOf(oid));
		setTokenByApi(view);
		return view;
	}

	/**
	 *
	 * <b>跳转到投保界面 </b>
	 *
	 * @param oid
	 * @return
	 * @author ZXF
	 * @date 2016年12月14日 下午5:22:29
	 * @注意事项 </b>
	 * <b>
	 */
	@LoginRequired(methodParamKey={"1#oid"}, redirectUrl = "insurance/gmr/policy/policyInit_iframe/{oid}")
	@RequestMapping("/insurance/gmr/policy/policyInit_iframe/{oid}")
	public ModelAndView policyInit_iframe(HttpServletRequest request,@PathVariable long oid) {
		ModelAndView view = new ModelAndView("/coninsweb/api/gmr/gmr_order_init");
		view.addObject("product_id", String.valueOf(oid));
		setTokenByApi(view);
		return view;
	}

	/**
	 *
	 * <b>跳转到投保界面 </b>
	 *
	 * @param oid
	 * @return
	 * @author ZXF
	 * @date 2016年12月14日 下午5:22:29
	 * @注意事项 </b>
	 * <b>
	 */
	@RequestMapping("/insurance/gmr/policy/payment_iframe/{oid}")
	public ModelAndView payment_iframe(@PathVariable long oid) {
		ModelAndView view = new ModelAndView("/coninsweb/api/gmr/gmr_order_pay");
		ClientUserVo userdetail = UserSupportUtil.getSessionUser();
		if (  userdetail == null ) {
			return new ModelAndView(DSUtil.operation()+"/insurance/gmr/policy/payment_iframe/"+oid);
		}
		OrderFormVo dto = policyService.accordingToOrderIDToGetPolicyDto(oid);
		view.addObject(ConstProp.DTO,dto);
		view.addObject(ConstProp.USERDETAIL,userdetail);
		view.addObject(ConstProp.ORDER_ID, String.valueOf(oid));
		setTokenByApi(view);
		return view;
	}



	/**
	 * <b>前台页面产品详情 </b> 
	 * 
	 * @param request
	 * @param oid
	 * @return
	 * @author ZXF 
	 * @date 2016年12月21日 下午1:40:41
	 * @注意事项 </b>
	 * <b>
	 */
	@RequestMapping("/insurance/gmr/product/productInfo/{oid}")
	public ModelAndView productInfo(HttpServletRequest request, @PathVariable long oid) {
		ModelAndView view = new ModelAndView();
		ClientUserVo userdetail = UserSupportUtil.getSessionUser();
		ProductVo pd = productService.getProduct(oid);
		if(StringUtils.isNotEmpty(pd.getOid())){
			view.addObject(ConstProp.SHAREPATH,productService.setSharePath(oid,userdetail));
		}else{
			return null;
		}
		if(StringUtils.isEmpty(pd.getProduct_code()) ? false : pd.getProduct_code().contains(ConstProp.TYX_PAC)){
			view.setViewName("/coninsweb/api/gmr/product/gmr_pnc_product_info");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : pd.getProduct_code().contains(ConstProp.TYX_PAS)){
			view.setViewName("/coninsweb/api/gmr/product/gmr_pn_product_info");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : pd.getProduct_code().contains(ConstProp.TYX_TK)){
			view.setViewName("/coninsweb/api/gmr/product/gmr_tk_product_info");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : pd.getProduct_code().contains(ConstProp.TYX_RB)){
			view.setViewName("/coninsweb/api/gmr/product/gmr_rb_product_info");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : pd.getProduct_code().contains(ConstProp.TYX_CA)){
			view.setViewName("/coninsweb/api/gmr/product/gmr_ca_product_info");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : pd.getProduct_code().contains(ConstProp.TYX_QH)){
			view.setViewName("/coninsweb/api/gmr/product/gmr_qh_product_info");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : pd.getProduct_code().contains(ConstProp.TYX_HT)){
			view.setViewName("/coninsweb/api/gmr/product/gmr_ht_product_info");
		}
		/*if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-TK-1".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_tk_plan_1");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-TK-2".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_tk_plan_2");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-TK-3".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_tk_plan_3");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-TK-4".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_tk_plan_4");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-TK-5".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_tk_plan_5");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-TK-6".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_tk_plan_6");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-PAS-1".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_pa_plan_1");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-PAS-2".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_pa_plan_2");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-PAS-3".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_pa_plan_3");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-PAS-4".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_pa_plan_4");
		}else if(StringUtils.isEmpty(pd.getProduct_code()) ? false : "TYX-PAS-5".equals(pd.getProduct_code())){
			view.setViewName("/coninsweb/api/gmr/product/productInfo_pa_plan_5");
		}*/
		view.addObject(ConstProp.PRODUCTDTO, pd);
		view.addObject(ConstProp.USERDETAIL,userdetail);
		setTokenByApi(view);

		return view;
	}

}
