1666 lines
58 KiB
Plaintext
1666 lines
58 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
import java.io.IOException;
|
||
import java.io.InputStream;
|
||
import java.io.UnsupportedEncodingException;
|
||
import java.math.BigDecimal;
|
||
import java.math.RoundingMode;
|
||
import java.net.URLDecoder;
|
||
import java.security.NoSuchAlgorithmException;
|
||
import java.sql.SQLException;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.ArrayList;
|
||
import java.util.Calendar;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.Iterator;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.SortedMap;
|
||
import java.util.TreeMap;
|
||
import java.util.regex.Matcher;
|
||
import java.util.regex.Pattern;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.servlet.http.HttpServletRequest;
|
||
|
||
import org.apache.http.HttpEntity;
|
||
import org.apache.http.HttpResponse;
|
||
import org.apache.http.NameValuePair;
|
||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||
import org.apache.http.client.methods.HttpPost;
|
||
import org.apache.http.impl.client.CloseableHttpClient;
|
||
import org.apache.http.impl.client.HttpClients;
|
||
import org.apache.http.message.BasicNameValuePair;
|
||
import org.apache.http.util.EntityUtils;
|
||
import org.codehaus.jackson.map.ObjectMapper;
|
||
import org.codehaus.jackson.type.TypeReference;
|
||
import org.json.JSONObject;
|
||
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.ResponseBody;
|
||
|
||
import com.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.AESUtil;
|
||
import com.nationalelectirc.utils.AesEncryptUtil;
|
||
import com.nationalelectirc.utils.HttpClient;
|
||
import com.nationalelectirc.utils.MD5Util;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectric.greenH5.DTO.GreenCardConsumptionDTO;
|
||
import com.nationalelectric.greenH5.bizc.IGreenImageInfoBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenOperateLogBizc;
|
||
import com.nationalelectric.greenH5.bizc.IGreenUserInfoBizc;
|
||
import com.nationalelectric.greenH5.po.CheckUserInfo;
|
||
import com.nationalelectric.greenH5.po.GreenCardConsumption;
|
||
import com.nationalelectric.greenH5.po.GreenImageInfo;
|
||
import com.nationalelectric.greenH5.po.GreenPermission;
|
||
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
import com.nationalelectric.greenH5.po.Result;
|
||
import com.nationalelectric.greenH5.po.SysMealInfo;
|
||
import com.nationalelectric.greenH5.po.UcenterParam;
|
||
import com.nationalelectric.greenH5.po.UserVo;
|
||
import com.nationalelectric.greenH5.utils.DateUtil;
|
||
import com.nationalelectric.greenH5.utils.DesUtil;
|
||
import com.nationalelectric.greenH5.utils.EncryptUtil;
|
||
import com.nationalelectric.greenH5.utils.JSONUtil;
|
||
import com.sgcc.isc.service.adapter.utils.JsonUtil;
|
||
import com.sgcc.uap.mdd.model.utils.StringUtil;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
import net.sf.json.JSONArray;
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
*
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
*
|
||
*
|
||
* @author chenweikang
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/greenUserInfo")
|
||
public class GreenUserInfoController extends GreenBaseController {
|
||
/**
|
||
* greenuserinfo GreenUserInfo逻辑构件
|
||
*/
|
||
@Resource
|
||
private IGreenUserInfoBizc greenuserinfoBizc;
|
||
|
||
@Resource
|
||
private IGreenUserInfoBizc greenUserInfoBizc;
|
||
|
||
@Resource
|
||
private IGreenOperateLogBizc greenOperateLogBizc;
|
||
|
||
@Resource
|
||
private GreenDictionaryInfoController greenDictionaryInfoController;
|
||
/**
|
||
* HibernateDao逻辑构件
|
||
*/
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
private static final String KY = "e7033d5ccecd45ba";
|
||
private static final String IV = "d885b28044194523";
|
||
|
||
private String CK_MONEY_URL = null;
|
||
private String CK_JY_URL = null;
|
||
private String CK_KY = null;
|
||
private String CK_IV = null;
|
||
private String CK_CONSUM_URL = null;
|
||
// @Autowired
|
||
// private JdbcUtil jdbcUtil;
|
||
|
||
@Resource
|
||
private IGreenImageInfoBizc greenimageinfoBizc;
|
||
|
||
/*
|
||
*
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping(value = "/checkUserInfo", method = RequestMethod.POST)
|
||
public HashMap<String, Object> checkUserInfo(@RequestBody Object requestBody) throws Exception {
|
||
UcenterParam ucenterParam = new ObjectMapper().convertValue(requestBody, new TypeReference<UcenterParam>() {
|
||
});
|
||
HashMap<String, Object> map = new HashMap<String, Object>();
|
||
System.out.println("checkUserInfo:数据--->" + ucenterParam.getData());
|
||
String DATAstring = AesEncryptUtil.desEncrypt(ucenterParam.getData());
|
||
// System.out.println("我们的解密:"+DATAstring);
|
||
String dataString2 = AESUtil.Decrypt(ucenterParam.getData(), KY, IV);
|
||
System.out.println("third en---->:" + dataString2);
|
||
|
||
JSONObject preDataSandUserCode = new JSONObject(dataString2);
|
||
String userCode = preDataSandUserCode.getString("usercode");
|
||
|
||
String str = "green_tk_" + userCode;
|
||
String md5 = MD5Util.getMD5(str);
|
||
if (!md5.equals(preDataSandUserCode.getString("sign"))) {
|
||
return map;
|
||
}
|
||
String desData = null;
|
||
CheckUserInfo userInfo = null;
|
||
try {
|
||
// String stri =
|
||
// "{\"mobile_phone\":\"13709801236\",\"meal_no\":\"\",\"user_name\":\"n123\",\"department\":\"n123\",\"company\":\"n123\",\"channelNum\":\"001\"}";
|
||
GreenUserInfo greenUserInfo = greenUserInfoBizc.get(userCode);
|
||
|
||
// JSONObject json = new JSONObject(stri);
|
||
userInfo = new CheckUserInfo();
|
||
|
||
userInfo.setUser_name(greenUserInfo.getLoginName());
|
||
|
||
userInfo.setCompany(greenUserInfo.getCompony());
|
||
|
||
userInfo.setDepartment(greenUserInfo.getDepartmentName());
|
||
|
||
userInfo.setMeal_no(greenUserInfo.getMealNo());
|
||
|
||
userInfo.setMobile_phone(greenUserInfo.getMobile());
|
||
// json.put("mobile_phone", greenUserInfo.getMobile());
|
||
// json.put("meal_no", greenUserInfo.getMealNo());
|
||
// json.put("user_name", greenUserInfo.getLoginName());
|
||
// json.put("department", greenUserInfo.getDepartmentName());
|
||
// json.put("company", greenUserInfo.getCompony());
|
||
String json = JsonUtil.toJson(userInfo);
|
||
desData = AESUtil.Encrypt(json, KY, IV);
|
||
map.put("data", desData);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return map;
|
||
|
||
}
|
||
|
||
/*
|
||
*
|
||
* 作废接口,不再使用了 前端 获取token 校验用户是否绑定餐卡
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping(value = "/userMealNo", method = RequestMethod.POST)
|
||
public RestResult userMealNo(@RequestBody Object requestBody) {
|
||
try {
|
||
GreenUserInfo greenUserInfo = new ObjectMapper().convertValue(requestBody,
|
||
new TypeReference<GreenUserInfo>() {
|
||
});
|
||
if (greenUserInfo.getId() != null) {
|
||
String id = greenUserInfo.getId();
|
||
String userInfoSql = "SELECT * FROM GREEN_USER_INFO WHERE id=?";
|
||
List<GreenUserInfo> userInfolist = hibernateDao.queryForListWithSql(userInfoSql, new Object[] { id },
|
||
new BeanPropertyRowMapper(GreenUserInfo.class));// 根据用户id获取用户餐卡号
|
||
if (userInfolist.get(0).getMealNo() != null) {
|
||
return new RestResult(Constant.SUCCESS, "请求成功!");
|
||
}
|
||
return new RestResult(Constant.FAILED, "卡号不存在");
|
||
}
|
||
return new RestResult(Constant.FAILED, "用户id为空");
|
||
} catch (Exception e) {
|
||
// TODO: handle exception
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 取余额请求URL
|
||
*
|
||
* @return
|
||
*/
|
||
private String getCkMoneyUrl() {
|
||
if (this.CK_MONEY_URL == null) {
|
||
String dataType = "ticketUrl";
|
||
String dataCode = "001";
|
||
List<Map<String, String>> urlInfo = greenDictionaryInfoController.getDictionaryInfo(dataType, dataCode);
|
||
Map<String, String> urlMap = urlInfo.get(0);
|
||
String ticketUrl = urlMap.get("data_value");
|
||
String tmp = ticketUrl.substring(ticketUrl.length() - 1);
|
||
if (tmp.equals("/")) {
|
||
ticketUrl = ticketUrl.substring(0, ticketUrl.length() - 1);
|
||
}
|
||
this.CK_MONEY_URL = ticketUrl;
|
||
}
|
||
return this.CK_MONEY_URL;
|
||
}
|
||
|
||
/**
|
||
* 查询餐卡消费记录的URL
|
||
*
|
||
* @return
|
||
*/
|
||
private String getCkConsumUrl() {
|
||
if (this.CK_CONSUM_URL == null) {
|
||
String dataType = "CKConsumUrl";
|
||
String dataCode = "001";
|
||
List<Map<String, String>> urlInfo = greenDictionaryInfoController.getDictionaryInfo(dataType, dataCode);
|
||
Map<String, String> urlMap = urlInfo.get(0);
|
||
String ticketUrl = urlMap.get("data_value");
|
||
String tmp = ticketUrl.substring(ticketUrl.length() - 1);
|
||
if (tmp.equals("/")) {
|
||
ticketUrl = ticketUrl.substring(0, ticketUrl.length() - 1);
|
||
}
|
||
this.CK_CONSUM_URL = ticketUrl;
|
||
}
|
||
return this.CK_CONSUM_URL;
|
||
}
|
||
|
||
/**
|
||
* 取余额请求KY
|
||
*
|
||
* @return
|
||
*/
|
||
private String getCkKy() {
|
||
if (this.CK_KY == null) {
|
||
String dataType = "mealcard_key";
|
||
String dataCode = "01";
|
||
List<Map<String, String>> urlInfo = greenDictionaryInfoController.getDictionaryInfo(dataType, dataCode);
|
||
Map<String, String> urlMap = urlInfo.get(0);
|
||
String ky = urlMap.get("data_value");
|
||
this.CK_KY = ky;
|
||
}
|
||
return this.CK_KY;
|
||
}
|
||
|
||
/**
|
||
* 取余额请求IV
|
||
*
|
||
* @return
|
||
*/
|
||
private String getCkIv() {
|
||
if (this.CK_IV == null) {
|
||
String dataType = "mealcard_iv";
|
||
String dataCode = "01";
|
||
List<Map<String, String>> urlInfo = greenDictionaryInfoController.getDictionaryInfo(dataType, dataCode);
|
||
Map<String, String> urlMap = urlInfo.get(0);
|
||
String iv = urlMap.get("data_value");
|
||
this.CK_IV = iv;
|
||
}
|
||
return this.CK_IV;
|
||
}
|
||
|
||
/**
|
||
* 取餐卡余额请求body
|
||
*
|
||
* @param mealNo
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
private String getCkMoneySignBody(String mealNo) throws Exception {
|
||
String ky = getCkKy();
|
||
String iv = getCkIv();
|
||
// String url = "http://192.168.222.121:8008/PersonMoney";
|
||
|
||
mealNo = DesUtil.encrypt(mealNo, ky, iv);
|
||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||
String dt = simpleDateFormat.format(new Date());
|
||
StringBuffer sBuffer = new StringBuffer("");
|
||
sBuffer.append("\"CardCode\":\"");
|
||
sBuffer.append(mealNo);
|
||
sBuffer.append("\",\"timestamp\":\"");
|
||
sBuffer.append(dt);
|
||
sBuffer.append("\"");
|
||
String ss = sBuffer.toString();
|
||
System.out.println("=======待签名数据:" + ss);
|
||
String sign = MD5Util.getMD5(ss);
|
||
// ==================================
|
||
|
||
StringBuffer ret = new StringBuffer("{");
|
||
ret.append("\"CardCode\":\"");
|
||
ret.append(mealNo);
|
||
ret.append("\",\"timestamp\":\"");
|
||
ret.append(dt);
|
||
ret.append("\",\"sign\":\"");
|
||
ret.append(sign);
|
||
ret.append("\"}");
|
||
String jsonString = ret.toString();
|
||
System.out.println("===签名后组装的jsonString:" + jsonString);
|
||
|
||
return jsonString;
|
||
}
|
||
|
||
/**
|
||
* 解密餐卡数据
|
||
*
|
||
* @param base64Str
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
private String getCkData(String base64Str) throws Exception {
|
||
String ky = getCkKy();
|
||
String iv = getCkIv();
|
||
String res = DesUtil.decrypt(base64Str, ky, iv);
|
||
return res;
|
||
}
|
||
|
||
/**
|
||
* 取餐卡消费记录请求body
|
||
*
|
||
* @param mealNo
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
private String getCkConsumSignBody(String mealNo) throws Exception {
|
||
String ky = getCkKy();
|
||
String iv = getCkIv();
|
||
|
||
mealNo = DesUtil.encrypt(mealNo, ky, iv);
|
||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||
String dt = simpleDateFormat.format(new Date());
|
||
SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||
String ymd = ymdFormat.format(new Date());
|
||
String start = ymd + " 00:00:00";
|
||
String end = ymd + " 23:59:59";
|
||
// String start = "2019-09-20 00:00:00";
|
||
// String end ="2019-09-20 23:59:59";
|
||
StringBuffer sBuffer = new StringBuffer("");
|
||
sBuffer.append("\"CardCode\":\"");
|
||
sBuffer.append(mealNo);
|
||
sBuffer.append("\",\"Start_Time\":\"");
|
||
sBuffer.append(start);
|
||
sBuffer.append("\",\"End_Time\":\"");
|
||
sBuffer.append(end);
|
||
sBuffer.append("\",\"timestamp\":\"");
|
||
sBuffer.append(dt);
|
||
sBuffer.append("\"");
|
||
String ss = sBuffer.toString();
|
||
String sign = MD5Util.getMD5(ss);
|
||
|
||
StringBuffer ret = new StringBuffer("{");
|
||
ret.append("\"CardCode\":\"");
|
||
ret.append(mealNo);
|
||
ret.append("\",\"Start_Time\":\"");
|
||
ret.append(start);
|
||
ret.append("\",\"End_Time\":\"");
|
||
ret.append(end);
|
||
ret.append("\",\"timestamp\":\"");
|
||
ret.append(dt);
|
||
ret.append("\",\"sign\":\"");
|
||
ret.append(sign);
|
||
ret.append("\"}");
|
||
String jsonString = ret.toString();
|
||
|
||
return jsonString;
|
||
}
|
||
|
||
/**
|
||
* 取餐卡消费记录请求body(最近一个月)
|
||
*
|
||
* @param mealNo
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
private String getCkConsumSignBody_lastmonth(String mealNo) throws Exception {
|
||
String ky = getCkKy();
|
||
String iv = getCkIv();
|
||
|
||
mealNo = DesUtil.encrypt(mealNo, ky, iv);
|
||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||
String dt = simpleDateFormat.format(new Date());
|
||
SimpleDateFormat ymdFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||
String ymd = ymdFormat.format(new Date());
|
||
// 取30天前日期
|
||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||
Date today = new Date();
|
||
// 获取三十天前日期
|
||
Calendar theCa = Calendar.getInstance();
|
||
theCa.setTime(today);
|
||
theCa.add(theCa.DATE, -30);// 最后一个数字30可改,30天的意思
|
||
Date startTime = theCa.getTime();
|
||
String startDate = sdf.format(startTime);// 三十天之前日期
|
||
|
||
String start = startDate + " 00:00:00";
|
||
String end = ymd + " 23:59:59";
|
||
// String start = "2019-09-20 00:00:00";
|
||
// String end ="2019-09-20 23:59:59";
|
||
StringBuffer sBuffer = new StringBuffer("");
|
||
sBuffer.append("\"CardCode\":\"");
|
||
sBuffer.append(mealNo);
|
||
sBuffer.append("\",\"Start_Time\":\"");
|
||
sBuffer.append(start);
|
||
sBuffer.append("\",\"End_Time\":\"");
|
||
sBuffer.append(end);
|
||
sBuffer.append("\",\"timestamp\":\"");
|
||
sBuffer.append(dt);
|
||
sBuffer.append("\"");
|
||
String ss = sBuffer.toString();
|
||
String sign = MD5Util.getMD5(ss);
|
||
|
||
StringBuffer ret = new StringBuffer("{");
|
||
ret.append("\"CardCode\":\"");
|
||
ret.append(mealNo);
|
||
ret.append("\",\"Start_Time\":\"");
|
||
ret.append(start);
|
||
ret.append("\",\"End_Time\":\"");
|
||
ret.append(end);
|
||
ret.append("\",\"timestamp\":\"");
|
||
ret.append(dt);
|
||
ret.append("\",\"sign\":\"");
|
||
ret.append(sign);
|
||
ret.append("\"}");
|
||
String jsonString = ret.toString();
|
||
|
||
return jsonString;
|
||
}
|
||
|
||
// public static void main(String[] args) throws Exception {
|
||
// // String string = getCkSignBody("0004774159");
|
||
// }
|
||
|
||
/**
|
||
* 前端返回二维码
|
||
*
|
||
* 前端调用接口返回时间戳和餐卡卡号和余额
|
||
*
|
||
* @param userId
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
|
||
@ResponseBody
|
||
@RequestMapping(value = "/buildNumber", method = RequestMethod.POST)
|
||
public RestResult buildNumber(@RequestBody Object requestBody) {
|
||
try {
|
||
|
||
UserVo user = new ObjectMapper().convertValue(requestBody, new TypeReference<UserVo>() {
|
||
});
|
||
String userId = user.getUserId();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if (info == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
// 此处时间戳+餐卡失效时长2分钟
|
||
String timeStr = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date().getTime() + 120000);
|
||
// 根据userId查询卡号
|
||
GreenUserInfo greenUserInfo = greenUserInfoBizc.get(user.getUserId());
|
||
|
||
String mealNo = greenUserInfo.getMealNo();
|
||
|
||
if (mealNo != null && !"".equals(mealNo)) {
|
||
/*
|
||
* String url = getCkMoneyUrl(); // String url =
|
||
* "http://124.193.158.122:8009/PersonMoney";//测试接口 String param
|
||
* = getCkMoneySignBody(mealNo);
|
||
*
|
||
* // 根据url和餐卡卡号调用餐卡接口 JSONObject jsonObject =
|
||
* HttpClient.httpPostSpecialTimeOut(url, param); if
|
||
* (jsonObject.has("StatusCode")) { // error return new
|
||
* RestResult(Constant.FAILED,
|
||
* jsonObject.getString("StatusMessage")); } if
|
||
* ((jsonObject.has("status") && jsonObject.getInt("status") !=
|
||
* 200) || jsonObject.has("getFail")) { // 如果是http请求错误或抛出异常捕获
|
||
* 都只返回二维码 String greenCard = mealNo + "_" + timeStr; // 餐卡加密
|
||
* int key = 0x0610; String enCode =
|
||
* EncryptUtil.Encrypt(greenCard, key); Map<String, String> map
|
||
* = new HashMap<String, String>(); map.put("enCode", enCode);
|
||
* map.put("balance", null); // JSONArray json =
|
||
* JSONArray.fromObject(map); return new
|
||
* RestResult(Constant.SUCCESS, "成功", map); }
|
||
*/
|
||
|
||
/*
|
||
* // 查询卡号余额 String balance =
|
||
* jsonObject.get("value").toString();
|
||
* System.out.println("==== 原始余额数据:" + balance); balance =
|
||
* getCkData(balance); BigDecimal a =
|
||
* BigDecimal.valueOf(Double.valueOf(balance)); BigDecimal
|
||
* b=a.setScale(2, RoundingMode.HALF_UP);
|
||
* System.out.println("==== 解密余额数据:" + b.toString());
|
||
*/
|
||
String greenCard = mealNo + "_" + timeStr;
|
||
// 餐卡加密
|
||
int key = 0x0610;
|
||
String enCode = EncryptUtil.Encrypt(greenCard, key);
|
||
|
||
List<Map<String, Object>> dictionaryInfo = greenDictionaryInfoController
|
||
.getDictionaryInfo("cardShowIcon");
|
||
int cardShowIcon = Integer.valueOf(dictionaryInfo.get(0).get("data_value") + "");
|
||
|
||
Map<String, String> map = new HashMap<String, String>();
|
||
/* map.put("balance", b.toString()); */
|
||
map.put("enCode", enCode);
|
||
map.put("showIcon", cardShowIcon + "");
|
||
// JSONArray json = JSONArray.fromObject(map);
|
||
return new RestResult(Constant.SUCCESS, "成功", map);
|
||
}
|
||
|
||
return new RestResult(Constant.NO_CK, "餐卡号不存在");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取餐卡余额
|
||
*
|
||
* @param requestBody
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping(value = "/getBalance", method = RequestMethod.POST)
|
||
public RestResult getBalance(@RequestBody Object requestBody) {
|
||
|
||
try {
|
||
UserVo user = new ObjectMapper().convertValue(requestBody, new TypeReference<UserVo>() {
|
||
});
|
||
String userId = user.getUserId();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if (info == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
// 根据userId查询卡号
|
||
GreenUserInfo greenUserInfo = greenUserInfoBizc.get(user.getUserId());
|
||
|
||
String mealNo = greenUserInfo.getMealNo();
|
||
if (mealNo != null && !"".equals(mealNo)) {
|
||
String url = getCkMoneyUrl();
|
||
// String url = "http://124.193.158.122:8009/PersonMoney";//测试接口
|
||
String param = getCkMoneySignBody(mealNo);
|
||
|
||
// 根据url和餐卡卡号调用餐卡接口
|
||
JSONObject jsonObject = HttpClient.httpPostSpecialTimeOut(url, param);
|
||
if (jsonObject.has("StatusCode")) {
|
||
// error
|
||
return new RestResult(Constant.FAILED, jsonObject.getString("StatusMessage"));
|
||
}
|
||
if ((jsonObject.has("status") && jsonObject.getInt("status") != 200) || jsonObject.has("getFail")) {
|
||
saveErorrLog("餐卡-获取余额", Constant.INSERT, Constant.OPERATE_FAIL, "获取餐卡余额失败!", "0", userId);
|
||
return new RestResult(Constant.FAILED, "餐卡余额获取失败!");
|
||
}
|
||
|
||
// 查询卡号余额
|
||
String balance = jsonObject.get("value").toString();
|
||
balance = getCkData(balance);
|
||
BigDecimal a = BigDecimal.valueOf(Double.valueOf(balance));
|
||
BigDecimal b = a.setScale(2, RoundingMode.HALF_UP);
|
||
System.out.println("==== 解密余额数据:" + b.toString());
|
||
Map<String, String> map = new HashMap<String, String>();
|
||
map.put("balance", b.toString());
|
||
// JSONArray json = JSONArray.fromObject(map);
|
||
return new RestResult(Constant.SUCCESS, "成功", map);
|
||
}
|
||
|
||
return new RestResult(Constant.NO_CK, "餐卡号不存在");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 记录餐卡消费记录
|
||
*
|
||
* @param userId
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
|
||
@ResponseBody
|
||
@RequestMapping(value = "/cardConsum", method = RequestMethod.POST)
|
||
public RestResult cardConsum(@RequestBody Object requestBody) {
|
||
|
||
try {
|
||
UserVo user = new ObjectMapper().convertValue(requestBody, new TypeReference<UserVo>() {
|
||
});
|
||
String userId = user.getUserId();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if (info == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
// 根据userId查询卡号
|
||
GreenUserInfo greenUserInfo = greenUserInfoBizc.get(user.getUserId());
|
||
|
||
String mealNo = greenUserInfo.getMealNo();
|
||
if (mealNo != null) {
|
||
String url = getCkConsumUrl();
|
||
// String url =
|
||
// "http://124.193.158.122:8009/consume_Records";//测试接口
|
||
String param = getCkConsumSignBody(mealNo);
|
||
|
||
// 根据url和餐卡卡号和起始时间+结束时间 调用餐卡消费记录接口
|
||
com.alibaba.fastjson.JSONArray jsonObject = HttpClient.httpPostSpecialTimeOutToArray(url, param);
|
||
|
||
if (jsonObject.isEmpty()) {
|
||
saveErorrLog("餐卡-消费记录", Constant.INSERT, Constant.OPERATE_FAIL, "获取餐卡消费记录失败!", "0", userId);
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
List<GreenCardConsumptionDTO> list = new ObjectMapper().convertValue(jsonObject,
|
||
new TypeReference<List<GreenCardConsumptionDTO>>() {
|
||
});
|
||
for (GreenCardConsumptionDTO greenCardConsumptionDTO : list) {
|
||
GreenCardConsumption greenCardConsumption = new GreenCardConsumption();
|
||
greenCardConsumption.setRecordid(getCkData(greenCardConsumptionDTO.getRecordid()));
|
||
greenCardConsumption.setEmpno(getCkData(greenCardConsumptionDTO.getEmpno()));
|
||
greenCardConsumption.setCardid(getCkData(greenCardConsumptionDTO.getCardid()));
|
||
greenCardConsumption.setOutmoney(getCkData(greenCardConsumptionDTO.getOutmoney()));
|
||
greenCardConsumption.setSoutmoney(getCkData(greenCardConsumptionDTO.getSoutmoney()));
|
||
greenCardConsumption.setBefmoney(getCkData(greenCardConsumptionDTO.getBefmoney()));
|
||
greenCardConsumption.setSbefmoney(getCkData(greenCardConsumptionDTO.getSbefmoney()));
|
||
greenCardConsumption.setCardtime(greenCardConsumptionDTO.getCardtime());
|
||
greenCardConsumption.setEmpname(greenCardConsumptionDTO.getEmpname());
|
||
greenCardConsumption.setBmname(greenCardConsumptionDTO.getBmname());
|
||
greenCardConsumption.setPosnanme(greenCardConsumptionDTO.getPosnanme());
|
||
greenCardConsumption.setSecName(greenCardConsumptionDTO.getSec_name());
|
||
greenCardConsumption.setConsname(greenCardConsumptionDTO.getConsname());
|
||
greenCardConsumption.setGmtCreated(new Date());
|
||
greenCardConsumption.setGmtModified(new Date());
|
||
greenCardConsumption.setCreator(info.getLoginName());
|
||
greenCardConsumption.setModifier(info.getLoginName());
|
||
greenCardConsumption.setIsDeleted("N");
|
||
hibernateDao.saveObject(greenCardConsumption);
|
||
}
|
||
return new RestResult(Constant.SUCCESS, "成功");
|
||
}
|
||
|
||
return new RestResult(Constant.NO_CK, "卡号不存在");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 查询餐卡消费记录(返回30条)
|
||
*
|
||
* @param userId
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
|
||
@ResponseBody
|
||
@RequestMapping(value = "/listConsumRecords", method = RequestMethod.POST)
|
||
public RestResult listConsumRecords(@RequestBody Object requestBody) {
|
||
|
||
try {
|
||
UserVo user = new ObjectMapper().convertValue(requestBody, new TypeReference<UserVo>() {
|
||
});
|
||
String userId = user.getUserId();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if (info == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
// 根据userId查询卡号
|
||
GreenUserInfo greenUserInfo = greenUserInfoBizc.get(user.getUserId());
|
||
|
||
String mealNo = greenUserInfo.getMealNo();
|
||
if (mealNo != null) {
|
||
// String url = getCkConsumUrl();
|
||
String url = "http://124.193.158.122:8009/consume_Records";// 测试接口
|
||
|
||
String param = getCkConsumSignBody_lastmonth(mealNo);
|
||
|
||
// 根据url和餐卡卡号和起始时间+结束时间 调用餐卡消费记录接口
|
||
com.alibaba.fastjson.JSONArray jsonObject = null;
|
||
try {
|
||
jsonObject = HttpClient.httpPostSpecialTimeOutToArray(url, param);
|
||
if (jsonObject.isEmpty()) {
|
||
saveErorrLog("餐卡-消费记录", Constant.INSERT, Constant.OPERATE_FAIL, "获取餐卡消费记录失败!", "0", userId);
|
||
return new RestResult(Constant.FAILED, "餐卡系统请求失败");
|
||
}
|
||
} catch (Exception e) {
|
||
List<Object> res = new ArrayList<Object>();
|
||
GreenCardConsumption greenCardConsumption = new GreenCardConsumption();
|
||
greenCardConsumption.setOutmoney("");
|
||
greenCardConsumption.setCardtime("暂未获取到消费记录");
|
||
res.add(greenCardConsumption);
|
||
saveErorrLog("餐卡-消费记录", Constant.INSERT, Constant.OPERATE_FAIL, "获取餐卡消费记录失败!", "0", userId);
|
||
return new RestResult(Constant.SUCCESS, res);
|
||
// return new RestResult(Constant.FAILED, "餐卡系统请求失败");
|
||
}
|
||
|
||
List<GreenCardConsumptionDTO> list = new ObjectMapper().convertValue(jsonObject,
|
||
new TypeReference<List<GreenCardConsumptionDTO>>() {
|
||
});
|
||
|
||
List<Object> res = new ArrayList<Object>();
|
||
int index = 0;
|
||
for (GreenCardConsumptionDTO greenCardConsumptionDTO : list) {
|
||
GreenCardConsumption greenCardConsumption = new GreenCardConsumption();
|
||
|
||
BigDecimal b1 = new BigDecimal(getCkData(greenCardConsumptionDTO.getOutmoney()));
|
||
BigDecimal b2 = b1.setScale(2, BigDecimal.ROUND_HALF_EVEN);
|
||
|
||
greenCardConsumption.setOutmoney(b2.toString());
|
||
greenCardConsumption.setCardtime(greenCardConsumptionDTO.getCardtime());
|
||
res.add(greenCardConsumption);
|
||
index = index + 1;
|
||
if (index > 30) {
|
||
break;
|
||
}
|
||
}
|
||
return new RestResult(Constant.SUCCESS, res);
|
||
}
|
||
|
||
return new RestResult(Constant.NO_CK, "卡号不存在");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 前端轮询调用接口返回查询二维码扫描支付结果
|
||
*
|
||
* 作废的代码
|
||
*
|
||
* @param userId
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
|
||
@ResponseBody
|
||
@RequestMapping(value = "/buildCode", method = RequestMethod.POST)
|
||
public RestResult buildCode(@RequestBody Object requestBody) {
|
||
UserVo user = new ObjectMapper().convertValue(requestBody, new TypeReference<UserVo>() {
|
||
});
|
||
try {
|
||
String userId = user.getUserId();
|
||
GreenUserInfo info = getUserInfo(userId);
|
||
if (info == null) {
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
// 根据userId查询卡号
|
||
GreenUserInfo greenUserInfo = greenUserInfoBizc.get(user.getUserId());
|
||
|
||
String mealNo = greenUserInfo.getMealNo();
|
||
if (mealNo != null) {
|
||
String dataType = "ticketUrl";
|
||
String dataCode = "002";
|
||
List<Map<String, String>> urlInfo = greenDictionaryInfoController.getDictionaryInfo(dataType, dataCode);
|
||
Map<String, String> urlMap = urlInfo.get(0);
|
||
String ticketUrl = urlMap.get("data_value");
|
||
String url = ticketUrl + mealNo;
|
||
// 根据url和餐卡卡号调用餐卡接口
|
||
JSONObject jsonObject = HttpClient.httpGet(url);
|
||
// 餐卡加密
|
||
// int key=0x0610;
|
||
// String enCode=EncryptUtil.Encrypt(greenCard,key);
|
||
// JSONArray json = JSONArray.fromObject(map);
|
||
return new RestResult(Constant.SUCCESS, "成功", jsonObject);
|
||
}
|
||
} catch (Exception e) {
|
||
return new RestResult(Constant.FAILED, "失败", null);
|
||
}
|
||
return new RestResult(Constant.FAILED, "失败", "卡号不存在");
|
||
|
||
}
|
||
|
||
/*
|
||
* @ResponseBody
|
||
*
|
||
* @RequestMapping(value="/verifyUser",method=RequestMethod.POST) public
|
||
* RestResult verifyUser(@RequestParam(value="userId",required=true) String
|
||
* userId) throws Exception{
|
||
*
|
||
* return new RestResult(Constant.SUCCESS,userAccess(userId));
|
||
*
|
||
* }
|
||
*/
|
||
|
||
@SuppressWarnings("deprecation")
|
||
/**
|
||
* 第三方能力平台认证接口调用
|
||
*
|
||
* @param operatorItemModel
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
|
||
@RequestMapping(value = "/platformAuthen", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult platformAuthen(@RequestBody Object requestBody) {
|
||
|
||
try {
|
||
GreenUserInfo greenUserInfo = new ObjectMapper().convertValue(requestBody,
|
||
new TypeReference<GreenUserInfo>() {
|
||
});
|
||
String dataType = "businessTokenUrl";
|
||
String dataCode = "101";
|
||
List<Map<String, String>> urlInfo = greenDictionaryInfoController.getDictionaryInfo(dataType, dataCode);
|
||
Map<String, String> urlMap = urlInfo.get(0);
|
||
String businessTokenUrl = urlMap.get("data_value");
|
||
|
||
// String url =
|
||
// "http://211.160.22.123:19084/protocolTrans/openapi/sunbox_gateway_api_service_system_SysSupportApiService_login1";
|
||
JSONObject model = new JSONObject();
|
||
JSONObject body = new JSONObject();
|
||
// 能力平台提供的服务订阅者账号(能力平台提供)
|
||
|
||
// String possword = "85eb01d4aebad7a093385a302e49b57e";
|
||
// 账号(能力平台提供)
|
||
List<Map<String, String>> tokenInfo = greenDictionaryInfoController.getDictionaryInfo("tokenAppAccount",
|
||
"101");
|
||
String userName = tokenInfo.get(0).get("data_value");
|
||
// appid是能力订阅者订购的能力应用id(订购应用后生成)
|
||
List<Map<String, String>> tokenInfoUser = greenDictionaryInfoController
|
||
.getDictionaryInfo("tokenAppPossword", "101");
|
||
String possword = MD5Util.getMD5(tokenInfoUser.get(0).get("data_value"));
|
||
String appId = "4028e5c66add2246016b69c764940133";
|
||
// 固定值(5为能力)
|
||
int businessLabel = 5;
|
||
// 封装账户信息
|
||
model.put("password", possword);
|
||
model.put("userName", userName);
|
||
model.put("businessLabel", businessLabel);
|
||
// 保存能力id
|
||
body.put("appId", appId);
|
||
// 参数加密
|
||
body.put("OperatorItemModel", AESUtil.Encrypt(model.toString(), KY, IV));
|
||
Map<String, Object> map = new HashMap<String, Object>();
|
||
map.put("args", body);
|
||
// 1.能力平台认证
|
||
String doRequest = "";
|
||
try {
|
||
|
||
doRequest = mapPost(businessTokenUrl, map, "utf-8");
|
||
|
||
} catch (Exception e) {
|
||
saveErorrLog("第三方能力平台认证接口", Constant.INSERT, Constant.OPERATE_FAIL, "第三方能力平台认证接口调用失败!", "0",
|
||
greenUserInfo.getId());
|
||
}
|
||
|
||
JSONObject result = new JSONObject(doRequest);
|
||
|
||
if (result.getInt("status") == 0) {// 成功
|
||
String datasytr = result.getString("data");
|
||
// 解密后的Data
|
||
String decrypt = URLDecoder.decode(AESUtil.Decrypt(datasytr, KY, IV));
|
||
|
||
JSONObject dataJson = new JSONObject(decrypt).getJSONObject("data");
|
||
|
||
// 用户token
|
||
String userToken = dataJson.getString("token");
|
||
|
||
// userID获取随后改为动态
|
||
String userId = greenUserInfo.getId();
|
||
// String appid = "appId";
|
||
// 2.用户认证
|
||
Map<Object, Object> tokenMap = userAccess(userId, userToken, appId);
|
||
|
||
return new RestResult(Constant.SUCCESS, "请求成功!", tokenMap);
|
||
}
|
||
saveErorrLog("第三方能力平台认证接口", Constant.INSERT, Constant.OPERATE_FAIL, "第三方能力平台认证接口调用失败!", "0",
|
||
greenUserInfo.getId());
|
||
return new RestResult(Constant.FAILED, "访问商城请求异常!");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "请求失败");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 用户认证/注册三方接口
|
||
*
|
||
* @param userId
|
||
* @return doRequest(token)
|
||
* @throws Exception
|
||
*/
|
||
public Map<Object, Object> userAccess(String userId, String userToken, String appid) throws Exception {
|
||
// 访问地址
|
||
// String url =
|
||
// "http://192.168.101.71:8080/protocolTrans/openapi/ShopService";
|
||
String dataType = "userTokenUrl";
|
||
String dataCode = "101";
|
||
List<Map<String, String>> urlInfo = greenDictionaryInfoController.getDictionaryInfo(dataType, dataCode);
|
||
Map<String, String> urlMap = urlInfo.get(0);
|
||
String userTokenUrl = urlMap.get("data_value");
|
||
|
||
JSONObject arg = new JSONObject();
|
||
JSONObject body = new JSONObject();
|
||
// 认证接口返回的token
|
||
body.put("authToken", AESUtil.Encrypt(userToken, KY, IV));
|
||
// 能力订阅后的应用id
|
||
body.put("appId", appid);
|
||
// 接口参数(后勤提供的用户唯一标识)
|
||
body.put("userCode", AESUtil.Encrypt(userId, KY, IV));
|
||
arg.put("args", body);
|
||
Map<String, Object> map = new HashMap<String, Object>();
|
||
map.put("args", body);
|
||
|
||
String tokenJson = mapPost(userTokenUrl, map, "utf-8");
|
||
JSONObject ouCardObj = new JSONObject(tokenJson);
|
||
// JSONObject ouCardObj = JSONObject.parseObject(tokenJson);
|
||
if (ouCardObj != null) {
|
||
|
||
if (ouCardObj.getInt("status") == 0) {
|
||
String decodeOuCar = ouCardObj.getString("data");
|
||
|
||
String decode = URLDecoder.decode(AESUtil.Decrypt(decodeOuCar, KY, IV));
|
||
|
||
JSONObject tokenData = new JSONObject(decode);
|
||
|
||
String token = tokenData.getString("data");
|
||
|
||
Map<Object, Object> tokenMap = new HashMap<Object, Object>();
|
||
tokenMap.put("authToken", userToken);
|
||
tokenMap.put("endToken", token);
|
||
return tokenMap;
|
||
}
|
||
}
|
||
return null;
|
||
|
||
}
|
||
|
||
/**
|
||
* 登录 获取 Cookie
|
||
*
|
||
* @param url
|
||
* API地址
|
||
* @param username
|
||
* 账号, 注意不要使用admin@megvii.com
|
||
* @param possword
|
||
* 密码
|
||
* @return cookie CookieStore
|
||
* @throws IOException
|
||
* @throws Exception
|
||
*/
|
||
// public static String dopost(String url, Map<String, Object> map) throws
|
||
// IOException{
|
||
//
|
||
// CloseableHttpClient httpclient = null;
|
||
// String responseBody = null;
|
||
// try {
|
||
// RequestConfig requestConfig =
|
||
// RequestConfig.custom().setConnectTimeout(2000).setConnectionRequestTimeout(3000)
|
||
// .setSocketTimeout(3000).build();
|
||
// httpclient = HttpClients.createDefault();
|
||
// HttpPost request = new HttpPost(url);
|
||
// request.setConfig(requestConfig);
|
||
//
|
||
// // 设置user-agent为 "Koala Admin"
|
||
// // 设置Content-Type为 "application/json"
|
||
// request.setHeader("Content-Type", "application/json");
|
||
//
|
||
// JSONObject json = new JSONObject(map);
|
||
//
|
||
// request.setEntity(new StringEntity(json.toString(), "UTF-8"));
|
||
//
|
||
// // 发起网络请求,获取结果值
|
||
// HttpClientContext context = HttpClientContext.create();
|
||
// CloseableHttpResponse response = httpclient.execute(request, context);
|
||
// responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||
//
|
||
// /*
|
||
// * //解析JSON数据 JSONObject resp = new JSONObject(responseBody); int result
|
||
// * = resp.optInt("code", -1); if (result != 0) {
|
||
// * System.err.println("Login failed, code:" + result); }else{
|
||
// * System.out.println("Login Success,id:" +
|
||
// * resp.getJSONObject("data").getInt("id")); return
|
||
// * context.getCookieStore(); }
|
||
// */
|
||
//
|
||
//
|
||
// } catch (Exception e) {
|
||
// e.printStackTrace();
|
||
// }finally {
|
||
// if (httpclient != null) {
|
||
// httpclient.close();
|
||
// }
|
||
// }
|
||
// return responseBody;
|
||
// }
|
||
|
||
// public static String doFormPost(String url, Map<String, Object> map) {
|
||
// RequestConfig requestConfig =
|
||
// RequestConfig.custom().setConnectTimeout(2000).setConnectionRequestTimeout(3000)
|
||
// .setSocketTimeout(3000).build();
|
||
// CloseableHttpClient httpclient = null;
|
||
// String responseBody = "";
|
||
// try {
|
||
//
|
||
// httpclient = HttpClients.createDefault();
|
||
// HttpPost request = new HttpPost(url);
|
||
// request.setConfig(requestConfig);
|
||
//
|
||
// // 设置user-agent为 "Koala Admin"
|
||
// // 设置Content-Type为 "application/json"
|
||
// // request.setHeader("Content-Type", "application/json");
|
||
// request.setHeader("Content-Type", "application/x-www-form-urlencoded");
|
||
// MultipartEntity reqEntity = new MultipartEntity();
|
||
//
|
||
// // JSONObject json = new JSONObject(map);
|
||
// for (String key : map.keySet()) {
|
||
// reqEntity.addPart(key, new StringBody(map.get(key).toString()));
|
||
// }
|
||
//
|
||
// request.setEntity(reqEntity);
|
||
//
|
||
// // 发起网络请求,获取结果值
|
||
// HttpClientContext context = HttpClientContext.create();
|
||
// CloseableHttpResponse response = httpclient.execute(request, context);
|
||
// responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
|
||
//
|
||
// /*
|
||
// * //解析JSON数据 JSONObject resp = new JSONObject(responseBody); int result
|
||
// * = resp.optInt("code", -1); if (result != 0) {
|
||
// * System.err.println("Login failed, code:" + result); }else{
|
||
// * System.out.println("Login Success,id:" +
|
||
// * resp.getJSONObject("data").getInt("id")); return
|
||
// * context.getCookieStore(); }
|
||
// */
|
||
// return responseBody;
|
||
// }
|
||
// catch (Exception e) {
|
||
//
|
||
// e.printStackTrace();
|
||
// }finally {
|
||
// try {
|
||
// if(httpclient!=null){
|
||
// httpclient.close();
|
||
// }
|
||
// } catch (IOException e) {
|
||
//
|
||
// e.printStackTrace();
|
||
// }
|
||
// }
|
||
// return null;
|
||
// }
|
||
|
||
/**
|
||
* 每日食堂
|
||
*
|
||
* @param url
|
||
* @param map
|
||
* @param encoding
|
||
* @return
|
||
* @throws IOException
|
||
*/
|
||
public static String mapPost(String url, Map<String, Object> map, String encoding) throws IOException {
|
||
System.out.println("调用http请求:" + url + "参数为:---->" + map.toString());
|
||
CloseableHttpClient httpClient = null;
|
||
HttpPost httpPost = null;
|
||
String result = null;
|
||
String userTokenUrl = "http://211.160.22.123:19118/protocolTrans/openapi/ShopService";
|
||
String businessTokenUrl = "http://211.160.22.123:19118/protocolTrans/openapi/sunbox_gateway_api_service_system_SysSupportApiService_login1";
|
||
// 不进行判断直接使用库里的url调用
|
||
try {
|
||
// if (!userTokenUrl.equals(url) && !businessTokenUrl.equals(url)) {
|
||
// return "";
|
||
// }
|
||
httpClient = HttpClients.createDefault();
|
||
httpPost = new HttpPost(url);
|
||
|
||
List<NameValuePair> list = new ArrayList<NameValuePair>();
|
||
Iterator iterator = map.entrySet().iterator();
|
||
while (iterator.hasNext()) {
|
||
Map.Entry<String, String> elem = (Map.Entry<String, String>) iterator.next();
|
||
String regex = "[`~!@#$%^&*()\\+\\=\\{}|:\"?><【】\\/r\\/n]";
|
||
Pattern pa = Pattern.compile(regex);
|
||
Matcher ma = pa.matcher(String.valueOf(elem.getValue()));
|
||
if (ma.find()) {
|
||
list.add(new BasicNameValuePair(elem.getKey(), String.valueOf(elem.getValue())));
|
||
} else {
|
||
return "";
|
||
}
|
||
|
||
}
|
||
if (list.size() > 0) {
|
||
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list, encoding);
|
||
httpPost.setEntity(entity);
|
||
}
|
||
HttpResponse response = httpClient.execute(httpPost);
|
||
if (response != null) {
|
||
HttpEntity resEntity = response.getEntity();
|
||
if (resEntity != null) {
|
||
result = EntityUtils.toString(resEntity, encoding);
|
||
|
||
}
|
||
}
|
||
System.out.println("调用http请求结果:" + result);
|
||
|
||
} catch (Exception ex) {
|
||
ex.printStackTrace();
|
||
} finally {
|
||
if (httpClient != null) {
|
||
httpClient.close();
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public static String getToken() throws Exception {
|
||
// // 访问地址(测试内网)
|
||
// String url =
|
||
// "http://192.168.101.71:8080/protocolTrans/openapi/sunbox_gateway_api_service_system_SysSupportApiService_login1";
|
||
// JSONObject model = new JSONObject();
|
||
// JSONObject body = new JSONObject();
|
||
// // 能力平台提供的服务订阅者账号(能力平台提供)
|
||
// String possword = "85eb01d4aebad7a093385a302e49b57e";
|
||
// // 账号(能力平台提供)
|
||
// String userName = "hqapp";
|
||
// // appid是能力订阅者订购的能力应用id(订购应用后生成)
|
||
// String appId = "4028e5c66add2246016b69c764940133";
|
||
// // 固定值(5为能力)
|
||
// int businessLabel = 5;
|
||
// // 封装账户信息
|
||
// model.put("password", possword);
|
||
// model.put("userName", userName);
|
||
// model.put("businessLabel", businessLabel);
|
||
// // 保存能力id
|
||
// body.put("appId", appId);
|
||
// // 参数加密
|
||
// body.put("OperatorItemModel",
|
||
// AesEncryptUtil.encrypt(model.toString()));
|
||
// Map<String, Object> map = new HashMap<String, Object>();
|
||
// map.put("args", body);
|
||
// String tokenJson = mapPost(url, map, "utf-8");
|
||
//
|
||
String token = null;
|
||
// JSONObject tokenObj = new JSONObject(tokenJson);
|
||
// // JSONObject tokenObj = JSONObject.parseObject(tokenJson);
|
||
// tokenObj.put("data",
|
||
// URLDecoder.decode(AesEncryptUtil.desEncrypt(tokenObj.getString("data"))));
|
||
|
||
// if (tokenObj.getString("status").equals("0")) {
|
||
// String d = tokenObj.getString("data");
|
||
// // JSONObject jj = (JSONObject)JSONObject.parse(d);
|
||
// // token = jj.get("data").toString();
|
||
// }
|
||
|
||
// JSONObject rr = (JSONObject)JSONObject.parse(token);
|
||
// System.err.println("------------"+rr.get("token"));
|
||
// return String.valueOf(rr.get("token"));
|
||
return token;
|
||
}
|
||
|
||
// public static void main(String[] args) throws Exception {
|
||
// getToken();
|
||
// }
|
||
|
||
/**
|
||
* 根据用户id查询该用户具有的权限
|
||
*
|
||
* @param greenUserInfo
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/getRoleInfo", method = RequestMethod.POST)
|
||
// public @ResponseBody RestResult getRoleInfo(@RequestBody Result Result) {
|
||
public @ResponseBody RestResult getRoleInfo(HttpServletRequest request) {
|
||
Map<String, String> str = getBodyStr(request);
|
||
String checkTime = str.get("checkTime");
|
||
Result Result = JSONUtil.json2Object(str.get("bodyData"), Result.class);
|
||
/*
|
||
* if(Utils.list.contains("greenUserInfo/getRoleInfo"+checkTime)){
|
||
* return new RestResult(Constant.FAILED, "您的请求存在异常!请重新请求..."); }else{
|
||
* Utils.list.add("greenUserInfo/getRoleInfo"+checkTime); }
|
||
*/
|
||
try {
|
||
// 查询sql
|
||
// String sql = " SELECT urr.user_id,ui.real_name,owner_location
|
||
// locationId,ui.mobile,ui.meal_no, "
|
||
// + " GROUP_CONCAT(" + " DISTINCT urr.role_id ORDER BY urr.role_id)
|
||
// AS userRole"
|
||
// + " FROM GREEN_USER_ROLE_REL urr" + " INNER JOIN
|
||
// GREEN_ROLE_COMPETENCE_REL rcr"
|
||
// + " ON urr.role_id = rcr.role_id AND rcr.is_deleted = 'N'" + "
|
||
// INNER JOIN GREEN_USER_INFO ui"
|
||
// + " ON urr.user_id = ui.id AND ui.is_deleted = 'N'" + " WHERE
|
||
// urr.is_deleted = 'N'"
|
||
// + " AND ui.id = ?" + " GROUP BY" + " urr.user_id,ui.real_name";
|
||
String sql = " SELECT dp.name departmentName,ui.id ,ui.real_name,ui.department_id,owner_location locationId,ui.mobile,ui.meal_no, "
|
||
+ " GROUP_CONCAT( DISTINCT urr.role_id ORDER BY urr.role_id) AS userRole"
|
||
+ " FROM GREEN_USER_INFO ui LEFT JOIN GREEN_USER_ROLE_REL urr"
|
||
+ " ON urr.user_id = ui.id AND urr.is_deleted = 'N' "
|
||
+ " LEFT JOIN green_department dp on ui.department_id = dp.id "
|
||
+ " WHERE ui.is_deleted = 'N' AND ui.id = ? GROUP BY urr.user_id,ui.real_name";
|
||
// 执行sql
|
||
List<Map<String, Object>> list = hibernateDao.queryForListWithSql(sql, new Object[] { Result.getUserId() });
|
||
System.err.println(Result.getUserId());
|
||
// 不存在当前用户
|
||
if (list.size() <= 0) {
|
||
addLog(Constant.LOGIN, Constant.LOGIN, Constant.OPERATE_FAIL, "非法用户登录", Constant.LOG_OPERATE,
|
||
Result.getUserId());
|
||
return new RestResult(Constant.FAILED, "非法用户");
|
||
}
|
||
Map<String, Object> userMap = list.get(0);
|
||
// 获取用户拥有的所有角色
|
||
Object userRole = list.get(0).get("userRole");
|
||
// 判断该用户拥有的角色是否为空
|
||
String departmentName = list.get(0).get("departmentName").toString();
|
||
String department_id = list.get(0).get("department_id").toString();
|
||
if (userRole == null || "".equals(userRole)) {
|
||
String[] userRoleArr = new String[] { "1" };
|
||
Map map = new HashMap();
|
||
|
||
map.put("userRole", userRoleArr);
|
||
Map user = list.get(0);
|
||
map.put("userInfo", user);
|
||
return new RestResult(Constant.SUCCESS, "", map);
|
||
// return new RestResult(Constant.FAILED, "该角色暂无任何权限,请联系管理员!");
|
||
}
|
||
|
||
Object meal_no = userMap.get("meal_no");
|
||
userMap.put("mealcardBindStatus", "0");
|
||
if (meal_no != null && !String.valueOf(meal_no).trim().equals("")) {
|
||
userMap.put("mealcardBindStatus", "1");
|
||
}
|
||
userMap.remove("meal_no");
|
||
// 切割查询的权限
|
||
String[] userRoleArr = userRole.toString().split(",");
|
||
/*
|
||
* //判断当前用户的权限并封装返回结果 for(String userRoleStr:userRoleArr){
|
||
* //判断该角色是否是后端管理平台需要的角色
|
||
* if(userRoleMap.get(userRoleStr)!=null&&!"".equals(userRoleMap.get
|
||
* (userRoleStr))){
|
||
* resultList.add(userRoleMap.get(userRoleStr).toString()); }else{
|
||
* continue; } }
|
||
*/
|
||
// 返回数据
|
||
Map map = new HashMap();
|
||
// 查询app端功能是否启用集合
|
||
List<Map<String, Object>> dictionaryInfo = greenDictionaryInfoController.getDictionaryInfo("appIconSwitch");
|
||
// 查询访客功能可使用部门集合
|
||
|
||
String visitDpListEffective = "1";
|
||
// 查询访客功能可使用部门集合是否生效
|
||
try {
|
||
List<Map<String, Object>> visitDpListEffectiveMap = greenDictionaryInfoController
|
||
.getDictionaryInfo("visitDpListEffective");
|
||
visitDpListEffective = visitDpListEffectiveMap.get(0).get("data_value").toString();
|
||
} catch (Exception e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
if (visitDpListEffective.equals("1")) {
|
||
List<Map<String, Object>> visitDpList = greenDictionaryInfoController.getDictionaryInfo("visitDpList");
|
||
for (int i = 0; i < dictionaryInfo.size(); i++) {
|
||
if (visitDpList.get(0).get("data_value").toString().contains(department_id)
|
||
&& "appVisitSwitch".equals(dictionaryInfo.get(i).get("data_code").toString())) {
|
||
map.put(dictionaryInfo.get(i).get("data_code").toString(), "1");
|
||
} else {
|
||
map.put(dictionaryInfo.get(i).get("data_code").toString(),
|
||
dictionaryInfo.get(i).get("data_value") + "");
|
||
}
|
||
}
|
||
} else {
|
||
for (int i = 0; i < dictionaryInfo.size(); i++) {
|
||
map.put(dictionaryInfo.get(i).get("data_code").toString(),
|
||
dictionaryInfo.get(i).get("data_value") + "");
|
||
}
|
||
}
|
||
|
||
String visitSwitch = "0";
|
||
if (!dictionaryInfo.isEmpty()) {
|
||
visitSwitch = dictionaryInfo.get(0).get("data_value") + "";
|
||
}
|
||
List<Map<String, Object>> dictionaryInfo1 = greenDictionaryInfoController.getDictionaryInfo("appParkLs");
|
||
String parkOnOff = null;
|
||
if (!dictionaryInfo1.isEmpty()) {
|
||
parkOnOff = dictionaryInfo1.get(0).get("data_value") + "";
|
||
}
|
||
|
||
List<Map<String, Object>> visitEndSwitchDictionaryInfo = greenDictionaryInfoController
|
||
.getDictionaryInfo("visitEndSwitch");
|
||
|
||
int visitEndSwitch = Integer.valueOf(visitEndSwitchDictionaryInfo.get(0).get("data_value") + "");
|
||
|
||
List<Map<String, String>> visitOutMsgMap = greenDictionaryInfoController.getDictionaryInfo("appTipMsg",
|
||
"appVisitOut");
|
||
|
||
String visitOutMsg = visitOutMsgMap.get(0).get("data_value").toString();
|
||
map.put("visitOutMsg", visitOutMsg);
|
||
map.put("visitEndSwitch", visitEndSwitch);
|
||
map.put("userRole", userRoleArr);
|
||
Map user = list.get(0);
|
||
map.put("userInfo", user);
|
||
map.put("parkOnOff", Integer.valueOf(parkOnOff));
|
||
map.put("departmentName", departmentName);
|
||
return new RestResult(Constant.SUCCESS, "", map);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "登录失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 根据用户id查询该用户具有的权限
|
||
*
|
||
* @param greenUserInfo
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
public List<Map<String, Object>> queryRoleById(String userId) {
|
||
// 查询sql
|
||
// String sql = " SELECT urr.user_id,urr.user_name," + " GROUP_CONCAT("
|
||
// + " DISTINCT rcr.role_id ORDER BY urr.role_id) AS userRole" + " FROM
|
||
// GREEN_USER_ROLE_REL urr"
|
||
// + " INNER JOIN GREEN_ROLE_COMPETENCE_REL rcr" + " ON urr.role_id =
|
||
// rcr.role_id AND rcr.is_deleted = 'N'"
|
||
// + " INNER JOIN GREEN_USER_INFO ui" + " ON urr.user_id = ui.id AND
|
||
// ui.is_deleted = 'N'"
|
||
// + " WHERE urr.is_deleted = 'N' AND ui.id = ?" + " GROUP BY
|
||
// urr.user_id,urr.user_name";
|
||
|
||
String sql = " SELECT ui.id ,ui.real_name,owner_location locationId,ui.mobile,ui.meal_no, " + " GROUP_CONCAT("
|
||
+ " DISTINCT urr.role_id ORDER BY urr.role_id) AS userRole" + " FROM GREEN_USER_INFO ui"
|
||
+ " LEFT JOIN GREEN_USER_ROLE_REL urr" + " ON urr.user_id = ui.id AND urr.is_deleted = 'N'"
|
||
+ " WHERE ui.is_deleted = 'N'" + " AND ui.id = ?" + " GROUP BY" + " urr.user_id,ui.real_name";
|
||
return hibernateDao.queryForListWithSql(sql, new Object[] { userId });
|
||
}
|
||
|
||
/**
|
||
* 根据用户id查询该用户具有的权限
|
||
*
|
||
* @param greenUserInfo
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
public List<Map<String, Object>> queryRoleById1(String userId) {
|
||
String sql = " SELECT ui.id ,ui.real_name,owner_location locationId,ui.mobile,ui.meal_no, " + " GROUP_CONCAT("
|
||
+ " DISTINCT gr.role_code ORDER BY gr.role_code) AS userRole" + " FROM GREEN_USER_INFO ui"
|
||
+ " LEFT JOIN GREEN_USER_ROLE_REL urr" + " ON urr.user_id = ui.id LEFT JOIN green_role gr "
|
||
+ " on urr.role_id=gr.id AND urr.is_deleted = 'N'" + " WHERE ui.is_deleted = 'N'" + " AND ui.id = ?"
|
||
+ " GROUP BY" + " urr.user_id,ui.real_name";
|
||
return hibernateDao.queryForListWithSql(sql, new Object[] { userId });
|
||
}
|
||
|
||
/**
|
||
* 根据用户id查询用户信息
|
||
*
|
||
* @param userId
|
||
* @return
|
||
*/
|
||
public GreenUserInfo queryInfoById(String userId) {
|
||
return greenuserinfoBizc.get(userId);
|
||
}
|
||
|
||
/**
|
||
* 根据用户手机号查询用户信息
|
||
*
|
||
* @param userId
|
||
* @return
|
||
*/
|
||
public List<Map<String, Object>> getInfoByPhoneNum(String phoneNum) {
|
||
String sql = "select t.id,t.department_name,t.org_name from GREEN_USER_INFO t where t.mobile = ?";
|
||
return hibernateDao.queryForListWithSql(sql, new Object[]{phoneNum});
|
||
}
|
||
|
||
/**
|
||
* 餐卡数据同步接口
|
||
*
|
||
* @param mealInfo
|
||
* @return
|
||
* @throws UnsupportedEncodingException
|
||
* @throws NoSuchAlgorithmException
|
||
*/
|
||
|
||
@ResponseBody
|
||
@RequestMapping(value = "/sysmealInfo", method = RequestMethod.POST)
|
||
public RestResult sysmealInfo(@RequestBody Object requestBody)
|
||
throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||
SysMealInfo mealInfo = new ObjectMapper().convertValue(requestBody, new TypeReference<SysMealInfo>() {
|
||
});
|
||
SortedMap<String, String> parms = new TreeMap<String, String>();
|
||
// 用户名
|
||
String real_name = mealInfo.getReal_name();
|
||
// 部门名称
|
||
String department_name = mealInfo.getDepartment_name();
|
||
// 请求参数中的中文按照urlEncoder utf-8 格式编码
|
||
if (MD5SignUtil.isContainChinese(real_name))
|
||
real_name = java.net.URLEncoder.encode(real_name, "utf-8");
|
||
if (MD5SignUtil.isContainChinese(department_name))
|
||
department_name = java.net.URLEncoder.encode(department_name, "utf-8");
|
||
|
||
parms.put("mobile", mealInfo.getMobile());
|
||
parms.put("real_name", real_name);
|
||
parms.put("department_name", department_name);
|
||
parms.put("meal_no", mealInfo.getMeal_no());
|
||
parms.put("status", mealInfo.getStatus());
|
||
parms.put("operate", mealInfo.getOperate());
|
||
// 生成sign
|
||
String createSign = MD5SignUtil.createSign(parms);
|
||
|
||
if (!mealInfo.getSign().equals(createSign)) {
|
||
return new RestResult("-1", "签名错误");
|
||
}
|
||
String mealInfoSql = "SELECT * FROM GREEN_USER_INFO user WHERE `user`.mobile=? AND is_deleted = 'N'";
|
||
|
||
List<GreenUserInfo> userList = hibernateDao.queryForListWithSql(mealInfoSql,
|
||
new Object[] { mealInfo.getMobile() }, new BeanPropertyRowMapper(GreenUserInfo.class));
|
||
if (userList.size() > 0) {
|
||
// 根据操作值判断用户操作
|
||
String operate = mealInfo.getOperate();
|
||
if (operate.equals("0")) {
|
||
GreenUserInfo user = userList.get(0);
|
||
user.setDepartmentName(mealInfo.getDepartment_name());
|
||
user.setMealStatus(mealInfo.getStatus());
|
||
user.setMealNo(mealInfo.getMeal_no());
|
||
greenUserInfoBizc.update(user, user.getId());
|
||
return new RestResult("200", "新增成功");
|
||
|
||
}
|
||
if (operate.equals("1")) {
|
||
GreenUserInfo userInfo = userList.get(0);
|
||
userInfo.setMobile(mealInfo.getMobile());
|
||
userInfo.setRealName(mealInfo.getReal_name());
|
||
userInfo.setDepartmentName(mealInfo.getDepartment_name());
|
||
userInfo.setMealNo(mealInfo.getMeal_no());
|
||
userInfo.setMealStatus(mealInfo.getStatus());
|
||
greenUserInfoBizc.update(userInfo, userInfo.getId());
|
||
|
||
return new RestResult("200", "修改成功");
|
||
|
||
}
|
||
if (operate.equals("2")) {
|
||
hibernateDao.updateWithSql("UPDATE GREEN_USER_INFO SET is_deleted ='Y' WHERE mobile=?",
|
||
new Object[] { mealInfo.getMobile() });
|
||
return new RestResult("200", "删除成功");
|
||
|
||
}
|
||
}
|
||
|
||
return new RestResult("1", "未找到匹配信息");
|
||
|
||
}
|
||
|
||
public static void main(String[] args) throws Exception {
|
||
//
|
||
System.out.println(MD5Util.getMD5("ddqc_123"));
|
||
System.out.println(AESUtil.Encrypt("ddqc_123", KY, IV));
|
||
|
||
}
|
||
|
||
@RequestMapping("/test")
|
||
@ResponseBody
|
||
public RestResult test() {
|
||
// jdbcUtil.getDataSource();
|
||
// Object object =
|
||
// ApplicationContextHelper.getBean("transactionManager");
|
||
// System.out.println("==== " + object.toString());
|
||
|
||
GreenImageInfo info = greenimageinfoBizc.get("50d02873dd264e918a7ac4b7c083e535");
|
||
try {
|
||
InputStream is = info.getImageContentBlob().getBinaryStream();
|
||
StringBuffer stringBuffer = new StringBuffer();
|
||
byte[] byt = new byte[4096];
|
||
for (int i; (i = is.read(byt)) != -1;) {
|
||
stringBuffer.append(new String(byt, 0, i));
|
||
}
|
||
String ss = stringBuffer.toString();
|
||
} catch (Exception e) {
|
||
// TODO Auto-generated catch block
|
||
e.printStackTrace();
|
||
}
|
||
return new RestResult("1");
|
||
}
|
||
|
||
/*
|
||
*
|
||
* 获取临时停车审批权限
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping(value = "/getParkRole", method = RequestMethod.POST)
|
||
public RestResult getParkRole(@RequestBody Object requestBody) {
|
||
try {
|
||
UserVo userVo = new ObjectMapper().convertValue(requestBody, new TypeReference<UserVo>() {
|
||
});
|
||
if (userVo != null) {
|
||
GreenUserInfo userInfo = getUserInfo(userVo.getUserId());
|
||
if (userInfo != null) {
|
||
String parkRoleSql = "SELECT i.id as userId,i.real_name as realName, i.login_name as loginName,i.mobile as mobile FROM green_user_info i LEFT JOIN green_user_role_rel r ON i.id = r.user_id LEFT JOIN green_role gr ON gr.id = r.role_id where 1=1 AND r.is_deleted = 'N' AND i.is_deleted = 'N' and i.is_deleted='N' AND gr.role_code = ? AND i.department_id=?";
|
||
String greenPark = "temp_park_section";
|
||
List<Map<String, Object>> list = hibernateDao.queryForListWithSql(parkRoleSql,
|
||
new Object[] { greenPark, userInfo.getDepartmentId() });
|
||
return new RestResult(Constant.SUCCESS, "成功", list);
|
||
}
|
||
return new RestResult(Constant.FAILED, "用户数据为空");
|
||
}
|
||
return new RestResult(Constant.FAILED, "数据类型为空");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "数据获取失败!");
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
*
|
||
* 获取用户信息 by wxopenId
|
||
*/
|
||
@ResponseBody
|
||
@RequestMapping(value = "/getUserInfoByOpenId", method = RequestMethod.POST)
|
||
public RestResult getUserInfoByOpenId(@RequestBody GreenUserInfo greenUserInfo) {
|
||
try {
|
||
String parkRoleSql = "select id,login_name,real_name as username,mobile,department_id as deptId,department_name as deptName,idnumber,wx_profile "
|
||
+ " from green_user_info where is_deleted='N' and wxopenid = ? ";
|
||
List<Map<String, Object>> list = hibernateDao.queryForListWithSql(parkRoleSql,
|
||
new Object[] { greenUserInfo.getWxOpenId() });
|
||
if (list.size() > 0) {
|
||
return new RestResult(Constant.SUCCESS, "成功", list.get(0));
|
||
} else {
|
||
return new RestResult(Constant.FAILED, "您还没有注册,请先在个人中心注册账号!");
|
||
}
|
||
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "数据获取失败!");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取用户权限
|
||
*
|
||
* @param greenUserInfo
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@ResponseBody
|
||
@RequestMapping("/getUserPers")
|
||
public RestResult getUserPermission(@RequestBody String userId,String deptId) {
|
||
try {
|
||
String sql = " SELECT p1.* FROM green_permission p1 WHERE p1.code IN ( SELECT rp.permission_id FROM green_user_info u "
|
||
+ " LEFT JOIN green_user_role_rel urr ON u.id = urr.user_id "
|
||
+ " LEFT JOIN green_role gr ON gr.id = urr.role_id "
|
||
+ " LEFT JOIN green_role_permission rp ON rp.role_id = gr.id WHERE u.id = ? ) ORDER BY p1.sort asc ";
|
||
List<GreenPermission> list = hibernateDao.queryForListWithSql(sql, new Object[]{userId}, new BeanPropertyRowMapper(GreenPermission.class));
|
||
List<Object> rList = new ArrayList<Object>();
|
||
List<Integer> gpIdList = new ArrayList<Integer>();
|
||
for (GreenPermission greenPermission : list) {
|
||
if (greenPermission.getParentCode().equals(0)) { // 一级菜单
|
||
Map<String, Object> map = new HashMap<String, Object>();
|
||
map.put("name",greenPermission.getName());
|
||
map.put("isOpen", greenPermission.getIsOpen());
|
||
map.put("pageUrl", greenPermission.getPageUrl());
|
||
map.put("iconUrl", greenPermission.getIconUrl());
|
||
map.put("code", greenPermission.getCode());
|
||
|
||
List<GreenPermission> list2 = new ArrayList<GreenPermission>();
|
||
for (GreenPermission gp : list) {
|
||
Integer tipNum = gp.getTipNum();
|
||
String tipNumQuery = gp.getTipNumQuery();
|
||
if(tipNum==1&&(!StringUtil.isEmpty(tipNumQuery))&&!gpIdList.contains(gp.getId())){
|
||
Integer tipNumDate=0;
|
||
if(tipNumQuery.indexOf("deptid=?")!=-1){
|
||
tipNumDate = hibernateDao.queryForIntWithSql(tipNumQuery, new Object[]{deptId});
|
||
}else if(tipNumQuery.indexOf("apply_date=?")!=-1){
|
||
String nowDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||
tipNumDate = hibernateDao.queryForIntWithSql(tipNumQuery, new Object[]{nowDate});
|
||
}else if(tipNumQuery.indexOf("take_food_time=?")!=-1){
|
||
String takeDay = "";
|
||
Integer week = DateUtil.getWeek(new Date());
|
||
if(week==1){
|
||
takeDay = DateUtil.addDays(2, new Date()).toString("yyyy-MM-dd");
|
||
}else if(week==2){
|
||
takeDay = DateUtil.addDays(1, new Date()).toString("yyyy-MM-dd");
|
||
}else if(week==3){
|
||
takeDay = DateUtil.addDays(0, new Date()).toString("yyyy-MM-dd");
|
||
}else if(week==4){
|
||
takeDay = DateUtil.addDays(1, new Date()).toString("yyyy-MM-dd");
|
||
}else if(week==5){
|
||
takeDay = DateUtil.addDays(0, new Date()).toString("yyyy-MM-dd");
|
||
}else if(week==6){
|
||
takeDay = DateUtil.addDays(4, new Date()).toString("yyyy-MM-dd");
|
||
}else if(week==7){
|
||
takeDay = DateUtil.addDays(3, new Date()).toString("yyyy-MM-dd");
|
||
}
|
||
tipNumDate = hibernateDao.queryForIntWithSql(tipNumQuery, new Object[]{takeDay});
|
||
}
|
||
else{
|
||
tipNumDate = hibernateDao.queryForIntWithSql(tipNumQuery);
|
||
}
|
||
gp.setTipNumDate(tipNumDate);
|
||
gpIdList.add(gp.getId());
|
||
}
|
||
List<GreenPermission> clist = new ArrayList<GreenPermission>();
|
||
for(GreenPermission per3 : list){
|
||
if(gp.getCode().equals(per3.getParentCode())){
|
||
clist.add(per3);
|
||
}
|
||
}
|
||
gp.setChildren(clist);
|
||
if (gp.getParentCode().equals(greenPermission.getCode())) {
|
||
list2.add(gp);
|
||
}
|
||
|
||
}
|
||
map.put("children", list2);
|
||
rList.add(map);
|
||
}
|
||
}
|
||
return new RestResult(Constant.SUCCESS, "",rList);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "数据获取失败!");
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取用户权限
|
||
*
|
||
* @param greenUserInfo
|
||
* @return
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@ResponseBody
|
||
@RequestMapping("/getUserPermission3")
|
||
public RestResult getUserPermission3(@RequestBody String userId,String parentCode) {
|
||
try {
|
||
String sql = " SELECT p1.* FROM green_permission p1 WHERE p1.code IN ( SELECT rp.permission_id FROM green_user_info u "
|
||
+ " LEFT JOIN green_user_role_rel urr ON u.id = urr.user_id "
|
||
+ " LEFT JOIN green_role gr ON gr.id = urr.role_id "
|
||
+ " LEFT JOIN green_role_permission rp ON rp.role_id = gr.id WHERE u.id = ? "
|
||
+ " and PARENT_CODE=? "
|
||
+ ") ORDER BY p1.sort asc ";
|
||
List<GreenPermission> list = hibernateDao.queryForListWithSql(sql, new Object[]{userId,parentCode}, new BeanPropertyRowMapper(GreenPermission.class));
|
||
return new RestResult(Constant.SUCCESS, "",list);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED, "数据获取失败!");
|
||
}
|
||
|
||
}
|
||
|
||
}
|