package org.jeecg.modules.demo.weibocontentcapture.controller;

import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import lombok.Data;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.demo.linkouterchaindetection.entity.LinkOuterChainDetection;
import org.jeecg.modules.demo.linkweibobankcarddetection.entity.LinkWeiboBankCardDetection;
import org.jeecg.modules.demo.linkweibobankcarddetection.service.ILinkWeiboBankCardDetectionService;
import org.jeecg.modules.demo.linkweibobankcarddetectionstatistics.entity.LinkWeiboBankCardDetectionStatistics;
import org.jeecg.modules.demo.linkweibobankcarddetectionstatistics.service.ILinkWeiboBankCardDetectionStatisticsService;
import org.jeecg.modules.demo.linkweiboerrorwordwhitelist.entity.LinkWeiboErrorWordWhiteList;
import org.jeecg.modules.demo.linkweiboerrorwordwhitelist.service.ILinkWeiboErrorWordWhiteListService;
import org.jeecg.modules.demo.linkweiboidnumberdetection.entity.LinkWeiboIdNumberDetection;
import org.jeecg.modules.demo.linkweiboidnumberdetection.service.ILinkWeiboIdNumberDetectionService;
import org.jeecg.modules.demo.linkweibopersonaliddetectionstatistics.entity.LinkWeiboPersonalIdDetectionStatistics;
import org.jeecg.modules.demo.linkweibopersonaliddetectionstatistics.service.ILinkWeiboPersonalIdDetectionStatisticsService;
import org.jeecg.modules.demo.linkweibophonedetection.entity.LinkWeiboPhoneDetection;
import org.jeecg.modules.demo.linkweibophonedetection.service.ILinkWeiboPhoneDetectionService;
import org.jeecg.modules.demo.linkweibophonedetectionlog.service.ILinkWeiboPhoneDetectionLogService;
import org.jeecg.modules.demo.linkweibophonedetectionstatistics.entity.LinkWeiboPhoneDetectionStatistics;
import org.jeecg.modules.demo.linkweibophonedetectionstatistics.service.ILinkWeiboPhoneDetectionStatisticsService;
import org.jeecg.modules.demo.linkwhitelist.entity.LinkWhiteList;
import org.jeecg.modules.demo.linkwhiteword.entity.LinkWhiteWord;
import org.jeecg.modules.demo.mainsite.entity.MainSite;
import org.jeecg.modules.demo.pagecontentcapture.controller.PageContentCaptureController;
import org.jeecg.modules.demo.pagecontentcapture.controller.Params;
import org.jeecg.modules.demo.pagecontentcapture.entity.JsResult;
import org.jeecg.modules.demo.pagecontentcapture.entity.PageContentCapture;
import org.jeecg.modules.demo.weibo.entity.Weibo;
import org.jeecg.modules.demo.weibo.service.IWeiboService;
import org.jeecg.modules.demo.weibocontentcapture.entity.WeiboContentCapture;
import org.jeecg.modules.demo.weibocontentcapture.entity.WeiboContentCaptureVo;
import org.jeecg.modules.demo.weibocontentcapture.service.IWeiboContentCaptureService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.demo.weibocontentcapture.service.IWeiboContentCaptureVoService;
import org.jeecg.modules.demo.weibocontentcapturelog.entity.WeiboContentCaptureLog;
import org.jeecg.modules.demo.weibocontentcapturelog.service.IWeiboContentCaptureLogService;
import org.jeecg.modules.demo.weiboerrorwordstatistics.entity.WeiboErrorWordStatistics;
import org.jeecg.modules.demo.weiboerrorwordstatistics.service.IWeiboErrorWordStatisticsService;
import org.jeecg.modules.demo.weibouser.entity.WeiboUser;
import org.jeecg.modules.demo.weibouser.service.IWeiboUserService;
import org.jeecg.modules.spyderUtils.SpyderUtils;
import org.jeecg.modules.spyderUtils.spider.*;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

 /**
 * @Description: 微博错抓取
 * @Author: jeecg-boot
 * @Date:   2023-05-16
 * @Version: V1.0
 */
@Api(tags="微博错抓取")
@RestController
@RequestMapping("/weibocontentcapture/weiboContentCapture")
@Slf4j
public class WeiboContentCaptureController extends JeecgController<WeiboContentCapture, IWeiboContentCaptureService> {
	@Autowired
	private IWeiboContentCaptureService weiboContentCaptureService;

	@Autowired
	private IWeiboUserService iWeiboUserService;

	@Autowired
	private IWeiboService iWeiboService;

	@Autowired
	private ReportSpyder reportSpyder;

	@Autowired
	private IWeiboContentCaptureLogService iWeiboContentCaptureLogService;

	@Autowired
	private IWeiboErrorWordStatisticsService iWeiboErrorWordStatisticsService;
	 @Autowired
	 private FangCunUtils fangCunUtils;

	 @Autowired
	 private LinkOrWordSaveUtils linkOrWordSaveUtils;

	 @Autowired
	 private JsoupUtils jsoupUtils;

	 @Autowired
	 private CrawlingUtils crawlingUtils;

	 @Autowired
	 private ILinkWeiboPhoneDetectionService iLinkWeiboPhoneDetectionService;

	 @Autowired
	 private ILinkWeiboPhoneDetectionLogService iLinkWeiboPhoneDetectionLogService;

	 @Autowired
	 private ILinkWeiboPhoneDetectionStatisticsService iLinkWeiboPhoneDetectionStatisticsService;

	 @Autowired
	 private ILinkWeiboIdNumberDetectionService iLinkWeiboIdNumberDetectionService;

	 @Autowired
	 private ILinkWeiboBankCardDetectionService iLinkWeiboBankCardDetectionService;

	 @Autowired
	 private ILinkWeiboPersonalIdDetectionStatisticsService idDetectionStatisticsService;

	 @Autowired
	 private ILinkWeiboBankCardDetectionStatisticsService iLinkWeiboBankCardDetection;

	 @Autowired
	 private ILinkWeiboErrorWordWhiteListService iLinkWeiboErrorWordWhiteListService;

	 @Autowired
	 private IWeiboContentCaptureVoService iWeiboContentCaptureVoService;


	 @Autowired
	 private SpyderUtils spyderUtils;

	/**
	 * 分页列表查询
	 *
	 * @param weiboContentCapture
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "微博错抓取-分页列表查询")
	@ApiOperation(value="微博错抓取-分页列表查询", notes="微博错抓取-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<WeiboContentCapture>> queryPageList(WeiboContentCapture weiboContentCapture,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<WeiboContentCapture> queryWrapper = QueryGenerator.initQueryWrapper(weiboContentCapture, req.getParameterMap());
		Page<WeiboContentCapture> page = new Page<WeiboContentCapture>(pageNo, pageSize);
		IPage<WeiboContentCapture> pageList = weiboContentCaptureService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	 @ApiOperation(value="微博错抓取-分页列表查询", notes="微博错抓取-分页列表查询")
	 @GetMapping(value = "/listVo")
	 public Result<IPage<WeiboContentCaptureVo>> queryPageListVo(WeiboContentCaptureVo weiboContentCaptureVo,
															   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
															   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
															   HttpServletRequest req) {
		 QueryWrapper<WeiboContentCaptureVo> queryWrapper = QueryGenerator.initQueryWrapper(weiboContentCaptureVo, req.getParameterMap());
		 Page<WeiboContentCaptureVo> page = new Page<WeiboContentCaptureVo>(pageNo, pageSize);
		 IPage<WeiboContentCaptureVo> pageList = iWeiboContentCaptureVoService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 @Data
	 class PageContentCaptureTrueOrFalse{
		 private String wordName;
		 private String wordValue;
		 private boolean flag;
	 }
	 @ApiOperation(value="页面内容抓取-通过id查询", notes="页面内容抓取-通过id查询")
	 @GetMapping(value = "/queryByIdErrorList")
	 public Result<List<PageContentCaptureTrueOrFalse>> queryByIdErrorList(@RequestParam(name="id",required=true) String id) {
		 List<PageContentCaptureTrueOrFalse> list = new ArrayList<PageContentCaptureTrueOrFalse>();
		 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
		 if(weiboContentCapture==null) {
			 return Result.error("未找到对应数据");
		 }
		 String sensitiveList = weiboContentCapture.getSensitiveList();
		 Document parseHtml = Jsoup.parse(sensitiveList);
		 Elements elements = parseHtml.select("span.proofreadSignClass.errorWordMark");
		 for (Element element : elements) {
			 PageContentCaptureTrueOrFalse captureTrueOrFalse = new PageContentCaptureTrueOrFalse();
			 String text = element.text();
			 QueryWrapper<LinkWeiboErrorWordWhiteList> queryWrapper = new QueryWrapper<LinkWeiboErrorWordWhiteList>();
			 queryWrapper.eq("white_content",text);
			 Page<LinkWeiboErrorWordWhiteList> page = new Page<LinkWeiboErrorWordWhiteList>(1, 1);
			 Page<LinkWeiboErrorWordWhiteList> page1 = iLinkWeiboErrorWordWhiteListService.page(page, queryWrapper);
			 if(page1.getRecords().size() > 0){
				 captureTrueOrFalse.setFlag(true);
				 captureTrueOrFalse.setWordName(text);
				 captureTrueOrFalse.setWordValue(element.toString());
				 list.add(captureTrueOrFalse);
			 }else{
				 captureTrueOrFalse.setFlag(false);
				 captureTrueOrFalse.setWordName(text);
				 captureTrueOrFalse.setWordValue(element.toString());
				 list.add(captureTrueOrFalse);
			 }
		 }
		 return Result.OK(list);
	 }

	 /**
	  *  编辑
	  * @return
	  */
	 @RequestMapping(value = "/ignore", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> ignore(@RequestBody Params params) {
		 String weiboId = params.getWeiboId();
		 System.out.println("=================="+weiboId);
		 if(!ObjectUtils.isEmpty(params) && weiboId != ""){
			 WeiboContentCapture byId = weiboContentCaptureService.getById(weiboId);
			 for (String plainOption : params.getPlainOptions()) {
				 QueryWrapper<LinkWeiboErrorWordWhiteList> whiteWordQueryWrapper = new QueryWrapper<LinkWeiboErrorWordWhiteList>();
				 whiteWordQueryWrapper.eq("white_content",plainOption);
				 try {
					 iLinkWeiboErrorWordWhiteListService.remove(whiteWordQueryWrapper);
				 }catch (Exception e){
					 e.printStackTrace();
				 }
			 }
			 for (String plainOption : params.getCheckedList()) {
				 LinkWeiboErrorWordWhiteList linkWhiteWord = new LinkWeiboErrorWordWhiteList();
				 linkWhiteWord.setId(IdWorker.getIdStr());
				 linkWhiteWord.setMainSiteId(byId.getUserId());
				 linkWhiteWord.setMainSiteName(byId.getScreenName());
				 linkWhiteWord.setMainSiteUrl(byId.getUserId());
				 linkWhiteWord.setTenantId(byId.getTenantId()+"");
				 linkWhiteWord.setWhiteContent(plainOption);
				 if(!ObjectUtils.isEmpty(plainOption) && plainOption != ""){
					 try {
						 iLinkWeiboErrorWordWhiteListService.save(linkWhiteWord);
					 }catch (Exception e){
						 e.printStackTrace();
					 }
				 }
			 }
		 }else{
			 return Result.error("编辑失败!");
		 }
		 return Result.OK("编辑成功!");
	 }

	 //@AutoLog(value = "微博错抓取-分页列表查询")
	 @ApiOperation(value="微博错抓取-分页列表查询", notes="微博错抓取-分页列表查询")
	 @GetMapping(value = "/listError")
	 public Result<IPage<WeiboContentCapture>> queryPageListError(WeiboContentCapture weiboContentCapture,
															 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
															 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
															 HttpServletRequest req) {
		 QueryWrapper<WeiboContentCapture> queryWrapper = QueryGenerator.initQueryWrapper(weiboContentCapture, req.getParameterMap());
		 Page<WeiboContentCapture> page = new Page<WeiboContentCapture>(pageNo, pageSize);
		 queryWrapper.isNotNull("sensitive_list");
		 queryWrapper.ne("sensitive_list","");
		 queryWrapper.gt("sensitive_count",0);
		 IPage<WeiboContentCapture> pageList = weiboContentCaptureService.page(page, queryWrapper);
		 for (WeiboContentCapture record : pageList.getRecords()) {
			 Document parse1 = Jsoup.parse(record.getSensitiveList());
			 Elements elements1 = parse1.select("span.proofreadSignClass.errorWordMark");
			 String sensitiveErrorList = "";
			 String errorMessage = "";
			 for(Element element : elements1){
				 try {
					 String title = element.attr("title")+"<br>";
					 errorMessage += Jsoup.parse(title).text() +"<br>";
					 String stringError = element.toString();
					 int i = record.getRetMsg().indexOf(stringError);
					 String t1 = "";
					 String t2 = "";
					 try {
						 t1 = record.getRetMsg().substring(i-20,i);
						 t2 = record.getRetMsg().substring(i+(stringError.length()),i+(stringError.length())+20);
					 }catch (Exception e){
					 }
					 sensitiveErrorList += t1 + stringError +t2+"<br>";
				 }catch (Exception e){
				 }
			 }
			 record.setErrorMessage(errorMessage);
			 record.setSensitiveErrorList(sensitiveErrorList);
		 }
		 return Result.OK(pageList);
	 }

	 @ApiOperation(value="微博错抓取-分页列表查询", notes="微博错抓取-分页列表查询")
	 @GetMapping(value = "/listVoError")
	 public Result<IPage<WeiboContentCaptureVo>> queryPageListVoError(WeiboContentCaptureVo weiboContentCaptureVo,
																  @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
																  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
																  HttpServletRequest req) {
		 QueryWrapper<WeiboContentCaptureVo> queryWrapper = QueryGenerator.initQueryWrapper(weiboContentCaptureVo, req.getParameterMap());
		 Page<WeiboContentCaptureVo> page = new Page<WeiboContentCaptureVo>(pageNo, pageSize);
		 queryWrapper.isNotNull("sensitive_list");
		 queryWrapper.ne("sensitive_list","");
		 queryWrapper.gt("sensitive_count",0);
		 IPage<WeiboContentCaptureVo> pageList = iWeiboContentCaptureVoService.page(page, queryWrapper);
		 for (WeiboContentCaptureVo record : pageList.getRecords()) {
			 try {
				 WeiboContentCapture byId = weiboContentCaptureService.getById(record.getId());
				 Document parse1 = Jsoup.parse(record.getSensitiveList());
				 Elements elements1 = parse1.select("span.proofreadSignClass.errorWordMark");
				 String sensitiveErrorList = "";
				 String errorMessage = "";
				 for(Element element : elements1){
					 try {
						 String title = element.attr("title")+"<br>";
						 errorMessage += Jsoup.parse(title).text() +"<br>";
						 String stringError = element.toString();
						 int i = byId.getRetMsg().indexOf(stringError);
						 String t1 = "";
						 String t2 = "";
						 try {
							 t1 = byId.getRetMsg().substring(i-20,i);
							 t2 = byId.getRetMsg().substring(i+(stringError.length()),i+(stringError.length())+20);
						 }catch (Exception e){
						 }
						 sensitiveErrorList += t1 + stringError +t2+"<br>";
					 }catch (Exception e){
					 }
				 }
				 record.setErrorMessage(errorMessage);
				 record.setSensitiveErrorList(sensitiveErrorList);
			 }catch (Exception e){
				 e.printStackTrace();
			 }
		 }
		 return Result.OK(pageList);
	 }


	@ApiOperation(value="微博错抓取-分页列表查询", notes="微博错抓取-分页列表查询")
	@GetMapping(value = "/listCrawling")
	public Result<String> queryPageListSpyder() {
		List<WeiboUser> list = iWeiboUserService.list();
		for (WeiboUser weiboUser : list) {
			crawlingWeiboContentCapture(weiboUser);
			saveErrorWordStatistics("1",weiboUser);
		}
		return Result.OK("校验成功");
	}


	 @ApiOperation(value="微博错抓取-分页列表查询", notes="微博错抓取-分页列表查询")
	 @GetMapping(value = "/listCrawlingHTML")
	 public Result<String> queryPageListSpyderHTML() {
		 List<WeiboUser> list = iWeiboUserService.list();
		 for (WeiboUser weiboUser : list) {
			 crawlingWeiboContentCaptureHTML(weiboUser);
			 saveErrorWordStatistics("1",weiboUser);
		 }
		 return Result.OK("校验成功");
	 }

	 @ApiOperation(value="微博数据复核-分页列表查询", notes="微博数据复核-分页列表查询")
	 @GetMapping(value = "/queryPageListCheck")
	 public Result<String> queryPageListCheck() {
		 List<WeiboUser> list = iWeiboUserService.list();
		 for (WeiboUser weiboUser : list) {
			 crawlingWeiboContentCapture(weiboUser);
			 saveErrorWordStatistics("2",weiboUser);
		 }
		 return Result.OK("校验成功");
	 }

	 @GetMapping(value = "/onHandleCheckWeiboContentCapture")
	 public Result<String> onHandleCheckWeiboContentCapture(HttpServletRequest request, WeiboContentCapture weiboContentCapture) {
		 String selections = request.getParameter("selections");
		 QueryWrapper<WeiboContentCapture> queryWrapper = QueryGenerator.initQueryWrapper(weiboContentCapture, request.getParameterMap());
		 if (oConvertUtils.isNotEmpty(selections)) {
			 List<String> selectionList = Arrays.asList(selections.split(","));
			 queryWrapper.in("id",selectionList);
			 List<WeiboContentCapture> exportList = weiboContentCaptureService.list(queryWrapper);
			 checkWeiboContentCapture(exportList);
		 }else{
			 queryWrapper.isNotNull("sensitive_list");
			 queryWrapper.ne("sensitive_list","");
			 queryWrapper.gt("sensitive_count",0);
			 Long count =  weiboContentCaptureService.count(queryWrapper);
			 Integer pageSize = 100;
			 Integer pageNum = (int)Math.ceil((double)count/pageSize);
			 for(int i = 1; i <= pageNum;i+=1){
				 Page<WeiboContentCapture> page = new Page<WeiboContentCapture>(i, pageSize);
				 IPage<WeiboContentCapture> pageList = weiboContentCaptureService.page(page, queryWrapper);
				 checkWeiboContentCapture(pageList.getRecords());
			 }
		 }
		 List<WeiboUser> list = iWeiboUserService.list();
		 for (WeiboUser weiboUser : list) {
			 saveErrorWordStatistics("2",weiboUser);
		 }
		 return Result.OK("成功");
	 }





	 @ApiOperation(value="页面内容抓取-通过id查询", notes="页面内容抓取-通过id查询")
	 @GetMapping(value = "/queryByIdModifyTrue")
	 public Result<WeiboContentCapture> queryByIdModifyTrue(@RequestParam(name="id",required=true) String id) {
		 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
		 if(weiboContentCapture==null) {
			 return Result.error("未找到对应数据");
		 }
		 weiboContentCapture.setModifyState("2");
		 weiboContentCaptureService.updateById(weiboContentCapture);
		 return Result.OK(weiboContentCapture);
	 }


	 @ApiOperation(value="页面内容抓取-通过id查询", notes="页面内容抓取-通过id查询")
	 @GetMapping(value = "/queryByIdModifyFalse")
	 public Result<WeiboContentCapture> queryByIdModifyFalse(@RequestParam(name="id",required=true) String id) {
		 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
		 if(weiboContentCapture==null) {
			 return Result.error("未找到对应数据");
		 }
		 weiboContentCapture.setModifyState("1");
		 weiboContentCaptureService.updateById(weiboContentCapture);
		 return Result.OK(weiboContentCapture);
	 }

	 @ApiOperation(value="页面内容抓取-通过id查询", notes="页面内容抓取-通过id查询")
	 @GetMapping(value = "/queryWhetherToIgnore")
	 public Result<WeiboContentCapture> queryWhetherToIgnore(@RequestParam(name="id",required=true) String id) {
		 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
		 if(weiboContentCapture==null) {
			 return Result.error("未找到对应数据");
		 }
		 weiboContentCapture.setIsIgnore("1");
		 weiboContentCaptureService.updateById(weiboContentCapture);
		 return Result.OK(weiboContentCapture);
	 }
	 @ApiOperation(value="页面内容抓取-通过id查询", notes="页面内容抓取-通过id查询")
	 @GetMapping(value = "/queryWhetherToIgnoreCancel")
	 public Result<WeiboContentCapture> queryWhetherToIgnoreCancel(@RequestParam(name="id",required=true) String id) {
		 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
		 if(weiboContentCapture==null) {
			 return Result.error("未找到对应数据");
		 }
		 weiboContentCapture.setIsIgnore("2");
		 weiboContentCaptureService.updateById(weiboContentCapture);
		 return Result.OK(weiboContentCapture);
	 }

	 /**
	 *   添加
	 *
	 * @param weiboContentCapture
	 * @return
	 */
	@AutoLog(value = "微博错抓取-添加")
	@ApiOperation(value="微博错抓取-添加", notes="微博错抓取-添加")
	@RequiresPermissions("weibocontentcapture:weibo_content_capture:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody WeiboContentCapture weiboContentCapture) {
		weiboContentCaptureService.save(weiboContentCapture);
		return Result.OK("添加成功！");
	}
	/**
	 *  编辑
	 *
	 * @param weiboContentCapture
	 * @return
	 */
	@AutoLog(value = "微博错抓取-编辑")
	@ApiOperation(value="微博错抓取-编辑", notes="微博错抓取-编辑")
	@RequiresPermissions("weibocontentcapture:weibo_content_capture:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody WeiboContentCapture weiboContentCapture) {
		weiboContentCaptureService.updateById(weiboContentCapture);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "微博错抓取-通过id删除")
	@ApiOperation(value="微博错抓取-通过id删除", notes="微博错抓取-通过id删除")
	@RequiresPermissions("weibocontentcapture:weibo_content_capture:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		weiboContentCaptureService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "微博错抓取-批量删除")
	@ApiOperation(value="微博错抓取-批量删除", notes="微博错抓取-批量删除")
	@RequiresPermissions("weibocontentcapture:weibo_content_capture:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.weiboContentCaptureService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}


	 @DeleteMapping(value = "/batchHIgnoreHandle")
	 public Result<String> IgnoreBatchTrue(@RequestParam(name="ids",required=true) String ids) {
		 String[] split = ids.split(",");
		 for (String sId : split) {
			 try {
				 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(sId);
				 weiboContentCapture.setIsIgnore("1");
				 weiboContentCaptureService.updateById(weiboContentCapture);
			 }catch (Exception e){
				 e.printStackTrace();
			 }
		 }
		 return Result.OK("批量设置成功!");
	 }

	 @DeleteMapping(value = "/batchHIgnoreHandleDelete")
	 public Result<String> IgnoreBatchFalse(@RequestParam(name="ids",required=true) String ids) {
		 String[] split = ids.split(",");
		 for (String sId : split) {
			 try {
				 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(sId);
				 weiboContentCapture.setIsIgnore("2");
				 weiboContentCaptureService.updateById(weiboContentCapture);
			 }catch (Exception e){
				 e.printStackTrace();
			 }
		 }
		 return Result.OK("批量设置成功!");
	 }

	 @DeleteMapping(value = "/batchHModifyTrue")
	 public Result<String> batchHModifyTrue(@RequestParam(name="ids",required=true) String ids) {
		 String[] split = ids.split(",");
		 for (String sId : split) {
			 try {
				 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(sId);
				 weiboContentCapture.setModifyState("2");
				 weiboContentCaptureService.updateById(weiboContentCapture);
			 }catch (Exception e){
				 e.printStackTrace();
			 }
		 }
		 return Result.OK("批量设置成功!");
	 }

	 @DeleteMapping(value = "/batchHModifyFalse")
	 public Result<String> batchHModifyFalse(@RequestParam(name="ids",required=true) String ids) {
		 String[] split = ids.split(",");
		 for (String sId : split) {
			 try {
				 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(sId);
				 weiboContentCapture.setModifyState("1");
				 weiboContentCaptureService.updateById(weiboContentCapture);
			 }catch (Exception e){
				 e.printStackTrace();
			 }
		 }
		 return Result.OK("批量设置成功!");
	 }
	 /**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "微博错抓取-通过id查询")
	@ApiOperation(value="微博错抓取-通过id查询", notes="微博错抓取-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<WeiboContentCapture> queryById(@RequestParam(name="id",required=true) String id) {
		WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
		if(weiboContentCapture==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(weiboContentCapture);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param weiboContentCapture
    */
    @RequiresPermissions("weibocontentcapture:weibo_content_capture:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, WeiboContentCapture weiboContentCapture) {
        return super.exportXls(request, weiboContentCapture, WeiboContentCapture.class, "微博错抓取");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequiresPermissions("weibocontentcapture:weibo_content_capture:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, WeiboContentCapture.class);
    }

	 public void  crawlingWeiboContentCaptureHTML(WeiboUser weiboUser) {
		 QueryWrapper<Weibo> weiboQueryWrapper = new QueryWrapper<Weibo>();
		 weiboQueryWrapper.eq("user_id",weiboUser.getId());
		 Long count =  iWeiboService.count(weiboQueryWrapper);
		 Integer pageSize = 100;
		 Integer pageNum = (int)Math.ceil((double)count/pageSize);
		 for (Integer i = 0; i < pageNum; i++) {
			 //抓取对应的原页面
		 }
	 }

	 public void  crawlingWeiboContentCapture(WeiboUser weiboUser) {
		 QueryWrapper<Weibo> weiboQueryWrapper = new QueryWrapper<Weibo>();
		 weiboQueryWrapper.eq("user_id",weiboUser.getId());
		 Long count =  iWeiboService.count(weiboQueryWrapper);
		 Integer pageSize = 100;
		 Integer pageNum = (int)Math.ceil((double)count/pageSize);
		 for (Integer i = 0; i < pageNum; i++) {
			 Page<Weibo> page = new Page<Weibo>(i, pageSize);
			 IPage<Weibo> pageList = iWeiboService.page(page,weiboQueryWrapper);
			 try {
				 for (Weibo record : pageList.getRecords()) 	{
					 WeiboContentCapture weiboContentCapture = new WeiboContentCapture();
					 weiboContentCapture.setCreateTime(new Date());
					 weiboContentCapture.setUpdateTime(new Date());
					 weiboContentCapture.setId(record.getId());
					 weiboContentCapture.setBid(record.getBid());
					 weiboContentCapture.setUserId(record.getUserId());
					 weiboContentCapture.setScreenName(record.getScreenName());
					 weiboContentCapture.setText(record.getText());
					 weiboContentCapture.setArticleUrl(record.getArticleUrl());
					 weiboContentCapture.setTopics(record.getTopics());
					 weiboContentCapture.setAtUsers(record.getAtUsers());
					 weiboContentCapture.setPics(record.getPics());
					 weiboContentCapture.setVideoUrl(record.getVideoUrl());
					 weiboContentCapture.setLocation(record.getLocation());
					 weiboContentCapture.setCreatedAt(record.getCreatedAt());
					 weiboContentCapture.setSource(record.getSource());
					 weiboContentCapture.setAttitudesCount(record.getAttitudesCount());
					 weiboContentCapture.setCommentsCount(record.getCommentsCount());
					 weiboContentCapture.setRepostsCount(record.getRepostsCount());
					 weiboContentCapture.setRetweetId(record.getRetweetId());
					 String text = record.getText();
					 JsResult jsonObject = fangCunUtils.getJsResult(text);
					 String ret_msg = jsonObject.getRet_msg();
					 weiboContentCapture.setErrorCount(jsonObject.getErrorCount());
					 weiboContentCapture.setRetMsg(jsonObject.getRet_msg());
					 weiboContentCapture.setRetCode(jsonObject.getRet_code());
					 if(!ObjectUtils.isEmpty(ret_msg)){
						 Document parse1 = Jsoup.parse(weiboContentCapture.getRetMsg());
						 Elements elements1 = parse1.select("span.proofreadSignClass.errorWordMark");
						 if(elements1.size() >= 1){
							 weiboContentCapture.setSensitiveList(elements1.toString());
							 weiboContentCapture.setSensitiveCount(elements1.size());
							 weiboContentCapture.setCheckErrorCount(elements1.size());
							 weiboContentCapture.setModifyState("1");
						 }else{
							 weiboContentCapture.setSensitiveCount(0);
						 }
					 }
					 weiboContentCapture.setRetCode(jsonObject.getRet_code());
					 weiboContentCapture.setHeavyCount(jsonObject.getHeavyCount());
					 String id = weiboContentCapture.getId();
					 WeiboContentCapture byId = weiboContentCaptureService.getById(id);
					 weiboContentCapture.setIsIgnore("2");
					 if(!ObjectUtils.isEmpty(byId)){
						 Integer numberScans = byId.getNumberScans();
						 if(!ObjectUtils.isEmpty(numberScans)){
							 numberScans = numberScans + 1;
							 weiboContentCapture.setNumberScans(numberScans);
						 }
						 weiboContentCapture.setIsIgnore(byId.getIsIgnore());
					 }else{
						 weiboContentCapture.setNumberScans(1);
					 }
					 weiboContentCapture.setTenantId(record.getTenantId());
					 //查看是否是失效文章
					 // 查看返回的文本当中是否包含  微博不存在或暂无查看权限!
					 try {
						 String pageHtml = reportSpyder.companyReportMessage("https://m.weibo.cn/detail/"+record.getId());
						 if(!ObjectUtils.isEmpty(pageHtml)){
							 int index = pageHtml.indexOf("微博不存在");
							 if(index >= 1){
								 weiboContentCapture.setIsInvalid("1");
							 }else{
								 weiboContentCapture.setIsInvalid("2");
							 }
						 }else{
							 weiboContentCapture.setIsInvalid("1");
						 }
					 }catch (Exception e){
					 }

					 weiboContentCapture.setCheckState("2");
					 weiboContentCaptureService.saveOrUpdate(weiboContentCapture);
					 saveiWeiboContentCaptureLog(weiboContentCapture);
					 try {
						 getPhone(record,record.getText(),weiboUser);
					 }catch (Exception e){
						 e.printStackTrace();
					 }
					 try {
						 getIdNumber(record,record.getText(),weiboUser);
					 }catch (Exception e){
						 e.printStackTrace();
					 }
					 try {
						 getBank(record,record.getText(),weiboUser);
					 }catch (Exception e){
						 e.printStackTrace();
					 }
				 }
				 //错敏词校验-----结束
			 }catch (Exception e){
				 e.printStackTrace();
			 }
		 }
	 }

	 private void checkWeiboContentCapture(List<WeiboContentCapture> exportList){
		 for (WeiboContentCapture weiboContentCapture : exportList) {
			 weiboContentCapture.setUpdateTime(new Date());
			 weiboContentCapture.setCreateTime(new Date());
			 Weibo weibo = iWeiboService.getById(weiboContentCapture.getId());
			 String text = weibo.getText();
			 //错敏词校验-----开始
			 JsResult jsonObject = fangCunUtils.getJsResult(text);
			 String ret_msg = jsonObject.getRet_msg();
			 weiboContentCapture.setErrorCount(jsonObject.getErrorCount());
			 weiboContentCapture.setRetMsg(jsonObject.getRet_msg());
			 weiboContentCapture.setRetCode(jsonObject.getRet_code());
			 if(!ObjectUtils.isEmpty(ret_msg)){
				 Document parse1 = Jsoup.parse(weiboContentCapture.getRetMsg());
				 Elements elements1 = parse1.select("span.proofreadSignClass.errorWordMark");
				 if(elements1.size() >= 1){
					 weiboContentCapture.setSensitiveList(elements1.toString());
					 weiboContentCapture.setSensitiveCount(elements1.size());
					 weiboContentCapture.setCheckErrorCount(elements1.size());
					 weiboContentCapture.setModifyState("1");
				 }else{
					 weiboContentCapture.setCheckErrorCount(0);
					 weiboContentCapture.setModifyState("2");
				 }
			 }
			 weiboContentCapture.setRetCode(jsonObject.getRet_code());
			 weiboContentCapture.setHeavyCount(jsonObject.getHeavyCount());
			 String id = weiboContentCapture.getId();
			 WeiboContentCapture byId = weiboContentCaptureService.getById(id);
			 if(!ObjectUtils.isEmpty(byId)){
				 Integer numberScans = byId.getNumberScans();
				 if(!ObjectUtils.isEmpty(numberScans)){
					 numberScans = numberScans + 1;
					 weiboContentCapture.setNumberScans(numberScans);
				 }
			 }else{
				 weiboContentCapture.setNumberScans(1);
			 }
			 //查看是否是失效文章
			 // 查看返回的文本当中是否包含  微博不存在或暂无查看权限!
			 try {
				 String pageHtml = reportSpyder.companyReportMessage("https://m.weibo.cn/detail/"+weiboContentCapture.getId());
				 if(!ObjectUtils.isEmpty(pageHtml)){
					 int index = pageHtml.indexOf("微博不存在");
					 if(index >= 1){
						 weiboContentCapture.setIsInvalid("1");
					 }else{
						 weiboContentCapture.setIsInvalid("2");
					 }
				 }else{
					 weiboContentCapture.setIsInvalid("1");
				 }
			 }catch (Exception e){
			 }
			 weiboContentCapture.setCheckState("1");
			 weiboContentCapture.setCheckTime(new Date());
			 weiboContentCaptureService.updateById(weiboContentCapture);
			 saveiWeiboContentCaptureLog(weiboContentCapture);
		 }
	 }

	 public void saveiWeiboContentCaptureLog(WeiboContentCapture weiboContentCapture){
		 WeiboContentCaptureLog weiboContentCaptureLog = new WeiboContentCaptureLog();
		 weiboContentCaptureLog.setCreateTime(weiboContentCapture.getCreateTime());
		 weiboContentCaptureLog.setUpdateTime(weiboContentCapture.getUpdateTime());
		 weiboContentCaptureLog.setId(IdWorker.getIdStr());
		 weiboContentCaptureLog.setWbwzId(weiboContentCapture.getId());
		 weiboContentCaptureLog.setBid(weiboContentCapture.getBid());
		 weiboContentCaptureLog.setUserId(weiboContentCapture.getUserId());
		 weiboContentCaptureLog.setScreenName(weiboContentCapture.getScreenName());
		 weiboContentCaptureLog.setText(weiboContentCapture.getText());
		 weiboContentCaptureLog.setArticleUrl(weiboContentCapture.getArticleUrl());
		 weiboContentCaptureLog.setTopics(weiboContentCapture.getTopics());
		 weiboContentCaptureLog.setAtUsers(weiboContentCapture.getAtUsers());
		 weiboContentCaptureLog.setPics(weiboContentCapture.getPics());
		 weiboContentCaptureLog.setVideoUrl(weiboContentCapture.getVideoUrl());
		 weiboContentCaptureLog.setLocation(weiboContentCapture.getLocation());
		 weiboContentCaptureLog.setCreatedAt(weiboContentCapture.getCreatedAt());
		 weiboContentCaptureLog.setSource(weiboContentCapture.getSource());
		 weiboContentCaptureLog.setAttitudesCount(weiboContentCapture.getAttitudesCount());
		 weiboContentCaptureLog.setCommentsCount(weiboContentCapture.getCommentsCount());
		 weiboContentCaptureLog.setRepostsCount(weiboContentCapture.getRepostsCount());
		 weiboContentCaptureLog.setRetweetId(weiboContentCapture.getRetweetId());
		 weiboContentCaptureLog.setSensitiveList(weiboContentCapture.getSensitiveList());
		 weiboContentCaptureLog.setSensitiveCount(weiboContentCapture.getSensitiveCount());
		 weiboContentCaptureLog.setRetMsg(weiboContentCapture.getRetMsg());
		 weiboContentCaptureLog.setRetCode(weiboContentCapture.getRetCode());
		 weiboContentCaptureLog.setErrorCount(weiboContentCapture.getErrorCount());
		 weiboContentCaptureLog.setHeavyCount(weiboContentCapture.getHeavyCount());
		 weiboContentCaptureLog.setModifyState(weiboContentCapture.getModifyState());
		 weiboContentCaptureLog.setNumberScans(weiboContentCapture.getNumberScans());
		 weiboContentCaptureLog.setIsIgnore(weiboContentCapture.getIsIgnore());
		 weiboContentCaptureLog.setCheckTime(weiboContentCapture.getCheckTime());
		 weiboContentCaptureLog.setCheckState(weiboContentCapture.getCheckState());
		 weiboContentCaptureLog.setCheckErrorCount(weiboContentCapture.getCheckErrorCount());
		 weiboContentCaptureLog.setIsInvalid(weiboContentCapture.getIsInvalid());
		 weiboContentCaptureLog.setTenantId(weiboContentCapture.getTenantId());
		 iWeiboContentCaptureLogService.save(weiboContentCaptureLog);
	 }

	 //统计错词信息
	 public void saveErrorWordStatistics(String type,WeiboUser weiboUser){
		 try {
			 WeiboErrorWordStatistics weiboErrorWordStatistics = new WeiboErrorWordStatistics();
			 weiboErrorWordStatistics.setId(IdWorker.getIdStr());
			 weiboErrorWordStatistics.setUserId(weiboUser.getId());
			 weiboErrorWordStatistics.setScreenName(weiboUser.getScreenName());
			 weiboErrorWordStatistics.setTestType(type);
			 weiboErrorWordStatistics.setScanTime(new Date());
			 weiboErrorWordStatistics.setTenantId(weiboUser.getTenantId());
			 QueryWrapper<WeiboContentCapture> queryWrapper = new QueryWrapper<WeiboContentCapture>();
			 queryWrapper.isNotNull("sensitive_list");
			 queryWrapper.ne("sensitive_list","");
			 queryWrapper.gt("sensitive_count",0);
			 queryWrapper.eq("is_ignore","2");
			 queryWrapper.eq("modify_state","1");
			 queryWrapper.eq("user_id",weiboUser.getId());
			 queryWrapper.select("sum(sensitive_count) as sumAll");
			 WeiboContentCapture one = weiboContentCaptureService.getOne(queryWrapper);
			 Integer sumAll = 0;
			 if(!ObjectUtils.isEmpty(one)){
				 sumAll = one.getSumAll();
			 }
			 weiboErrorWordStatistics.setErrorWordCount(sumAll);
			 iWeiboErrorWordStatisticsService.save(weiboErrorWordStatistics);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
	 }

	 public void getIdNumber(Weibo record,String text,WeiboUser weiboUser){

		 String url = "https://m.weibo.cn/detail/"+record.getId();

		 //从正文当中提取身份证号
		 log.info("============从正文当中提取身份证号=================");
		 JsoupReturn phone = spyderUtils.getIdNumber(text);
		 LinkWeiboIdNumberDetection linkWeiboIdNumberDetection = new LinkWeiboIdNumberDetection();
		 linkWeiboIdNumberDetection.setCreateTime(new Date());
		 linkWeiboIdNumberDetection.setUpdateTime(new Date());
		 linkWeiboIdNumberDetection.setUserId(record.getUserId());
		 linkWeiboIdNumberDetection.setScreenName(record.getScreenName());
		 linkWeiboIdNumberDetection.setSource(record.getArticleUrl());
		 linkWeiboIdNumberDetection.setTitle(record.getScreenName());
		 linkWeiboIdNumberDetection.setArticleReleaseTime(record.getCreatedAt());
		 linkWeiboIdNumberDetection.setContent(record.getText());
		 linkWeiboIdNumberDetection.setRetMsg(phone.getHtml());
		 linkWeiboIdNumberDetection.setErrorCount(phone.getHtmlList().size());
		 try {
			 String HtmlListStr = "";
			 List<String> htmlList = phone.getHtmlList();
			 for (String sH : htmlList) {
				 HtmlListStr += sH;
			 }
			 linkWeiboIdNumberDetection.setHtmlList(HtmlListStr);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 try {
			 String strListStr = "";
			 List<String> strList = phone.getStrList();
			 for (String sH : strList) {
				 strListStr += sH;
			 }
			 linkWeiboIdNumberDetection.setStrList(strListStr);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 try {
			 String strListA = "";
			 List<String> strList = phone.getAList();
			 for (String sH : strList) {
				 strListA += sH;
			 }
			 linkWeiboIdNumberDetection.setAhtmlList(strListA);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 linkWeiboIdNumberDetection.setIsInvalid("2");
		 linkWeiboIdNumberDetection.setIsRevise("1");
		 linkWeiboIdNumberDetection.setIsIgnore("2");
		 linkWeiboIdNumberDetection.setCheckTime(new Date());
		 linkWeiboIdNumberDetection.setCheckState("2");
		 linkWeiboIdNumberDetection.setNumberScans(1);
		 linkWeiboIdNumberDetection.setTenantId(record.getTenantId()+"");
		 linkWeiboIdNumberDetection.setId( record.getId() );
		 String idNumberId = linkWeiboIdNumberDetection.getId();


		 LinkWeiboIdNumberDetection linkWeiboIdNumber = iLinkWeiboIdNumberDetectionService.getById(idNumberId);
		 if(!ObjectUtils.isEmpty(linkWeiboIdNumber)){
			 linkWeiboIdNumberDetection.setIsInvalid(linkWeiboIdNumber.getIsInvalid());
			 linkWeiboIdNumberDetection.setIsRevise(linkWeiboIdNumber.getIsRevise());
			 linkWeiboIdNumberDetection.setIsIgnore(linkWeiboIdNumber.getIsIgnore());
			 linkWeiboIdNumberDetection.setCheckTime(new Date());
			 linkWeiboIdNumberDetection.setCheckState(linkWeiboIdNumber.getCheckState());
			 Integer numberScans = linkWeiboIdNumber.getNumberScans();
			 if(!ObjectUtils.isEmpty(numberScans)){
				 linkWeiboIdNumberDetection.setNumberScans( 1 + numberScans);
			 }
		 }
		 linkWeiboIdNumberDetection.setSource(url);
		 if(phone.getAList().size() > 0){
			 iLinkWeiboIdNumberDetectionService.saveOrUpdate(linkWeiboIdNumberDetection);
		 }
		 //统计手机号信息
		 try {
			 saveIdNumberStatistics("1",weiboUser);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
	 }

	 public void getBank(Weibo record,String text,WeiboUser weiboUser){
		 String url = "https://m.weibo.cn/detail/"+record.getId();
		 //从正文当中提取银行卡号
		 log.info("============从正文当中提取银行卡号=================");
		 JsoupReturn phone = spyderUtils.getBankCardNumber(text);
		 LinkWeiboBankCardDetection linkWeiboBankCardDetection = new LinkWeiboBankCardDetection();
		 linkWeiboBankCardDetection.setCreateTime(new Date());
		 linkWeiboBankCardDetection.setUpdateTime(new Date());
		 linkWeiboBankCardDetection.setUserId(record.getUserId());
		 linkWeiboBankCardDetection.setScreenName(record.getScreenName());
		 linkWeiboBankCardDetection.setSource(record.getArticleUrl());
		 linkWeiboBankCardDetection.setTitle(record.getScreenName());
		 linkWeiboBankCardDetection.setArticleReleaseTime(record.getCreatedAt());
		 linkWeiboBankCardDetection.setContent(record.getText());
		 linkWeiboBankCardDetection.setRetMsg(phone.getHtml());
		 linkWeiboBankCardDetection.setErrorCount(phone.getHtmlList().size());
		 try {
			 String HtmlListStr = "";
			 List<String> htmlList = phone.getHtmlList();
			 for (String sH : htmlList) {
				 HtmlListStr += sH;
			 }
			 linkWeiboBankCardDetection.setHtmlList(HtmlListStr);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 try {
			 String strListStr = "";
			 List<String> strList = phone.getStrList();
			 for (String sH : strList) {
				 strListStr += sH;
			 }
			 linkWeiboBankCardDetection.setStrList(strListStr);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 try {
			 String strListA = "";
			 List<String> strList = phone.getAList();
			 for (String sH : strList) {
				 strListA += sH;
			 }
			 linkWeiboBankCardDetection.setAhtmlList(strListA);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 linkWeiboBankCardDetection.setIsInvalid("2");
		 linkWeiboBankCardDetection.setIsRevise("1");
		 linkWeiboBankCardDetection.setIsIgnore("2");
		 linkWeiboBankCardDetection.setCheckTime(new Date());
		 linkWeiboBankCardDetection.setCheckState("2");
		 linkWeiboBankCardDetection.setNumberScans(1);
		 linkWeiboBankCardDetection.setTenantId(record.getTenantId()+"");
		 linkWeiboBankCardDetection.setId(  record.getId() );
		 String idNumberId = linkWeiboBankCardDetection.getId();

		 LinkWeiboBankCardDetection linkWeiboBankCard  = iLinkWeiboBankCardDetectionService.getById(idNumberId);
		 if(!ObjectUtils.isEmpty(linkWeiboBankCard)){
			 linkWeiboBankCardDetection.setIsInvalid(linkWeiboBankCard.getIsInvalid());
			 linkWeiboBankCardDetection.setIsRevise(linkWeiboBankCard.getIsRevise());
			 linkWeiboBankCardDetection.setIsIgnore(linkWeiboBankCard.getIsIgnore());
			 linkWeiboBankCardDetection.setCheckTime(new Date());
			 linkWeiboBankCardDetection.setCheckState(linkWeiboBankCard.getCheckState());
			 Integer numberScans = linkWeiboBankCard.getNumberScans();
			 if(!ObjectUtils.isEmpty(numberScans)){
				 linkWeiboBankCardDetection.setNumberScans( 1 + numberScans);
			 }
		 }
		 linkWeiboBankCardDetection.setSource(url);
		 if(phone.getAList().size() > 0){
			 iLinkWeiboBankCardDetectionService.saveOrUpdate(linkWeiboBankCardDetection);
		 }
		 try {
			 saveBankStatistics("1",weiboUser);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
	 }

	 public void getPhone(Weibo record,String text,WeiboUser weiboUser){
		 String url = "https://m.weibo.cn/detail/"+record.getId();
		 //从正文当中提取手机号
		 log.info("============从正文当中提取手机号=================");
		 JsoupReturn phone = spyderUtils.getPhone(text);
		 LinkWeiboPhoneDetection linkWeiboPhoneDetection = new LinkWeiboPhoneDetection();
		 linkWeiboPhoneDetection.setCreateTime(new Date());
		 linkWeiboPhoneDetection.setUpdateTime(new Date());
		 linkWeiboPhoneDetection.setUserId(record.getUserId());
		 linkWeiboPhoneDetection.setScreenName(record.getScreenName());
		 linkWeiboPhoneDetection.setSource(record.getArticleUrl());
		 linkWeiboPhoneDetection.setTitle(record.getScreenName());
		 linkWeiboPhoneDetection.setArticleReleaseTime(record.getCreatedAt());
		 linkWeiboPhoneDetection.setContent(record.getText());
		 linkWeiboPhoneDetection.setRetMsg(phone.getHtml());
		 linkWeiboPhoneDetection.setErrorCount(phone.getHtmlList().size());
		 try {
			 String HtmlListStr = "";
			 List<String> htmlList = phone.getHtmlList();
			 for (String sH : htmlList) {
				 HtmlListStr += sH;
			 }
			 linkWeiboPhoneDetection.setHtmlList(HtmlListStr);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 try {
			 String strListStr = "";
			 List<String> strList = phone.getStrList();
			 for (String sH : strList) {
				 strListStr += sH;
			 }
			 linkWeiboPhoneDetection.setStrList(strListStr);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 try {
			 String strListA = "";
			 List<String> strList = phone.getAList();
			 for (String sH : strList) {
				 strListA += sH;
			 }
			 linkWeiboPhoneDetection.setAhtmlList(strListA);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
		 linkWeiboPhoneDetection.setIsInvalid("2");
		 linkWeiboPhoneDetection.setIsRevise("1");
		 linkWeiboPhoneDetection.setIsIgnore("2");
		 linkWeiboPhoneDetection.setCheckTime(new Date());
		 linkWeiboPhoneDetection.setCheckState("2");
		 linkWeiboPhoneDetection.setNumberScans(1);
		 linkWeiboPhoneDetection.setTenantId(record.getTenantId()+"");
		 linkWeiboPhoneDetection.setId(record.getId());
		 String idWeiboPhone = linkWeiboPhoneDetection.getId();
		 LinkWeiboPhoneDetection byIdWeiboPhoneDetection = iLinkWeiboPhoneDetectionService.getById(idWeiboPhone);
		 if(!ObjectUtils.isEmpty(byIdWeiboPhoneDetection)){
			 linkWeiboPhoneDetection.setIsInvalid(byIdWeiboPhoneDetection.getIsInvalid());
			 linkWeiboPhoneDetection.setIsRevise(byIdWeiboPhoneDetection.getIsRevise());
			 linkWeiboPhoneDetection.setIsIgnore(byIdWeiboPhoneDetection.getIsIgnore());
			 linkWeiboPhoneDetection.setCheckTime(new Date());
			 linkWeiboPhoneDetection.setCheckState(byIdWeiboPhoneDetection.getCheckState());
			 Integer numberScans = byIdWeiboPhoneDetection.getNumberScans();
			 if(!ObjectUtils.isEmpty(numberScans)){
				 linkWeiboPhoneDetection.setNumberScans( 1 + numberScans);
			 }
		 }
		 linkWeiboPhoneDetection.setSource(url);
		 if(phone.getAList().size() > 0){
			 iLinkWeiboPhoneDetectionService.saveOrUpdate(linkWeiboPhoneDetection);
		 }
		 //统计手机号信息
		 try {
			 savePhoneStatistics("1",weiboUser);
		 }catch (Exception e){
			 e.printStackTrace();
		 }
	 }

	 //统计错词信息
	 public void savePhoneStatistics(String type,WeiboUser weiboUser){
		 try {
			 LinkWeiboPhoneDetectionStatistics weiboPhoneDetectionStatistics = new LinkWeiboPhoneDetectionStatistics();
			 weiboPhoneDetectionStatistics.setId(IdWorker.getIdStr());
			 weiboPhoneDetectionStatistics.setUserId(weiboUser.getId());
			 weiboPhoneDetectionStatistics.setScreenName(weiboUser.getScreenName());
			 weiboPhoneDetectionStatistics.setTestType(type);
			 weiboPhoneDetectionStatistics.setScanTime(new Date());
			 weiboPhoneDetectionStatistics.setTenantId(weiboUser.getTenantId());
			 Integer sumAll  = iLinkWeiboPhoneDetectionService.getSumStatistics(weiboUser.getId());
			 if(ObjectUtils.isEmpty(sumAll)){
				 sumAll = 0;
			 }
			 weiboPhoneDetectionStatistics.setPersonalPhoneCount(sumAll);

			 iLinkWeiboPhoneDetectionStatisticsService.save(weiboPhoneDetectionStatistics);
		 }catch (Exception e){
		 }
	 }

	 private void saveIdNumberStatistics(String type, WeiboUser weiboUser) {
		 try {
			 LinkWeiboPersonalIdDetectionStatistics weiboPhoneDetectionStatistics = new LinkWeiboPersonalIdDetectionStatistics();
			 weiboPhoneDetectionStatistics.setId(IdWorker.getIdStr());
			 weiboPhoneDetectionStatistics.setUserId(weiboUser.getId());
			 weiboPhoneDetectionStatistics.setScreenName(weiboUser.getScreenName());
			 weiboPhoneDetectionStatistics.setTestType(type);
			 weiboPhoneDetectionStatistics.setScanTime(new Date());
			 weiboPhoneDetectionStatistics.setTenantId(weiboUser.getTenantId());
			 Integer sumAll = idDetectionStatisticsService.getSumStatistics(weiboUser.getId());
			 if(ObjectUtils.isEmpty(sumAll)){
				 sumAll = 0;
			 }
			 weiboPhoneDetectionStatistics.setPersonalIdCount(sumAll);
			 idDetectionStatisticsService.save(weiboPhoneDetectionStatistics);
		 }catch (Exception e){
		 }
	 }

	 private void saveBankStatistics(String type, WeiboUser weiboUser) {
		 try {
			 LinkWeiboBankCardDetectionStatistics weiboBankCardDetectionStatistics = new LinkWeiboBankCardDetectionStatistics();
			 weiboBankCardDetectionStatistics.setId(IdWorker.getIdStr());
			 weiboBankCardDetectionStatistics.setUserId(weiboUser.getId());
			 weiboBankCardDetectionStatistics.setScreenName(weiboUser.getScreenName());
			 weiboBankCardDetectionStatistics.setTestType(type);
			 weiboBankCardDetectionStatistics.setScanTime(new Date());
			 weiboBankCardDetectionStatistics.setTenantId(weiboUser.getTenantId());
			 Integer sumAll = iLinkWeiboBankCardDetection.getSumStatistics(weiboUser.getId());
			 if(ObjectUtils.isEmpty(sumAll)){
				 sumAll = 0;
			 }
			 weiboBankCardDetectionStatistics.setBankCardCount(sumAll);
			 iLinkWeiboBankCardDetection.save(weiboBankCardDetectionStatistics);
		 }catch (Exception e){
		 }
	 }
	 /**
	  * 批量忽略
	  * @param ids
	  * @return
	  */
	 @DeleteMapping(value = "/ignoreAll")
	 public Result<String> ignoreAllBatch(@RequestParam(name="ids",required=true) String ids) {
		 String[] split = ids.split(",");
		 if(split.length > 0){
			 for (String id : split) {
				 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
				 try {
					 String sensitiveList = weiboContentCapture.getSensitiveList();
					 Document parseHtml = Jsoup.parse(sensitiveList);
					 Elements elements = parseHtml.select("span.proofreadSignClass.errorWordMark");
					 for (Element element : elements) {
						 String text = element.text();
						 if(!ObjectUtils.isEmpty(text)){
							 QueryWrapper<LinkWeiboErrorWordWhiteList> whiteWordQueryWrapper = new QueryWrapper<LinkWeiboErrorWordWhiteList>();
							 whiteWordQueryWrapper.eq("white_content",text);
							 try {
								 iLinkWeiboErrorWordWhiteListService.remove(whiteWordQueryWrapper);
							 }catch (Exception e){
								 e.printStackTrace();
							 }
							 LinkWeiboErrorWordWhiteList linkWhiteWord = new LinkWeiboErrorWordWhiteList();
							 linkWhiteWord.setId(IdWorker.getIdStr());
							 linkWhiteWord.setMainSiteId(weiboContentCapture.getUserId());
							 linkWhiteWord.setMainSiteName(weiboContentCapture.getScreenName());
							 linkWhiteWord.setMainSiteUrl(weiboContentCapture.getUserId());
							 linkWhiteWord.setTenantId(weiboContentCapture.getTenantId()+"");
							 linkWhiteWord.setWhiteContent(text);
							 if(!ObjectUtils.isEmpty(text) && text != ""){
								 try {
									 iLinkWeiboErrorWordWhiteListService.save(linkWhiteWord);
								 }catch (Exception e){
									 e.printStackTrace();
								 }
							 }
						 }
					 }
				 }catch (Exception e){
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.OK("编辑成功!");
	 }
	 /**
	  * 批量取消忽略
	  * @param ids
	  * @return
	  */
	 @DeleteMapping(value = "/ignoreAllCancell")
	 public Result<String> ignoreAllCancell(@RequestParam(name="ids",required=true) String ids) {
		 String[] split = ids.split(",");
		 if(split.length > 0){
			 for (String id : split) {
				 WeiboContentCapture weiboContentCapture = weiboContentCaptureService.getById(id);
				 try {
					 String sensitiveList = weiboContentCapture.getSensitiveList();
					 Document parseHtml = Jsoup.parse(sensitiveList);
					 Elements elements = parseHtml.select("span.proofreadSignClass.errorWordMark");
					 for (Element element : elements) {
						 String text = element.text();
						 if(!ObjectUtils.isEmpty(text)){
							 QueryWrapper<LinkWeiboErrorWordWhiteList> whiteWordQueryWrapper = new QueryWrapper<LinkWeiboErrorWordWhiteList>();
							 whiteWordQueryWrapper.eq("white_content",text);
							 try {
								 iLinkWeiboErrorWordWhiteListService.remove(whiteWordQueryWrapper);
							 }catch (Exception e){
								 e.printStackTrace();
							 }
						 }
					 }
				 }catch (Exception e){
					 e.printStackTrace();
				 }
			 }
		 }
		 return Result.OK("编辑成功!");
	 }

}
