Commit 91ad5c07 authored by huagnxiner's avatar huagnxiner

添加下载二维码以及删除用户需要验证绑定楼盘代码

parent 49dcc6e0
......@@ -34,6 +34,7 @@ import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -45,10 +46,11 @@ import org.springside.modules.web.Servlets;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.io.*;
import java.util.*;
/**
* 角色控制器<br>
*
......@@ -93,6 +95,9 @@ public class RoleController extends BaseController {
@Autowired
private IAttachmentInterface attachmentInterface;
@Value("${twodimensional.code.url}")
private String twoDimensionalUrl;
/**
* 去新增角色
......@@ -956,5 +961,25 @@ public class RoleController extends BaseController {
return response;
}
/**
* 下载一键呼二维码
*
* @return 结果视图
*/
@RequestMapping(value = "downLoadCallCode")
public void downLoadCallCode(HttpServletRequest request,HttpServletResponse response,@RequestParam("userId") String userId) throws Exception {
//根据userid获取city信息
String cityName=user.getCityById(userId);
//二维码中包含的信息
StringBuilder content=new StringBuilder();
content.append(twoDimensionalUrl).append("uid=").append(userId).append("&").append("city=").append(cityName);
response.reset();
//设置请求头
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment; filename=1.png");
OutputStream outputStream =new BufferedOutputStream(response.getOutputStream());
outputStream.write(QrCodeUtil.createImg(content.toString()));
outputStream.flush();
outputStream.close();
}
}
package com.house365.web.controller;
import com.alibaba.dubbo.common.json.JSON;
import com.beust.jcommander.internal.Lists;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Joiner;
......@@ -23,6 +24,7 @@ import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -69,6 +71,9 @@ public class UserController extends BaseController {
@Autowired
private ICustomer customer;
@Value("${tlf.bandpeople.url}")
private String tlfBandPeopleUrl;
/**
* 去新增账户
*
......@@ -1072,4 +1077,32 @@ public class UserController extends BaseController {
return accessToken;
}
/**
* 根据id获取用户的绑定楼盘信息
*
* @param id 账户页面表单对象唯一标识
* @return 用户的绑定信息结果
*/
@RequestMapping(value = "/bindPeople/{id}",method = RequestMethod.GET)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public HResult getBindPeopleInfo(@PathVariable String id) {
HResult result = new HResult();
try {
Map<String, String> paramMap =new HashMap<>();
paramMap.put("userId",id);
//通过http调用接口获取用户绑定楼盘信息
String res=HttpUtil.simpleGet(tlfBandPeopleUrl,paramMap,null);
HResult finalInfo=JSON.parse(res,HResult.class);
result.setStatus(finalInfo.getStatus());
result.setData(finalInfo.getData());
logger.info(id+" bindpeopleInfo:"+finalInfo.getData());
} catch (Exception e) {
result.setStatus(-1);
result.setErrorMessage("获取绑定用户信息失败");
e.printStackTrace();
logger.error("获取绑定用户信息失败", e);
}
return result;
}
}
......@@ -6,10 +6,7 @@ import com.house365.beans.entity.WxUserEntity;
import com.house365.rest.exception.ServiceException;
import com.house365.rest.parameter.House365RestResponse;
import net.sf.json.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.*;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
......@@ -17,26 +14,32 @@ import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.hibernate.validator.internal.util.privilegedactions.GetMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class HttpUtil {
private static final Logger LOG = LoggerFactory.getLogger("HttpUtil");
private static final String DEFAULT_ENCODING = "UTF-8";
private final static int DEFAULT_CONNECT_TIMEOUT = 5000; // 设置连接超时时间,单位毫秒
private final static int DEFAULT_CONNECTION_REQUEST_TIMEOUT = 1000;// 设置从connect Manager获取Connection 超时时间,单位毫秒
private final static int DEFAULT_SOCKET_TIMEOUT = 5000;// 请求获取数据的超时时间,单位毫秒 如果访问一个接口,多少时间内无法返回数据,就直接放弃此次调用
/**
*新:get请求
* @param url
......@@ -270,4 +273,79 @@ public class HttpUtil {
}
return null;
}
/**
* 简单get请求传输
* @param url
* @param paramMap
* @param encoding
* @return
*/
public static String simpleGet(String url, Map<String,String> paramMap, String encoding){
String body = "";
encoding = StringUtils.isBlank(encoding)?DEFAULT_ENCODING:encoding;
//1、创建CloseableHttpClient对象
CloseableHttpClient client = HttpClients.createDefault();
//2、创建get请求
HttpGet httpGet = new HttpGet(url);
//装填参数
List<NameValuePair> lists = new ArrayList<NameValuePair>();
if(paramMap != null){
//每个key-value构成一个entrySet对象
Set<Map.Entry<String, String>> setMap = paramMap.entrySet();
//遍历对象 将值保存list集合种
for (Map.Entry<String, String> entry:setMap) {
lists.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
}
//将传递参数 编码化
String param = URLEncodedUtils.format(lists, encoding);
LOG.info("simpleGet------->"+param);
//设置数据
httpGet.setURI(URI.create(url+"?"+param));
LOG.info("simpleGet --- url------->"+httpGet.getURI().toString());
//配置连接参数信息
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT).setConnectionRequestTimeout(DEFAULT_CONNECTION_REQUEST_TIMEOUT)
.setSocketTimeout(DEFAULT_SOCKET_TIMEOUT).build();
httpGet.setConfig(requestConfig);
//执行请求操作,并拿到结果(同步阻塞)
CloseableHttpResponse response = null;
try {
//5、调用CloseableHttpClient对象的execute(HttpUriRequest request)发送请求,该方法返回一个CloseableHttpResponse。
response = client.execute(httpGet);
//6、调用HttpResponse的getEntity()方法可获取HttpEntity对象,该对象包装了服务器的响应内容。程序可通过该对象获取服务器的响应内容;调用CloseableHttpResponse的getAllHeaders()、getHeaders(String name)等方法可获取服务器的响应头。
StatusLine status = response.getStatusLine();
LOG.info("get请求回调状态 :"+status);
//获取结果实体
HttpEntity entity = response.getEntity();
if (entity != null) {
//按指定编码转换结果实体为String类型
body = EntityUtils.toString(entity, encoding);
LOG.info("get请求回调数据 :"+body);
}
//7、释放连接。无论执行方法是否成功,都必须释放连接
EntityUtils.consume(entity);
}catch (UnsupportedEncodingException e){
e.printStackTrace();
LOG.error("简单get请求遇到UnSpEcode异常",e);
} catch (IOException e) {
e.printStackTrace();
LOG.error("简单get请求遇到IO异常",e);
} catch (ParseException e) {
e.printStackTrace();
LOG.error("简单get请求遇到PE异常",e);
throw new ParseException();
} finally{
//释放链接
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return body;
}
}
package com.house365.web.util;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.util.Hashtable;
/**
* 根据url生产二维码
* @author huang xiner
* @version 1.0
* @date 2021/5/25 10:44
*/
public class QrCodeUtil {
private final static Logger logger = LoggerFactory.getLogger(QrCodeUtil.class.getName());
private static final int BLACK = 0xFF000000;
private static final int WHITE = 0xFFFFFFFF;
private static final int WIDTH = 750;
private static final int HEIGHT = 750;
/**
* 功能描述:生成二维码字节数组
* @param content 文本内容
* @return
*/
public static byte[] createImg(String content) throws Exception{
byte[] data = null;
File tempFile = null;
FileInputStream input = null;
ByteArrayOutputStream output = null;
try {
output = new ByteArrayOutputStream();
tempFile = File.createTempFile("temp", null);
//生成临时图片
Hashtable<EncodeHintType, Object> hints = new Hashtable<EncodeHintType, Object>();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.MARGIN, 1);
BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, WIDTH, HEIGHT, hints);
MatrixToImageWriter.writeToFile(matrix, "png", tempFile);
//图片转储字节数组
input = new FileInputStream(tempFile);
byte[] temp = new byte[1000];
int n;
while ((n = input.read(temp)) != -1) {
output.write(temp, 0, n);
}
data = output.toByteArray();
logger.info("根据内容{}创建二维码成功",content);
} catch (Exception ex) {
throw new Exception("生成二维码图片异常",ex);
} finally {
try {
if(input!=null)
input.close();
if(output!=null)
output.close();
} catch (IOException ex) {
logger.error("创建二维码成功,文件流关闭异常",ex);
}
if (tempFile != null)
tempFile.delete();
}
return data;
}
}
......@@ -93,6 +93,11 @@
<span id="hotlinenum">&nbsp;4008908365&nbsp;${entity.hotlinephone}</span>
<font color="red"><form:errors path="userVo.entity.mobile"/></font>
<!--新增下载二维码 -->
<c:if test="${not empty entity.hotlinephone}">
<input class="btn blue" type="button" onclick="downLoadCallCode(${entity.id})" value="下载一键呼二维码">
</c:if>
</div>
</div>
</div>
......@@ -388,6 +393,10 @@
return false;
}
}
// 下载一键呼二维码
function downLoadCallCode(id){
window.open("${ctx}/role/downLoadCallCode?userId="+id);
}
</script>
</body>
......
......@@ -477,6 +477,18 @@
House365Util.createModal("删除员工", "员工名下还有客户,请转移交接给其他置业顾问后再删除。", function () {
});
} else {
//获取删除用户的绑定楼盘信息
$.ajax({
url: '${ctx}/user/bindPeople/' + selectedId,
type: "GET",
success: function (result) {
console.info(result.data)
if (result.status == 0) {
if(result.data!=null && result.data.length>0){
//员工有绑定的楼盘,不能删除
alert("请在团立方后台解绑该顾问");
return;
}else {
House365Util.createModal("删除员工", "删除后将无法恢复员工账号,请确认是否继续?", function () {
debugger;
if (selectedId.includes("257") == true) {
......@@ -493,6 +505,30 @@
});
});
}
}else{
alert(result.errorMessage);
}
}
});
<%--House365Util.createModal("删除员工", "删除后将无法恢复员工账号,请确认是否继续?", function () {--%>
<%-- debugger;--%>
<%-- if (selectedId.includes("257") == true) {--%>
<%-- alert("appstore账户,请勿操作");--%>
<%-- return;--%>
<%-- }--%>
<%-- $.ajax({--%>
<%-- url: '${ctx}/user/' + selectedId,--%>
<%-- type: "DELETE",--%>
<%-- success: function () {--%>
<%-- $("input[name='memberCheck']").removeAttr("checked");--%>
<%-- window.location.reload();--%>
<%-- }--%>
<%-- });--%>
<%--});--%>
}
}
};
......
......@@ -185,4 +185,6 @@ public interface IUser extends IService {
void update(UserWxRelation userWxRelation);
String getCityById(String userId);
}
......@@ -51,4 +51,6 @@ public interface UserMapper {
void updateUserStatus(Map<String,Object> map);
String getCityById(String userId);
}
......@@ -1104,6 +1104,11 @@ public class UserImpl implements IUser {
relationMapper.update(userWxRelation);
}
@Override
public String getCityById(String userId) {
return userMapper.getCityById(userId);
}
/**
* 以下均为自动生成
*/
......
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