修改增加接口

parent e94e42f7
package cn.quantgroup.xyqb.controller.external.user;
import cn.quantgroup.user.enums.Relation;
import cn.quantgroup.xyqb.Constants;
import cn.quantgroup.xyqb.aspect.logcaller.LogHttpCaller;
import cn.quantgroup.xyqb.controller.IBaseController;
import cn.quantgroup.xyqb.entity.*;
import cn.quantgroup.xyqb.entity.enumerate.*;
import cn.quantgroup.xyqb.exception.UserNotExistException;
import cn.quantgroup.xyqb.model.*;
import cn.quantgroup.xyqb.service.api.IUserApiService;
import cn.quantgroup.xyqb.service.auth.IIdCardService;
......@@ -25,15 +25,20 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.*;
......@@ -82,12 +87,15 @@ public class InnerController implements IBaseController {
@Value("${xyqb.auth.url}")
private String hanguguanUrl;
private final String pwdSalt = "_lkb";
private static final ObjectMapper MAPPER = new ObjectMapper();
static {
MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MAPPER.configure(SerializationFeature.WRITE_ENUMS_USING_INDEX, true);
}
private static final char[] PWD_BASE = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
......@@ -127,16 +135,17 @@ public class InnerController implements IBaseController {
return JsonResult.buildSuccessResult(null, null);
}
User user = userService.findByUuidInDb(uuid);
if(null!=user){
if(!user.getEnable()){
if (null != user) {
if (!user.getEnable()) {
return JsonResult.buildSuccessResult("", null);
}
UserDetail userDetail = userDetailService.findByUserId(user.getId());
UserInfo info = new UserInfo(user,userDetail);
UserInfo info = new UserInfo(user, userDetail);
return JsonResult.buildSuccessResult("", info);
}
return JsonResult.buildSuccessResult("", null);
}
@RequestMapping("/userInfo/search/phone")
@LogHttpCaller
public JsonResult findUserInfoByPhone(@RequestParam(value = "phone") String phone) {
......@@ -146,12 +155,12 @@ public class InnerController implements IBaseController {
return JsonResult.buildSuccessResult(null, null);
}
User user = userService.findByPhoneInDb(phone);
if(null!=user){
if(!user.getEnable()){
if (null != user) {
if (!user.getEnable()) {
return JsonResult.buildSuccessResult("", null);
}
UserDetail userDetail = userDetailService.findByUserId(user.getId());
UserInfo info = new UserInfo(user,userDetail);
UserInfo info = new UserInfo(user, userDetail);
return JsonResult.buildSuccessResult("", info);
}
return JsonResult.buildSuccessResult("", null);
......@@ -179,7 +188,7 @@ public class InnerController implements IBaseController {
public JsonResult saveUser(
String phoneNo, Long registeredFrom, Long createdAt, Long updatedAt,
String password, String uuid) {
LOGGER.info("保存用户,phoneNo:{},registeredFrom;{},uuid:{}",phoneNo,registeredFrom,uuid);
LOGGER.info("保存用户,phoneNo:{},registeredFrom;{},uuid:{}", phoneNo, registeredFrom, uuid);
//参数验证
if (StringUtils.isBlank(phoneNo)) {
return JsonResult.buildErrorStateResult("用户手机号不能为空.", null);
......@@ -188,7 +197,7 @@ public class InnerController implements IBaseController {
registeredFrom = 0L;
}
if (StringUtils.isBlank(password)) {
password= genRandomPwd();
password = genRandomPwd();
password = PasswordUtil.MD5(password.toLowerCase() + Constants.PASSWORD_SALT);
}
if (StringUtils.isBlank(uuid)) {
......@@ -202,7 +211,7 @@ public class InnerController implements IBaseController {
if (user == null) {
user = new User();
} else if (!user.getEnable()) {
LOGGER.info("用户已经注销,phoneNo:{},",phoneNo);
LOGGER.info("用户已经注销,phoneNo:{},", phoneNo);
return JsonResult.buildErrorStateResult("用户已经注销", null);
}
if (org.apache.commons.lang.StringUtils.isEmpty(user.getUuid())) {
......@@ -218,7 +227,7 @@ public class InnerController implements IBaseController {
user = userService.saveUser(user);
UserRet userRet = null;
if (user != null) {
userRet = MqUtils.sendRegisterMessage(registeredFrom, null,user);
userRet = MqUtils.sendRegisterMessage(registeredFrom, null, user);
}
return JsonResult.buildSuccessResult(null, userRet);
}
......@@ -230,7 +239,7 @@ public class InnerController implements IBaseController {
@RequestMapping("/user_detail/save")
public JsonResult saveUserDetail(Long userId, String phoneNo, String name, String idNo,
String email, Long id) {
LOGGER.info("保存用户详细信息,phoneNo:{},userId;{},name:{},idNo:{},email;{}",phoneNo,userId,name,idNo,email);
LOGGER.info("保存用户详细信息,phoneNo:{},userId;{},name:{},idNo:{},email;{}", phoneNo, userId, name, idNo, email);
//参数验证
if (userId == null || userId == 0L) {
return JsonResult.buildErrorStateResult("用户id为空.", null);
......@@ -257,9 +266,9 @@ public class InnerController implements IBaseController {
if (Objects.isNull(info) || !info.isValid()) {
return JsonResult.buildErrorStateResult("身份证号码错误", null);
}
UserDetail userDetail=userDetailService.findByUserId(userId);
UserDetail userDetail = userDetailService.findByUserId(userId);
Timestamp time = new Timestamp(System.currentTimeMillis());
if(null==userDetail){
if (null == userDetail) {
userDetail = new UserDetail();
userDetail.setCreatedAt(time);
}
......@@ -316,6 +325,7 @@ public class InnerController implements IBaseController {
/**
* 根据phone查找用户完整信息
*
* @param phoneNo
* @return
*/
......@@ -336,6 +346,7 @@ public class InnerController implements IBaseController {
/**
* 根据uuid查找用户完整信息
*
* @param uuid
* @return
*/
......@@ -378,7 +389,7 @@ public class InnerController implements IBaseController {
@RequestMapping("/contact/save/contacts")
public JsonResult save2Contact(Long userId, @RequestParam(value = "contacts") String contactsStr) {
LOGGER.info("保存用户联系人:userId:{}, contacts:{}",userId, contactsStr);
LOGGER.info("保存用户联系人:userId:{}, contacts:{}", userId, contactsStr);
if (StringUtils.isEmpty(contactsStr)) {
return JsonResult.buildErrorStateResult(null, null);
}
......@@ -386,12 +397,13 @@ public class InnerController implements IBaseController {
LOGGER.info("用户ID不能为空");
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>(){});
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>() {
});
if (CollectionUtils.isEmpty(contacts)) {
LOGGER.info("联系人不能空");
return JsonResult.buildErrorStateResult(null, null);
}
for(Contact contact : contacts){
for (Contact contact : contacts) {
if (!contact.valid()) {
LOGGER.info("用户手机号或姓名错误, phoneNo:{},name:{}", contact.getPhoneNo(), contact.getName());
return JsonResult.buildErrorStateResult(null, null);
......@@ -405,12 +417,12 @@ public class InnerController implements IBaseController {
public JsonResult updateContact(@RequestParam Long contactId, @RequestParam(required = false) String name,
@RequestParam(required = false) String phoneNo,
@RequestParam(required = false) Relation relation, String key,
@RequestParam String reason,HttpServletRequest request) {
@RequestParam String reason, HttpServletRequest request) {
if (!"@qwsdedad131323213w!".equals(key) || contactId == null) {
return JsonResult.buildErrorStateResult("参数不合法", null);
}
if (StringUtils.isEmpty(name) && StringUtils.isEmpty(phoneNo) ){
if (StringUtils.isEmpty(name) && StringUtils.isEmpty(phoneNo)) {
return JsonResult.buildErrorStateResult("修改联系人修改条件不能都为空", null);
}
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
......@@ -421,7 +433,7 @@ public class InnerController implements IBaseController {
LOGGER.info("用户姓名错误, name:{}", name);
return JsonResult.buildErrorStateResult("用户姓名错误", null);
}
if(StringUtils.isEmpty(reason)){
if (StringUtils.isEmpty(reason)) {
return JsonResult.buildErrorStateResult("修改原因不能为空", null);
}
Contact contact = contactService.findById(contactId);
......@@ -429,7 +441,7 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("修改联系人不存在", null);
}
contact = contactService.saveContact(name, phoneNo, relation, contact);
LOGGER.info("修改后联系人信息:{},修改原因:{},操作ip:{}",contact,reason,IPUtil.getRemoteIP(request));
LOGGER.info("修改后联系人信息:{},修改原因:{},操作ip:{}", contact, reason, IPUtil.getRemoteIP(request));
return JsonResult.buildSuccessResult("修改联系人成功", contact);
}
......@@ -450,9 +462,9 @@ public class InnerController implements IBaseController {
public JsonResult saveAddress(
Long userId, Long provinceCode, Long cityCode, String city,
Long districtCode, String district, String address, String province) {
LOGGER.info("保存地址详情:city:{},province:{},district:{}, address:{},userId:{}" , city, province, district, address, userId);
LOGGER.info("保存地址详情:city:{},province:{},district:{}, address:{},userId:{}", city, province, district, address, userId);
if (userId == null || provinceCode == null || cityCode == null || StringUtils.isBlank(address)) {
LOGGER.info("错误保存地址详情,其中参数不能为空:city:{},province:{},district:{}, address:{},userId:{}" , city, province, district, address, userId);
LOGGER.info("错误保存地址详情,其中参数不能为空:city:{},province:{},district:{}, address:{},userId:{}", city, province, district, address, userId);
return JsonResult.buildErrorStateResult("参数不能为空", null);
}
Address addressObj = addressService.findByUserId(userId);
......@@ -471,7 +483,7 @@ public class InnerController implements IBaseController {
addressObj.setAddress(address);
addressObj.setProvince(province);
addressObj = addressService.save(addressObj);
LOGGER.info("保存后地址详情:{}",addressObj);
LOGGER.info("保存后地址详情:{}", addressObj);
return JsonResult.buildSuccessResult(null, AddressRet.address2AddressRet(addressObj));
}
......@@ -589,13 +601,14 @@ public class InnerController implements IBaseController {
* 地址信息
* 联系人信息
* }
*
* @param userId - 用户表主键
* @return
*/
@RequestMapping("/user-association/search/userId")
@LogHttpCaller
public JsonResult findUserAssociationModelByUserId(Long userId) {
if(Objects.isNull(userId) || userId < 0){
if (Objects.isNull(userId) || userId < 0) {
return JsonResult.buildErrorStateResult("", "");
}
UserAssociationModel bean = new UserAssociationModel();
......@@ -619,19 +632,19 @@ public class InnerController implements IBaseController {
}
UserExtInfo extInfo = userExtInfoService.findByUserId(userDetail.getUserId());
if (!Objects.isNull(extInfo)) {
if(null==extInfo.getEducationEnum()){
if (null == extInfo.getEducationEnum()) {
bean.setEducationEnum(cn.quantgroup.user.enums.EducationEnum.UNKNOWN.getName());
}else{
} else {
bean.setEducationEnum(extInfo.getEducationEnum().getName());
}
if(null==extInfo.getOccupationEnum()){
if (null == extInfo.getOccupationEnum()) {
bean.setOccupationEnum(cn.quantgroup.user.enums.OccupationEnum.UNKNOWN.getName());
}else{
} else {
bean.setOccupationEnum(extInfo.getOccupationEnum().getName());
}
if(null==extInfo.getMarryStatus()){
if (null == extInfo.getMarryStatus()) {
bean.setMarryStatus(cn.quantgroup.user.enums.MaritalStatus.UNKNOWN.getDescription());
}else{
} else {
bean.setMarryStatus(extInfo.getMarryStatus().getDescription());
}
}
......@@ -664,10 +677,11 @@ public class InnerController implements IBaseController {
/**
* 获取用户综合信息
*
* @param userDetail
* @return
*/
private UserAssociation getUserAssociation(UserDetail userDetail){
private UserAssociation getUserAssociation(UserDetail userDetail) {
UserAssociation bean = new UserAssociation();
if (null != userDetail) {
Address address = addressService.findByUserId(userDetail.getUserId());
......@@ -686,19 +700,19 @@ public class InnerController implements IBaseController {
bean.setAddress(address.getAddress());
}
if (null != extInfo) {
if(null==extInfo.getEducationEnum()){
if (null == extInfo.getEducationEnum()) {
bean.setEducationEnum(cn.quantgroup.user.enums.EducationEnum.UNKNOWN.getName());
}else{
} else {
bean.setEducationEnum(extInfo.getEducationEnum().getName());
}
if(null==extInfo.getOccupationEnum()){
if (null == extInfo.getOccupationEnum()) {
bean.setOccupationEnum(cn.quantgroup.user.enums.OccupationEnum.UNKNOWN.getName());
}else{
} else {
bean.setOccupationEnum(extInfo.getOccupationEnum().getName());
}
if(null==extInfo.getMarryStatus()){
if (null == extInfo.getMarryStatus()) {
bean.setMarryStatus(cn.quantgroup.user.enums.MaritalStatus.UNKNOWN.getDescription());
}else{
} else {
bean.setMarryStatus(extInfo.getMarryStatus().getDescription());
}
}
......@@ -733,6 +747,7 @@ public class InnerController implements IBaseController {
}
return contactRets;
}
@RequestMapping("/user/wechat/phone_no")
@LogHttpCaller
public JsonResult queryOpenIdByPhoneNo(String phoneNo) {
......@@ -768,6 +783,7 @@ public class InnerController implements IBaseController {
/**
* 清除用户缓存信息
*
* @param phoneNo
* @return
*/
......@@ -785,6 +801,7 @@ public class InnerController implements IBaseController {
LOGGER.info("删除用户缓存信息,phoneNo:{},userId:{},", user.getPhoneNo(), user.getId());
return JsonResult.buildSuccessResult("用户缓存信息已经删除", null);
}
@RequestMapping("/user/spouse/save")
public JsonResult saveSpouse(Long userId, MaritalStatus status, String spousePhone, String spouseName) {
if (userId == null || userId == 0) {
......@@ -849,6 +866,7 @@ public class InnerController implements IBaseController {
/**
* 手机号批量查询uuid
*
* @param userPhones
* @return
*/
......@@ -857,6 +875,7 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("主库不提供查询", null);
}
/**
* 重置密码接口,供内部人员使用(例如绝影)
*/
......@@ -897,7 +916,7 @@ public class InnerController implements IBaseController {
String districtCode,
String district,
String address,
String contacts,@RequestParam(defaultValue = "0",required =false ) Long btRegisterChannelId) {
String contacts, @RequestParam(defaultValue = "0", required = false) Long btRegisterChannelId) {
LOGGER.info("[/innerapi/user/save_multi]保存用户、联系人、地址信息:registeredFrom:[{}], phoneNo[{}],name[{}],idNo[{}],provinceCode[{}],cityCode[{}],districtCode[{}]," +
"address[{}],contacts[{}]", registeredFrom, phoneNo, name, idNo, provinceCode, cityCode, districtCode, address, contacts);
......@@ -949,7 +968,7 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("用户已存在,手机号被占用", null);
}
user = userRegisterService.register(Long.valueOf(registeredFrom), Long.valueOf(channelId), phoneNo, name, idNo, provinceCode, province, cityCode, city, districtCode, district, address, contacts,btRegisterChannelId);
user = userRegisterService.register(Long.valueOf(registeredFrom), Long.valueOf(channelId), phoneNo, name, idNo, provinceCode, province, cityCode, city, districtCode, district, address, contacts, btRegisterChannelId);
UserRet userRet = new UserRet(user);
return JsonResult.buildSuccessResult(null, userRet);
......@@ -975,11 +994,11 @@ public class InnerController implements IBaseController {
@RequestMapping("/contract/queryRegisterUsers")
@LogHttpCaller
public JsonResult findRegisterUserByTime(String beginTime,String endTime) {
if (null == beginTime||endTime==null) {
public JsonResult findRegisterUserByTime(String beginTime, String endTime) {
if (null == beginTime || endTime == null) {
return JsonResult.buildErrorStateResult(null, null);
}
List<User> userList=userService.findRegisterUserByTime(beginTime,endTime);
List<User> userList = userService.findRegisterUserByTime(beginTime, endTime);
return JsonResult.buildSuccessResult(null, userList);
}
......@@ -996,13 +1015,13 @@ public class InnerController implements IBaseController {
if (null == str || !str.equals(userId.toString())) {
return JsonResult.buildErrorStateResult("解密有误", null);
}
int affectedRows=wechatService.forbiddenUserWeChat(userId);
LOGGER.info("用户微信禁用,userId:{},禁用的原因reason:{},受影响的行数affectedRows:{}",userId,reason,affectedRows);
int affectedRows = wechatService.forbiddenUserWeChat(userId);
LOGGER.info("用户微信禁用,userId:{},禁用的原因reason:{},受影响的行数affectedRows:{}", userId, reason, affectedRows);
return JsonResult.buildSuccessResult("用户禁用微信成功", affectedRows);
}
@RequestMapping("/updateIdCard")
public JsonResult updateIdCard(@RequestParam(required = false)String name, @RequestParam(required = false)String idNo,
public JsonResult updateIdCard(@RequestParam(required = false) String name, @RequestParam(required = false) String idNo,
@RequestParam String phoneNo, @RequestParam String reason, @RequestParam String content) {
//密文
if (null != content) {
......@@ -1012,18 +1031,18 @@ public class InnerController implements IBaseController {
if (null == str || !str.equals(phoneNo)) {
return JsonResult.buildErrorStateResult("解密有误", null);
}
if(StringUtils.isBlank(name) && StringUtils.isBlank(idNo)){
if (StringUtils.isBlank(name) && StringUtils.isBlank(idNo)) {
return JsonResult.buildErrorStateResult("不能全为空", null);
}
if ( StringUtils.isBlank(phoneNo) || StringUtils.isBlank(reason)) {
if (StringUtils.isBlank(phoneNo) || StringUtils.isBlank(reason)) {
return JsonResult.buildErrorStateResult("参数有误", null);
}
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("手机号有误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
int affectedRows=userDetailService.updateIdCard(name, idNo, phoneNo);
LOGGER.info("更新用户的信息,name;{},idNo:{},phoneNo:{},操作的理由reason:{},受影响的行数affectedRows:{}", name, idNo, phoneNo, reason,affectedRows);
int affectedRows = userDetailService.updateIdCard(name, idNo, phoneNo);
LOGGER.info("更新用户的信息,name;{},idNo:{},phoneNo:{},操作的理由reason:{},受影响的行数affectedRows:{}", name, idNo, phoneNo, reason, affectedRows);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("phoneNo", phoneNo);
builder.put("name", name);
......@@ -1055,8 +1074,8 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
int affectedRows=userService.forbiddenUser(enable, phoneNo);
LOGGER.info("禁用或者重启用户的理由,reason:{},手机号phoneNo:{},受影响的行数affectedRows:{}", reason, phoneNo,affectedRows);
int affectedRows = userService.forbiddenUser(enable, phoneNo);
LOGGER.info("禁用或者重启用户的理由,reason:{},手机号phoneNo:{},受影响的行数affectedRows:{}", reason, phoneNo, affectedRows);
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
builder.put("phoneNo", phoneNo);
builder.put("enable", String.valueOf(enable));
......@@ -1067,6 +1086,7 @@ public class InnerController implements IBaseController {
httpService.get(hanguguanUrl.concat("/innerapi/forbiddenUserOrNot"), param);
return JsonResult.buildSuccessResult("用户禁用或重启成功成功", affectedRows);
}
private String genRandomPwd() {
int pwdMax = PWD_BASE.length;
// 生成的随机数
......@@ -1085,4 +1105,73 @@ public class InnerController implements IBaseController {
}
return pwd.toString();
}
@LogHttpCaller
@RequestMapping("/login")
public JsonResult login(@RequestParam String phoneNo, @RequestParam String password) {
User user = checkPhoneNoAndPassword(phoneNo, password);
if (user == null) {
return JsonResult.buildErrorStateResult("用户名或密码不正确", null);
}
UserRet model = new UserRet(user);
return JsonResult.buildSuccessResult("校验成功", model);
}
private User checkPhoneNoAndPassword(@RequestParam String phoneNo, @RequestParam String password) {
byte[] byPhoneNo = org.apache.commons.codec.binary.Base64.decodeBase64(phoneNo);
String bufPhoneNo = "";
try {
bufPhoneNo = new String(byPhoneNo, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.error("不支持的编码: ", e);
}
if (!ValidationUtil.validatePhoneNo(bufPhoneNo)) {
LOGGER.info("手机号错误, phoneNo:{}", bufPhoneNo);
throw new UserNotExistException("手机号错误");
}
byte[] byPassword = org.apache.commons.codec.binary.Base64.decodeBase64(password);
String bufPassword = "";
try {
bufPassword = new String(byPassword, "UTF-8");
} catch (UnsupportedEncodingException e) {
LOGGER.error("不支持的编码: ", e);
}
User user = userService.findByPhoneWithCache(bufPhoneNo);
if (user == null || !user.getEnable()) {
return null;
}
//验证密码
if (!validatePassword(bufPassword, user.getPassword())) {
return null;
}
return user;
}
private boolean validatePassword(String paramPass, String targetPassword) {
return org.apache.commons.lang.StringUtils.defaultString(targetPassword, "").equals(PasswordUtil.MD5(paramPass.toLowerCase() + pwdSalt));
}
/**
* 查询用户是否存在
*
* @param phoneNo
* @return
*/
@RequestMapping("/user/enable")
public JsonResult isEnable(String phoneNo) {
boolean flag = false;
Map validMap = Maps.newHashMap();
validMap.put("valid", flag);
User user = userService.findByPhoneInDb(phoneNo);
if (user != null && user.getEnable()) {
validMap.put("valid", true);
return JsonResult.buildSuccessResult("查询成功", validMap);
}
return JsonResult.buildErrorStateResult("用户不存在", validMap);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment