Commit 479ab021 authored by nie'hong's avatar nie'hong

扫描二维码后记录用户地区

parent 9283b537
......@@ -40,7 +40,7 @@ public class AddressUtil {
*/
public static String getAddresses(String content, String encodingString) throws UnsupportedEncodingException {
//调用淘宝API
String urlStr = "https://ip.taobao.com/outGetIpInfo";
String urlStr = "http://whois.pconline.com.cn/ipJson.jsp?json=true";
String returnStr = getResult(urlStr, content, encodingString);
if (returnStr != null) {
......@@ -108,30 +108,36 @@ public class AddressUtil {
public static Map<String, String> getAddressByIp(String ip) {
// 参数ip
// ip = "118.213.176.78";
// ip = "122.49.20.247";
// json_result用于接收返回的json数据
String json_result = null;
Map<String, String> map = new HashMap<>();
try {
json_result = getAddresses("ip=" + ip, "utf-8");
json_result = getAddresses("ip=" + ip, "gbk");
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("json_result = " + json_result);
JSONObject json = JSONObject.fromObject(json_result);
System.out.println("json数据: " + json);
String country = JSONObject.fromObject(json.get("data")).get("country").toString();
String region = JSONObject.fromObject(json.get("data")).get("region").toString();
String city = JSONObject.fromObject(json.get("data")).get("city").toString();
String county = JSONObject.fromObject(json.get("data")).get("county").toString();
String isp = JSONObject.fromObject(json.get("data")).get("isp").toString();
String area = JSONObject.fromObject(json.get("data")).get("area").toString();
map.put("country", country);//国家
map.put("area", area);//区域
map.put("region", region);//省
String pro = json.get("pro").toString();
String proCode = json.get("proCode").toString();
String city = json.get("city").toString();
String cityCode = json.get("cityCode").toString();
String region = json.get("region").toString();
String regionCode = json.get("regionCode").toString();
String addr = json.get("addr").toString();
// String country = json.get("country").toString();
// String isp = json.get("isp").toString();
// map.put("country", country);//国家
map.put("addr", addr);//区域
map.put("pro", pro);//省
map.put("proCode", proCode);//省编码
map.put("city", city);//市
map.put("county", county);//区
map.put("isp", isp);//互联网服务提供商
map.put("cityCode", cityCode);//市编码
map.put("region", region);//区
map.put("regionCode", regionCode);//区编码
// map.put("isp", isp);//互联网服务提供商
return map;
}
......
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* <pre>
......@@ -24,4 +25,6 @@ public interface TUserMapper extends BaseMapper<TUser> {
TUser getById(String id);
List<TUser> getUserList(@Param("user") TUser user);
List<TUser> getListByRole(Map<String, Object> map);
}
......@@ -164,6 +164,9 @@ public class TUser implements Serializable {
@TableField(exist = false)
private String jwtToken;
@TableField(exist = false)
private String roleId;
@ApiModelProperty("开始日期")
@TableField(exist = false)
private LocalDateTime beginDate;
......
......@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
* <p>
......@@ -25,4 +26,7 @@ public interface TUserService extends IService<TUser> {
List<TUser> getUserList(TUser user);
boolean addBox(TUser user);
List<TUser> getUserListByRole(Map<String, Object> map);
}
......@@ -20,6 +20,7 @@ import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* <pre>
......@@ -111,4 +112,10 @@ public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser> implements
return ret;
}
@Override
public List<TUser> getUserListByRole(Map<String, Object> map) {
return tUserMapper.getListByRole(map);
}
}
......@@ -75,7 +75,7 @@ public class StatisticController extends BaseController {
TVideoVisitor tVideoVisitor = new TVideoVisitor();
if (StringUtils.isBlank(videoId)) {
resultMap.put("resultCoed", "400");
resultMap.put("message", "视频不能为空");
resultMap.put("message", "展板不能为空");
}else {
tVideoVisitor.setVideoId(StringUtils.trimToNull(videoId));
}
......@@ -83,10 +83,16 @@ public class StatisticController extends BaseController {
if (StringUtils.isBlank(ipAddress)) {
resultMap.put("resultCoed", "400");
resultMap.put("message", "获取数据异常");
}else{
}
Map<String, String> addressByIp = AddressUtil.getAddressByIp(ipAddress);
tVideoVisitor.setArea(StringUtils.trimToNull(addressByIp.get("city")));
if (StringUtils.isNotBlank(addressByIp.get("region"))) {
tVideoVisitor.setArea(addressByIp.get("regionCode"));
}else if(StringUtils.isNotBlank(addressByIp.get("city"))){
tVideoVisitor.setArea(addressByIp.get("cityCode"));
}else {
tVideoVisitor.setArea(addressByIp.get("proCode"));
}
// 该条信息的创建时间和更新时间
tVideoVisitor.setCreateTime(new Date());
tVideoVisitor.setUpdateTime(new Date());
......@@ -97,6 +103,10 @@ public class StatisticController extends BaseController {
resultMap.put("resultCode", "500");
resultMap.put("message", "服务器忙");
return resultMap;
}else{
resultMap.put("resultCode", "200");
resultMap.put("message", "成功");
return resultMap;
}
} catch (Exception e) {
resultMap.put("resultCode", "500");
......
......@@ -201,26 +201,66 @@ public class TUserController extends BaseController {
} else {
user.setPassword(StringUtils.trimToNull(user.getPassword()));
}
if (StringUtils.isBlank(user.getPhone())) {
resultMap.put("resultCode", "400");
resultMap.put("message", "请填写手机号码!");
return resultMap;
}
String s1 = StringUtils.trimToNull(user.getPhone());
byte[] bytes = s1.getBytes();
if (bytes.length != 11) {
resultMap.put("resultCode", "400");
resultMap.put("message", "手机号码长度错误!");
return resultMap;
}
if (StringUtils.isBlank(user.getOrgId())) {
resultMap.put("resultCode", "400");
resultMap.put("message", "请选择机构!");
return resultMap;
}
if ("2".equals(user.getType())) {
QueryWrapper<TUser> ew = new QueryWrapper<>();
if (StringUtils.isBlank(user.getRoleId())) {
resultMap.put("resultCode", "200");
resultMap.put("message", "请选择管理员账号类型");
return resultMap;
}
user.setUserName(user.getUserName().trim());
ew.eq("is_deleted", false);
ew.eq("type", "2");
ew.eq("org_id", user.getOrgId());
List<TUser> list = userService.list(ew);
if (list.size() >= 3) {
Map<String, Object> map = new HashMap<>();
map.put("is_deleted", false);
map.put("role_id", user.getRoleId());
map.put("org_id", user.getOrgId());
List<TUser> list = userService.getUserListByRole(map);
if ("2".equals(user.getRoleId()) && list.size() >= 2) {
resultMap.put("resultCode", "200");
resultMap.put("message", "机构已存在三个单位管理员!");
resultMap.put("message", "机构已存在两个单位管理员!");
return resultMap;
}
if ("17".equals(user.getRoleId()) && list.size() >= 1) {
resultMap.put("resultCode", "200");
resultMap.put("message", "机构已存在一个互动审核员!");
return resultMap;
}
ArrayList<String> strings = new ArrayList<>();
strings.add("2");
strings.add(user.getRoleId());
user.setRoleList(strings);
/** 这是修改之前代码,保留以防出错
* QueryWrapper<TUser> ew = new QueryWrapper<>();
* user.setUserName(user.getUserName().trim());
* ew.eq("is_deleted", false);
* ew.eq("type", "2");
* ew.eq("org_id", user.getOrgId());
* List<TUser> list = userService.list(ew);
* if (list.size() >= 3) {
* resultMap.put("resultCode", "200");
* resultMap.put("message", "机构已存在三个单位管理员!");
* return resultMap;
* }
* ArrayList<String> strings = new ArrayList<>();
* strings.add("2");
* user.setRoleList(strings);
*/
}
if (user.getRoleList() == null || user.getRoleList().size() < 1) {
......@@ -328,6 +368,19 @@ public class TUserController extends BaseController {
}
}
if ("2".equals(user.getType())) {
if (StringUtils.isBlank(user.getRoleId())) {
resultMap.put("resultCode", "200");
resultMap.put("message", "请选择管理员账号类型");
return resultMap;
}
user.setUserName(user.getUserName().trim());
Map<String, Object> map = new HashMap<>();
map.put("is_deleted", false);
map.put("role_id", user.getRoleId());
map.put("org_id", user.getOrgId());
List<TUser> list = userService.getUserListByRole(map);
/** 修改之前
QueryWrapper<TUser> ew = new QueryWrapper<>();
ew.eq("is_deleted", false);
ew.eq("type", "2");
......@@ -339,6 +392,19 @@ public class TUserController extends BaseController {
resultMap.put("message", "机构已存在三个单位管理员!");
return resultMap;
}
**/
TUser tUser = userService.getById(user.getId());
if ("2".equals(user.getRoleId()) && list.size() >= 2 && !tUser.getOrgId().equals(user.getOrgId())) {
resultMap.put("resultCode", "400");
resultMap.put("message", "机构已存在两个单位管理员!");
return resultMap;
}
if ("17".equals(user.getRoleId()) && list.size() >= 1 && !tUser.getOrgId().equals(user.getOrgId())) {
resultMap.put("resultCode", "400");
resultMap.put("message", "机构已存在一个互动审核员!");
return resultMap;
}
}
// user.setUserName(StringUtils.trimToNull(user.getUserName()));
// user.setPassword(StringUtils.trimToNull(user.getPassword()));
......
......@@ -141,4 +141,11 @@
</if>
</select>
<select id="getListByRole" resultMap="BaseResultMap">
select <include refid="Base_Column_List"/>
from t_user u
left join t_user_role_link ur on u.id = ur.role_id
where u.org_id = #{org_id} and u.is_deleted = #{is_deleted} and ur.role_id =#{role_id}
</select>
</mapper>
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