WxOrderController.java 5.97 KB
/**
 * Copyright &copy; 2015-2018 <a href="#">J-Site</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.wechat.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.interfaces.service.WXService;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.thinkgem.jeesite.modules.wechat.entity.WxOrder;
import com.thinkgem.jeesite.modules.wechat.service.WxOrderService;

/**
 * 微信预约Controller
 * @author lzj
 * @version 2020-03-06
 */
@Controller
@RequestMapping(value = "${adminPath}/wechat/wxOrder")
public class WxOrderController extends BaseController {

	@Autowired
	private WxOrderService wxOrderService;
	@Autowired
	private WXService wxService;
	
	@ModelAttribute
	public WxOrder get(@RequestParam(required=false) String id) {
		WxOrder entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = wxOrderService.get(id);
		}
		if (entity == null){
			entity = new WxOrder();
		}
		return entity;
	}
	
	@RequiresPermissions("wechat:wxOrder:view")
	@RequestMapping(value = {"list", ""})
	public String list(WxOrder wxOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
		User user = UserUtils.getUser();
		String office = user.getOffice().getName();
		if(StringUtils.isNotBlank(office)) {
			if(office.indexOf("权证") != -1) {
				wxOrder.setYwdl("10");
			}else if(office.indexOf("抵押") != -1) {
				wxOrder.setYwdl("20");
			}else if(office.indexOf("预告") != -1) {
				wxOrder.setYwdl("30");
			}else if(office.indexOf("农林") != -1) {
				wxOrder.setYwdl("40");
			}else {
				wxOrder.setYwdl("-");
			}
		List<WxOrder> list = wxOrderService.findList(wxOrder); 
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		if(list.size()>0) {
			for(int i=0;i<list.size();i++) {
				wxOrder = list.get(i);
				String sj = wxOrder.getYydate()+" "+wxOrder.getYysjd().substring(wxOrder.getYysjd().indexOf("-")+1);
				logger.info(sj);
				try {
					if(!(wxOrder.getSign().equals("1")) && !(wxOrder.getSign().equals("4")) && !(wxOrder.getSign().equals("3")) && (sdf.parse(sj).before(new Date()))) {
						wxOrder.setSign("3");
					}
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		model.addAttribute("list", list);
		}
		return "modules/wechat/wxOrderList";
	}

	@RequiresPermissions("wechat:wxOrder:view")
	@RequestMapping(value = "form")
	public String form(WxOrder wxOrder, Model model) {
		model.addAttribute("wxOrder", wxOrder);
		return "modules/wechat/wxOrderForm";
	}

	@RequiresPermissions("wechat:wxOrder:edit")
	@RequestMapping(value = "save")
	public String save(WxOrder wxOrder, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, wxOrder)){
			return form(wxOrder, model);
		}
		wxOrderService.save(wxOrder);
		addMessage(redirectAttributes, "保存微信预约成功");
		return "redirect:"+Global.getAdminPath()+"/wechat/wxOrder/?repage";
	}
	
	@RequiresPermissions("wechat:wxOrder:view")
	@RequestMapping(value = "sign")
	public String sign(WxOrder wxOrder, Model model, RedirectAttributes redirectAttributes) {
		wxOrder.setSign("1");
		String ckbh = UserUtils.getUser().getCkbh();
		wxOrder.setBlck(ckbh);
		wxOrderService.save(wxOrder);
		Map map = new HashMap();
		try {
			map = wxService.sign(wxOrder);
			}catch(Exception e){
				e.printStackTrace();
				map.put("success", false);
				map.put("resultMsg", e.getMessage());
			}
		addMessage(redirectAttributes, "签到成功");
		return "redirect:"+Global.getAdminPath()+"/wechat/wxOrder/?repage";
	}
	
	@ResponseBody
	@RequestMapping(value = "call")
	public Map call(WxOrder wxOrder, Model model, HttpServletRequest request) {
		Map map = new HashMap();
		try {
		map = wxService.call(request);
		}catch(Exception e){
			e.printStackTrace();
			map.put("success", false);
			map.put("resultMsg", e.getMessage());
		}
		return map;
	}
	
	@ResponseBody
	@RequestMapping(value = "send")
	public Map send(WxOrder wxOrder, Model model, HttpServletRequest request) {
		Map map = new HashMap();
		try {
		map = wxService.send(request);
		}catch(Exception e){
			e.printStackTrace();
			map.put("success", false);
			map.put("resultMsg", e.getMessage());
		}
		return map;
	}
	
	@RequiresPermissions("wechat:wxOrder:view")
	@RequestMapping(value = "ckwindow")
	public String ckwindow(WxOrder wxOrder, Model model, RedirectAttributes redirectAttributes) {
		model.addAttribute("wxOrder", wxOrder);
		return "modules/wechat/ckwindow";
	}
	
	@RequiresPermissions("wechat:wxOrder:view")
	@RequestMapping(value = "windowsave")
	public void windowsave(WxOrder wxOrder, Model model, RedirectAttributes redirectAttributes) {
		wxOrderService.save(wxOrder);
	}
	
	@RequiresPermissions("wechat:wxOrder:edit")
	@RequestMapping(value = "delete")
	public String delete(WxOrder wxOrder, RedirectAttributes redirectAttributes) {
		wxOrderService.delete(wxOrder);
		addMessage(redirectAttributes, "删除微信预约成功");
		return "redirect:"+Global.getAdminPath()+"/wechat/wxOrder/?repage";
	}

}