package com.yc.userCenter.action;
|
|
import java.io.File;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.regex.Matcher;
|
import java.util.regex.Pattern;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import org.apache.commons.fileupload.FileItem;
|
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
import org.apache.commons.lang3.StringUtils;
|
import org.apache.poi.util.StringUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import com.google.gson.GsonBuilder;
|
import com.yc.action.BaseAction;
|
import com.yc.action.grid.GridUtils;
|
import com.yc.entity.UserAccountEntity;
|
import com.yc.entity.attachment.AttachmentEntity;
|
import com.yc.entity.attachment.AttachmentWhereEntity;
|
import com.yc.exception.CallBackMessage;
|
import com.yc.factory.FactoryBean;
|
import com.yc.multiData.SpObserver;
|
import com.yc.service.impl.DBHelper;
|
import com.yc.service.upload.AttachmentIfc;
|
import com.yc.service.user.UserAccountServiceIfc;
|
import com.yc.userCenter.entity.JurisdictionEntiy;
|
import com.yc.userCenter.entity.UserEntity;
|
import com.yc.userCenter.service.*;
|
import com.yc.utils.EncodeUtil;
|
import com.yc.utils.SessionKey;
|
|
/**
|
* 新权限设置界面
|
*
|
* @author xinyb_
|
*
|
*/
|
@Controller
|
@RequestMapping("/userCenter.do")
|
public class UserCenterAction extends BaseAction {
|
@Autowired
|
UserCenterIfc UserCenterIfc;
|
@Autowired
|
AttachmentIfc AttachmentIfc;
|
@Autowired
|
UserAccountServiceIfc userAccountService;
|
|
/**
|
* 加载所有用户信息
|
* @param value
|
* @param page
|
* @param limit
|
* @param allow
|
* @param appAllow 是否已经注册APP
|
* @param request
|
* @param response
|
*/
|
@RequestMapping(params = "m=user")
|
public void userCenter(String value, int page, int limit,String allow ,String appAllow,HttpServletRequest request,
|
HttpServletResponse response) {
|
List<Map<String, Object>> result = null;
|
try {
|
Map<String, Object> map = new HashMap<String, Object>();
|
String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID);
|
String alist="";
|
value = StringUtils.isNotBlank(value) ? value : "";
|
if (StringUtils.isBlank(appAllow)) {
|
appAllow = "1";
|
}
|
List<String> applist = null;
|
if (!"1".equals(appAllow)) {//查询APP的
|
try {
|
SpObserver.setDBtoDemo();
|
applist = UserCenterIfc.selectApps(dbId);
|
if (applist != null && applist.size() > 0) {
|
alist = String.join(",", applist);
|
}
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
try {
|
SpObserver.setDBtoInstance("_" + dbId);
|
allow = StringUtils.isNotBlank(allow) ? allow : "";
|
result = UserCenterIfc.getUserCenter(value, page, limit, allow, appAllow,alist);
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
Integer t = 0;
|
if (result != null && result.get(0) != null) {
|
t = DBHelper.getValueInt(result.get(0), "total");
|
}
|
map.put("code", 0);
|
map.put("msg", "");
|
map.put("count", t + (limit * (page - 1)));
|
map.put("data", result);
|
this.printJson(response, GridUtils.toJson(map));
|
} catch (Exception e) {
|
this.printJson(response, "{\"error\":\"" + this.getErrorMsg(e) + "\"}");
|
}
|
}
|
|
/**
|
* 删除维护登录用户
|
*
|
* @param usercode
|
* @param request
|
* @param response
|
*/
|
@RequestMapping(params = "m=deluser")
|
public void delUser(String usercode, Integer logontype,HttpServletRequest request, HttpServletResponse response) {
|
try {
|
String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID);
|
SpObserver.setDBtoInstance("_" + dbId);
|
int cont = UserCenterIfc.delUser(usercode,logontype);
|
this.printJson(response, "{\"info\":\"" + cont + "\"}");
|
} catch (Exception e) {
|
this.printJson(response, "{\"error\":\"" + this.getErrorMsg(e) + "\"}");
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
/**
|
* 修改密码
|
*
|
* @param mobileos
|
* @param request
|
* @param response
|
*/
|
@RequestMapping(params = "m=usercPwd")
|
public void updateuserPwdCenter(String oldpwd, String newpwd, Boolean isCode, String usercode,
|
Integer logontype,HttpServletRequest request, HttpServletResponse response) {
|
try {
|
String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID);
|
SpObserver.setDBtoInstance("_" + dbId);
|
if (!isCode) {// 是false的话需要验证旧密码,true为找回密码已经手机验证后才能找回(修改)
|
oldpwd = EncodeUtil.replaceUrlChar(oldpwd);
|
UserAccountEntity userAccount = userAccountService.getUserInfoByUserCode(usercode);
|
if (!userAccount.checkPassword(oldpwd)) {
|
this.printJson(response, "{\"msg\":\"旧密码错误,请检查是否输入正确\",\"state\":-1}");
|
return;
|
}
|
}
|
if ("".equals(newpwd)) {
|
this.printJson(response, "{\"msg\":\"新密码不能为空\",\"state\":-1}");
|
return;
|
}
|
Map<String, Object> map = UserCenterIfc.getUpdateUserPwd(newpwd, usercode,logontype);
|
this.printJson(response, new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm").disableHtmlEscaping()
|
.serializeNulls().create().toJson(map));
|
} catch (Exception e) {
|
this.printJson(response, "{\"msg\":\"" + this.getErrorMsg(e) + "\"}");
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
/**
|
* 保存对应控件值到数据库
|
*
|
* @param value
|
* @param usercode
|
* @param request
|
* @param response
|
*/
|
@RequestMapping(params = "m=Info")
|
public void setUserCenterInfo(String value, String usercode,Integer logontype, HttpServletRequest request,
|
HttpServletResponse response) {
|
CallBackMessage callBackMessage = new CallBackMessage();
|
try {
|
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
int cont = UserCenterIfc.getUserCenterInfo(value, usercode,logontype);
|
if (cont == 1) {
|
this.printJson(response, callBackMessage.sendSuccessMessage("保存成功!"));
|
}
|
} catch (Exception e) {//
|
this.printJson(response, callBackMessage
|
.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
/**
|
* 保存头像图片
|
*
|
* @param id
|
* @param request
|
* @param response
|
*/
|
@RequestMapping(params = "m=Image")
|
public void setUserCenterCobox(String id, HttpServletRequest request, HttpServletResponse response) {
|
try {
|
String uploadPath = System.getProperty("java.io.tmpdir");
|
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
File tempPathFile = null;
|
DiskFileItemFactory factory = new DiskFileItemFactory();
|
// Set factory constraints
|
factory.setSizeThreshold(40960); // 设置缓冲区大小,这里是4kb
|
factory.setRepository(tempPathFile);// 设置缓冲区目录
|
// Create a new file upload handler
|
ServletFileUpload upload = new ServletFileUpload(factory);
|
// Set overall request size constraint
|
upload.setSizeMax(419430400); // 设置最大文件尺寸,这里是4MB
|
|
@SuppressWarnings("unchecked")
|
List<FileItem> items = upload.parseRequest(request);// 得到所有的文件
|
Iterator<FileItem> i = items.iterator();
|
Map<String, String> param = new HashMap<String, String>(); // 所有填写的文本字段
|
// List<File> fileList = new ArrayList<File>(); // 所有上传的文件
|
File files = null;
|
while (i.hasNext()) {
|
FileItem fi = (FileItem) i.next();
|
String fileName = fi.getName();
|
if (fileName != null) {
|
File fullFile = new File(new String(fi.getName().getBytes(), "utf-8")); // 解决文件名乱码问题
|
File savedFile = new File(uploadPath, fullFile.getName() + ".JPG");
|
fi.write(savedFile);
|
// fileList.add(savedFile);
|
files = savedFile;
|
} else {
|
param.put(fi.getFieldName(), fi.getString("utf-8"));// 如果你页面编码是utf-8的
|
}
|
}
|
AttachmentEntity attachmentEntity = new AttachmentEntity();
|
attachmentEntity.setAuthorCode(param.get("usercode"));
|
attachmentEntity.setAuthorName(param.get("username"));
|
if (files != null) {
|
attachmentEntity.setOriginalFileName(files.getName());
|
// 上传图片
|
AttachmentWhereEntity attachmentWhereEntity = AttachmentIfc.saveAttachment(attachmentEntity, files,
|
"0");
|
if (!attachmentWhereEntity.getUnid().equals("")) {
|
int cont = UserCenterIfc.getUserCenterInfo("avatarunid='" + attachmentWhereEntity.getUnid() + ";"
|
+ attachmentWhereEntity.getSeq() + "'", param.get("usercode"),0);
|
if (cont == 1) {
|
this.printJson(response, "{\"info\":\"/getImage.do?uuid=" + attachmentWhereEntity.getUnid()
|
+ ";" + attachmentWhereEntity.getSeq() + "&type=1\"}");
|
}
|
}
|
}
|
} catch (Exception e) {
|
this.printJson(response, e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
/**
|
* 手机或Email绑定后保存到后台数据库
|
*
|
* @param dbId
|
* @param v
|
* @param code
|
* @param usercode
|
* @param request
|
* @param response
|
*/
|
@SuppressWarnings("unchecked")
|
@RequestMapping(params = "m=phoneEmail")
|
public void phoneEmail(String dbId, String v, String code, String usercode,String userId,Integer logontype, HttpServletRequest request,
|
HttpServletResponse response) {
|
try {
|
@SuppressWarnings("rawtypes")
|
RedisTemplate redisTemplate = (RedisTemplate) FactoryBean.getBean("redisTemplate");
|
if (!redisTemplate.hasKey("CODE:" + v + ":" + dbId)) {
|
this.printJson(response, "{\"info\":\"验证码已失效,请重新获取验证码。\"}");
|
return;
|
}
|
String rediscode = redisTemplate.opsForValue().get("CODE:" + v + ":" + dbId) + "";
|
if (!code.equals(rediscode)) {// 验证码匹配
|
this.printJson(response, "{\"info\":\"验证码错误,请输入正确的验证码。\"}");
|
return;
|
}
|
if (usercode == null || usercode.equals("")) {
|
this.printJson(response, "{\"info\":\"获取不到当前用户userCode。\"}");
|
return;
|
}
|
String value = v;
|
Pattern regex = Pattern
|
.compile("^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
|
Matcher matcher = regex.matcher(v);
|
Pattern regex1 = Pattern.compile(
|
"^[1](([3][0-9])|([4][5,7,9])|([5][0-9])|([6][6])|([7][3,5,6,7,8])|([8][0-9])|([9][8,9]))[0-9]{8}$");
|
Matcher matcher1 = regex1.matcher(v);
|
if (matcher.matches()) {// 邮箱
|
value = "email='" + v + "'";
|
} else if (matcher1.matches()) {// 手机
|
value = "tel='" + v + "'";
|
} else {
|
this.printJson(response, "{\"info\":\"格式不正确!\"}");
|
return;
|
}
|
int cont = 0;
|
try {
|
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
cont = UserCenterIfc.getUserCenterInfo(value, usercode,logontype);
|
if (cont == 1 && matcher1.matches()) {
|
redisTemplate.delete("CODE:" + v + ":" + dbId);// 删除
|
UserCenterIfc.updateTelephone(v, usercode, "");
|
}
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
if (cont == 1 && matcher1.matches() && userId != null && !"".equals(userId)) {// 修改的是手机进入
|
try {
|
SpObserver.setDBtoDemo();
|
UserCenterIfc.updateTelephone(v, "", userId);
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
this.printJson(response, "{\"info\":\"" + cont + "\"}");
|
} catch (Exception e) {
|
this.printJson(response, "{\"info\":\"验证过程出现错误:"
|
+ (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()) + "\"}");
|
}
|
}
|
|
@RequestMapping(params = "m=mess")
|
public void getMessage(String key, String search, HttpServletRequest request, HttpServletResponse response) {
|
try {
|
SpObserver.setDBtoDemo();
|
List<Map<String, Object>> list = UserCenterIfc.getMessage(key, search);
|
this.printJson(response, GridUtils.toJson(list));
|
} catch (Exception e) {
|
this.printJson(response, (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping(params = "m=delmess")
|
public void delMessage(String id, HttpServletRequest request, HttpServletResponse response) {
|
try {
|
SpObserver.setDBtoDemo();
|
int cont = UserCenterIfc.delMessage(id);
|
this.printJson(response, "{\"info\":" + cont + "}");
|
} catch (Exception e) {
|
this.printJson(response, (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping(params = "m=getSelect")
|
public void getCccode(String codeId, String userCode, String companyId,HttpServletRequest request, HttpServletResponse response) {
|
try {
|
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
Map<String, Object> map = UserCenterIfc.getselect2SQL(codeId, userCode); // 获取需要的下拉sql
|
Map<String, Object> userMap = new HashMap<String, Object>();
|
if(companyId!=null) {
|
userMap.put("companyid", companyId);
|
}else {
|
userMap.put("companyid", request.getSession().getAttribute(SessionKey.COMPANY_ID));
|
}
|
String sql = DBHelper.getValRepShi(DBHelper.getValue(map, "sqlscript"), request.getSession(), userMap,
|
false);
|
SqlRowSet srs = UserCenterIfc.getSelect(sql);
|
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
while (srs != null && srs.next()) {
|
Map<String, Object> map2 = new HashMap<String, Object>();
|
map2.put("name", DBHelper.replaceBlank(srs.getString(2)));
|
map2.put("value", DBHelper.replaceBlank(srs.getString(1)).toLowerCase().trim());
|
list.add(map2);
|
}
|
//选中的值
|
String[] val = DBHelper.getValue(map, "val").toLowerCase().trim().split(";");
|
List<String> vList=new ArrayList<String>();
|
for (int i = 0; i < val.length; i++) {
|
vList.add(val[i]);
|
}
|
this.printJson(response,"{\"value\":"+GridUtils.toJson(vList)+",\"data\":"+GridUtils.toJson(list)+"}");
|
} catch (Exception e) {
|
this.printJson(response, (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping(params = "m=addUser")
|
public void adUser(UserEntity user, HttpServletRequest request, HttpServletResponse response) {
|
try {
|
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
if (user != null) {
|
user.setCompanyId((String) request.getSession().getAttribute(SessionKey.COMPANY_ID));// 获取公司Id
|
user.setCompanyName((String) request.getSession().getAttribute(SessionKey.COMPANY_NAME));// 获取公司名称
|
int count = UserCenterIfc.addUser(user);
|
this.printJson(response, "{\"info\":" + count + "}");
|
}
|
} catch (Exception e) {
|
this.printJson(response, (e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping(params = "m=updateApp")
|
public void updateApp(String value, String userId, String dbId, HttpServletRequest request,
|
HttpServletResponse response) {
|
CallBackMessage callBackMessage = new CallBackMessage();
|
try {
|
SpObserver.setDBtoDemo();
|
int cont = UserCenterIfc.updateApp(value, userId, dbId);
|
if (cont == 1) {
|
this.printJson(response, callBackMessage.sendSuccessMessage("修改成功!"));
|
} else {
|
this.printJson(response, callBackMessage.sendErrorMessage("修改失败!"));
|
}
|
} catch (Exception e) {
|
this.printJson(response, callBackMessage
|
.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping(params = "m=delApp")
|
public void delApp(String userId, String dbId, HttpServletRequest request, HttpServletResponse response) {
|
CallBackMessage callBackMessage = new CallBackMessage();
|
try {
|
SpObserver.setDBtoDemo();
|
int cont = UserCenterIfc.deleteApp(userId, dbId);
|
if (cont == 1) {
|
this.printJson(response, callBackMessage.sendSuccessMessage("删除成功!"));
|
} else {
|
this.printJson(response, callBackMessage.sendErrorMessage("删除失败!"));
|
}
|
} catch (Exception e) {
|
this.printJson(response, callBackMessage
|
.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
|
@RequestMapping(params = "m=setting")
|
public void setTing(JurisdictionEntiy jurisdiction, HttpServletRequest request, HttpServletResponse response) {
|
CallBackMessage callBackMessage = new CallBackMessage();
|
try {
|
SpObserver.setDBtoInstance("_" + request.getSession().getAttribute(SessionKey.DATA_BASE_ID));
|
int cont = UserCenterIfc.updateSetTing(jurisdiction);
|
if (cont == 1) {
|
this.printJson(response, callBackMessage.sendSuccessMessage("保存成功!"));
|
} else {
|
this.printJson(response, callBackMessage.sendErrorMessage("保存失败!"));
|
}
|
} catch (Exception e) {
|
this.printJson(response, callBackMessage
|
.sendErrorMessage(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()));
|
} finally {
|
SpObserver.setDBtoInstance();
|
}
|
}
|
}
|