Commit 6b715105 authored by 技术部-任文超's avatar 技术部-任文超

解决用户联系人和地址信息的入库校验问题,1)开放保存数量限制(原来限制不超过2个联系人),2)严格校验联系人(或列表)的电话、姓名规则,3)严格校验地址信息

parent 832425e2
......@@ -353,14 +353,21 @@ public class MotanUserServiceImpl implements UserMotanService {
String jsonContacts = JSON.toJSONString(contacts);
List<Contact> contactList = null;
try {
contactList = MAPPER.readValue(jsonContacts, new TypeReference<List<Contact>>() {
});
contactList = MAPPER.readValue(jsonContacts, new TypeReference<List<Contact>>(){});
} catch (Exception e) {
log.error("联系人列表转换错误", e);
return returnErrorValue("联系人转换错误");
}
Timestamp now = new Timestamp(System.currentTimeMillis());
for (Contact c : contactList) {
if (!ValidationUtil.validatePhoneNo(c.getPhoneNo())) {
log.info("用户手机号错误, phoneNo:{}", c.getPhoneNo());
return returnErrorValue("用户手机号错误");
}
if (!ValidationUtil.validateChinese(c.getName())) {
log.info("用户姓名错误, name:{}", c.getName());
return returnErrorValue("用户姓名错误");
}
c.setId(null);
c.setUserId(userId);
c.setRelation(c.getRelation() == null ? Relation.OTHER : c.getRelation());
......@@ -368,8 +375,7 @@ public class MotanUserServiceImpl implements UserMotanService {
c.setUpdateAt(now);
}
List<Contact> result = contactService.save(contactList);
List<XContact> xResult = convertObject(JSON.toJSONString(result), new TypeReference<List<XContact>>() {
});
List<XContact> xResult = convertObject(JSON.toJSONString(result), new TypeReference<List<XContact>>(){});
return returnSuccessValue(xResult);
}
......@@ -388,7 +394,7 @@ public class MotanUserServiceImpl implements UserMotanService {
@Override
public UserSysResult<XAddress> saveAddress(Long userId, Long provinceCode, String province, Long cityCode, String city,
Long districtCode, String district, String address) {
if (null == userId || null == provinceCode || null == cityCode) {
if (null == userId || null == provinceCode || null == cityCode || StringUtils.isBlank(address)) {
return returnErrorValue("参数不能为空");
}
Address addressObj = addressService.findByUserId(userId);
......
......@@ -380,25 +380,28 @@ public class InnerController implements IBaseController {
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> userContact = contactService.findByUserId(userId);
if (userContact != null && userContact.size() >= 2) {
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(userContact));
}
List<Contact> contacts = JSONObject.parseObject(contactsStr, new TypeReference<List<Contact>>() {
});
/*
* 推翻之前逻辑,联系人可以更改.如果数据库已有记录.则更改
*
if(userContact != null && userContact.size() >= 2) {
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(userContact));
}
*/
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){
if (!ValidationUtil.validatePhoneNo(contact.getPhoneNo())) {
LOGGER.info("用户手机号错误, phoneNo:{}", contact.getPhoneNo());
return JsonResult.buildErrorStateResult(null, null);
}
if (!ValidationUtil.validateChinese(contact.getName())) {
LOGGER.info("用户姓名错误, name:{}", contact.getName());
return JsonResult.buildErrorStateResult("null", null);
}
}
for(Contact contact : contacts){
if (!ValidationUtil.validatePhoneNo(contact.getPhoneNo())) {
LOGGER.info("用户手机号错误, phoneNo:{}", contact.getPhoneNo());
return JsonResult.buildErrorStateResult(null, null);
}
if (!ValidationUtil.validateChinese(contact.getName())) {
LOGGER.info("用户姓名错误, name:{}", contact.getName());
return JsonResult.buildErrorStateResult("null", null);
}
}
Timestamp now = new Timestamp(System.currentTimeMillis());
convertContactList(userId, contacts, now);
List<Contact> result = contactService.save(contacts);
......@@ -412,18 +415,19 @@ public class InnerController implements IBaseController {
@RequestParam(required = false) String phoneNo,
@RequestParam(required = false) Relation relation, String key,
@RequestParam String reason,HttpServletRequest request) {
if (!"@qwsdedad131323213w!".equals(key)) {
if (!"@qwsdedad131323213w!".equals(key) || contactId == null) {
return JsonResult.buildErrorStateResult("参数不合法", null);
}
if (StringUtils.isEmpty(name) && StringUtils.isEmpty(phoneNo) ){
return JsonResult.buildErrorStateResult("修改联系人修改条件不能都为空", null);
}
if (!ValidationUtil.validatePhoneNo(phoneNo)) {
LOGGER.info("用户手机号错误, phoneNo:{}", phoneNo);
return JsonResult.buildErrorStateResult("用户手机号错误", null);
}
if (!ValidationUtil.validateChinese(name)) {
LOGGER.info("用户姓名错误, name:{}", name);
return JsonResult.buildErrorStateResult("用户姓名错误", null);
}
if(StringUtils.isEmpty(reason)){
......@@ -469,9 +473,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:{},userId:{}" + city, province,userId);
if (userId == null || provinceCode == null || cityCode == null) {
return JsonResult.buildErrorStateResult(null, null);
LOGGER.info("保存地址详情:city:{},province:{},district:{}, address:{},userId:{}" + city, province, district, address, userId);
if (userId == null || provinceCode == null || cityCode == null || StringUtils.isBlank(address)) {
return JsonResult.buildErrorStateResult("参数不能为空", null);
}
Address addressObj = addressService.findByUserId(userId);
if (addressObj == null) {
......
......@@ -11,6 +11,7 @@ import cn.quantgroup.xyqb.model.ContactRet;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.*;
import cn.quantgroup.user.enums.*;
import cn.quantgroup.xyqb.util.ValidationUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import org.apache.commons.collections.CollectionUtils;
......@@ -245,11 +246,14 @@ public class UserCenterController {
return JsonResult.buildErrorStateResult(null, null);
}
List<Contact> userContact = contactService.findByUserId(userId);
/*if(userContact != null && userContact.size() >= 2) {
/*
* 推翻之前逻辑,联系人可以更改.如果数据库已有记录.则更改
*
if(userContact != null && userContact.size() >= 2) {
return JsonResult.buildSuccessResult(null, ContactRet.contacts2ContactRets(userContact));
}*/
//推翻之前逻辑,联系人可以更改.如果数据库已有记录.则更改
List<Contact> contacts = JSONObject.parseObject(contactJson, new TypeReference<List<Contact>>() {});
}
*/
List<Contact> contacts = JSONObject.parseObject(contactJson, new TypeReference<List<Contact>>(){});
Timestamp now = new Timestamp(System.currentTimeMillis());
if (CollectionUtils.isEmpty(contacts)) {
return JsonResult.buildErrorStateResult("参数转换错误", null);
......@@ -258,7 +262,9 @@ public class UserCenterController {
for(int i = 0; i < contacts.size(); i ++) {
contacts.get(i).setId(userContact.get(i).getId());
contacts.get(i).setUserId(userContact.get(i).getUserId());
contacts.get(i).setCreatedAt(now);
if(contacts.get(i).getCreatedAt() == null) {
contacts.get(i).setCreatedAt(now);
}
contacts.get(i).setUpdateAt(now);
}
} else {
......@@ -269,6 +275,16 @@ public class UserCenterController {
c.setUpdateAt(now);
}
}
for(Contact contact : contacts){
if (!ValidationUtil.validatePhoneNo(contact.getPhoneNo())) {
LOGGER.info("用户手机号错误, phoneNo:{}", contact.getPhoneNo());
return JsonResult.buildErrorStateResult(null, null);
}
if (!ValidationUtil.validateChinese(contact.getName())) {
LOGGER.info("用户姓名错误, name:{}", contact.getName());
return JsonResult.buildErrorStateResult("null", null);
}
}
List<Contact> result = contactService.save(contacts);
return JsonResult.buildSuccessResult(null, result);
}
......@@ -285,8 +301,8 @@ public class UserCenterController {
@RequestMapping("/address/save")
public JsonResult saveUserAddress(String phoneNo, String province, Long provinceCode, String city, Long cityCode, String address,
Long districtCode, String district) {
LOGGER.info("保存用户地址信息, phoneNo:{}, province:{}, provinceCode:{}, city:{}, cityCode:{}", phoneNo, province, provinceCode, city, cityCode);
if (StringUtils.isEmpty(phoneNo) || provinceCode == null || cityCode == null) {
LOGGER.info("保存用户地址信息, phoneNo:{}, province:{}, provinceCode:{}, city:{}, cityCode:{},district:{}, address:{}", phoneNo, province, provinceCode, city, cityCode, district, address);
if (StringUtils.isEmpty(phoneNo) || provinceCode == null || cityCode == null || StringUtils.isBlank(address)) {
return JsonResult.buildErrorStateResult("参数错误", null);
}
Long userId = queryUserId(phoneNo);
......
......@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.controller.external.user.InnerController;
import cn.quantgroup.xyqb.entity.Contact;
import cn.quantgroup.xyqb.repository.IContactRepository;
import cn.quantgroup.xyqb.service.user.IContactService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
......@@ -46,11 +47,12 @@ public class ContactServiceImpl implements IContactService {
return contactRepository.save(contact);
}
@Override
public Contact saveContact(String name, String phoneNo, Relation relation, Contact contact) {
if (null != name) {
if (StringUtils.isNotBlank(name)) {
contact.setName(name);
}
if (null != phoneNo) {
if (StringUtils.isNotBlank(phoneNo)) {
contact.setPhoneNo(phoneNo);
}
if (null != relation) {
......
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