424 lines
18 KiB
Plaintext
424 lines
18 KiB
Plaintext
package com.nationalelectric.greenH5;
|
||
|
||
import org.springframework.web.bind.annotation.RequestMethod;
|
||
import org.springframework.web.bind.annotation.ResponseBody;
|
||
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
||
import com.nationalelectirc.Constant.Constant;
|
||
import com.nationalelectirc.utils.RestResult;
|
||
import com.nationalelectirc.utils.Utils;
|
||
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
||
import com.nationalelectric.greenH5.po.GreenOperateLog;
|
||
import com.nationalelectric.greenH5.po.GreenPersonElecAcc;
|
||
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
||
import com.nationalelectric.greenH5.po.GreenUserRoleRel;
|
||
import com.nationalelectric.greenH5.utils.DateTimeHelper;
|
||
import com.nationalelectric.greenH5.utils.GetTokenUtil;
|
||
import com.sgcc.uap.mdd.model.utils.StringUtil;
|
||
import com.sgcc.uap.persistence.IHibernateDao;
|
||
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.jysoft.unipush.AliasManage;
|
||
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
|
||
import java.io.Serializable;
|
||
import java.net.URLDecoder;
|
||
import java.util.*;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
|
||
import org.springframework.stereotype.Controller;
|
||
|
||
|
||
|
||
|
||
|
||
/**
|
||
* <b>概述</b>:<br>
|
||
* TODO
|
||
* <p>
|
||
* <b>功能</b>:<br>
|
||
* TODO
|
||
*
|
||
* @author niguang
|
||
*/
|
||
@Controller
|
||
@RequestMapping("/applogin")
|
||
public class AppLoginController {
|
||
|
||
|
||
@Autowired
|
||
IHibernateDao hibernateDao;
|
||
@Autowired
|
||
private BaseServiceImpl baseService;
|
||
|
||
@Autowired
|
||
private GreenDictionaryInfoController greenDictionaryInfoController;
|
||
/**
|
||
* 注册
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/register", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult register(GreenUserInfo user) {
|
||
try {
|
||
String vCode = user.getvCode();
|
||
String codeKey = user.getCodeKey();
|
||
|
||
Map<String, Object> res = Utils.map.get(codeKey);
|
||
if(res==null){
|
||
Utils.map.remove(codeKey);
|
||
return new RestResult(Constant.FAILED, "验证码错误!");
|
||
}
|
||
String mapCode = (String) res.get("code");
|
||
if(!mapCode.equals(vCode)){
|
||
Utils.map.remove(codeKey);
|
||
return new RestResult(Constant.FAILED, "验证码错误!");
|
||
}
|
||
|
||
String mobile = user.getMobile();
|
||
String realName = user.getRealName();
|
||
Long orgId = user.getOrgId();
|
||
String deptName = user.getDepartmentName();
|
||
Long deptId = user.getDepartmentId();
|
||
String userId = UUID.randomUUID().toString().replace("-", "");
|
||
user.setId(userId);
|
||
user.setWxOpenId(userId);
|
||
// user.setGmtCreated(new Date());
|
||
user.setGmtCreated(DateTimeHelper.getNowDate());
|
||
|
||
|
||
//查询手机号是否已注册
|
||
String mExistNumSql = "select count(*) from green_user_info where mobile = ? and is_deleted = 'N' ";
|
||
Integer mExistNum = hibernateDao.queryForIntWithSql(mExistNumSql, new Object[]{mobile});
|
||
if(mExistNum>0){
|
||
return new RestResult(Constant.FAILED,"该手机号已被注册,请验证后重新注册");
|
||
}
|
||
hibernateDao.saveObject(user);
|
||
|
||
|
||
//查询是否有初始化人员信息
|
||
String internalSql = "select role_id from green_internal_user where name=? and company=? and phone=? ";//and department=?
|
||
List<Map<String,Object>> internalList = hibernateDao.queryForListWithSql(internalSql, new Object[]{realName,orgId,mobile});//deptName,
|
||
if(internalList.size()!=0){//有初始化人员信息
|
||
Long role_id = new Long(0);
|
||
if(internalList.get(0).get("role_id")==null||"".equals(internalList.get(0).get("role_id"))){//初始化人员信息无角色信息,取部门默认角色
|
||
String deptSql = "select role_id from green_department where id = ? ";
|
||
List<Map<String, Object>> deptList = hibernateDao.queryForListWithSql(deptSql, new Object[] { deptId });
|
||
role_id = (Long) deptList.get(0).get("role_id");
|
||
}else{
|
||
role_id = (Long) internalList.get(0).get("role_id");
|
||
}
|
||
GreenUserRoleRel greenUserRoleRel = new GreenUserRoleRel();
|
||
greenUserRoleRel.setRoleId(role_id);
|
||
greenUserRoleRel.setRoleName("");
|
||
greenUserRoleRel.setUserId(userId);
|
||
greenUserRoleRel.setUserName(realName);
|
||
//hibernateDao.saveObject(greenUserRoleRel);
|
||
}else{
|
||
GreenUserRoleRel greenUserRoleRel = new GreenUserRoleRel();
|
||
greenUserRoleRel.setRoleId(new Long(0));
|
||
greenUserRoleRel.setRoleName("");
|
||
greenUserRoleRel.setUserId(userId);
|
||
greenUserRoleRel.setUserName(realName);
|
||
//hibernateDao.saveObject(greenUserRoleRel);
|
||
}
|
||
|
||
|
||
return new RestResult(Constant.SUCCESS,"查询成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"查询失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 登录
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult login(GreenUserInfo user,String clientId) {
|
||
try {
|
||
String mobile = user.getMobile();
|
||
String userPossword = user.getUserPossword();
|
||
String sql = "select u.id,u.wxOpenId,u.user_possword, u.wx_profile as wxProfile,u.real_name as realName,u.mobile,u.face_Pic1,u.identityAuth,u.id_card,u.userLevel,u.department_id,"
|
||
+ "u.department_name as departmentName,u.org_name as orgName ,u.gender,u.class_name as className,"
|
||
+ "u.is_inner as isInner,u.user_status as userStatus,r.role_id as role from green_user_info u "
|
||
+ "left join green_user_role_rel r on u.id = r.user_id "
|
||
+ "where u.mobile = ? AND u.IS_DELETED = 'N'";
|
||
List<Map<String,Object>> userList = hibernateDao.queryForListWithSql(sql.toString(),new Object[]{mobile});
|
||
if(userList.size()==0){
|
||
return new RestResult(Constant.FAILED,"用户名或密码错误");
|
||
}else{
|
||
Map<String,Object> map =userList.get(0);
|
||
String pwd = (String) map.get("user_possword");
|
||
if(pwd.equals(userPossword)){
|
||
|
||
if(map.get("face_Pic1") != null){
|
||
String picture1= (String)map.get("face_Pic1");
|
||
map.put("face_Pic1", baseService.getImageBase64(picture1) );
|
||
}
|
||
AliasManage.bindAlias(clientId, (String)(userList.get(0).get("id")));
|
||
|
||
return new RestResult(Constant.SUCCESS,"登录成功",map);
|
||
}else{
|
||
return new RestResult(Constant.FAILED,"用户名或密码错误");
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"查询失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更新用户信息
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult updateUserInfo(GreenUserInfo user) {
|
||
try {
|
||
String mobile = user.getMobile();
|
||
String realName = user.getRealName();
|
||
Long orgId = user.getOrgId();
|
||
String orgName = user.getOrgName();
|
||
String deptName = user.getDepartmentName();
|
||
Long deptId = user.getDepartmentId();
|
||
String userId = user.getId();
|
||
// String wxProfile = user.getWxProfile();
|
||
String deptTextUrl = user.getDeptTextUrl();
|
||
String deptIdUrl = user.getDeptIdUrl();
|
||
|
||
//查询用户信息
|
||
String queryUserInfoSql = "select u.department_id as \"department_id\","
|
||
+ " u.department_name as \"departmentName\",u.org_name as \"orgName\" ,u.org_id as \"orgId\","
|
||
+ " u.dept_name_url as \"deptNameUrl\" "
|
||
+ " from green_user_info u "
|
||
+ "left join green_user_role_rel r on u.id = r.user_id "
|
||
+ "where u.id=? AND u.IS_DELETED = 'N'";
|
||
List<Map<String,Object>> oldUserInfoList = hibernateDao.queryForListWithSql(queryUserInfoSql.toString(),new Object[]{userId});
|
||
|
||
//查询手机号是否已注册
|
||
String mExistNumSql = "select count(*) from green_user_info where mobile = ? and is_deleted = 'N' and id !=?";
|
||
Integer mExistNum = hibernateDao.queryForIntWithSql(mExistNumSql, new Object[]{mobile,userId});
|
||
if(mExistNum>0){
|
||
return new RestResult(Constant.FAILED,"该手机号已被注册,请验证后重新注册");
|
||
}
|
||
//更新用户信息
|
||
String updateUserInfoSql = "update green_user_info set mobile=?,real_name=?,org_id=?,org_name=?,department_id=?,department_name=?,dept_name_url = ?,dept_id_url = ? where id=?";
|
||
hibernateDao.executeSqlUpdate(updateUserInfoSql,new Object[]{mobile,realName,orgId,orgName,deptId,deptName,deptTextUrl,deptIdUrl,userId});
|
||
|
||
Map<String,Object> oldUserInfo = oldUserInfoList.get(0);
|
||
GreenOperateLog log = new GreenOperateLog();
|
||
log.setOperatorId(userId);
|
||
log.setOperatorName(realName);
|
||
log.setOperateFunction("用户信息");
|
||
log.setOperateType("修改部门");
|
||
log.setOperateStatus("成功");
|
||
log.setCreator(userId);
|
||
log.setGmtCreated(new Date());
|
||
log.setIsDeleted("N");
|
||
log.setOperatorContent("原部门:"+oldUserInfo.get("deptNameUrl")+",现部门:"+deptTextUrl);
|
||
log.setLogType("0");
|
||
log.setSource("2");
|
||
log.setLogRank("0");
|
||
hibernateDao.saveObject(log);
|
||
|
||
|
||
//查询是否有初始化人员信息
|
||
// String internalSql = "select role_id from green_internal_user where name=? and company=? and department=? and phone=? ";
|
||
// List<Map<String,Object>> internalList = hibernateDao.queryForListWithSql(internalSql, new Object[]{realName,orgId,deptName,mobile});
|
||
// if(internalList.size()!=0){//有初始化人员信息,更新角色
|
||
// Long role_id = new Long(0);
|
||
// if(internalList.get(0).get("role_id")==null||"".equals(internalList.get(0).get("role_id"))){//初始化人员信息无角色信息,取部门默认角色
|
||
// String deptSql = "select role_id from green_department where id = ? ";
|
||
// List<Map<String, Object>> deptList = hibernateDao.queryForListWithSql(deptSql, new Object[] { deptId });
|
||
// role_id = (Long) deptList.get(0).get("role_id");
|
||
// }else{
|
||
// role_id = (Long) internalList.get(0).get("role_id");
|
||
// }
|
||
// String updateUserRoleRelSql = "update green_user_role_rel set role_id=? where user_id=?";
|
||
// hibernateDao.executeSqlUpdate(updateUserRoleRelSql,new Object[]{role_id,userId});
|
||
// }
|
||
|
||
List<Map<String,Object>> openIdList = hibernateDao.queryForListWithSql(queryUserInfoSql.toString(),new Object[]{userId});
|
||
Map<String,Object> map =openIdList.get(0);
|
||
return new RestResult(Constant.SUCCESS,"成功",map);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"更新失败!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更新用户信息
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult updatePwd(Map<String,Object> map) {
|
||
try {
|
||
//String id =(String) map.get("id");
|
||
//String oldPwd = (String) map.get("oldPwd");
|
||
String mobile = (String) map.get("mobile");
|
||
String vCode = (String) map.get("vCode");
|
||
String codeKey = (String) map.get("codeKey");
|
||
String newPwd = (String) map.get("newPwd");
|
||
|
||
Map<String, Object> res = Utils.map.get(codeKey);
|
||
if(res==null){
|
||
Utils.map.remove(codeKey);
|
||
return new RestResult(Constant.FAILED, "验证码错误!");
|
||
}
|
||
String mapCode = (String) res.get("code");
|
||
if(!mapCode.equals(vCode)){
|
||
Utils.map.remove(codeKey);
|
||
return new RestResult(Constant.FAILED, "验证码错误!");
|
||
}
|
||
|
||
String queryUserInfoSql = "select user_possword from green_user_info where mobile = ? and is_deleted='N'";
|
||
List<Map<String,Object>> list = hibernateDao.queryForListWithSql(queryUserInfoSql, new Object[]{mobile});
|
||
if(list.size()==0){
|
||
return new RestResult(Constant.FAILED,"当前用户不存在");
|
||
}
|
||
//String queryOldPwd = (String) list.get(0).get("user_possword");
|
||
// if(!oldPwd.equals(queryOldPwd)){
|
||
// return new RestResult(Constant.FAILED,"原密码输入错误,请重新输入");
|
||
// }
|
||
String updatePwdSql = "update green_user_info set user_possword=? where mobile=?";
|
||
hibernateDao.executeSqlUpdate(updatePwdSql,new Object[]{newPwd,mobile});
|
||
|
||
return new RestResult(Constant.SUCCESS,"密码修改成功");
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"密码修改失败");
|
||
}
|
||
}
|
||
/**
|
||
* 获取商城token
|
||
*/
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/getShopMallToken", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult getShopMallToken(Map<String,Object> map,HttpServletResponse response,HttpServletRequest request) {
|
||
try {
|
||
String id =(String) map.get("id");
|
||
String realName = (String) map.get("realName");
|
||
String mobile = (String) map.get("mobile");
|
||
String deptName = (String) map.get("deptName");
|
||
String getCardNoSql = "select account,is_lock from green_person_elec_acc where person_id = ? and is_del='0' ";
|
||
List<Map<String,Object>> accountList = hibernateDao.queryForListWithSql(getCardNoSql,new Object[]{ id});
|
||
String account="";
|
||
if(accountList.size()==0){
|
||
//自动生成
|
||
GreenPersonElecAcc gp = new GreenPersonElecAcc();
|
||
gp.setPersonId(id);
|
||
gp.setPersonName(realName);
|
||
gp.setPhone(mobile);
|
||
gp.setDepartName(deptName);
|
||
String randomDate = new Date().getTime()+"";
|
||
account = mobile+randomDate.substring(randomDate.length()-6);
|
||
gp.setAccount(account);
|
||
|
||
Long elec_acc_id = (Long) hibernateDao.saveObject(gp);
|
||
String rechargemoney = greenDictionaryInfoController.getDictionaryInfo("rechargemoney", "rechargemoney").get(0).get("data_value");
|
||
|
||
String insertRechargeSql = "insert into green_person_recharge (elec_acc_id,account,user_name,depart_name,money,creater,create_time)"
|
||
+ "values(?,?,?,?,?,?,?)";
|
||
hibernateDao.executeSqlUpdate(insertRechargeSql, new Object[] {elec_acc_id, account,realName,deptName,rechargemoney,"system", new Date()});
|
||
}else{
|
||
String is_lock = (String) accountList.get(0).get("is_lock");
|
||
if("1".equals(is_lock)){
|
||
return new RestResult(Constant.FAILED,"您的账户当前处于锁定状态,无权进入商城!");
|
||
}
|
||
account = (String) accountList.get(0).get("account");
|
||
}
|
||
String getTokenUrl = greenDictionaryInfoController.getDictionaryInfo("getTokenUrl", "getTokenUrl").get(0).get("data_value");
|
||
String shopMallUrl = greenDictionaryInfoController.getDictionaryInfo("shopMallUrl", "shopMallUrl").get(0).get("data_value");
|
||
//String url = "http://124.126.19.5:19118/protocolTrans/openapi/ShopService_getUserToken";
|
||
JSONObject model = new JSONObject();
|
||
JSONObject body = new JSONObject();
|
||
// 在调用接口前需要先进行平台认证,获取token
|
||
// 将能力开放平台需要的参数封装入body
|
||
body.put("appId", "40282a077337e97601734b09cca80180"); // appId必填,不加密
|
||
body.put("authToken", GetTokenUtil.encrypt("myAuthToken")); // authToken必填,需加密
|
||
model.put("phone", mobile);//mobile 13999999999
|
||
model.put("card_no", account);
|
||
model.put("system_code", "300028");
|
||
model.put("name",realName);
|
||
model.put("department", "");
|
||
body.put("map", GetTokenUtil.encrypt(model.toJSONString()));
|
||
Map<String, Object> tokenMap = new HashMap<String, Object>();
|
||
map.put("args", body); // 这里必须是args
|
||
String jsonStr = GetTokenUtil.mapPost(getTokenUrl, map, "utf-8");
|
||
JSONObject jsonObj = JSONObject.parseObject(jsonStr);
|
||
jsonObj.put("data", URLDecoder.decode(GetTokenUtil.dencrypt(jsonObj.getString("data"))));// 为防止中文乱码
|
||
if (jsonObj.getString("status").equals("0")) {
|
||
JSONObject para1 = jsonObj.getJSONObject("data");
|
||
String token = para1.getString("data").toString();
|
||
// response.sendRedirect();
|
||
//request.getRequestDispatcher("http://124.126.19.5:19847/vuemrst-wh/index.html#/?token="+token).forward(request,response);
|
||
Map<String,String> mapr = new HashMap<String,String>();
|
||
mapr.put("token", token);
|
||
mapr.put("url", shopMallUrl);
|
||
return new RestResult(Constant.SUCCESS,"获取Token成功",mapr);
|
||
}else{
|
||
return new RestResult(Constant.FAILED,"获取Token失败");
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
return new RestResult(Constant.FAILED,"获取Token失败");
|
||
}
|
||
}
|
||
|
||
@SuppressWarnings("unchecked")
|
||
@RequestMapping(value = "/insertUser", method = RequestMethod.POST)
|
||
public @ResponseBody RestResult insertUser(String args){
|
||
String qSql = "select u.*,m.code as dept_id from green_internal_user u left join green_department m on u.department = m.name where u.id>1736";
|
||
List<Map<String,Object>> list = hibernateDao.queryForListWithSql( qSql);
|
||
for(int i=0;i<list.size();i++){
|
||
Map<String,Object> map = list.get(i);
|
||
String phone = (String) map.get("phone");
|
||
String name = (String) map.get("name");
|
||
Long role_id = (Long) map.get("role_id");
|
||
|
||
//查询手机号是否已注册
|
||
String mExistNumSql = "select count(*) from green_user_info where mobile = ? and is_deleted = 'N' ";
|
||
Integer mExistNum = hibernateDao.queryForIntWithSql(mExistNumSql, new Object[]{phone});
|
||
if(mExistNum>0){
|
||
System.out.println("该手机号已注册"+phone+" "+name);
|
||
continue;
|
||
}
|
||
System.out.println("正在导入:"+phone+" "+name);
|
||
String orgId = (String) map.get("company");
|
||
String deptName = (String) map.get("department");
|
||
Long deptId = (Long) map.get("dept_id");
|
||
String userId = UUID.randomUUID().toString().replace("-", "");
|
||
GreenUserInfo user = new GreenUserInfo();
|
||
|
||
user.setMobile(phone);
|
||
user.setRealName(name);
|
||
user.setOrgId(Long.parseLong(orgId));
|
||
user.setOrgName("华中分部");
|
||
user.setDepartmentId(deptId);
|
||
user.setDepartmentName(deptName);
|
||
user.setUserPossword("640347f617e954878de6034990fec38cc6b9beb16485aecf96a7301b30e0795c");//aaaa1111
|
||
user.setId(userId);
|
||
user.setWxOpenId(userId);
|
||
// user.setGmtCreated(new Date());
|
||
user.setGmtCreated(DateTimeHelper.getNowDate());
|
||
hibernateDao.saveObject(user);
|
||
|
||
GreenUserRoleRel greenUserRoleRel = new GreenUserRoleRel();
|
||
greenUserRoleRel.setRoleId(role_id);
|
||
greenUserRoleRel.setRoleName("");
|
||
greenUserRoleRel.setUserId(userId);
|
||
greenUserRoleRel.setUserName(name);
|
||
hibernateDao.saveObject(greenUserRoleRel);
|
||
}
|
||
return new RestResult(Constant.SUCCESS,"insertUser成功");
|
||
|
||
}
|
||
}
|