Commit 04a3bf20 authored by 赵啸非's avatar 赵啸非

修改同步抓取脚本

parent 80469f94
package com.mortals.xhx;
import com.mortals.framework.springcloud.boot.BaseWebApplication;
import com.mortals.framework.util.HttpUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
......
package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
......@@ -11,6 +13,14 @@ import com.mortals.xhx.module.matter.model.MatterQuery;
import com.mortals.xhx.module.matter.model.vo.MatterInfo;
import com.mortals.xhx.module.matter.service.MatterService;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -18,8 +28,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import static com.mortals.framework.ap.SysConstains.MESSAGE_INFO;
import static com.mortals.framework.ap.SysConstains.PAGEINFO_KEY;
......@@ -31,13 +43,10 @@ import static com.mortals.framework.ap.SysConstains.PAGEINFO_KEY;
* @date: 2022/12/14 9:18
*/
@RestController
@CommonsLog
@RequestMapping("test")
@Slf4j
public class DemoWebApiController {
@Autowired
private MatterService matterService;
@PostMapping(value = "testGov")
@UnAuth
public Rest<String> testGov(@RequestBody MatterQuery query) {
......@@ -45,5 +54,61 @@ public class DemoWebApiController {
return Rest.ok(resp);
}
@PostMapping(value = "testCookie")
@UnAuth
public Rest<String> testCookie(@RequestBody MatterQuery query) {
log.info("测试cookie");
HttpClient http = null;
CookieStore httpCookieStore = new BasicCookieStore();
http = HttpClientBuilder.create().setDefaultCookieStore(httpCookieStore).build();
/* do stuff */
HttpGet httpRequest = new HttpGet(query.getUrl());
HttpResponse httpResponse = null;
try {
httpResponse = http.execute(httpRequest);
byte[] data = EntityUtils.toByteArray(httpResponse.getEntity());
String encode = Base64.encode(data);
//String content = EntityUtils.toString(entity, charset);
//httpResponse.getEntity()
//httpResponse.toString()
} catch (Exception e) {
log.error("异常", e);
}
/* check cookies */
String cookieStr = Arrays.asList(httpCookieStore.getCookies()).stream().map(item -> JSON.toJSONString(item)).collect(Collectors.joining("|"));
log.info("cookies:{}", cookieStr);
return Rest.ok(cookieStr);
}
public static void main(String[] args) {
HttpClient http = null;
CookieStore httpCookieStore = new BasicCookieStore();
http = HttpClientBuilder.create().setDefaultCookieStore(httpCookieStore).build();
/* do stuff */
HttpGet httpRequest = new HttpGet("http://zxbl.sczwfw.gov.cn/app/account/imageCode");
HttpResponse httpResponse = null;
try {
httpResponse = http.execute(httpRequest);
byte[] data = EntityUtils.toByteArray(httpResponse.getEntity());
String encode = Base64.encode(data);
log.info("encode64:{}",encode);
// String resp = com.mortals.framework.util.HttpUtil.processMultipartResponse(httpResponse);
// log.info("resp:{}", resp);
//String content = EntityUtils.toString(entity, charset);
//httpResponse.getEntity()
//httpResponse.toString()
} catch (Exception e) {
log.error("异常", e);
}
/* check cookies */
String cookieStr = Arrays.asList(httpCookieStore.getCookies()).stream().map(item -> JSON.toJSONString(item)).collect(Collectors.joining("|"));
// log.info("cookies:{}", cookieStr);
}
}
package com.mortals.xhx.busiz.web;
import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.annotation.UnAuth;
import com.mortals.framework.common.Rest;
import com.mortals.framework.model.Context;
import com.mortals.framework.model.PageInfo;
import com.mortals.framework.model.Result;
import com.mortals.framework.util.HttpUtil;
import com.mortals.framework.web.BaseJsonBodyController;
import com.mortals.xhx.module.matter.model.MatterEntity;
import com.mortals.xhx.module.matter.model.MatterQuery;
......@@ -12,6 +15,14 @@ import com.mortals.xhx.module.matter.model.vo.MatterInfo;
import com.mortals.xhx.module.matter.service.MatterService;
import com.mortals.xhx.module.matters.service.MattersService;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
......@@ -20,8 +31,10 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import static com.mortals.framework.ap.SysConstains.MESSAGE_INFO;
import static com.mortals.framework.ap.SysConstains.PAGEINFO_KEY;
......@@ -33,7 +46,7 @@ import static com.mortals.framework.ap.SysConstains.PAGEINFO_KEY;
* @date: 2022/12/14 9:18
*/
@RestController
@CommonsLog
@Slf4j
@RequestMapping("micro")
public class MicroWebApiController extends BaseJsonBodyController {
......@@ -65,7 +78,27 @@ public class MicroWebApiController extends BaseJsonBodyController {
return ret;
}
@PostMapping(value = "getPicAndCookie")
@UnAuth
public Rest<Map<String,String>> getPicAndCookie(@RequestBody MatterQuery query) {
log.info("请求查询图片与cookies:{}",JSON.toJSONString(query));
HashMap<String, String> resultMap = new HashMap<>();
CookieStore httpCookieStore = new BasicCookieStore();
HttpClient http = HttpClientBuilder.create().setDefaultCookieStore(httpCookieStore).build();
HttpGet httpRequest = new HttpGet(query.getUrl());
HttpResponse httpResponse = null;
try {
httpResponse = http.execute(httpRequest);
byte[] data = EntityUtils.toByteArray(httpResponse.getEntity());
String encode = Base64.encode(data);
resultMap.put("base64img","data:image/jpg;base64,"+encode);
resultMap.put("cookieStr",JSON.toJSONString(httpCookieStore.getCookies()));
} catch (Exception e) {
log.error("异常", e);
}
return Rest.ok(resultMap);
}
protected PageInfo buildPageInfo(MatterQuery query) {
PageInfo pageInfo = new PageInfo();
......
......@@ -986,6 +986,14 @@ public class MatterServiceImpl extends AbstractCRUDServiceImpl<MatterDao, Matter
Setting baseInfoSetting = interceptorConfig.getBaseInfoSetting();
Setting sqclInfoSetting = interceptorConfig.getSqclInfoSetting();
//更新部门信息
DeptEntity extCache = deptService.getExtCache(matterEntity.getDeptCode());
matterEntity.setDeptName(extCache==null?"":extCache.getName());
/* if(!ObjectUtils.isEmpty(matterEntity.getDeptCode())&&ObjectUtils.isEmpty(matterEntity.getDeptName())){
DeptEntity extCache = deptService.getExtCache(matterEntity.getDeptCode());
matterEntity.setDeptName(extCache==null?"":extCache.getName());
}*/
//构建基础信息参数
savebaseInfo(matterEntity, dom, baseInfoSetting);
......
......@@ -51,5 +51,6 @@ public class SiteBusinessVo extends BaseEntityLong {
private Integer businessType;
private List<Long> idNotList;
}
\ No newline at end of file
......@@ -105,7 +105,7 @@ public class SiteThemeMatterServiceImpl extends AbstractCRUDServiceImpl<SiteThem
siteMatterQuery.setSiteId(siteId);
siteMatterQuery.setMatterCodeList(matterCodeList);
List<SiteMatterEntity> siteMatterEntities = siteMatterService.find(siteMatterQuery, context);
log.info(String.format("size1:%s,size2:%s", allList.size(), siteMatterEntities.size()));
log.info(String.format("抓取数量:%s,本地数量:%s", allList.size(), siteMatterEntities.size()));
if (!ObjectUtils.isEmpty(siteMatterEntities)) {
List<SiteThemeMatterEntity> collect = siteMatterEntities.stream().map(siteMatterEntity -> {
SiteThemeMatterEntity siteThemeMatterEntity = new SiteThemeMatterEntity();
......
......@@ -40,6 +40,8 @@ public interface WorkmanService extends ICRUDCacheService<WorkmanEntity,Long> {
*/
boolean updateUserPwd(String loginName, String oldPwd, String newPwd) throws AppException;
boolean updateUserPwd(String loginName, String newPwd) throws AppException;
......
......@@ -61,8 +61,8 @@ public class WorkmanServiceImpl extends AbstractCRUDCacheServiceImpl<WorkmanDao,
if (StringUtils.isNull(entity.getLoginPwd())) {
throw new AppException("密码不能为空!");
}
int count = this.count(new WorkmanQuery().loginName(entity.getLoginName()),context);
if (count>0) {
int count = this.count(new WorkmanQuery().loginName(entity.getLoginName()), context);
if (count > 0) {
throw new AppException("账号已存在!");
}
......@@ -123,13 +123,34 @@ public class WorkmanServiceImpl extends AbstractCRUDCacheServiceImpl<WorkmanDao,
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
throw new AppException("帐号错误!");
}
// try {
// if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(oldPwd))) {
// throw new AppException("原始密码错误!");
// }
// } catch (Exception e) {
// throw new AppException("密码验认出错!", e);
// }
try {
if (!sysUser.getLoginPwd().equals(SecurityUtil.md5DoubleEncoding(oldPwd))) {
throw new AppException("原始密码错误!");
}
} catch (Exception e) {
throw new AppException("密码验认出错!", e);
}
try {
sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd));
} catch (Exception e) {
throw new AppException("密码转换异常!", e);
}
dao.update(sysUser);
return true;
}
/**
* @param loginName
* @param newPwd
* @return
* @throws AppException
*/
@Override
public boolean updateUserPwd(String loginName, String newPwd) throws AppException {
WorkmanEntity sysUser = this.selectOne(new WorkmanQuery().loginName(loginName));
if (sysUser == null || !sysUser.getLoginName().equals(loginName)) {
throw new AppException("帐号错误!");
}
try {
sysUser.setLoginPwd(SecurityUtil.md5DoubleEncoding(newPwd));
} catch (Exception e) {
......@@ -152,11 +173,11 @@ public class WorkmanServiceImpl extends AbstractCRUDCacheServiceImpl<WorkmanDao,
throw new AppException("文件不存在!");
}
//解压图片
String fileEncode ="UTF-8";
String fileEncode = "UTF-8";
try {
fileEncode = EncodeUtil.getEncode(targetFilePath,true);
fileEncode = EncodeUtil.getEncode(targetFilePath, true);
} catch (Exception e) {
log.error("异常",e);
log.error("异常", e);
}
ZipUtil.unzip(targetFilePath, disPath, Charset.forName(fileEncode));
//读取目录下的所有图片
......
......@@ -133,6 +133,27 @@ public class WorkmanController extends BaseCRUDJsonBodyMappingController<Workman
@RequestMapping(value = "change/password", method = RequestMethod.POST)
@UnAuth
public String changePassword(@RequestBody WorkmanEntity query) {
JSONObject ret = new JSONObject();
try {
boolean bool = service.updateUserPwd(query.getLoginName(), query.getNewPwd());
if (bool) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
ret.put(KEY_RESULT_MSG, "密码修改成功!");
} else {
throw new AppException("账户密码修改失败!");
}
} catch (Exception e) {
ret.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
ret.put(KEY_RESULT_MSG, super.convertException(e));
}
return ret.toJSONString();
}
@RequestMapping(value = "person/change/password", method = RequestMethod.POST)
@UnAuth
public String personChangePassword(@RequestBody WorkmanEntity query) {
JSONObject ret = new JSONObject();
try {
boolean bool = service.updateUserPwd(query.getLoginName(), query.getOldPwd(), query.getNewPwd());
......@@ -188,8 +209,8 @@ public class WorkmanController extends BaseCRUDJsonBodyMappingController<Workman
workmanEntity.setLoginName(loginName);
}
log.info("loginPwd:"+workmanEntity.getLoginPwd());
if (ObjectUtils.isEmpty(workmanEntity.getLoginPwd())||"".equals(workmanEntity.getLoginPwd().trim())) {
log.info("loginPwd:" + workmanEntity.getLoginPwd());
if (ObjectUtils.isEmpty(workmanEntity.getLoginPwd()) || "".equals(workmanEntity.getLoginPwd().trim())) {
workmanEntity.setLoginPwd("123");
}
......
###站点业务列表
POST {{baseUrl}}/site/business/list
Authorization: {{authToken}}
Content-Type: application/json
{
"idNotList": [11,12],
"siteId": 1,
"page":1,
"size":10
......
......@@ -5,7 +5,7 @@ Content-Type: application/json
{
"page": 1,
"size": 10
"size": 100
}
......
......@@ -45,8 +45,31 @@ Authorization: {{authToken}}
GET {{baseUrl}}/sms/set/delete?id={{SmsSet_id}}
Accept: application/json
###test Gov
POST {{baseUrl}}/test/testGov
Content-Type: application/json
{
"url":"http://172.15.28.113:8900"
}
###test Cookie
POST {{baseUrl}}/test/testCookie
Content-Type: application/json
{
"url":"http://172.15.28.113:8902"
}
###test Cookie
POST {{baseUrl}}/micro/getPicAndCookie
Content-Type: application/json
{
"url":"http://172.15.28.113:8902"
}
###短信设置编辑
GET {{baseUrl}}/sms/set/edit?id={{SmsSet_id}}
......
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