|
@@ -1,12 +1,9 @@
|
|
package com.jeeplus.modules.wexintheorder.web;
|
|
package com.jeeplus.modules.wexintheorder.web;
|
|
|
|
|
|
import com.jeeplus.common.json.AjaxJson;
|
|
import com.jeeplus.common.json.AjaxJson;
|
|
-import com.jeeplus.common.utils.StringUtils;
|
|
|
|
import com.jeeplus.common.web.BaseController;
|
|
import com.jeeplus.common.web.BaseController;
|
|
import com.jeeplus.modules.sys.entity.User;
|
|
import com.jeeplus.modules.sys.entity.User;
|
|
-import com.jeeplus.modules.wexinpackage.access.util.access.WeChatParamsUtil;
|
|
|
|
-import com.jeeplus.modules.wexinpackage.access.util.encryption.WXBizMsgCrypt;
|
|
|
|
-import com.jeeplus.modules.wexintheorder.dao.TheLeadershipDao;
|
|
|
|
|
|
+import com.jeeplus.modules.wexintheorder.Utils.OrderUtils;
|
|
import com.jeeplus.modules.wexintheorder.entity.TheLeadership;
|
|
import com.jeeplus.modules.wexintheorder.entity.TheLeadership;
|
|
import com.jeeplus.modules.wexintheorder.entity.TheOrder;
|
|
import com.jeeplus.modules.wexintheorder.entity.TheOrder;
|
|
import com.jeeplus.modules.wexintheorder.service.TheLeadershipService;
|
|
import com.jeeplus.modules.wexintheorder.service.TheLeadershipService;
|
|
@@ -15,16 +12,16 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.ui.Model;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
|
-import java.io.BufferedReader;
|
|
|
|
-import java.io.PrintWriter;
|
|
|
|
-import java.util.Date;
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
+import java.text.DateFormat;
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
-@RequestMapping(value = "${adminPath}/weXin/theOrder")
|
|
|
|
|
|
+@RequestMapping(value = "/weXin/theOrder")
|
|
public class TheOrderController extends BaseController {
|
|
public class TheOrderController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private TheOrderService theOrderService;
|
|
private TheOrderService theOrderService;
|
|
@@ -32,109 +29,73 @@ public class TheOrderController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private TheLeadershipService theLeadershipService;
|
|
private TheLeadershipService theLeadershipService;
|
|
|
|
|
|
|
|
+
|
|
//页面显示
|
|
//页面显示
|
|
@RequestMapping(value = "orderFrom")
|
|
@RequestMapping(value = "orderFrom")
|
|
- public String getOrderFrom(Model model, HttpServletRequest request){
|
|
|
|
- return "modules/weixin/theorder/home";//返回一个界面
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @RequestMapping(value = "callBack")
|
|
|
|
- public void getCallBack(HttpServletRequest request, HttpServletResponse response) throws Exception{
|
|
|
|
- String method = request.getMethod();
|
|
|
|
- if ("GET".equals(method)){
|
|
|
|
- doGet(request,response);
|
|
|
|
- }else {
|
|
|
|
- doPost(request,response);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- private void doGet(HttpServletRequest request, HttpServletResponse response){
|
|
|
|
- String token = "AL8aMOYlujP28AE8WDHrxQqW9D5bfxBa";
|
|
|
|
- String aceKey = "yIpls2iEHKcp7Pftlp8MrieuJ6HJAb9yeKLqZGLmeHL";
|
|
|
|
- // 微信加密签名
|
|
|
|
- String msg_signature = request.getParameter("msg_signature");
|
|
|
|
- // 时间戳
|
|
|
|
- String timestamp = request.getParameter("timestamp");
|
|
|
|
- // 随机数
|
|
|
|
- String nonce = request.getParameter("nonce");
|
|
|
|
- // 随机字符串
|
|
|
|
- String echoStr = request.getParameter("echostr");
|
|
|
|
- //回调key值
|
|
|
|
- String sEchoStr = null;
|
|
|
|
- WXBizMsgCrypt wxcpt;
|
|
|
|
- try {
|
|
|
|
- PrintWriter writer = response.getWriter();
|
|
|
|
- wxcpt = new WXBizMsgCrypt(token,aceKey,WeChatParamsUtil.corpId);
|
|
|
|
- sEchoStr = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echoStr);
|
|
|
|
- if (StringUtils.isBlank(sEchoStr)){
|
|
|
|
- logger.error("url验证失败");
|
|
|
|
- }
|
|
|
|
- writer.write(sEchoStr);
|
|
|
|
- writer.close();
|
|
|
|
- }catch (Exception e){
|
|
|
|
- logger.error("企业微信回调验证错误",e);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- private void doPost(HttpServletRequest request, HttpServletResponse response) throws Exception{
|
|
|
|
- String sReqMsgSig = request.getParameter("msg_signature");
|
|
|
|
- String sReqTimeStamp = request.getParameter("timestamp");
|
|
|
|
- String sReqNonce = request.getParameter("nonce");
|
|
|
|
-// try {
|
|
|
|
- BufferedReader reader = request.getReader();
|
|
|
|
- char[] buf = new char[512];
|
|
|
|
- int len = 0;
|
|
|
|
- StringBuffer stringBuffer = new StringBuffer();
|
|
|
|
- while ((len = (int) reader.read(buf))!= -1){
|
|
|
|
- stringBuffer = stringBuffer.append(buf, 0, len);
|
|
|
|
- }
|
|
|
|
- String content = stringBuffer.toString();
|
|
|
|
- if (content == null){
|
|
|
|
- content = "";
|
|
|
|
- }
|
|
|
|
- WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(WeChatParamsUtil.contacts_token,WeChatParamsUtil.encodingAESKey,WeChatParamsUtil.corpId);
|
|
|
|
- String sMsg = wxcpt.DecryptMsg(sReqMsgSig, sReqTimeStamp, sReqNonce, content);
|
|
|
|
-// weChatCallbackService.getMapOperation(sMsg,request);
|
|
|
|
- // 循环所有子元素
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
-// // TODO
|
|
|
|
-// // 解密失败,失败原因请查看异常
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// }
|
|
|
|
|
|
+ public String getOrderFrom(Model model, HttpServletRequest request,@RequestParam String code){
|
|
|
|
+ String userId = OrderUtils.findUserId(code);//获取useerid
|
|
|
|
+ String weChatUserId = "00000011";
|
|
|
|
+ TheOrder userOrderEcho = getUserOrderEcho(weChatUserId);
|
|
|
|
+ model.addAttribute("theOrder",userOrderEcho);
|
|
|
|
+ return "modules/weixin/theorder/orderMeal";//返回一个界面
|
|
}
|
|
}
|
|
|
|
|
|
//获取部门以及分管领导信息--回显FROM
|
|
//获取部门以及分管领导信息--回显FROM
|
|
public TheOrder getUserOrderEcho(String weChatUserId){
|
|
public TheOrder getUserOrderEcho(String weChatUserId){
|
|
TheOrder theOrder = new TheOrder();
|
|
TheOrder theOrder = new TheOrder();
|
|
- weChatUserId = "00000011";
|
|
|
|
- //获取用户user
|
|
|
|
User user = theLeadershipService.findUser(weChatUserId);
|
|
User user = theLeadershipService.findUser(weChatUserId);
|
|
- //获取用户id
|
|
|
|
- String userId = user.getId();
|
|
|
|
|
|
+ String userId = user.getId();//获取用户id
|
|
|
|
+ //获取用户user
|
|
//添加回显对象
|
|
//添加回显对象
|
|
theOrder.setName(user.getName());//姓名
|
|
theOrder.setName(user.getName());//姓名
|
|
theOrder.setCorrelationId(userId);
|
|
theOrder.setCorrelationId(userId);
|
|
- theOrder.setDepartment(user.getOffice().getName());//部门
|
|
|
|
TheLeadership theLeadership = new TheLeadership();
|
|
TheLeadership theLeadership = new TheLeadership();
|
|
- theLeadership.setUserId(userId);
|
|
|
|
|
|
+ theLeadership.setCorrelationId(userId);
|
|
List<TheLeadership> listUserId = theLeadershipService.findListUserId(theLeadership);
|
|
List<TheLeadership> listUserId = theLeadershipService.findListUserId(theLeadership);
|
|
if (listUserId.size()>0){
|
|
if (listUserId.size()>0){
|
|
- theLeadership = listUserId.get(1);//获取分管领导信息
|
|
|
|
- theOrder.setLeadership(theLeadership.getLeadership());//添加分管领导
|
|
|
|
|
|
+ theLeadership.setTeam(listUserId.get(0).getTeam());
|
|
|
|
+ if (listUserId.get(0).getTeam().equals("潘中")){
|
|
|
|
+ theOrder.setDepartment("1");
|
|
|
|
+ }
|
|
|
|
+ theOrder.setDepartment("2");//全显示
|
|
|
|
+ theLeadership.setSpecific(listUserId.get(0).getSpecific());
|
|
|
|
+ theLeadership.setDepartment(listUserId.get(0).getDepartment());
|
|
theOrder.setStatus("0"); //是回显
|
|
theOrder.setStatus("0"); //是回显
|
|
}else {
|
|
}else {
|
|
- theOrder.setLeadership("");//无分管领导
|
|
|
|
|
|
+ theLeadership.setTeam("");
|
|
|
|
+ theLeadership.setSpecific("");
|
|
|
|
+ theLeadership.setDepartment("");
|
|
theOrder.setStatus("1"); //不是回显
|
|
theOrder.setStatus("1"); //不是回显
|
|
|
|
+ theOrder.setDepartStatus("1");//显示一级
|
|
}
|
|
}
|
|
return theOrder;
|
|
return theOrder;
|
|
}
|
|
}
|
|
|
|
|
|
//获取--预定餐
|
|
//获取--预定餐
|
|
- public AjaxJson getReservation(String status,TheOrder theOrder){
|
|
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @RequestMapping(value = "noSureTem")
|
|
|
|
+ public AjaxJson getReservation(TheOrder theOrder){
|
|
|
|
+ DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
+ DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ Date date = new Date();//当前时间
|
|
AjaxJson ajaxJson = new AjaxJson();
|
|
AjaxJson ajaxJson = new AjaxJson();
|
|
try {
|
|
try {
|
|
- //保存分管领导
|
|
|
|
- saveLeader(status,theOrder);
|
|
|
|
- //保存订单信息 需要处理周末
|
|
|
|
- theOrder.setScheduled(new Date());
|
|
|
|
|
|
+ //获取工作日 -- 第二天
|
|
|
|
+ String addOrMinusDayString = OrderUtils.getAddOrMinusDayString(1, dateFormat);
|
|
|
|
+ //验证是否存在订单 --true未为存在
|
|
|
|
+ boolean planOrder = getPlanOrder(theOrder.getCorrelationId(), addOrMinusDayString);
|
|
|
|
+ if (planOrder){
|
|
|
|
+ ajaxJson.setSuccess(true);
|
|
|
|
+ ajaxJson.setMsg("您已经预定过餐");
|
|
|
|
+ return ajaxJson;
|
|
|
|
+ }
|
|
|
|
+ //修改分管领导
|
|
|
|
+// updateLeader(theOrder);
|
|
|
|
+ //保存团队信息,如果status为1,说明是回显信息,无需保存
|
|
|
|
+ saveLeader(theOrder);
|
|
|
|
+ addOrMinusDayString = addOrMinusDayString+" 12:00:00";
|
|
|
|
+ Date parse = dateFormat1.parse(addOrMinusDayString);
|
|
|
|
+ theOrder.setScheduled(parse);//添加预定时间
|
|
theOrderService.insertOrder(theOrder);//保存订单信息
|
|
theOrderService.insertOrder(theOrder);//保存订单信息
|
|
ajaxJson.setSuccess(true);
|
|
ajaxJson.setSuccess(true);
|
|
ajaxJson.setMsg("预定餐成功");
|
|
ajaxJson.setMsg("预定餐成功");
|
|
@@ -147,35 +108,57 @@ public class TheOrderController extends BaseController {
|
|
return ajaxJson;
|
|
return ajaxJson;
|
|
}
|
|
}
|
|
|
|
|
|
- //获取确定订餐时间
|
|
|
|
- public AjaxJson getConfirmOrder(String status,TheOrder theOrder){
|
|
|
|
- AjaxJson ajaxJson = new AjaxJson();
|
|
|
|
- //用来查找昨天的预定餐情况
|
|
|
|
- TheOrder to = new TheOrder();
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- saveLeader(status,theOrder);
|
|
|
|
- theOrderService.findList(theOrder);
|
|
|
|
- ajaxJson.setSuccess(true);
|
|
|
|
- ajaxJson.setMsg("确定订餐成功");
|
|
|
|
- return ajaxJson;
|
|
|
|
- }catch (Exception e){
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- ajaxJson.setSuccess(false);
|
|
|
|
- ajaxJson.setMsg("确定订餐失败,请重新确定");
|
|
|
|
- return ajaxJson;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //保存分管领导
|
|
|
|
- public void saveLeader(String status,TheOrder theOrder){
|
|
|
|
|
|
+ //保存团队部门信息
|
|
|
|
+ public void saveLeader(TheOrder theOrder){
|
|
//保存分管领导信息
|
|
//保存分管领导信息
|
|
- if (status.equals("1")){
|
|
|
|
|
|
+ if (theOrder.getStatus().equals("1")){
|
|
//保存信息分管领导信息
|
|
//保存信息分管领导信息
|
|
TheLeadership theLeadership = new TheLeadership();
|
|
TheLeadership theLeadership = new TheLeadership();
|
|
- theLeadership.setUserId(theOrder.getCorrelationId());
|
|
|
|
- theLeadership.setLeadership(theOrder.getLeadership());
|
|
|
|
|
|
+ theLeadership.setTeam(theOrder.getTeam());//添加团队
|
|
|
|
+ theLeadership.setDepartment(theOrder.getDepartment());//部门
|
|
|
|
+ theLeadership.setSpecific(theOrder.getSpecific());//具体部门
|
|
|
|
+ theLeadership.setCorrelationId(theOrder.getCorrelationId());//关联id
|
|
theLeadershipService.insertLeaderShip(theLeadership);
|
|
theLeadershipService.insertLeaderShip(theLeadership);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+ //确定是否预定过餐
|
|
|
|
+ public boolean getPlanOrder(String userId,String addOrMinusDayString){
|
|
|
|
+ boolean flag = false;
|
|
|
|
+ try {
|
|
|
|
+ DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+ addOrMinusDayString = addOrMinusDayString+" 12:00:00";
|
|
|
|
+ TheOrder toOrderDate = new TheOrder();
|
|
|
|
+ toOrderDate.setDateStart(addOrMinusDayString);//开始时间
|
|
|
|
+ toOrderDate.setCorrelationId(userId);
|
|
|
|
+ List<TheOrder> list = theOrderService.findList(toOrderDate);//查询上个工作日时间范围内容
|
|
|
|
+ if(null!=list&&list.size()>0){
|
|
|
|
+ flag = true;
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return flag;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //验证是否订过餐
|
|
|
|
+// public boolean getSureOrder(String userid){
|
|
|
|
+// boolean flag = false;
|
|
|
|
+// try {
|
|
|
|
+// DateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
+// //查询今天是否订过餐
|
|
|
|
+// TheOrder sureOrder = new TheOrder();
|
|
|
|
+// Date date = new Date();
|
|
|
|
+// sureOrder.setDateEnd(dateFormat.format(date));
|
|
|
|
+// List<TheOrder> list1 = theOrderService.findList(sureOrder);
|
|
|
|
+// for (TheOrder theOrder:list1){
|
|
|
|
+// if (theOrder.getCorrelationId().equals(userid)){
|
|
|
|
+// flag =true;
|
|
|
|
+// break;
|
|
|
|
+// }
|
|
|
|
+// }
|
|
|
|
+// }catch (Exception e){
|
|
|
|
+// e.printStackTrace();
|
|
|
|
+// }
|
|
|
|
+// return flag;
|
|
|
|
+// }
|
|
|
|
+}
|