1284 lines
55 KiB
Plaintext
1284 lines
55 KiB
Plaintext
package com.jysoft.weChat.controller;
|
||
|
||
import java.io.BufferedReader;
|
||
import java.net.URLEncoder;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Arrays;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.Iterator;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Map.Entry;
|
||
import java.util.UUID;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpSession;
|
||
|
||
import org.codehaus.jackson.map.ObjectMapper;
|
||
import org.codehaus.jackson.type.TypeReference;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||
import org.springframework.stereotype.Controller;
|
||
import org.springframework.web.bind.annotation.RequestBody;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RequestMethod;
|
||
import org.springframework.web.bind.annotation.RequestParam;
|
||
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.jysoft.weChat.service.WechatService;
|
||
import com.jysoft.weChat.util.HttpUtil;
|
||
import com.jysoft.weChat.util.ParseUtil;
|
||
import com.jysoft.weChat.util.WechatUtil;
|
||
import com.jysoft.weChat.util.Wechatconfig;
|
||
import com.jysoft.weChat.vo.ContentVo;
|
||
import com.jysoft.weChat.vo.WechatMenuVo;
|
||
import com.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectric.greenH5.GreenBaseController;
|
||
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
||
import com.nationalelectric.greenH5.bizc.IGreenGrantAuthBizc;
|
||
import com.nationalelectric.greenH5.po.GreenGrantAuth;
|
||
import com.nationalelectric.greenH5.po.GreenInternalUser;
|
||
import com.nationalelectric.greenH5.po.GreenPersonElecAcc;
|
||
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
import com.nationalelectric.greenH5.po.GreenUserRoleRel;
|
||
import com.nationalelectric.greenH5.service.InternalUserService;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
import com.sgcc.uap.rest.annotation.RawResponseBody;
|
||
import com.sun.org.apache.bcel.internal.generic.SIPUSH;
|
||
|
||
import net.sf.json.JSONObject;
|
||
|
||
/**
|
||
* @author yeping
|
||
* @date 2019-10-21
|
||
* @描述:微信公众号-菜单功能
|
||
*
|
||
*/
|
||
|
||
@Controller
|
||
@RequestMapping("/wechat")
|
||
public class WechatController extends GreenBaseController {
|
||
|
||
@Resource
|
||
private WechatService wService;
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
@Resource
|
||
private IGreenGrantAuthBizc greenGrantAuthBizc;
|
||
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
|
||
@Autowired
|
||
private InternalUserService internalUserService;
|
||
|
||
/**
|
||
* 创建菜单
|
||
*/
|
||
@SuppressWarnings({ "static-access", "deprecation" })
|
||
@RawResponseBody
|
||
@RequestMapping(value = "/createMenu", method = { RequestMethod.POST, RequestMethod.GET })
|
||
public String createMenu(HttpServletRequest request, HttpSession session) {
|
||
try {
|
||
String url = String.format("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s",
|
||
Wechatconfig.accessToken.getTokenName());
|
||
System.out.println(url);
|
||
// 创建菜单对象
|
||
WechatMenuVo menu = new WechatMenuVo();
|
||
// 一级菜单数组
|
||
List<WechatMenuVo> buttons = new ArrayList<WechatMenuVo>();
|
||
|
||
WechatMenuVo button1 = new WechatMenuVo();
|
||
button1.setName("智慧后勤");
|
||
button1.setType("view");
|
||
|
||
// String url1 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.zhhqUrl) + "&state=STATE#wechat_redirect";
|
||
String url1 = Wechatconfig.DNS + Wechatconfig.zhhqUrl;
|
||
button1.setUrl(url1);
|
||
System.out.println(url1);
|
||
|
||
// WechatMenuVo button2 = new WechatMenuVo();
|
||
// button2.setName("大客户专版");
|
||
// button2.setType("view");
|
||
// // 访问菜单页面进行授权
|
||
// // snsapi_userinfo (弹出授权页面)
|
||
//// String url2 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
//// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
//// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.enterpriseUrl) + "&state=STATE#wechat_redirect";
|
||
// String url2 = Wechatconfig.DNS + Wechatconfig.enterpriseUrl;
|
||
// button2.setUrl(url2);
|
||
// System.out.println(url2);
|
||
|
||
WechatMenuVo button3 = new WechatMenuVo();
|
||
button3.setName("用户中心");
|
||
button3.setType("view");
|
||
// 访问菜单页面进行授权
|
||
// snsapi_userinfo (弹出授权页面)
|
||
// String url3 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.registerUrl) + "&state=STATE#wechat_redirect";
|
||
// button3.setUrl(url3);
|
||
// System.out.println(url3);
|
||
|
||
WechatMenuVo subButton1 = new WechatMenuVo();
|
||
subButton1.setName("用户注册");
|
||
subButton1.setType("view");
|
||
// 访问菜单页面进行授权
|
||
// snsapi_userinfo (弹出授权页面)
|
||
// String registerUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.registerUrl) + "&state=STATE#wechat_redirect";
|
||
String registerUrl = Wechatconfig.DNS + Wechatconfig.registerUrl;
|
||
subButton1.setUrl(registerUrl);
|
||
System.out.println(registerUrl);
|
||
|
||
// WechatMenuVo subButton3 = new WechatMenuVo();
|
||
// subButton3.setName("高校用户");
|
||
// subButton3.setType("view");
|
||
// // 访问菜单页面进行授权
|
||
// // snsapi_userinfo (弹出授权页面)
|
||
//// String registerUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
//// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
//// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.registerUrl) + "&state=STATE#wechat_redirect";
|
||
// String registerUrlOfSchool= Wechatconfig.DNS + Wechatconfig.registerUrlOfSchool;
|
||
// subButton3.setUrl(registerUrlOfSchool);
|
||
// System.out.println(registerUrlOfSchool);
|
||
|
||
WechatMenuVo subButton2 = new WechatMenuVo();
|
||
subButton2.setName("帮助");
|
||
subButton2.setType("view");
|
||
// 访问菜单页面进行授权
|
||
// snsapi_userinfo (弹出授权页面)
|
||
// String helpUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.helpUrl) + "&state=STATE#wechat_redirect";
|
||
String helpUrl = Wechatconfig.DNS + Wechatconfig.helpUrl;
|
||
subButton2.setUrl(helpUrl);
|
||
System.out.println(helpUrl);
|
||
|
||
List<WechatMenuVo> menus = new ArrayList<WechatMenuVo>();
|
||
menus.add(subButton1);
|
||
// menus.add(subButton3);
|
||
menus.add(subButton2);
|
||
button3.setSub_button(menus);
|
||
|
||
|
||
// WechatMenuVo button1 = new WechatMenuVo();
|
||
// button1.setName("智慧后勤");
|
||
// button1.setType("view");
|
||
//
|
||
// String url1 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.zhhqUrl) + "&state=STATE#wechat_redirect";
|
||
// button1.setUrl(url1);
|
||
// System.out.println(url1);
|
||
//
|
||
// WechatMenuVo button2 = new WechatMenuVo();
|
||
// button2.setName("个人中心");
|
||
// button2.setType("view");
|
||
// // 访问菜单页面进行授权
|
||
// // snsapi_userinfo (弹出授权页面)
|
||
// String url2 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.registerUrl) + "&state=STATE#wechat_redirect";
|
||
// button2.setUrl(url2);
|
||
// System.out.println(url2);
|
||
//
|
||
// WechatMenuVo button3 = new WechatMenuVo();
|
||
// button3.setName("后勤发布");
|
||
// button3.setType("view");
|
||
// // 访问菜单页面进行授权
|
||
// // snsapi_userinfo (弹出授权页面)
|
||
// String url3 = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + Wechatconfig.appId
|
||
// + "&response_type=code" + "&scope=snsapi_userinfo" + "&redirect_uri="//
|
||
// + URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.hqfbUrl) + "&state=STATE#wechat_redirect";
|
||
// button3.setUrl(url3);
|
||
// System.out.println(url3);
|
||
buttons.add(button1);
|
||
// buttons.add(button2);
|
||
buttons.add(button3);
|
||
menu.setButton(buttons);
|
||
|
||
// 将菜单对象转换成json字符串
|
||
String jsonMenu = JSONObject.fromObject(menu).toString();
|
||
// 调用接口创建菜单
|
||
String resultStr = HttpUtil.postHttpsResponse(url, jsonMenu);
|
||
|
||
if (resultStr.length() > 0) {
|
||
|
||
JSONObject jsonObject = new JSONObject().fromObject(resultStr);
|
||
int code = jsonObject.getInt("errcode");
|
||
if (code != 0) {
|
||
System.out.println("创建菜单失败原因:" + jsonObject.getString("errmsg"));
|
||
|
||
}
|
||
}
|
||
// 创建菜单end
|
||
return "";
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return "";
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 网页授权2
|
||
* 进入页面后返回code
|
||
*/
|
||
@SuppressWarnings("static-access")
|
||
@RawResponseBody
|
||
@RequestMapping(value = "/wechatOAuth2", method = { RequestMethod.POST, RequestMethod.GET })
|
||
public RestResult wechatOAuth2(@RequestBody Object requestBody) {
|
||
try {
|
||
|
||
Map<String, Object> map = new ObjectMapper().convertValue(requestBody,
|
||
new TypeReference<Map<String, Object>>() {
|
||
});
|
||
|
||
String code = ParseUtil.parseText(map.get("code"));
|
||
if (code.length() > 0) {
|
||
|
||
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Wechatconfig.appId
|
||
+ "&secret=" + Wechatconfig.appSecret + "&code=" + code + "&grant_type=authorization_code";
|
||
String tokenString = HttpUtil.getHttpsResponse(url, "");
|
||
System.out.println(tokenString);
|
||
JSONObject tokenJson = new JSONObject().fromObject(tokenString);
|
||
|
||
String openid = ParseUtil.parseText(tokenJson.get("openid"));
|
||
String access_token = ParseUtil.parseText(tokenJson.get("access_token"));
|
||
|
||
// 获取用户信息
|
||
|
||
// http:GET(请使用https协议)
|
||
|
||
String getUserUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid="
|
||
+ openid + "&lang=zh_CN";
|
||
String userString = HttpUtil.getHttpsResponse(getUserUrl, "");
|
||
|
||
String json = new String(userString.getBytes("ISO-8859-1"), "UTF-8");
|
||
|
||
JSONObject resultObj = new JSONObject().fromObject(json);
|
||
System.out.println(json);
|
||
//openid = "o1Y6NxBPOM_7E7HNdOA1GxSlwNp8"; //本地浏览器测试用
|
||
String sqlByOpenId = "select id from green_user_info where wxopenid = '" + openid
|
||
+ "' AND IS_DELETED = 'N'";
|
||
List<Map<String, Object>> openIdList = hibernateDao.queryForListWithSql(sqlByOpenId.toString());
|
||
if (openIdList.size() == 0) {
|
||
System.out.println(6666);
|
||
GreenUserInfo greenUserInfo = new GreenUserInfo();
|
||
String userid = UUID.randomUUID().toString().replace("-", "");
|
||
greenUserInfo.setWxOpenId(openid);
|
||
greenUserInfo.setId(userid);
|
||
greenUserInfo.setIsDeleted("N");
|
||
greenUserInfo.setGmtCreated(new Date());
|
||
hibernateDao.saveObject(greenUserInfo);
|
||
System.out.println("openid=" + openid + "已记录入系统");
|
||
GreenUserRoleRel greenUserRoleRel = new GreenUserRoleRel();
|
||
greenUserRoleRel.setCreator(userid);
|
||
greenUserRoleRel.setGmtCreated(new Date());
|
||
greenUserRoleRel.setGmtModified(new Date());
|
||
greenUserRoleRel.setIsDeleted("N");
|
||
greenUserRoleRel.setModifier(userid);
|
||
greenUserRoleRel.setRoleId((long) 9);
|
||
greenUserRoleRel.setRoleName("外部人员");
|
||
greenUserRoleRel.setUserId(userid);
|
||
greenUserRoleRel.setUserName("");
|
||
hibernateDao.saveObject(greenUserRoleRel);
|
||
}
|
||
|
||
return new RestResult("1", "授权成功", resultObj);
|
||
|
||
}
|
||
return new RestResult("0", "授权失败");
|
||
} catch (Exception e) {
|
||
return new RestResult("0", "授权失败");
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 网页授权
|
||
*/
|
||
@SuppressWarnings("static-access")
|
||
@RawResponseBody
|
||
@RequestMapping(value = "/wechatOAuth", method = { RequestMethod.POST, RequestMethod.GET })
|
||
public RestResult wechatOAuth(@RequestBody Object requestBody) {
|
||
try {
|
||
|
||
Map<String, Object> map = new ObjectMapper().convertValue(requestBody,
|
||
new TypeReference<Map<String, Object>>() {
|
||
});
|
||
|
||
String code = ParseUtil.parseText(map.get("code"));
|
||
if (code.length() > 0) {
|
||
|
||
String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Wechatconfig.appId
|
||
+ "&secret=" + Wechatconfig.appSecret + "&code=" + code + "&grant_type=authorization_code";
|
||
String tokenString = HttpUtil.getHttpsResponse(url, "");
|
||
System.out.println(tokenString);
|
||
JSONObject tokenJson = new JSONObject().fromObject(tokenString);
|
||
if(!code.equals("o1Y6NxBPOM_7E7HNdOA1GxSlwNp8")&& !tokenJson.containsKey("openid")){
|
||
return new RestResult("0", "授权失败");
|
||
}
|
||
|
||
String openid = ParseUtil.parseText(tokenJson.get("openid"));
|
||
String access_token = ParseUtil.parseText(tokenJson.get("access_token"));
|
||
|
||
// 获取用户信息
|
||
|
||
// http:GET(请使用https协议)
|
||
|
||
String getUserUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid="
|
||
+ openid + "&lang=zh_CN";
|
||
String userString = HttpUtil.getHttpsResponse(getUserUrl, "");
|
||
|
||
String json = new String(userString.getBytes("ISO-8859-1"), "UTF-8");
|
||
|
||
JSONObject resultObj = new JSONObject().fromObject(json);
|
||
System.out.println(json);
|
||
//openid = "o1Y6NxBPOM_7E7HNdOA1GxSlwNp8"; //本地浏览器测试用
|
||
String sqlByOpenId = "select id from green_user_info where wxopenid = '" + openid
|
||
+ "' AND IS_DELETED = 'N'";
|
||
List<Map<String, Object>> openIdList = hibernateDao.queryForListWithSql(sqlByOpenId.toString());
|
||
if (openIdList.size() == 0) {
|
||
System.out.println(6666);
|
||
GreenUserInfo greenUserInfo = new GreenUserInfo();
|
||
String userid = UUID.randomUUID().toString().replace("-", "");
|
||
greenUserInfo.setWxOpenId(openid);
|
||
greenUserInfo.setId(userid);
|
||
greenUserInfo.setIsDeleted("N");
|
||
greenUserInfo.setGmtCreated(new Date());
|
||
hibernateDao.saveObject(greenUserInfo);
|
||
System.out.println("openid=" + openid + "已记录入系统");
|
||
GreenUserRoleRel greenUserRoleRel = new GreenUserRoleRel();
|
||
greenUserRoleRel.setCreator(userid);
|
||
greenUserRoleRel.setGmtCreated(new Date());
|
||
greenUserRoleRel.setGmtModified(new Date());
|
||
greenUserRoleRel.setIsDeleted("N");
|
||
greenUserRoleRel.setModifier(userid);
|
||
greenUserRoleRel.setRoleId((long) 9);
|
||
greenUserRoleRel.setRoleName("外部人员");
|
||
greenUserRoleRel.setUserId(userid);
|
||
greenUserRoleRel.setUserName("");
|
||
hibernateDao.saveObject(greenUserRoleRel);
|
||
}
|
||
|
||
return new RestResult("1", "授权成功", resultObj);
|
||
|
||
}
|
||
return new RestResult("0", "授权失败");
|
||
} catch (Exception e) {
|
||
return new RestResult("0", "授权失败");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* js-sdk(用于授权)
|
||
*/
|
||
@RawResponseBody
|
||
@RequestMapping(value = "/wechatJsSdk", method = { RequestMethod.POST, RequestMethod.GET })
|
||
public RestResult wechatJsSdk(HttpServletRequest request, HttpSession session) {
|
||
try {
|
||
String url = ParseUtil.parseText(request.getParameter("url"));
|
||
Map<String, String> map = new HashMap<>();
|
||
String timestamp = ParseUtil.parseText(new Date().getTime() / 1000);
|
||
|
||
map.put("noncestr", UUID.randomUUID().toString());
|
||
map.put("timestamp", timestamp);
|
||
map.put("url", url);
|
||
map.put("jsapi_ticket", Wechatconfig.ticket);
|
||
|
||
String[] strArray = { "noncestr", "timestamp", "url", "jsapi_ticket" };
|
||
Arrays.sort(strArray);
|
||
|
||
String string1 = strArray[0] + "=" + map.get(strArray[0]) + "&" + strArray[1] + "=" + map.get(strArray[1])
|
||
+ "&" + strArray[2] + "=" + map.get(strArray[2]) + "&" + strArray[3] + "=" + map.get(strArray[3]);
|
||
|
||
String signature = WechatUtil.shal(string1);
|
||
map.put("signature", signature);
|
||
map.put("appId", Wechatconfig.appId);
|
||
return new RestResult("1", "");
|
||
} catch (Exception e) {
|
||
|
||
return new RestResult("1", "");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* js-sdk(用于签名)
|
||
*/
|
||
@RawResponseBody
|
||
@RequestMapping(value = "/wechatJsSdk2", method = { RequestMethod.POST, RequestMethod.GET })
|
||
public RestResult wechatJsSdk2(Map<String, Object> pMap) {
|
||
try {
|
||
String url = ParseUtil.parseText(pMap.get("url"));
|
||
Map<String, String> map = new HashMap<String, String>();
|
||
String timestamp = ParseUtil.parseText(new Date().getTime() / 1000);
|
||
|
||
map.put("noncestr", UUID.randomUUID().toString());
|
||
map.put("timestamp", timestamp);
|
||
map.put("url", url);
|
||
map.put("jsapi_ticket", Wechatconfig.ticket);
|
||
|
||
String[] strArray = { "noncestr", "timestamp", "url", "jsapi_ticket" };
|
||
Arrays.sort(strArray);
|
||
|
||
String string1 = strArray[0] + "=" + map.get(strArray[0]) + "&" + strArray[1] + "=" + map.get(strArray[1])
|
||
+ "&" + strArray[2] + "=" + map.get(strArray[2]) + "&" + strArray[3] + "=" + map.get(strArray[3]);
|
||
|
||
String signature = WechatUtil.shal(string1);
|
||
map.put("signature", signature);
|
||
map.put("appId", Wechatconfig.appId);
|
||
return new RestResult("1", map);
|
||
} catch (Exception e) {
|
||
|
||
return new RestResult("0", "失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**************************************** 微信共用方法 **********************************************************************/
|
||
|
||
// /**
|
||
// * 菜单分享功能
|
||
// */
|
||
// @SuppressWarnings("deprecation")
|
||
// @RawResponseBody
|
||
// @RequestMapping(value = "/wechatFilter", method = RequestMethod.GET)
|
||
// public RestResult wechatFilter(HttpServletRequest request, HttpSession
|
||
// session) {
|
||
//
|
||
// try {
|
||
// String page = ParseUtil.parseText(request.getParameter("page"));
|
||
// String url = URLEncoder.encode(Wechatconfig.DNS + Wechatconfig.shareUrl +
|
||
// page);
|
||
// String redirect =
|
||
// "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
|
||
// Wechatconfig.appId + "&response_type=code" + "&scope=snsapi_userinfo" +
|
||
// "&redirect_uri="//
|
||
// + url + "&state=STATE#wechat_redirect";
|
||
// System.out.println(redirect);
|
||
// return new RestResult("1", redirect);
|
||
// } catch (Exception e) {
|
||
// e.printStackTrace();
|
||
// return new RestResult("1", "分享失败!");
|
||
// }
|
||
//
|
||
// }
|
||
|
||
/**************************************** 模板推送功能 **********************************************************************/
|
||
|
||
// /**
|
||
// * 单条告警信息详细数据(warnId)
|
||
// */
|
||
// @RequestMapping(value = "/warnDetail", method = { RequestMethod.GET,
|
||
// RequestMethod.POST })
|
||
// @RawResponseBody
|
||
// public RestResult warnDetail(HttpServletRequest request, HttpSession
|
||
// session) {
|
||
// try {
|
||
// String warnId = ParseUtil.parseText(request.getParameter("warnId"));
|
||
// if (warnId.length() > 0) {
|
||
//
|
||
// //ContentInfoVo vo = wService.queryByID(warnId);
|
||
// return new RestResult("1", "成功!", vo);
|
||
// } else {
|
||
// return new RestResult(1, null);
|
||
//
|
||
// }
|
||
// } catch (Exception e) {
|
||
// e.printStackTrace();
|
||
// return new RestResult(1, "获取预警详细信息失败!");
|
||
//
|
||
// }
|
||
// }
|
||
|
||
// 查询部门名称
|
||
@RequestMapping(value = "/getOrgname", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult getOrgname() {
|
||
// 查询单位部门名称SELECT id,name from green_department WHERE name is not null;
|
||
String sqlQueryOrgname = "SELECT name from green_department WHERE parent_id>0 and name is not null order by seq asc;";
|
||
RestResult rs = null;
|
||
try {
|
||
List<Map<String, Object>> OrgnameList = hibernateDao.queryForListWithSql(sqlQueryOrgname);
|
||
List<String> resultList = new ArrayList<String>();
|
||
for (Map<String, Object> map : OrgnameList) {
|
||
resultList.add((String) map.get("name"));
|
||
}
|
||
System.out.println(OrgnameList);
|
||
/*
|
||
* hibernateDao.updateWithSql(sqlQueryOrgname, new Object[] {});
|
||
*/
|
||
return new RestResult("1", resultList); // 正确提示
|
||
} catch (Exception e) {
|
||
return new RestResult("0", "查询异常"); // 错误提示
|
||
}
|
||
|
||
}
|
||
|
||
/**************************************** 用户注册页面功能 **********************************************************************/
|
||
|
||
// /**
|
||
// * 用户注册页面---保存用户消息,2020-02-16
|
||
// */
|
||
@RequestMapping(value = "/saveWechatUserOfSchool", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult saveWechatUserOfSchool(@RequestBody GreenUserInfo greenUserInfo) {
|
||
HashMap<String, Object> rMap = new HashMap<String,Object>();
|
||
rMap.put("role", 40);
|
||
rMap.put("returnMsg", "更新成功");
|
||
try {
|
||
System.out.println("111");
|
||
String openId = greenUserInfo.getWxOpenId();
|
||
String wxProfile = greenUserInfo.getWxProfile();
|
||
String realname = greenUserInfo.getRealName();
|
||
String mobile = greenUserInfo.getMobile();
|
||
String department_name = greenUserInfo.getDepartmentName();
|
||
long departmentId = greenUserInfo.getDepartmentId();
|
||
String orgName = greenUserInfo.getOrgName();
|
||
String gender = greenUserInfo.getGender();
|
||
// String idnumber = greenUserInfo.getIdnumber();
|
||
String isInner = greenUserInfo.getIsInner();
|
||
String className = greenUserInfo.getClassName();
|
||
|
||
String sqlByOpenId = "select id from green_user_info where wxopenid = '" + openId
|
||
+ "' AND IS_DELETED = 'N'";
|
||
List<Map<String, Object>> openIdList = hibernateDao.queryForListWithSql(sqlByOpenId.toString());
|
||
List<Map<String, Object>> deptList = new ArrayList<Map<String,Object>>();
|
||
if (openIdList.size() > 0) {
|
||
String id = (String) openIdList.get(0).get("id");
|
||
//如果用户已审核通过,只需要更新手机号和部门或单位字段
|
||
// if(greenUserInfo.getUserStatus() != null && greenUserInfo.getUserStatus().equals("2")){
|
||
// String updateSql = "update green_user_info set mobile=?, department_id = ?, department_name = ?,"
|
||
// + "class_name=?,org_name=?,user_status=? where id = ?";
|
||
//
|
||
// //内部用户更新手机号、部门字段
|
||
// if(!orgName.equals("其它")){
|
||
// String deptSql = "select * from green_department where name = ?";
|
||
// deptList = hibernateDao.queryForListWithSql(deptSql, new Object[] { orgName });
|
||
// if(deptList.size() > 0){
|
||
// //如果部门匹配
|
||
// hibernateDao.updateWithSql(updateSql,
|
||
// new Object[] { mobile, deptList.get(0).get("id").toString(),department_name,
|
||
// className,orgName, 2,id });
|
||
// }
|
||
// }
|
||
//
|
||
// return new RestResult("1", "更新成功");
|
||
// }
|
||
|
||
String updateSql = "update green_user_info set wx_profile=?,real_name=?,mobile=?, org_name = ?,gender=?, "
|
||
+ "department_id = ?, department_name = ?,class_name=?,is_inner = ?,user_status=? "
|
||
+ "where id = ?";
|
||
// 查权限
|
||
String roleSql = "select * from green_user_role_rel where user_id = ?";
|
||
List<GreenUserRoleRel> urr = hibernateDao.queryForListWithSql(roleSql, new Object[] { id }, new BeanPropertyRowMapper<GreenUserRoleRel>(GreenUserRoleRel.class) );
|
||
GreenUserRoleRel role = null;
|
||
if (urr.size() > 0) {
|
||
role = urr.get(0);
|
||
}
|
||
|
||
//注册时选择了某个公司
|
||
if(!orgName.equals("其它")){
|
||
|
||
if (role != null) {
|
||
|
||
// 自动 给予普通员工角色
|
||
role.setRoleId((long) 40);
|
||
role.setRoleName("学生");
|
||
role.setGmtModified(new Date());
|
||
hibernateDao.updateObject(role, role.getId());
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { wxProfile, realname, mobile, orgName, gender,
|
||
departmentId,department_name,className,isInner, 2,id });
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
return new RestResult("1", rMap);
|
||
|
||
}
|
||
|
||
|
||
}
|
||
|
||
|
||
return new RestResult("1", rMap);
|
||
} else {
|
||
greenUserInfo.setWxOpenId(openId);
|
||
greenUserInfo.setId(UUID.randomUUID().toString().replace("-", ""));
|
||
greenUserInfo.setIsDeleted("N");
|
||
greenUserInfo.setGmtCreated(new Date());
|
||
hibernateDao.saveObject(greenUserInfo);
|
||
return new RestResult("1", rMap);
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult("0", "更新失败!");
|
||
}
|
||
}
|
||
|
||
/**************************************** 用户注册页面功能 **********************************************************************/
|
||
|
||
// /**
|
||
// * 用户注册页面---保存用户消息,2020-02-16
|
||
// */
|
||
@RequestMapping(value = "/saveWechatUser", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult saveWechatUser(@RequestBody GreenUserInfo greenUserInfo) {
|
||
try {
|
||
System.out.println("111");
|
||
String openId = greenUserInfo.getWxOpenId();
|
||
String wxProfile = greenUserInfo.getWxProfile();
|
||
String realname = greenUserInfo.getRealName();
|
||
String mobile = greenUserInfo.getMobile();
|
||
String department_name = greenUserInfo.getDepartmentName();
|
||
Long department_id = greenUserInfo.getDepartmentId();
|
||
String orgName = greenUserInfo.getOrgName();
|
||
String gender = greenUserInfo.getGender();
|
||
// String idnumber = greenUserInfo.getIdnumber();
|
||
String isInner = greenUserInfo.getIsInner();
|
||
|
||
String sqlByOpenId = "select id from green_user_info where wxopenid = '" + openId
|
||
+ "' AND IS_DELETED = 'N'";
|
||
List<Map<String, Object>> openIdList = hibernateDao.queryForListWithSql(sqlByOpenId.toString());
|
||
if (openIdList.size() > 0) {
|
||
String id = (String) openIdList.get(0).get("id");
|
||
//如果用户已审核通过,只需要更新手机号和部门或单位字段
|
||
if(greenUserInfo.getUserStatus() != null && greenUserInfo.getUserStatus().equals("2")){
|
||
String updateSql = "update green_user_info set mobile=?, department_id = ?, department_name = ?,user_status=? where id = ?";
|
||
|
||
//内部用户更新手机号、部门字段
|
||
if(!orgName.equals("其它")){
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { mobile,department_id,department_name, 2,id });
|
||
// String deptSql = "select * from green_department where name = ?";
|
||
// List<Map<String, Object>> deptList = hibernateDao.queryForListWithSql(deptSql, new Object[] { orgName });
|
||
// if(deptList.size() > 0){
|
||
// //如果部门匹配
|
||
// hibernateDao.updateWithSql(updateSql,
|
||
// new Object[] { mobile, deptList.get(0).get("id").toString(),orgName, 2,id });
|
||
//
|
||
// }
|
||
|
||
}
|
||
//外部用户更新手机号、单位字段
|
||
else if(orgName.equals("其它")){
|
||
//如果部门匹配
|
||
updateSql = "update green_user_info set mobile=?, org_name = ?,user_status=? where id = ?";
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { mobile,orgName, 2,id });
|
||
}
|
||
|
||
return new RestResult("1", "更新成功");
|
||
}
|
||
|
||
// 查权限
|
||
String roleSql = "select * from green_user_role_rel where user_id = ?";
|
||
List<GreenUserRoleRel> urr = hibernateDao.queryForListWithSql(roleSql, new Object[] { id }, new BeanPropertyRowMapper<GreenUserRoleRel>(GreenUserRoleRel.class) );
|
||
GreenUserRoleRel role = null;
|
||
if (urr.size() > 0) {
|
||
role = urr.get(0);
|
||
}
|
||
|
||
//注册时选择了某个公司
|
||
if(!orgName.equals("其它")){
|
||
// 根据用户名和手机号 查询是否存在内部用户表中
|
||
List<GreenInternalUser> internalUsers = internalUserService.getListByNameAndPhone(realname, mobile);
|
||
|
||
// String deptSql = "select * from green_department where name = ?";
|
||
// List<Map<String, Object>> deptList = hibernateDao.queryForListWithSql(deptSql, new Object[] { department_name });
|
||
String deptSql = "select * from green_department where id = ?";
|
||
List<Map<String, Object>> deptList = hibernateDao.queryForListWithSql(deptSql, new Object[] { department_id });
|
||
if(deptList.size() == 0){
|
||
//如果部门不匹配,通知审核结果,没有此部门
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核不通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("部门信息未匹配成功", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
return new RestResult("2", "更新失败,请注意查收消息");
|
||
}
|
||
String updateSql = "update green_user_info set wx_profile=?,real_name=?,mobile=?, org_name = ?,gender=?, department_id = ?, department_name = ?,is_inner = ?,user_status=? where id = ?";
|
||
|
||
//如果姓名、手机号能匹配上 // 内部员工
|
||
if (internalUsers.size() > 0) {
|
||
//内部员工,自动生成账户
|
||
// GreenPersonElecAcc gp = new GreenPersonElecAcc();
|
||
// gp.setPersonId(id);
|
||
// gp.setPersonName(realname);
|
||
// gp.setPhone(mobile);
|
||
// gp.setDepartName(orgName);
|
||
// String randomDate = new Date().getTime()+"";
|
||
// String account = mobile+randomDate.substring(randomDate.length()-6);
|
||
// gp.setAccount(account);
|
||
// hibernateDao.saveObject(gp);
|
||
//内部员工,自动生成充值金额管理记录
|
||
// 修改
|
||
if (role != null) {
|
||
GreenInternalUser gUser = internalUsers.get(0);
|
||
//如果部门也正确,即确认是省公司员工
|
||
if (gUser.getDepartment().equals(department_name)) { // 填写的部门信息与 数据库录入的部门一致
|
||
Long deptRole = (Long)(deptList.get(0).get("role_id"));
|
||
Long internalUserRole = gUser.getRoleId();
|
||
if(internalUserRole==null){
|
||
role.setRoleId(deptRole);
|
||
}else{
|
||
role.setRoleId(internalUserRole);
|
||
}
|
||
// 自动 给予普通员工角色
|
||
|
||
// if(gUser.getDepartment().equals("新技术应用事业部")){
|
||
// role.setRoleId((long) 4);
|
||
// }
|
||
role.setRoleName("");
|
||
role.setGmtModified(new Date());
|
||
hibernateDao.updateObject(role, role.getId());
|
||
// if(orgName.equals("")){
|
||
//
|
||
// }
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { wxProfile, realname, mobile, department_name, gender,deptList.get(0).get("id").toString(),orgName,1, 2,id });
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
return new RestResult("1", "更新成功");
|
||
} else {
|
||
//如果部门不匹配,通知审核结果,该部门未查询到注册的用户
|
||
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核不通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("该部门未查询到当前注册用户", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
return new RestResult("2", "更新失败,部门信息错误");*/
|
||
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { wxProfile, realname, mobile, "继远软件", gender,deptList.get(0).get("id").toString(),orgName,isInner, 1,id });
|
||
// 未授权
|
||
System.out.println("未授权,推送消息");
|
||
// 通知用户审核结果
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核不通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("部门信息与内部人员库信息不一致,请核查信息,或联系管理员", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
|
||
// 通知管理员 审核
|
||
Map<String, ContentVo> data = new HashMap<String, ContentVo>();
|
||
data.put("first", new ContentVo("新用户注册成功", "#173177"));
|
||
data.put("keyword1", new ContentVo(realname, "#black"));
|
||
data.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
data.put("keyword3", new ContentVo("待审核", "#black"));
|
||
data.put("remark", new ContentVo("该用户部门信息与内部人员库信息不一致,请您及时审核此用户", "#173177"));
|
||
|
||
// 查询后台配置的 授权管理员 openId
|
||
List<Map<String, String>> list = baseService.getDictionaryInfo("checkUserReg", "checkUserReg");
|
||
String dataValue = list.get(0).get("dataValue");
|
||
if (dataValue == null || dataValue.equals("")) {
|
||
dataValue = Wechatconfig.ADMIN_CHECK_USER;
|
||
}
|
||
wService.publishMsg(data, dataValue, 3);
|
||
|
||
|
||
return new RestResult("2", "部门信息与内部人员库信息不一致,已保存!请核查信息,或联系管理员");
|
||
|
||
}
|
||
|
||
} else {
|
||
// 添加
|
||
// GreenUserRoleRel roleRel = new GreenUserRoleRel();
|
||
// roleRel.setCreator(id);
|
||
// roleRel.setGmtCreated(new Date());
|
||
// roleRel.setGmtModified(new Date());
|
||
// roleRel.setIsDeleted("N");
|
||
// roleRel.setModifier(id);
|
||
// roleRel.setRoleId((long) 2);
|
||
// roleRel.setRoleName("普通员工");
|
||
// roleRel.setUserId(id);
|
||
// roleRel.setUserName("");
|
||
// hibernateDao.saveObject(roleRel);
|
||
}
|
||
|
||
|
||
}
|
||
else { // 选择了某个公司,但是不是此公司员工,记录信息,并通知用户和管理员
|
||
|
||
if (role == null || role.getRoleId().longValue() == 9) {
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { wxProfile, realname, mobile, orgName, gender,deptList.get(0).get("id").toString(),orgName,isInner, 1,id });
|
||
// 未授权
|
||
System.out.println("未授权,推送消息");
|
||
// 通知用户审核结果
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核不通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("人员库未查询到当前注册用户信息,请核查信息,或联系管理员", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
|
||
// 通知管理员 审核
|
||
Map<String, ContentVo> data = new HashMap<String, ContentVo>();
|
||
data.put("first", new ContentVo("新用户注册成功", "#173177"));
|
||
data.put("keyword1", new ContentVo(realname, "#black"));
|
||
data.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
data.put("keyword3", new ContentVo("待审核", "#black"));
|
||
data.put("remark", new ContentVo("内部人员库未查询到此用户,请您及时审核此用户", "#173177"));
|
||
|
||
// 查询后台配置的 授权管理员 openId
|
||
List<Map<String, String>> list = baseService.getDictionaryInfo("checkUserReg", "checkUserReg");
|
||
String dataValue = list.get(0).get("dataValue");
|
||
if (dataValue == null || dataValue.equals("")) {
|
||
dataValue = Wechatconfig.ADMIN_CHECK_USER;
|
||
}
|
||
wService.publishMsg(data, dataValue, 3);
|
||
|
||
|
||
return new RestResult("2", "人员库未查询到当前注册用户信息,已保存!请重新核实,或联系管理员");
|
||
}
|
||
}
|
||
|
||
}
|
||
else { // 非内部员工
|
||
System.out.println(333);
|
||
String updateSql = "update green_user_info set wx_profile=?,real_name=?,mobile=?, org_name = ?,gender=?,is_inner=?,user_status=? where id = ?";
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { wxProfile, realname, mobile, orgName, gender,isInner,2, id });
|
||
|
||
if (role == null || role.getRoleId().longValue() == 9) {
|
||
// 未授权
|
||
System.out.println("未授权,推送消息");
|
||
// 通知用户审核通过
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
return new RestResult("1", "更新成功");
|
||
}
|
||
}
|
||
|
||
return new RestResult("1", "更新成功!");
|
||
} else {
|
||
greenUserInfo.setWxOpenId(openId);
|
||
greenUserInfo.setId(UUID.randomUUID().toString().replace("-", ""));
|
||
greenUserInfo.setIsDeleted("N");
|
||
greenUserInfo.setGmtCreated(new Date());
|
||
hibernateDao.saveObject(greenUserInfo);
|
||
return new RestResult("1", "更新成功");
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult("0", "更新失败!");
|
||
}
|
||
}
|
||
|
||
// /**
|
||
// * 用户注册页面---保存用户消息,2020-02-16前
|
||
// */
|
||
@RequestMapping(value = "/saveWechatUser2", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult saveWechatUser2(@RequestBody GreenUserInfo greenUserInfo) {
|
||
try {
|
||
System.out.println("111");
|
||
String openId = greenUserInfo.getWxOpenId();
|
||
String wxProfile = greenUserInfo.getWxProfile();
|
||
String realname = greenUserInfo.getRealName();
|
||
String mobile = greenUserInfo.getMobile();
|
||
/* String department_name = greenUserInfo.getDepartmentName(); */
|
||
String orgName = greenUserInfo.getOrgName();
|
||
String gender = greenUserInfo.getGender();
|
||
// String idnumber = greenUserInfo.getIdnumber();
|
||
|
||
String sqlByOpenId = "select id from green_user_info where wxopenid = '" + openId
|
||
+ "' AND IS_DELETED = 'N'";
|
||
List<Map<String, Object>> openIdList = hibernateDao.queryForListWithSql(sqlByOpenId.toString());
|
||
if (openIdList.size() > 0) {
|
||
String id = (String) openIdList.get(0).get("id");
|
||
|
||
String deptSql = "select * from green_department where name = ?";
|
||
List<Map<String, Object>> deptList = hibernateDao.queryForListWithSql(deptSql, new Object[] { orgName });
|
||
if (deptList.size() > 0) {
|
||
System.out.println(999);
|
||
String updateSql = "update green_user_info set wx_profile=?,real_name=?,mobile=?, org_name = ?,gender=?, department_id = ?, department_name = ? where id = ?";
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { wxProfile, realname, mobile, "继远软件", gender,deptList.get(0).get("id").toString(),orgName, id });
|
||
} else {
|
||
System.out.println(333);
|
||
String updateSql = "update green_user_info set wx_profile=?,real_name=?,mobile=?, org_name = ?,gender=? where id = ?";
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { wxProfile, realname, mobile, orgName, gender, id });
|
||
}
|
||
|
||
// 查权限
|
||
String roleSql = "select * from green_user_role_rel where user_id = ?";
|
||
List<GreenUserRoleRel> urr = hibernateDao.queryForListWithSql(roleSql, new Object[] { id }, new BeanPropertyRowMapper<GreenUserRoleRel>(GreenUserRoleRel.class) );
|
||
GreenUserRoleRel role = null;
|
||
if (urr.size() > 0) {
|
||
role = urr.get(0);
|
||
}
|
||
// 根据用户名和手机号 查询是否存在内部用户表中
|
||
System.out.println(555);
|
||
List<GreenInternalUser> internalUsers = internalUserService.getListByNameAndPhone(realname, mobile);
|
||
System.out.println(666);
|
||
if (internalUsers.size() > 0) {// 内部员工
|
||
System.out.println(777);
|
||
// 修改
|
||
if (role != null) {
|
||
GreenInternalUser gUser = internalUsers.get(0);
|
||
if (gUser.getDepartment().equals(orgName)) { // 填写的部门信息与 数据库录入的部门一致
|
||
// 自动 给予普通员工角色
|
||
role.setRoleId((long) 2);
|
||
role.setRoleName("普通员工");
|
||
role.setGmtModified(new Date());
|
||
hibernateDao.updateObject(role, role.getId());
|
||
} else {
|
||
// 通知管理员 审核
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> data = new HashMap<String, ContentVo>();
|
||
data.put("first", new ContentVo("新用户注册成功", "#173177"));
|
||
data.put("keyword1", new ContentVo(realname, "#black"));
|
||
data.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
data.put("keyword3", new ContentVo("待审核", "#black"));
|
||
data.put("remark", new ContentVo("请您及时审核当前用户", "#173177"));
|
||
|
||
// 查询后台配置的 授权管理员 openId
|
||
List<Map<String, String>> list = baseService.getDictionaryInfo("checkUserReg", "checkUserReg");
|
||
String dataValue = list.get(0).get("dataValue");
|
||
if (dataValue == null || dataValue.equals("")) {
|
||
dataValue = Wechatconfig.ADMIN_CHECK_USER;
|
||
}
|
||
wService.publishMsg(data, dataValue, 3);
|
||
// 改为待审核状态
|
||
String updateSql = "update green_user_info set user_status = ? where id = ?";
|
||
hibernateDao.updateWithSql(updateSql,
|
||
new Object[] { "1", id }); // 改为待审核状态
|
||
return new RestResult("2", "更新成功,请等待管理员审核");
|
||
}
|
||
|
||
} else {
|
||
// 添加
|
||
GreenUserRoleRel roleRel = new GreenUserRoleRel();
|
||
roleRel.setCreator(id);
|
||
roleRel.setGmtCreated(new Date());
|
||
roleRel.setGmtModified(new Date());
|
||
roleRel.setIsDeleted("N");
|
||
roleRel.setModifier(id);
|
||
roleRel.setRoleId((long) 2);
|
||
roleRel.setRoleName("普通员工");
|
||
roleRel.setUserId(id);
|
||
roleRel.setUserName("");
|
||
hibernateDao.saveObject(roleRel);
|
||
}
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
|
||
} else { // 非内部员工
|
||
|
||
if (role == null || role.getRoleId().longValue() == 9) {
|
||
// 未授权
|
||
System.out.println("未授权,推送消息");
|
||
// 通知用户审核通过
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, openId , 2);
|
||
|
||
// // 通知管理员 审核
|
||
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
// Map<String, ContentVo> data = new HashMap<String, ContentVo>();
|
||
// data.put("first", new ContentVo("新用户注册成功", "#173177"));
|
||
// data.put("keyword1", new ContentVo(realname, "#black"));
|
||
// data.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
// data.put("keyword3", new ContentVo("待审核", "#black"));
|
||
// data.put("remark", new ContentVo("请您及时审核当前用户", "#173177"));
|
||
//
|
||
// // 查询后台配置的 授权管理员 openId
|
||
// List<Map<String, String>> list = baseService.getDictionaryInfo("checkUserReg", "checkUserReg");
|
||
// String dataValue = list.get(0).get("dataValue");
|
||
// if (dataValue == null || dataValue.equals("")) {
|
||
// dataValue = Wechatconfig.ADMIN_CHECK_USER;
|
||
// }
|
||
// wService.publishMsg(data, dataValue, 3);
|
||
return new RestResult("1", "更新成功");
|
||
}
|
||
}
|
||
|
||
return new RestResult("1", "更新成功!");
|
||
} else {
|
||
greenUserInfo.setWxOpenId(openId);
|
||
greenUserInfo.setId(UUID.randomUUID().toString().replace("-", ""));
|
||
greenUserInfo.setIsDeleted("N");
|
||
greenUserInfo.setGmtCreated(new Date());
|
||
hibernateDao.saveObject(greenUserInfo);
|
||
return new RestResult("1", "更新成功");
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult("0", "更新失败!");
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 用户注册页面---获取验证码
|
||
*/
|
||
@RequestMapping(value = "/getCodeInfo", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult getCodeInfo(Map<String, Object> map) {
|
||
try {
|
||
String phone = (String) map.get("phone");
|
||
String checkTime = (String)map.get("checkTime");
|
||
Date date = new Date(Long.parseLong(checkTime));
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||
String dateStr = sdf.format(date);
|
||
String sql = "select date_format(create_date,'%Y-%m-%d %H:%i:%S') as create_date from green_message_monitor where mobile = ? and DATE_FORMAT(create_date,'%Y-%m-%d') = ? order by create_date DESC";
|
||
List<Map<String,Object>> list = hibernateDao.queryForListWithSql(sql, new Object[]{phone,dateStr});
|
||
|
||
if(list.size()>0){
|
||
String numSql = "select data_value from GREEN_DICTIONARY_INFO where data_type='messageMonitorNum' ";
|
||
List<Map<String,Object>> numList = hibernateDao.queryForListWithSql(numSql);
|
||
Integer messageNum = 5;
|
||
if(numList.size()>0){
|
||
messageNum = Integer.parseInt((String) numList.get(0).get("data_value"));
|
||
}
|
||
if(list.size()>=messageNum){
|
||
return new RestResult(Constant.FAILED, "验证码发送次数已到达今日上限,请明日再试");
|
||
}
|
||
String latelyDate = (String) list.get(0).get("create_date");
|
||
Long latelyDateLong = sdf2.parse(latelyDate).getTime();
|
||
if(date.getTime()-latelyDateLong<60*1000){
|
||
return new RestResult(Constant.FAILED, "请间隔一分钟后再次发送");
|
||
}
|
||
}
|
||
|
||
String uuid = UUID.randomUUID().toString().replace("-", "");
|
||
String insertSql = "insert into green_message_monitor(id,mobile,create_date) values(?,?,?)";
|
||
hibernateDao.executeSqlUpdate(insertSql, new Object[] { uuid, phone,date});
|
||
return wService.getCodeInfo(phone);
|
||
} catch (Exception e) {
|
||
return new RestResult(Constant.FAILED, "获取验证码信息失败!");
|
||
|
||
}
|
||
|
||
}
|
||
|
||
// /**
|
||
// * 用户注册页面---根据用户openid获取用户信息
|
||
// */
|
||
// @RequestMapping(value = "/findUserByOpenid", method = {
|
||
// RequestMethod.GET, RequestMethod.POST })
|
||
// @RawResponseBody
|
||
// public RestResult findUserByOpenid(HttpServletRequest request,
|
||
// HttpSession session) {
|
||
// try {
|
||
// String openid = ParseUtil.parseText(request.getParameter("openid"));
|
||
// if (openid.length() > 0) {
|
||
// Map<String, Object> rMap = wService.findUserByOpenid(openid);
|
||
// return new RestResult(0, rMap);
|
||
// } else {
|
||
// return new RestResult(1, null);
|
||
//
|
||
// }
|
||
// } catch (Exception e) {
|
||
// e.printStackTrace();
|
||
// return new RestResult(1, "获取用户信息失败!");
|
||
//
|
||
// }
|
||
// }
|
||
/**
|
||
* 模板消息推送---测试方法
|
||
*/
|
||
@RequestMapping(value = "/senTemplateMessage", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult senTemplateMessage(HttpServletRequest request, HttpSession session) {
|
||
try {
|
||
String openid = request.getParameter("openid") == null ? "o1Y6NxBPOM_7E7HNdOA1GxSlwNp8"
|
||
: request.getParameter("openid");
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> data = new HashMap<String, ContentVo>();
|
||
// data.put("first", new ContentVo("尊敬的用户,您的访客申请审核结果已出",
|
||
// "#173177"));
|
||
// data.put("keyword1", new ContentVo("审核通过", "#black"));
|
||
// data.put("keyword2", new ContentVo(sdf.format(new Date()),
|
||
// "#black"));
|
||
// data.put("remark", new ContentVo("查看详情", "#173177"));
|
||
// wService.publishMsg(data, openid, 2);
|
||
|
||
// data.put("first", new ContentVo("您好,您有一条访客信息需处理", "#173177"));
|
||
// data.put("keyword1", new ContentVo("刘小明", "#black"));
|
||
// data.put("keyword2", new ContentVo("男", "#black"));
|
||
// data.put("keyword3", new ContentVo("15322332233", "#black"));
|
||
// data.put("keyword4", new ContentVo("测试中", "#black"));
|
||
// data.put("keyword5", new ContentVo(sdf.format(new Date()),
|
||
// "#black"));
|
||
// data.put("remark", new ContentVo("请您至\"指尖上的后勤\"微信公众号审核确认",
|
||
// "#173177"));
|
||
// wService.publishMsg(data, openid, 1);
|
||
|
||
data.put("first", new ContentVo("新用户注册成功", "#173177"));
|
||
data.put("keyword1", new ContentVo("刘小明", "#black"));
|
||
data.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
data.put("keyword3", new ContentVo("待审核", "#black"));
|
||
data.put("remark", new ContentVo("请您及时审核当前用户", "#173177"));
|
||
wService.publishMsg(data, openid, 3);
|
||
return new RestResult(Constant.SUCCESS, "推送成功!");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "推送失败!");
|
||
|
||
}
|
||
}
|
||
|
||
@RequestMapping(value = "/sendMsgCheckUser", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult sendMsgCheckUser(HttpServletRequest request) {
|
||
try {
|
||
StringBuffer json = new StringBuffer();
|
||
BufferedReader reader = request.getReader();
|
||
String line = null;
|
||
while ((line = reader.readLine()) != null) {
|
||
json.append(line);
|
||
}
|
||
System.out.println("接收到的json数据为----------------->" + json.toString());
|
||
com.alibaba.fastjson.JSONObject parseObject = JSONArray.parseObject(json.toString());
|
||
String userId = parseObject.getString("toUserId");
|
||
|
||
GreenUserInfo userInfo = getUserInfo(userId);
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的用户注册审核结果已出", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("审核通过", "#black"));
|
||
dataMap.put("keyword2", new ContentVo(sdf.format(new Date()), "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, userInfo.getWxOpenId(), 1);
|
||
|
||
// String updateSql = "update green_user_info set user_status = ? where id = ?";
|
||
// hibernateDao.updateWithSql(updateSql,
|
||
// new Object[] { "", userInfo.getId()}); // 改为已审核状态
|
||
//
|
||
return new RestResult(Constant.SUCCESS, "推送成功!");
|
||
} catch (Exception e) {
|
||
return new RestResult(Constant.FAILED, "推送失败!");
|
||
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 临时停车即将超时提醒
|
||
* @param request
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "/sendMsgCarParking", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult sendMsgCarParking(HttpServletRequest request) {
|
||
try {
|
||
|
||
/*StringBuffer json = new StringBuffer();
|
||
BufferedReader reader = request.getReader();
|
||
String line = null;
|
||
while ((line = reader.readLine()) != null) {
|
||
json.append(line);
|
||
}
|
||
System.out.println("接收到的json数据为----------------->" + json.toString());
|
||
com.alibaba.fastjson.JSONObject parseObject = JSONArray.parseObject(json.toString());
|
||
String userId = parseObject.getString("toUserId");*/
|
||
String userId = request.getParameter("toUserId");
|
||
|
||
GreenUserInfo userInfo = getUserInfo(userId);
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的用户,您的车辆【甘A3248K】停车时间即将超时", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("2020-03-02 10:20", "#black"));
|
||
dataMap.put("keyword2", new ContentVo("2020-03-02 16:20", "#black"));
|
||
dataMap.put("keyword3", new ContentVo("地面停车场", "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, userInfo.getWxOpenId(), 4);
|
||
|
||
// String updateSql = "update green_user_info set user_status = ? where id = ?";
|
||
// hibernateDao.updateWithSql(updateSql,
|
||
// new Object[] { "", userInfo.getId()}); // 改为已审核状态
|
||
//
|
||
return new RestResult(Constant.SUCCESS, "推送成功!");
|
||
} catch (Exception e) {
|
||
return new RestResult(Constant.FAILED, "推送失败!");
|
||
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 临时停车即将超时提醒
|
||
* @param request
|
||
* @return
|
||
*/
|
||
@RequestMapping(value = "/sendMsgVisitorOver", method = { RequestMethod.GET, RequestMethod.POST })
|
||
@RawResponseBody
|
||
public RestResult sendMsgVisitorOver(HttpServletRequest request) {
|
||
try {
|
||
|
||
/*StringBuffer json = new StringBuffer();
|
||
BufferedReader reader = request.getReader();
|
||
String line = null;
|
||
while ((line = reader.readLine()) != null) {
|
||
json.append(line);
|
||
}
|
||
System.out.println("接收到的json数据为----------------->" + json.toString());
|
||
com.alibaba.fastjson.JSONObject parseObject = JSONArray.parseObject(json.toString());
|
||
String userId = parseObject.getString("toUserId");*/
|
||
String userId = request.getParameter("toUserId");
|
||
|
||
GreenUserInfo userInfo = getUserInfo(userId);
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||
Map<String, ContentVo> dataMap = new HashMap<String, ContentVo>();
|
||
dataMap.put("first", new ContentVo("尊敬的访客,您好!您预约的访问时间即将到期", "#173177"));
|
||
dataMap.put("keyword1", new ContentVo("王宇", "#black"));
|
||
dataMap.put("keyword2", new ContentVo("2020-03-02 16:20", "#black"));
|
||
dataMap.put("remark", new ContentVo("感谢您的参于与支持", "#173177"));
|
||
wService.publishMsg(dataMap, userInfo.getWxOpenId(), 5);
|
||
|
||
// String updateSql = "update green_user_info set user_status = ? where id = ?";
|
||
// hibernateDao.updateWithSql(updateSql,
|
||
// new Object[] { "", userInfo.getId()}); // 改为已审核状态
|
||
//
|
||
return new RestResult(Constant.SUCCESS, "推送成功!");
|
||
} catch (Exception e) {
|
||
return new RestResult(Constant.FAILED, "推送失败!");
|
||
|
||
}
|
||
}
|
||
|
||
}
|