|
@@ -6,16 +6,26 @@ package com.jeeplus.enterpriseinfo.controller;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.jeeplus.buildinginfo.service.BuildingManagementService;
|
|
|
import com.jeeplus.buildinginfo.service.dto.BuildingManagementDTO;
|
|
|
+import com.jeeplus.common.redis.RedisUtils;
|
|
|
+import com.jeeplus.common.utils.RequestUtils;
|
|
|
+import com.jeeplus.common.utils.ResponseUtil;
|
|
|
+import com.jeeplus.config.properties.JeePlusProperties;
|
|
|
+import com.jeeplus.core.errors.ErrorConstants;
|
|
|
import com.jeeplus.core.excel.EasyExcelUtils;
|
|
|
import com.jeeplus.core.excel.ExcelOptions;
|
|
|
import com.jeeplus.core.excel.annotation.ExportMode;
|
|
|
import com.jeeplus.core.query.QueryWrapperGenerator;
|
|
|
import com.jeeplus.aop.logging.annotation.ApiLog;
|
|
|
+import com.jeeplus.enterpriseinfo.service.dto.WxBean;
|
|
|
+import com.jeeplus.security.jwt.TokenProvider;
|
|
|
import com.jeeplus.security.util.SecurityUtils;
|
|
|
+import com.jeeplus.sys.constant.CacheNames;
|
|
|
+import com.jeeplus.sys.constant.enums.LogTypeEnum;
|
|
|
import com.jeeplus.sys.domain.DictValue;
|
|
|
import com.jeeplus.sys.domain.Office;
|
|
|
import com.jeeplus.sys.service.DictValueService;
|
|
@@ -37,10 +47,14 @@ import org.apache.http.client.HttpClient;
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
import org.apache.http.client.methods.HttpPost;
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.security.authentication.AuthenticationManager;
|
|
|
+import org.springframework.security.authentication.DisabledException;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -55,11 +69,18 @@ import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URI;
|
|
|
import java.net.URISyntaxException;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Random;
|
|
|
import java.util.UUID;
|
|
|
import java.util.stream.Collectors;
|
|
|
import org.json.JSONObject;
|
|
@@ -76,6 +97,11 @@ import org.json.JSONObject;
|
|
|
@RequestMapping(value = "/enterpriseinfo/enterpriseInfo")
|
|
|
public class EnterpriseInfoController {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ AuthenticationManager authenticationManager;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtils redisUtils;
|
|
|
+
|
|
|
@Autowired
|
|
|
private EnterpriseInfoService enterpriseInfoService;
|
|
|
|
|
@@ -95,6 +121,9 @@ public class EnterpriseInfoController {
|
|
|
private OfficeService officeService;
|
|
|
@Autowired
|
|
|
private BuildingManagementService buildingManagementService;
|
|
|
+ String appId = "wx510821957a261e8d"; // 替换为你的微信公众号 AppID
|
|
|
+ String jsapiTicket = "";
|
|
|
+
|
|
|
/**
|
|
|
* 企业基本信息列表数据
|
|
|
*/
|
|
@@ -107,7 +136,7 @@ public class EnterpriseInfoController {
|
|
|
UserDTO userDTO = UserUtils.getCurrentUserDTO();
|
|
|
List<HashMap<String, Object>> map=new ArrayList<>();
|
|
|
|
|
|
- IPage<EnterpriseInfoDTO> result = enterpriseInfoService.findPage (page, queryWrapper,enterpriseInfoDTO.getIndustry());
|
|
|
+ IPage<EnterpriseInfoDTO> result = enterpriseInfoService.findPage (page, queryWrapper,enterpriseInfoDTO.getIndustry(),enterpriseInfoDTO.getName(),enterpriseInfoDTO.getBz2());
|
|
|
//未登录限制
|
|
|
if(userDTO.getLoginName()==null){
|
|
|
for(int i=0;i<result.getRecords().size();i++){
|
|
@@ -188,6 +217,19 @@ public class EnterpriseInfoController {
|
|
|
return ResponseEntity.ok (map);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 选择产业链上下游
|
|
|
+ */
|
|
|
+ @ApiLog("选择产业链上下游")
|
|
|
+ @ApiOperation(value = "选择产业链上下游")
|
|
|
+ @GetMapping("getIndustryChainList")
|
|
|
+ public ResponseEntity<List<HashMap<String, Object>>> getIndustryChainList() throws Exception {
|
|
|
+ List<HashMap<String, Object>> map=enterpriseInfoService.getIndustryChainList();
|
|
|
+ return ResponseEntity.ok (map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* Post 请求百度云模型
|
|
|
*/
|
|
@@ -235,6 +277,171 @@ public class EnterpriseInfoController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public String GetWxtoken() {
|
|
|
+
|
|
|
+
|
|
|
+ String appSecret = "c6a75986065e33182384ba2209761de3"; // 替换为你的微信公众号 AppSecret
|
|
|
+ // 构造获取 access_token 的 URL
|
|
|
+ String urlString = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
|
|
|
+ boolean isgettoke=false;
|
|
|
+ String retoken="";
|
|
|
+
|
|
|
+
|
|
|
+ HashMap<String, Object> aa=enterpriseInfoService.getWxtoke();
|
|
|
+ if(aa!=null){
|
|
|
+ String time=aa.get("create_time").toString();
|
|
|
+ retoken=aa.get("wxtoken").toString();
|
|
|
+ jsapiTicket=aa.get("expires_in").toString();
|
|
|
+
|
|
|
+ // 当前时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ // 将给定的时间字符串转换为LocalDateTime对象
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
|
|
+ LocalDateTime givenTime = LocalDateTime.parse(time, formatter);
|
|
|
+ // 计算两个时间之间的差值
|
|
|
+ Duration duration = Duration.between(givenTime, now);
|
|
|
+
|
|
|
+ // 判断差值是否超过10分钟
|
|
|
+ if (duration.toMinutes() > 120) {
|
|
|
+ System.out.println("给定的时间已经超过了120分钟。");
|
|
|
+ isgettoke=true;
|
|
|
+ } else {
|
|
|
+ System.out.println("给定的时间没有超过120分钟。");
|
|
|
+ isgettoke=false;
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ isgettoke=true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if(isgettoke){
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
+ HttpGet request = new HttpGet(urlString);
|
|
|
+
|
|
|
+ // 执行请求
|
|
|
+ HttpResponse response = httpClient.execute(request);
|
|
|
+
|
|
|
+ // 获取响应状态码
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ System.out.println("Response Code: " + statusCode);
|
|
|
+
|
|
|
+ // 获取响应内容
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
+ String responseString = EntityUtils.toString(entity, "UTF-8");
|
|
|
+
|
|
|
+ // 打印响应内容
|
|
|
+ System.out.println("Response: " + responseString);
|
|
|
+
|
|
|
+ JSONObject jo = new JSONObject(responseString);
|
|
|
+ if(jo.get("access_token")!=null){
|
|
|
+ retoken=jo.get("access_token").toString();
|
|
|
+ jsapiTicket=getJsapiTicket(retoken);
|
|
|
+
|
|
|
+ String id= UUID.randomUUID().toString().replace("-","");
|
|
|
+ enterpriseInfoService.setWxtoke(id,retoken,jsapiTicket);
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "fail";
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return retoken;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取 jsapi_ticket
|
|
|
+ public String getJsapiTicket(String accessToken) throws IOException {
|
|
|
+ String ticket="";
|
|
|
+ String urlString = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + accessToken + "&type=jsapi";
|
|
|
+ try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
|
+ HttpGet request = new HttpGet(urlString);
|
|
|
+
|
|
|
+ // 执行请求
|
|
|
+ HttpResponse response = httpClient.execute(request);
|
|
|
+
|
|
|
+ // 获取响应状态码
|
|
|
+ int statusCode = response.getStatusLine().getStatusCode();
|
|
|
+ System.out.println("Response Code: " + statusCode);
|
|
|
+
|
|
|
+ // 获取响应内容
|
|
|
+ HttpEntity entity = response.getEntity();
|
|
|
+ String responseString = EntityUtils.toString(entity, "UTF-8");
|
|
|
+
|
|
|
+ // 打印响应内容
|
|
|
+ System.out.println("Response: " + responseString);
|
|
|
+
|
|
|
+ JSONObject jo = new JSONObject(responseString);
|
|
|
+ if(jo.get("ticket")!=null){
|
|
|
+ ticket=jo.get("ticket").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "fail";
|
|
|
+ }
|
|
|
+ return ticket;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+// try {
|
|
|
+// String accessToken = WeChatUtil.getAccessToken();
|
|
|
+// String jsapiTicket = WeChatUtil.getJsapiTicket(accessToken);
|
|
|
+// return WeChatUtil.generateSignature(jsapiTicket, url);
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ // 生成签名
|
|
|
+ public Map<String, String> generateSignature(String jsapiTicket, String url) {
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("jsapi_ticket", jsapiTicket);
|
|
|
+ params.put("noncestr", "random_string"); // 随机字符串
|
|
|
+ params.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
|
|
|
+ params.put("url", url);
|
|
|
+
|
|
|
+ String signature = createSHA1String(params);
|
|
|
+
|
|
|
+ return new HashMap() {{
|
|
|
+ put("appId", appId);
|
|
|
+ put("timestamp", params.get("timestamp"));
|
|
|
+ put("nonceStr", params.get("noncestr"));
|
|
|
+ put("signature", signature);
|
|
|
+ }};
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建 SHA1 签名
|
|
|
+ private static String createSHA1String(Map<String, String> params) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (String key : new String[]{"jsapi_ticket", "noncestr", "timestamp", "url"}) {
|
|
|
+ sb.append(key).append("=").append(params.get(key)).append("&");
|
|
|
+ }
|
|
|
+ sb.deleteCharAt(sb.length() - 1);
|
|
|
+
|
|
|
+ try {
|
|
|
+ MessageDigest digest = MessageDigest.getInstance("SHA-1");
|
|
|
+ byte[] bytes = digest.digest(sb.toString().getBytes());
|
|
|
+ StringBuilder hexString = new StringBuilder();
|
|
|
+ for (byte b : bytes) {
|
|
|
+ String hex = Integer.toHexString(0xff & b);
|
|
|
+ if (hex.length() == 1) {
|
|
|
+ hexString.append('0');
|
|
|
+ }
|
|
|
+ hexString.append(hex);
|
|
|
+ }
|
|
|
+ return hexString.toString();
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 根据Id获取企业基本信息数据
|
|
|
*/
|
|
@@ -262,6 +469,139 @@ public class EnterpriseInfoController {
|
|
|
return ResponseEntity.ok ( map );
|
|
|
}
|
|
|
|
|
|
+ @ApiLog("创建登录链接(时效10分钟)")
|
|
|
+ @ApiOperation(value = "创建登录链接(时效10分钟)")
|
|
|
+ @GetMapping("getloginstr")
|
|
|
+ public ResponseEntity<HashMap<String, Object>> getloginstr(String username) throws IOException {
|
|
|
+ UserDTO userDTO = UserUtils.getCurrentUserDTO();
|
|
|
+ String res="";
|
|
|
+ if(userDTO.getLoginName()!=null&&userDTO.getLoginName().equals("admin")){
|
|
|
+ //创建时效10分钟的登录入口
|
|
|
+ String id= UUID.randomUUID().toString().replace("-","");
|
|
|
+ enterpriseInfoService.getloginstr(id,username);
|
|
|
+ res=id;
|
|
|
+ }else{
|
|
|
+ res="0";
|
|
|
+ }
|
|
|
+ WxBean ab=new WxBean();
|
|
|
+ ab.setId(res);
|
|
|
+ ab.wxtoke=GetWxtoken();
|
|
|
+
|
|
|
+
|
|
|
+ String rs=generateRandomString(10);
|
|
|
+ String times=String.valueOf(System.currentTimeMillis() / 1000);
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("jsapi_ticket", jsapiTicket);
|
|
|
+ params.put("noncestr",rs ); // 随机字符串
|
|
|
+ params.put("timestamp", times);
|
|
|
+ //params.put("url", "https://miniapp.huidutech.com.cn/yd_qycpfbH5/pages/index/index?loginid="+res);
|
|
|
+ params.put("url", "https://miniapp.huidutech.com.cn/yd_qycpfbH5");
|
|
|
+ String signature = createSHA1String(params);
|
|
|
+ ab.signature=signature;
|
|
|
+
|
|
|
+ HashMap<String, Object> aa=new HashMap<>();
|
|
|
+ aa.put("Id", res);
|
|
|
+ aa.put("wxtoke", ab.wxtoke);
|
|
|
+ aa.put("appId", appId);
|
|
|
+ aa.put("timestamp", times);
|
|
|
+ aa.put("nonceStr", rs);
|
|
|
+ aa.put("signature", signature);
|
|
|
+ //aa.put("url", "https://miniapp.huidutech.com.cn/yd_qycpfbH5/pages/index/index?loginid="+res);
|
|
|
+ aa.put("url", "https://miniapp.huidutech.com.cn/yd_qycpfbH5");
|
|
|
+
|
|
|
+ System.out.println("Response: " + aa);
|
|
|
+ return ResponseEntity.ok (aa);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String generateRandomString(int length) {
|
|
|
+ String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
+ StringBuilder sb = new StringBuilder(length);
|
|
|
+ Random random = new Random();
|
|
|
+
|
|
|
+ for (int i = 0; i < length; i++) {
|
|
|
+ int index = random.nextInt(characters.length());
|
|
|
+ sb.append(characters.charAt(index));
|
|
|
+ }
|
|
|
+
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @ApiLog(value = "通过临时id登录", type = LogTypeEnum.LOGIN)
|
|
|
+ @ApiOperation(value = "通过临时id登录")
|
|
|
+ @PostMapping("loginid")
|
|
|
+ public ResponseEntity loginid(@RequestBody String id) {
|
|
|
+
|
|
|
+ ResponseUtil responseUtil = new ResponseUtil ( );
|
|
|
+ String res="";
|
|
|
+ HashMap<String, Object> map=enterpriseInfoService.loginid(id);
|
|
|
+ if(map!=null){
|
|
|
+ String loginname=map.get("loginname").toString();
|
|
|
+
|
|
|
+ //去除链接的限制,保持一直能通过链接登录
|
|
|
+// String createtime=map.get("createtime").toString();
|
|
|
+//
|
|
|
+// // 当前时间
|
|
|
+// LocalDateTime now = LocalDateTime.now();
|
|
|
+// // 将给定的时间字符串转换为LocalDateTime对象
|
|
|
+// DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
|
|
+// LocalDateTime givenTime = LocalDateTime.parse(createtime, formatter);
|
|
|
+// // 计算两个时间之间的差值
|
|
|
+// Duration duration = Duration.between(givenTime, now);
|
|
|
+//
|
|
|
+// // 判断差值是否超过10分钟
|
|
|
+// if (duration.toMinutes() > 10) {
|
|
|
+// System.out.println("给定的时间已经超过了10分钟。");
|
|
|
+// res="0";
|
|
|
+// } else {
|
|
|
+// System.out.println("给定的时间没有超过10分钟。");
|
|
|
+// res="1";
|
|
|
+// HashMap<String, Object> map2=enterpriseInfoService.getchupassword(loginname);
|
|
|
+// responseUtil=login(responseUtil,loginname,map2.get("des5").toString());
|
|
|
+// }
|
|
|
+
|
|
|
+// HashMap<String, Object> map2=enterpriseInfoService.getchupassword(loginname);
|
|
|
+// responseUtil=login(responseUtil,loginname,map2.get("des5").toString());
|
|
|
+
|
|
|
+ responseUtil=login(responseUtil,loginname,"");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return responseUtil.ok ( );
|
|
|
+ }
|
|
|
+
|
|
|
+ private ResponseUtil login(ResponseUtil responseUtil,String username,String password){
|
|
|
+
|
|
|
+// SecurityUtils.login ( username, password, authenticationManager ); //登录操作spring security
|
|
|
+// if ( !userService.isEnableLogin ( username ) ) {
|
|
|
+// throw new DisabledException( ErrorConstants.LOGIN_ERROR_FORBID_LOGGED_IN_ELSEWHERE );
|
|
|
+// }
|
|
|
+ //登录成功,生成token
|
|
|
+ UserDTO userDTO = UserUtils.getByLoginName ( username );
|
|
|
+ String token = TokenProvider.createAccessToken ( username, userDTO.getPassword ( ) );
|
|
|
+ responseUtil.add ( TokenProvider.TOKEN, token );
|
|
|
+ //更新登录信息
|
|
|
+ updateUserLoginInfo ( responseUtil, userDTO, token );
|
|
|
+ return responseUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateUserLoginInfo(ResponseUtil responseUtil, UserDTO userDTO, String token) {
|
|
|
+
|
|
|
+ String username = userDTO.getLoginName ( );
|
|
|
+ redisUtils.set ( CacheNames.USER_CACHE_TOKEN + username + ":" + token, token );
|
|
|
+ redisUtils.expire ( CacheNames.USER_CACHE_TOKEN + username + ":" + token, JeePlusProperties.newInstance ( ).getEXPIRE_TIME ( ) );
|
|
|
+ responseUtil.add ( "oldLoginDate", userDTO.getLoginDate ( ) );
|
|
|
+ responseUtil.add ( "oldLoginIp", userDTO.getLoginIp ( ) );
|
|
|
+ //更新登录日期
|
|
|
+ userDTO.setLoginDate ( new Date ( ) );
|
|
|
+ userDTO.setLoginIp ( ServletUtil.getClientIP ( RequestUtils.getRequest ( ) ) );
|
|
|
+ userService.updateUserLoginInfo ( userDTO );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存企业基本信息
|
|
|
*/
|
|
@@ -399,7 +739,7 @@ public class EnterpriseInfoController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List < EnterpriseInfoDTO> result = enterpriseInfoService.findPage (page, queryWrapper,enterpriseInfoDTO.getIndustry()).getRecords();
|
|
|
+ List < EnterpriseInfoDTO> result = enterpriseInfoService.findPage (page, queryWrapper,enterpriseInfoDTO.getIndustry(),enterpriseInfoDTO.getName(),enterpriseInfoDTO.getBz2()).getRecords();
|
|
|
EasyExcelUtils.newInstance ( enterpriseInfoService, enterpriseInfoWrapper ).exportExcel ( result, options.getSheetName ( ), EnterpriseInfoDTO.class, fileName,options.getExportFields (), response );
|
|
|
}
|
|
|
|