Commit efba1137 by 杨清松

场站用户账号 手机号重复校验

parent 55d3f413
...@@ -14,4 +14,8 @@ public interface WarehouseUserDao extends BaseDao { ...@@ -14,4 +14,8 @@ public interface WarehouseUserDao extends BaseDao {
KObject findByUsernameOrTelephone(String username); KObject findByUsernameOrTelephone(String username);
List<KObject> findAllByStationId(UUID stationId); List<KObject> findAllByStationId(UUID stationId);
List<KObject> queryPositionByName(String phone);
List<KObject> userNameRepeatCheck(String username);
} }
...@@ -3,8 +3,11 @@ package com.beecode.inz.basis.internal.dao; ...@@ -3,8 +3,11 @@ package com.beecode.inz.basis.internal.dao;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateCallback;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -71,4 +74,30 @@ public class WarehouseUserDaoImpl extends AbstractBaseDao implements WarehouseUs ...@@ -71,4 +74,30 @@ public class WarehouseUserDaoImpl extends AbstractBaseDao implements WarehouseUs
return listByAttributes(buildSingleMap(WarehouseUserConstants.TELEPHONE, telephone)); return listByAttributes(buildSingleMap(WarehouseUserConstants.TELEPHONE, telephone));
} }
@Override
public List<KObject> queryPositionByName(String phone) {
return (List<KObject>)template.execute(new HibernateCallback<List<KObject>>() {
@SuppressWarnings("unchecked")
@Override
public List<KObject> doInHibernate(Session session) throws HibernateException {
Query<KObject> query = session.createQuery("from " + WarehouseUserConstants.ENTITY + " where (discard is null or discard = 0) and (enabled = 1) and telephone =:phone ", KObject.class);
query.setParameter("phone", phone);
return query.getResultList();
}
});
}
@Override
public List<KObject> userNameRepeatCheck(String username) {
return (List<KObject>)template.execute(new HibernateCallback<List<KObject>>() {
@SuppressWarnings("unchecked")
@Override
public List<KObject> doInHibernate(Session session) throws HibernateException {
Query<KObject> query = session.createQuery("from " + WarehouseUserConstants.ENTITY + " where (discard is null or discard = 0) and (enabled = 1) and username =:username ", KObject.class);
query.setParameter("username", username);
return query.getResultList();
}
});
}
} }
...@@ -199,6 +199,26 @@ public class WarehouseUserServiceImpl implements WarehouseUserService { ...@@ -199,6 +199,26 @@ public class WarehouseUserServiceImpl implements WarehouseUserService {
dao.update(entity); dao.update(entity);
} }
} }
@Override
public Boolean phoneRepeatCheck(String phone) {
List<KObject> list = dao.queryPositionByName(phone);
Boolean flag = false;
if (list != null && list.size() > 0 ) {
flag = true;
}
return flag;
}
@Override
public Boolean userNameRepeatCheck(String username) {
List<KObject> list = dao.userNameRepeatCheck(username);
Boolean flag = false;
if (list != null && list.size() > 0 ) {
flag = true;
}
return flag;
}
......
...@@ -63,4 +63,8 @@ public interface WarehouseUserService { ...@@ -63,4 +63,8 @@ public interface WarehouseUserService {
*/ */
List<KObject> getAllByStationId(UUID stationId); List<KObject> getAllByStationId(UUID stationId);
Boolean phoneRepeatCheck(String parameter);
Boolean userNameRepeatCheck(String parameter);
} }
...@@ -3,6 +3,8 @@ package com.beecode.inz.basis.web; ...@@ -3,6 +3,8 @@ package com.beecode.inz.basis.web;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.PostMapping; ...@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.beecode.bcp.core.context.AminoContextHolder; import com.beecode.bcp.core.context.AminoContextHolder;
...@@ -22,6 +25,9 @@ import com.beecode.inz.basis.pojo.WarehouseUser; ...@@ -22,6 +25,9 @@ import com.beecode.inz.basis.pojo.WarehouseUser;
import com.beecode.inz.basis.service.WarehouseUserService; import com.beecode.inz.basis.service.WarehouseUserService;
import com.beecode.inz.basis.team.pojo.ResponseObj; import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.beecode.inz.basis.util.JsonUtil; import com.beecode.inz.basis.util.JsonUtil;
import com.beecode.xlib.json.JSONException;
import com.beecode.xlib.json.JSONObject;
import com.beecode.xlib.runtime.Assert;
import com.beecode.xlib.utils.StringUtil; import com.beecode.xlib.utils.StringUtil;
/** /**
...@@ -36,6 +42,9 @@ public class WarehouseUserController { ...@@ -36,6 +42,9 @@ public class WarehouseUserController {
@Autowired @Autowired
private WarehouseUserService warehouseUserService; private WarehouseUserService warehouseUserService;
@Autowired
private HttpServletRequest request;
/** /**
* 创建场站用户 * 创建场站用户
...@@ -156,4 +165,42 @@ public class WarehouseUserController { ...@@ -156,4 +165,42 @@ public class WarehouseUserController {
return Integer.toString(HttpStatus.OK.value()); return Integer.toString(HttpStatus.OK.value());
} }
/**
* 用户名,手机号校验重复
*
* @param obj
* @return
*/
@ResponseBody
@RequestMapping(value = "/warehouse/user/verify", method = RequestMethod.PUT)
public Object verify(@RequestBody String body){
Assert.notNull(body, "The body must not be null");
String operation = request.getHeader("operation");
Assert.notNull(operation, "'operation' must not be null");
String parameter = null;
JSONObject object;
try {
object = new JSONObject(body);
parameter = object.optString("parameter",null);
} catch (JSONException e) {
e.printStackTrace();
}
switch (operation) {
case "PHONE_CHECK":
// 手机号重复查询 true为重复
Boolean phoneResult = warehouseUserService.phoneRepeatCheck(parameter);
if(phoneResult){
return ResponseObj.error("手机号码重复");
}
case "USERNAME_CHECK":
Boolean userNameResult = warehouseUserService.userNameRepeatCheck(parameter);
if(userNameResult){
return ResponseObj.error("账号重复");
}
default:
return null;
}
}
} }
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