提交 fe227a50 作者: JQW

功能开发

上级 eb605b68
package com.zzsn.clb.fegin; package com.zzsn.clb.fegin;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.common.api.vo.Result; import org.jeecg.common.api.vo.Result;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 常规feign接口定义 * 常规feign接口定义
...@@ -16,24 +19,41 @@ import java.util.List; ...@@ -16,24 +19,41 @@ import java.util.List;
@Component @Component
public interface IServiceProjectClient { public interface IServiceProjectClient {
/** /***
* 根据专题类型id查询数据 * 根据专题类型id查询数据
* @param id *
* @param map
* @param userId
* @param video
* @param pageNo 当前页码
* @param pageSize 每页显示多少条
* @param column 排序字段
* @param order 排序升序asc,降序desc
* @param crawler
* @param isSubject 是否专题 0-否 1-是
* @param subjectType 专题类别(1:通用专题 2:事件专题)
* @return * @return
*/ */
Result<?> getListBySubjectType(@RequestParam(required = true) String id); @GetMapping(value = "/subject/display/list")
Result<?> getListBySubject(@RequestParam Map<String, Object> map, @RequestParam String userId,@RequestParam String video,@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestParam String column,@RequestParam String order,@RequestParam String crawler,@RequestParam String isSubject,@RequestParam String subjectType,@RequestParam String labelIds);
/** /**
* 根据专题id查询数据 * 根据信息id查询数据
*
* @param id * @param id
* @return * @return
*/ */
Result<?> getSubjectById(@RequestParam(required = true) String id); @GetMapping(value = "/subject/display/queryById")
Result<JSONObject> getInfoById(@RequestParam(required = true) String id);
/**
* 根据信息id查询数据 /***
* @param id * 查询专题数据
* @param jsonObject 查询条件
* @param pageNo 页码
* @param pageSize 每页显示条数
* @return * @return
*/ */
Result<?> getListBySubject(@RequestParam(required = true) String id); @GetMapping(value = "/subject/subject/list")
Result<JSONObject> getSubjectList(@RequestParam(required = true) JSONObject jsonObject,@RequestParam(required = false) Integer pageNo,@RequestParam(required = false) Integer pageSize);
} }
package com.zzsn.clb.member.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.fegin.IServiceProjectClient;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.zzsn.clb.member.service.ISubjectTreeService;
import com.zzsn.clb.web.service.ISubjectService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import com.zzsn.clb.member.entity.MemCollect;
import com.zzsn.clb.member.service.IMemCollectService;
import java.util.Date;
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.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* @Description: 会员收藏表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Slf4j
@Api(tags = "会员收藏表")
@RestController
@RequestMapping("/mach/mem/collect")
public class MemCollectController extends JeecgController<MemCollect, IMemCollectService> {
@Autowired
private IMemCollectService memCollectService;
@Resource
IServiceProjectClient serviceProjectClient;
@Resource
ISubjectTreeService subjectTreeService;
/**
* 分页列表查询
*
* @param memCollect
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@AutoLog(value = "会员收藏表-分页列表查询")
@ApiOperation(value = "会员收藏表-分页列表查询", notes = "会员收藏表-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(MemCollect memCollect,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<MemCollect> queryWrapper = QueryGenerator.initQueryWrapper(memCollect, req.getParameterMap());
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
queryWrapper.eq("user_id", user.getId());
Page<MemCollect> page = new Page<MemCollect>(pageNo, pageSize);
IPage<MemCollect> pageList = memCollectService.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加
*
* @param memCollect
* @return
*/
@AutoLog(value = "会员收藏表-添加")
@ApiOperation(value = "会员收藏表-添加", notes = "会员收藏表-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody MemCollect memCollect) {
if (StringUtils.isBlank(memCollect.getArticleId())) {
return Result.error("文章ID不能为空!");
}
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
memCollect.setUserId(user.getId());
LambdaQueryWrapper<MemCollect> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemCollect::getUserId, memCollect.getUserId()).eq(MemCollect::getArticleId, memCollect.getArticleId());
if (this.memCollectService.count(queryWrapper) > 0) {
memCollectService.delete(queryWrapper, memCollect);
return Result.OK("取消成功!");
} else {
Result<JSONObject> result =this.serviceProjectClient.getInfoById(memCollect.getArticleId());
if(!result.isSuccess())
{
return Result.error("文章ID有误!");
}
memCollect.setTitle(result.getResult().getString("title"));
memCollect.setPublishDate(result.getResult().getDate("publishDate"));
memCollect.setOrigin(result.getResult().getString("origin"));
memCollect.setSubjectId(result.getResult().getString("subjectId"));
memCollect.setSubjectName(subjectTreeService.getById(memCollect.getSubjectId()).getSubjectName());
memCollectService.add(memCollect);
return Result.OK("收藏成功!");
}
}
/**
* 通过id删除
*
* @param articleId 文章ID
* @return
*/
@AutoLog(value = "会员收藏表-通过id删除")
@ApiOperation(value = "会员收藏表-通过id删除", notes = "会员收藏表-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name = "articleId", required = true) String articleId) {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
MemCollect memCollect = new MemCollect();
memCollect.setUserId(user.getId());
memCollect.setArticleId(articleId);
LambdaQueryWrapper<MemCollect> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemCollect::getUserId, memCollect.getUserId()).eq(MemCollect::getArticleId, memCollect.getArticleId());
memCollectService.remove(queryWrapper);
return Result.OK("删除成功!");
}
}
package com.zzsn.clb.member.controller;
import java.util.*;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.zzsn.clb.member.service.ISubjectTreeService;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import com.zzsn.clb.member.entity.MemSubject;
import com.zzsn.clb.member.service.IMemSubjectService;
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.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* @Description: 会员推送栏目表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Slf4j
@Api(tags = "会员推送栏目表")
@RestController
@RequestMapping("/mach/mem/subject")
public class MemSubjectController extends JeecgController<MemSubject, IMemSubjectService> {
@Autowired
private IMemSubjectService memSubjectService;
@Autowired
ISubjectTreeService subjectTreeService;
/**
* 获取推送栏目信息
*
* @return
*/
@AutoLog(value = "会员推送栏目表-列表查询")
@ApiOperation(value = "会员推送栏目表-列表查询", notes = "会员推送栏目表-列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList() {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
LambdaQueryWrapper<MemSubject> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemSubject::getUserId, user.getId());
queryWrapper.select(MemSubject::getSubjectId);
return Result.OK(memSubjectService.list(queryWrapper).stream().map(m -> m.getSubjectId()).collect(Collectors.toList()));
}
/**
* 添加
*
* @param jsonArray
* @return
*/
@AutoLog(value = "会员推送栏目表-添加")
@ApiOperation(value = "会员推送栏目表-添加", notes = "会员推送栏目表-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody JSONArray jsonArray) {
if (jsonArray.size() == 0)
return Result.error("请选择栏目!");
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
LambdaQueryWrapper<MemSubject> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemSubject::getUserId, user.getId());
//清空原有数据
memSubjectService.remove(queryWrapper);
List<MemSubject> list = new ArrayList<>();
jsonArray.forEach(x -> {
MemSubject memSubject = new MemSubject();
memSubject.setUserId(user.getId());
memSubject.setSubjectId(x.toString());
list.add(memSubject);
});
//添加新数据
memSubjectService.saveBatch(list);
return Result.OK("操作成功!");
}
/**
* 获取推送栏目信息
*
* @return
*/
@AutoLog(value = "会员推送栏目表-所有栏目")
@ApiOperation(value = "会员推送栏目表-所有栏目", notes = "会员推送栏目表-所有栏目")
@GetMapping(value = "/getSubjectList")
public Result<?> getSubjectList() {
return Result.OK(subjectTreeService.getSubjectList());
}
}
package com.zzsn.clb.member.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.fegin.IServiceProjectClient;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.zzsn.clb.member.service.IMemThumbsUpService;
import java.util.Date;
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.common.system.base.controller.JeecgController;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* @Description: 会员点赞表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Slf4j
@Api(tags="会员点赞表")
@RestController
@RequestMapping("/mach/mem/thumbsUp")
public class MemThumbsUpController extends JeecgController<MemThumbsUp, IMemThumbsUpService> {
@Autowired
private IMemThumbsUpService memThumbsUpService;
@Resource
IServiceProjectClient serviceProjectClient;
/**
* 分页列表查询
*
* @param memThumbsUp
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@AutoLog(value = "会员点赞表-分页列表查询")
@ApiOperation(value="会员点赞表-分页列表查询", notes="会员点赞表-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(MemThumbsUp memThumbsUp,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<MemThumbsUp> queryWrapper = QueryGenerator.initQueryWrapper(memThumbsUp, req.getParameterMap());
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
queryWrapper.eq("user_id", user.getId());
Page<MemThumbsUp> page = new Page<MemThumbsUp>(pageNo, pageSize);
IPage<MemThumbsUp> pageList = memThumbsUpService.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 添加
*
* @param memThumbsUp
* @return
*/
@AutoLog(value = "会员点赞表-添加")
@ApiOperation(value="会员点赞表-添加", notes="会员点赞表-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody MemThumbsUp memThumbsUp) {
if (StringUtils.isBlank(memThumbsUp.getArticleId())) {
return Result.error("文章ID不能为空!");
}
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
memThumbsUp.setUserId(user.getId());
LambdaQueryWrapper<MemThumbsUp> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemThumbsUp::getUserId,memThumbsUp.getUserId()).eq(MemThumbsUp::getArticleId,memThumbsUp.getArticleId());
if(this.memThumbsUpService.count(queryWrapper)>0)
{
memThumbsUpService.delete(queryWrapper,memThumbsUp);
return Result.OK("取消成功!");
}else {
if(!this.serviceProjectClient.getInfoById(memThumbsUp.getArticleId()).isSuccess())
{
return Result.error("文章ID有误!");
}
memThumbsUpService.add(memThumbsUp);
return Result.OK("点赞成功!");
}
}
/**
* 通过id删除
*
* @param id
* @return
*/
@AutoLog(value = "会员点赞表-通过id删除")
@ApiOperation(value="会员点赞表-通过id删除", notes="会员点赞表-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
memThumbsUpService.removeById(id);
return Result.OK("删除成功!");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@AutoLog(value = "会员点赞表-批量删除")
@ApiOperation(value="会员点赞表-批量删除", notes="会员点赞表-批量删除")
@DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.memThumbsUpService.removeByIds(Arrays.asList(ids.split(",")));
return Result.OK("批量删除成功!");
}
/**
* 通过id查询
*
* @param id
* @return
*/
@AutoLog(value = "会员点赞表-通过id查询")
@ApiOperation(value="会员点赞表-通过id查询", notes="会员点赞表-通过id查询")
@GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
MemThumbsUp memThumbsUp = new MemThumbsUp();
memThumbsUp.setUserId(user.getId());
LambdaQueryWrapper<MemThumbsUp> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemThumbsUp::getUserId,memThumbsUp.getUserId()).eq(MemThumbsUp::getArticleId,memThumbsUp.getArticleId());
if(this.memThumbsUpService.count(queryWrapper)>0)
{
return Result.OK(memThumbsUp);
}else
{
return Result.error("无此数据!");
}
}
}
package com.zzsn.clb.member.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* @Description: 会员收藏表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Data
@TableName("mem_collect")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="mem_collect对象", description="会员收藏表")
public class MemCollect {
/**用户ID*/
@Excel(name = "用户ID", width = 15)
@ApiModelProperty(value = "用户ID")
private String userId;
/**文章ID*/
@Excel(name = "文章ID", width = 15)
@ApiModelProperty(value = "文章ID")
private String articleId;
/**标题*/
@Excel(name = "标题", width = 15)
@ApiModelProperty(value = "标题")
private String title;
/**栏目名称*/
@Excel(name = "栏目名称", width = 15)
@ApiModelProperty(value = "栏目名称")
private String subjectName;
/**栏目id*/
@Excel(name = "栏目id", width = 15)
@ApiModelProperty(value = "栏目id")
private String subjectId;
/**来源*/
@Excel(name = "来源", width = 15)
@ApiModelProperty(value = "来源")
private String origin;
/**发布时间*/
@Excel(name = "发布时间", width = 15)
@ApiModelProperty(value = "发布时间")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date publishDate;
/**创建人*/
@Excel(name = "创建人", width = 15)
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建时间*/
@Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建时间")
private Date createTime;
/**更新人*/
@Excel(name = "更新人", width = 15)
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新时间*/
@Excel(name = "更新时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新时间")
private Date updateTime;
}
package com.zzsn.clb.member.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* @Description: 会员推送栏目表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Data
@TableName("mem_subject")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="mem_subject对象", description="会员推送栏目表")
public class MemSubject {
/**用户ID*/
@Excel(name = "用户ID", width = 15)
@ApiModelProperty(value = "用户ID")
private String userId;
/**专题ID*/
@Excel(name = "专题ID", width = 15)
@ApiModelProperty(value = "专题ID")
private String subjectId;
/**标签ID*/
@Excel(name = "标签ID", width = 15)
@ApiModelProperty(value = "标签ID")
private String labelId;
}
package com.zzsn.clb.member.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* @Description: 会员点赞表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Data
@TableName("mem_thumbs_up")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="mem_thumbs_up对象", description="会员点赞表")
public class MemThumbsUp {
/**用户ID*/
@Excel(name = "用户ID", width = 15)
@ApiModelProperty(value = "用户ID")
private String userId;
/**文章ID*/
@Excel(name = "文章ID", width = 15)
@ApiModelProperty(value = "文章ID")
private String articleId;
}
package com.zzsn.clb.member.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 专题表
* @Author: jeecg-boot
* @Date: 2021-12-15
* @Version: V1.0
*/
@Data
@TableName("subject")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="subject对象", description="专题表")
public class Subject implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private String id;
/**专题编码*/
@Excel(name = "专题编码", width = 15)
@ApiModelProperty(value = "专题编码")
private String subjectCode;
/**专题名称*/
@Excel(name = "专题名称", width = 15)
@ApiModelProperty(value = "专题名称")
private String subjectName;
/**图片策略*/
@Excel(name = "图片策略", width = 15, dicCode = "clb_save_policy")
@Dict(dicCode = "clb_save_policy")
@ApiModelProperty(value = "图片策略")
private String picturePolicy;
/**网页策略*/
@Excel(name = "网页策略", width = 15, dicCode = "clb_save_policy")
@Dict(dicCode = "clb_save_policy")
@ApiModelProperty(value = "网页策略")
private String pagePolicy;
/**状态*/
@Excel(name = "状态", width = 15, dicCode = "use_status")
@Dict(dicCode = "use_status")
@ApiModelProperty(value = "状态")
private Integer status;
/**启用时间*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
@Excel(name = "启用时间", width = 15, format = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
@ApiModelProperty(value = "启用时间")
private Date timeEnable;
/**停用时间*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
@Excel(name = "停用时间", width = 15, format = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern="yyyy-MM-dd")
@ApiModelProperty(value = "停用时间")
private Date timeDisable;
/**划分专题库*/
@Excel(name = "划分专题库", width = 15, dicCode = "Thematic_Library")
@Dict(dicCode = "Thematic_Library")
@ApiModelProperty(value = "划分专题库")
private String library;
/**定时单位(1分;2小时;3日;4月)*/
@ApiModelProperty(value = "定时单位")
private String unit;
/**定时数值*/
@ApiModelProperty(value = "定时数值")
private Integer space;
/**cron表达式*/
@ApiModelProperty(value = "cron表达式")
private String cron;
/**是否提取热词*/
@ApiModelProperty(value = "是否提取热词")
private String ynExtractHotWords;
/**事件专题增量分析规则*/
@ApiModelProperty(value = "事件专题增量分析规则")
private Integer increAnaRule;
/**事件专题总量分析规则*/
@ApiModelProperty(value = "事件专题总量分析规则")
private Integer totalAnaRule;
/**事件专题时间间隔分析规则(天)*/
@ApiModelProperty(value = "事件专题时间间隔分析规则(天)")
private Integer timeAnaRule;
/**专题最近一次分析时间*/
@ApiModelProperty(value = "专题最近一次分析时间")
private Date analysisTime;
/**外事办映射id*/
@ApiModelProperty(value = "外事办映射id")
private Integer wsbMapId;
/**创建人*/
@ApiModelProperty(value = "创建人")
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private Date createTime;
/**更新人*/
@ApiModelProperty(value = "更新人")
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private Date updateTime;
/**所属部门*/
@ApiModelProperty(value = "所属部门")
private String sysOrgCode;
/**所属客户*/
@ApiModelProperty(value = "所属客户")
private String customerId;
/**专题类别(1:通用专题 2:事件专题)*/
private Integer subjectType;
}
package com.zzsn.clb.member.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.zzsn.clb.member.entity.MemCollect;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @Description: 会员收藏表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface MemCollectMapper extends BaseMapper<MemCollect> {
}
package com.zzsn.clb.member.mapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
import com.zzsn.clb.member.entity.MemSubject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @Description: 会员推送栏目表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface MemSubjectMapper extends BaseMapper<MemSubject> {
}
package com.zzsn.clb.member.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* @Description: 会员点赞表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface MemThumbsUpMapper extends BaseMapper<MemThumbsUp> {
}
package com.zzsn.clb.member.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzsn.clb.member.entity.Subject;
import java.util.List;
import java.util.Map;
/**
* @Description: 专题表
* @Author: jeecg-boot
* @Date: 2021-12-01
* @Version: V1.0
*/
public interface SubjectMapper extends BaseMapper<Subject> {
/***
* 获取栏目树
* @return
*/
List<Map<String,Object>> getSubjectList();
/***
* 负面信息
* @return
*/
List<Map<String,Object>> getNegativeLabelList();
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.clb.member.mapper.MemSubjectMapper">
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.clb.member.mapper.MemThumbsUpMapper">
</mapper>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.clb.member.mapper.SubjectMapper">
<select id="getSubjectList" resultType="java.util.Map">
SELECT s.id subjectId,
s.subject_name subjectName,
le.id labelId,
le.`name` labelName
FROM `subject` s
INNER JOIN subject_type_map stm ON s.id = stm.subject_id
INNER JOIN subject_model_map smm ON s.id = smm.subject_id
INNER JOIN python_model pm ON smm.model_id = pm.id
INNER JOIN sys_base_label_type lb ON lb.id = pm.label_id
INNER JOIN sys_base_label_type_map lm ON lb.id = lm.label_id
INNER JOIN label_entity le ON le.id = lm.relation_id
WHERE stm.type_id = '1627954091596574722'
AND le.`status` = 1
ORDER BY s.id,
le.sort ASC
</select>
<select id="getNegativeLabelList" resultType="java.util.Map">
SELECT lb.label_mark as labelMark,
le.id labelId,
le.`name` labelName
FROM sys_base_label_type lb
LEFT JOIN sys_base_label_type_map lm ON lb.id = lm.label_id
LEFT JOIN label_entity le ON le.id = lm.relation_id
WHERE lb.id = '1628282342760095746'
ORDER BY le.sort ASC
</select>
</mapper>
package com.zzsn.clb.member.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.member.entity.MemCollect;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description: 会员收藏表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface IMemCollectService extends IService<MemCollect> {
void delete(LambdaQueryWrapper<MemCollect> queryWrapper, MemCollect memCollect);
void add(MemCollect memCollect);
}
package com.zzsn.clb.member.service;
import com.zzsn.clb.member.entity.MemSubject;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description: 会员推送栏目表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface IMemSubjectService extends IService<MemSubject> {
}
package com.zzsn.clb.member.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description: 会员点赞表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface IMemThumbsUpService extends IService<MemThumbsUp> {
void delete(LambdaQueryWrapper<MemThumbsUp> queryWrapper, MemThumbsUp memThumbsUp);
void add(MemThumbsUp memThumbsUp);
}
package com.zzsn.clb.member.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.zzsn.clb.member.entity.Subject;
import java.util.List;
import java.util.Map;
public interface ISubjectTreeService extends IService<Subject> {
/***
* 获取栏目树
* @return
*/
List<Map<String,Object>> getSubjectList();
}
package com.zzsn.clb.member.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.member.entity.MemCollect;
import com.zzsn.clb.member.mapper.MemCollectMapper;
import com.zzsn.clb.member.service.IMemCollectService;
import com.zzsn.clb.web.mapper.entity.SubjectDataExt;
import com.zzsn.clb.web.mapper.SubjectDataExtMapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* @Description: 会员收藏表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Service
public class MemCollectServiceImpl extends ServiceImpl<MemCollectMapper, MemCollect> implements IMemCollectService {
@Resource
SubjectDataExtMapper subjectDataExtMapper;
@Override
@Transactional
public void delete(LambdaQueryWrapper<MemCollect> queryWrapper, MemCollect memCollect) {
this.baseMapper.delete(queryWrapper);
subjectDataExtMapper.updateNum(memCollect.getArticleId(), "collect_num", -1);
}
@Override
@Transactional
public void add(MemCollect memCollect) {
this.baseMapper.insert(memCollect);
if (subjectDataExtMapper.selectById(memCollect.getArticleId()) == null) {
SubjectDataExt subjectDataExt = new SubjectDataExt();
subjectDataExt.setArticleId(memCollect.getArticleId());
subjectDataExt.setThumbsUpNum(0);
subjectDataExt.setCollectNum(0);
subjectDataExtMapper.insert(subjectDataExt);
}
subjectDataExtMapper.updateNum(memCollect.getArticleId(), "collect_num", 1);
}
}
package com.zzsn.clb.member.service.impl;
import com.zzsn.clb.member.entity.MemSubject;
import com.zzsn.clb.member.mapper.MemSubjectMapper;
import com.zzsn.clb.member.service.IMemSubjectService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @Description: 会员推送栏目表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Service
public class MemSubjectServiceImpl extends ServiceImpl<MemSubjectMapper, MemSubject> implements IMemSubjectService {
}
package com.zzsn.clb.member.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.zzsn.clb.member.mapper.MemThumbsUpMapper;
import com.zzsn.clb.member.service.IMemThumbsUpService;
import com.zzsn.clb.web.mapper.entity.SubjectDataExt;
import com.zzsn.clb.web.mapper.SubjectDataExtMapper;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
/**
* @Description: 会员点赞表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Service
public class MemThumbsUpServiceImpl extends ServiceImpl<MemThumbsUpMapper, MemThumbsUp> implements IMemThumbsUpService {
@Resource
SubjectDataExtMapper subjectDataExtMapper;
@Override
@Transactional
public void delete(LambdaQueryWrapper<MemThumbsUp> queryWrapper, MemThumbsUp memThumbsUp) {
this.baseMapper.delete(queryWrapper);
subjectDataExtMapper.updateNum(memThumbsUp.getArticleId(), "thumbs_up_num", -1);
}
@Override
@Transactional
public void add(MemThumbsUp memThumbsUp) {
this.baseMapper.insert(memThumbsUp);
if(subjectDataExtMapper.selectById(memThumbsUp.getArticleId())==null)
{
SubjectDataExt subjectDataExt = new SubjectDataExt();
subjectDataExt.setArticleId(memThumbsUp.getArticleId());
subjectDataExt.setThumbsUpNum(0);
subjectDataExt.setCollectNum(0);
subjectDataExtMapper.insert(subjectDataExt);
}
subjectDataExtMapper.updateNum(memThumbsUp.getArticleId(), "thumbs_up_num", 1);
}
}
package com.zzsn.clb.member.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzsn.clb.member.entity.Subject;
import com.zzsn.clb.member.mapper.SubjectMapper;
import com.zzsn.clb.member.service.ISubjectTreeService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Service
@DS("multi-clb-project")
public class SubjectTreeServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements ISubjectTreeService {
@Resource
SubjectMapper subjectMapper;
@Override
public List<Map<String, Object>> getSubjectList() {
List<Map<String, Object>> list = subjectMapper.getSubjectList();
List<String> idList = list.stream().distinct().map(m -> m.get("subjectId").toString()).collect(Collectors.toList());
List<Map<String, Object>> treeList = new ArrayList<>();
String subjectId = "";
List<Map<String, Object>> chdlist = null;
Map<String, Object> map = null;
for (Map<String, Object> tmpMap : list) {
if (!subjectId.equals(tmpMap.get("subjectId"))) {
chdlist = new ArrayList<>();
subjectId = tmpMap.get("subjectId").toString();
map = new HashMap<>();
map.put("key", subjectId);
map.put("name", tmpMap.get("subjectName"));
map.put("child", chdlist);
treeList.add(map);
}
Map<String, Object> childMap = new HashMap<>();
childMap.put("key", tmpMap.get("labelId"));
childMap.put("name", tmpMap.get("labelName"));
chdlist.add(childMap);
}
return treeList;
}
}
package com.zzsn.clb.test;
import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.zzsn.clb.member.mapper.SubjectMapper;
import com.zzsn.utils.ExcelExportUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.jeecg.common.api.vo.Result;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* 系统用户单元测试
*/
@Service
@Slf4j
@DS("multi-clb-project")
public class ImportExcelData {
@Resource
private RestHighLevelClient client;
@Resource
SubjectMapper subjectMapper;
public void importData() {
String path = "C:\\Users\\EDY\\Documents\\WeChat Files\\wxid_7d7tl0zyfdxb21\\FileStorage\\File\\2023-02\\克虏宝汇总审核后数据.xlsx";
try {
impData(1, 10, path, 21);
} catch (IOException e) {
e.printStackTrace();
}
}
protected List<Map<String, Object>> importExcel(String path) {
try {
FileInputStream fileInputStream = new FileInputStream(path);
ImportParams params = new ImportParams();
params.setTitleRows(1);
params.setHeadRows(1);
params.setNeedSave(true);
List<Map<String, Object>> list = ExcelImportUtil.importExcel(fileInputStream, Map.class, params);
List<Map<String, Object>> subjectList = subjectMapper.getSubjectList();
list.forEach(x -> {
//setEsData(x, subjectList);
});
long start = System.currentTimeMillis();
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
Result var13 = Result.ok("文件导入成功!数据行数:" + list.size());
return list;
} catch (Exception var23) {
log.error(var23.getMessage(), var23);
} finally {
}
return null;
}
private List<List<String>> impData(Integer firstRow, Integer columnNum, String path, Integer rowLength) throws IOException {
List<List<String>> dataList = new ArrayList<>();
List<Map<String, Object>> subjectList = subjectMapper.getSubjectList();
List<Map<String, Object>> negativeList = subjectMapper.getNegativeLabelList();
FileInputStream is = new FileInputStream(path);// 获取上传文件对象
// FileInputStream is = (FileInputStream) file.getInputStream();
//获取整个excel
XSSFWorkbook hb = new XSSFWorkbook(is);
int sheets = hb.getNumberOfSheets();
for (int i = 0; i < sheets; i++) {
XSSFSheet sheet = hb.getSheetAt(i);
//第一行
int firstRowNum = sheet.getFirstRowNum();
//最后一行
int lastRowNum = rowLength;//sheet.getPhysicalNumberOfRows();
for (int j = firstRowNum + firstRow; j < lastRowNum; j++) {
//获取行
XSSFRow row = sheet.getRow(j);
if (row != null) {
List<String> list = new ArrayList<>();
for (int m = 0; m < columnNum; m++) {
String data = ExcelExportUtil.getValue(row.getCell(m)).trim();
list.add(data);
}
setEsData(list, subjectList,negativeList);
//dataList.add(list);
}
}
}
return dataList;
}
String subjectId = "";
String labelId = null;
String labelName = null;
String labelMark = null;
private void setEsData(List<String> list, List<Map<String, Object>> subjectList, List<Map<String, Object>> negativeList) throws IOException {
SubjectData subjectData = new SubjectData();
Integer score = 0;
String title = null;
String content = null;
String author = null;
String origin = null;
String publishDate = null;
if (StringUtils.isNotBlank(list.get(3))) {
subjectData.setTitle(list.get(3));
} else {
return;
}
if (StringUtils.isNotBlank(list.get(0))) {
String subjectName = list.get(0);
if (!subjectName.equals("负面舆情")) {
try {
subjectId = subjectList.stream().filter(f -> f.get("subjectName").equals(subjectName)).map(m -> m.get("subjectId")).findFirst().get().toString();
} catch (Exception ex) {
log.error("错误:" + subjectName);
return;
}
labelName = list.get(1);
// Map<String, Object> map = subjectList.stream().filter(f -> f.get("labelName").equals(labelName) && f.get("subjectName").equals(subjectName)).findFirst().get();
Map<String, Object> map = subjectList.stream().filter(f -> f.get("labelName").equals(labelName)).findFirst().get();
labelId = map.get("labelId").toString();
labelMark = map.get("labelMark").toString();
} else {
labelName = list.get(1);
Map<String, Object> map = subjectList.stream().filter(f -> f.get("labelName").equals(labelName)).findFirst().get();
labelId = map.get("labelId").toString();
labelMark = map.get("labelMark").toString();
}
}
subjectData.setSubjectId(subjectId);
if (StringUtils.isNotBlank(list.get(4))) {
subjectData.setSummary(list.get(4));
}
if (StringUtils.isNotBlank(list.get(5))) {
subjectData.setContent(list.get(5));
}
if (StringUtils.isNotBlank(list.get(6))) {
subjectData.setAuthor(list.get(6));
}
if (StringUtils.isNotBlank(list.get(7))) {
subjectData.setOrigin(list.get(7));
}
if (StringUtils.isNotBlank(list.get(8))) {
subjectData.setPublishDate(list.get(8));
}
if (StringUtils.isNotBlank(list.get(9))) {
subjectData.setSourceAddress(list.get(9));
}
if (StringUtils.isNotBlank(subjectData.getTitle())) {
List<Label> labelListlist = new ArrayList<>();
String id = String.valueOf(IdWorker.getId());
subjectData.setId(id);
Label label = new Label();
label.setRelationId(labelId);
label.setRelationName(labelName);
label.setLabelMark(labelMark);
labelListlist.add(label);
subjectData.setLabels(labelListlist);
subjectData.setDeleteFlag(0);
subjectData.setCheckStatus(1);
log.info(JSON.toJSONString(subjectData));
IndexRequest request = new IndexRequest("subjectdatabase")
.id(id)
.source(JSON.toJSONString(subjectData), XContentType.JSON);
IndexResponse indexResponse = client.index(request, RequestOptions.DEFAULT);
log.info(indexResponse.toString());
//log.info("同步保存doc成功, _index=[{}], _id=[{}], _body=[{}]",index, id, jsonStr);
// return indexResponse.getId();
}
}
}
package com.zzsn.clb.test;
import lombok.Data;
/**
* 基础信息打上标签的实体对象
*/
@Data
public class Label {
//命中标识
private String hitRemarks;
//标签标识
private String labelMark;
//标签备注
private String labelRemarks;
//项目标签id
private String projectLabelId;
//关联标签id
private String relationId;
//关联标签名称
private String relationName;
//审核状态
private Integer status;
}
package com.zzsn.clb.test;
import lombok.Data;
import java.util.List;
@Data
public class SubjectData {
//作者
private String author;
private String authorRaw;
//审核状态
private Integer checkStatus;
//正文
private String content;
private String contentRaw;
//带标签正文
private String contentWithTag;
private String contentWithTagRaw;
//创建时间
private String createDate;
//删除标志
private Integer deleteFlag;
//id
private String id;
//关键词
private String keyWords;
//语言
private String lang;
//来源
private String origin;
private String originRaw;
//发布时间
private String publishDate;
//得分
private Double score;
//信息源id
private String sid;
//地址
private String sourceAddress;
//专题id
private String subjectId;
//摘要
private String summary;
private String summaryRaw;
//标题
private String title;
private String titleRaw;
//置顶
private Integer topNum;
private String type;
private List<Label> labels;
}
package com.zzsn.clb.web.controller; package com.zzsn.clb.web.controller;
import com.zzsn.clb.fegin.IServiceProjectClient; import com.zzsn.clb.fegin.IServiceProjectClient;
import com.zzsn.clb.test.ImportExcelData;
import com.zzsn.clb.web.service.ISubjectService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -12,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -12,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
/** /**
* @Description: 根据专题获取信息 * @Description: 根据专题获取信息
...@@ -20,52 +24,77 @@ import javax.annotation.Resource; ...@@ -20,52 +24,77 @@ import javax.annotation.Resource;
* @Version: V1.0 * @Version: V1.0
*/ */
@Slf4j @Slf4j
@Api(tags="对标分析菜单数据配置") @Api(tags = "网站首页")
@RestController @RestController
@RequestMapping("/") @RequestMapping("/mach/web")
public class SubjectController { public class SubjectController {
@Resource @Resource
IServiceProjectClient serviceProjectClient; IServiceProjectClient serviceProjectClient;
/** @Resource
* 根据专题类型id查询数据 ISubjectService subjectService;
* @param id @Resource
ImportExcelData importExcelData;
/***
* 专题数据
* @param type 本月-month 季度-quarter 本年-year
* @param size 返回数据条数
* @param subjectType 专题类型 通用-1 事件-2
* @return * @return
*/ */
@AutoLog(value = "根据专题类型id查询数据") @AutoLog(value = "专题数据")
@ApiOperation(value="根据专题类型id查询数据", notes="根据专题类型id查询数据") @ApiOperation(value = "专题数据", notes = "专题数据")
@GetMapping(value = "/getListBySubjectType") @GetMapping(value = "/getSubjectCollect")
public Result<?> getListBySubjectType(@RequestParam(required = true) String id) public Result<?> SubjectCollect(@RequestParam(required = true,defaultValue = "month") String type,@RequestParam(defaultValue = "6") Integer size,@RequestParam(defaultValue = "1") Integer subjectType) {
{ return Result.OK(subjectService.getSubjectCollect(type,size,subjectType));
return serviceProjectClient.getListBySubjectType(id);
} }
/** /***
* 根据专题id查询数据 * 据专题id查询数据
* @param id * @param pageNo 当前页码
* @param pageSize 每页显示的条数
* @param subjectId 专题id
* @return * @return
*/ */
@AutoLog(value = "根据专题id查询数据") @AutoLog(value = "根据专题id查询数据")
@ApiOperation(value="根据专题id查询数据", notes="根据专题id查询数据") @ApiOperation(value = "根据专题id查询数据", notes = "根据专题id查询数据")
@GetMapping(value = "/getListBySubject") @GetMapping(value = "/getListBySubject")
public Result<?> getListBySubject(@RequestParam(required = true) String id) public Result<?> getListBySubject(Integer pageNo, Integer pageSize, @RequestParam(required = true) String subjectId,@RequestParam(required = false) String lableIds) {
{ //http://114.115.205.50:9988/subject/display/list?_t=1676630456&column=score&order=desc&field=id,,info&pageNo=1&pageSize=10&subjectId=1600743965735264258&checkStatusList=&isSubject=1
return serviceProjectClient.getListBySubject(id); Map<String, Object> map = new HashMap<>();
map.put("subjectId", subjectId);
return serviceProjectClient.getListBySubject(map, null, null, pageNo, pageSize, "publishDate", "desc", null, "1", null,lableIds);
} }
/**
* 根据信息id查询数据
*
* @param id
* @return
*/
@AutoLog(value = "根据信息id查询数据")
@ApiOperation(value = "根据信息id查询数据", notes = "根据信息id查询数据")
@GetMapping(value = "/getById")
public Result<?> getById(@RequestParam(required = true) String id) {
//http://114.115.236.206:9988/subject/display/queryById?_t=1676875032&id=21123000014507
return serviceProjectClient.getInfoById(id);
}
/** /**
* 根据信息id查询数据 * 根据信息id查询数据
*
* @param id * @param id
* @return * @return
*/ */
@AutoLog(value = "根据信息id查询数据") @AutoLog(value = "根据信息id查询数据")
@ApiOperation(value="根据信息id查询数据", notes="根据信息id查询数据") @ApiOperation(value = "根据信息id查询数据", notes = "根据信息id查询数据")
@GetMapping(value = "/getSubjectById") @GetMapping(value = "/import")
public Result<?> getSubjectById(@RequestParam(required = true) String id) public Result<?> importData() {
{ //http://114.115.236.206:9988/subject/display/queryById?_t=1676875032&id=21123000014507
return serviceProjectClient.getSubjectById(id); importExcelData.importData();
return Result.OK();
} }
} }
package com.zzsn.clb.web.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zzsn.clb.member.entity.MemCollect;
import com.zzsn.clb.member.entity.MemThumbsUp;
import com.zzsn.clb.member.service.IMemCollectService;
import com.zzsn.clb.member.service.IMemThumbsUpService;
import org.apache.shiro.authc.AuthenticationException;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import com.zzsn.clb.web.mapper.entity.SubjectDataExt;
import com.zzsn.clb.web.service.ISubjectDataExtService;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.config.shiro.ShiroRealm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
* @Description: 文章扩展表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Slf4j
@Api(tags = "文章扩展表")
@RestController
@RequestMapping("/mach/web")
public class SubjectDataExtController extends JeecgController<SubjectDataExt, ISubjectDataExtService> {
@Autowired
private ISubjectDataExtService subjectDataExtService;
@Autowired
private IMemThumbsUpService memThumbsUpService;
@Autowired
private IMemCollectService memCollectService;
@Resource
private ShiroRealm shiroRealm;
/**
* 通过id查询
*
* @param articleId
* @return
*/
@AutoLog(value = "文章扩展表-通过id查询")
@ApiOperation(value = "文章扩展表-通过id查询", notes = "文章扩展表-通过id查询")
@GetMapping(value = "/queryArticleById")
public Result<?> queryById(@RequestParam(name = "id", required = true) String articleId, HttpServletRequest request) {
SubjectDataExt subjectDataExt = subjectDataExtService.getById(articleId);
LoginUser user = null;
try {
user = shiroRealm.checkUserTokenIsEffect(request.getHeader("X-Access-Token"));
} catch (AuthenticationException ex) {
}
if (user != null) {
LambdaQueryWrapper<MemThumbsUp> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(MemThumbsUp::getUserId, user.getId()).eq(MemThumbsUp::getArticleId, articleId);
subjectDataExt.setThumbsStatus(memThumbsUpService.count(queryWrapper) > 0 ? true : false);
LambdaQueryWrapper<MemCollect> queryWrapperCollect = new LambdaQueryWrapper<>();
queryWrapperCollect.eq(MemCollect::getUserId, user.getId()).eq(MemCollect::getArticleId, articleId);
subjectDataExt.setCollectStatus(memCollectService.count(queryWrapperCollect) > 0 ? true : false);
}else
{
subjectDataExt.setThumbsStatus(false);
subjectDataExt.setCollectStatus(false);
}
return Result.OK(subjectDataExt);
}
}
package com.zzsn.clb.web.mapper;
import org.apache.ibatis.annotations.Param;
import com.zzsn.clb.web.mapper.entity.SubjectDataExt;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Update;
/**
* @Description: 文章扩展表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface SubjectDataExtMapper extends BaseMapper<SubjectDataExt> {
@Update("update subject_data_ext set ${column}=${column}+#{num} where article_id=#{articleId}")
void updateNum(@Param("articleId") String articleId, @Param("column") String column, @Param("num") int num);
}
package com.zzsn.clb.web.mapper.entity;
import java.io.Serializable;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
/**
* @Description: 文章扩展表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Data
@TableName("subject_data_ext")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="subject_data_ext对象", description="文章扩展表")
public class SubjectDataExt {
/**文章ID*/
@TableId(type = IdType.INPUT)
@ApiModelProperty(value = "文章ID")
private String articleId;
/**收藏数量*/
@Excel(name = "收藏数量", width = 15)
@ApiModelProperty(value = "收藏数量")
@JsonIgnore
private Integer collectNum;
/**点赞数量*/
@Excel(name = "点赞数量", width = 15)
@ApiModelProperty(value = "点赞数量")
private Integer thumbsUpNum;
/**收藏状态*/
@ApiModelProperty(value = "收藏状态")
@TableField(exist = false)
private Boolean collectStatus;
/**点赞状态*/
@ApiModelProperty(value = "点赞状态")
@TableField(exist = false)
private Boolean thumbsStatus;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zzsn.clb.web.mapper.SubjectDataExtMapper">
</mapper>
\ No newline at end of file
package com.zzsn.clb.web.service;
import com.zzsn.clb.web.mapper.entity.SubjectDataExt;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* @Description: 文章扩展表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
public interface ISubjectDataExtService extends IService<SubjectDataExt> {
}
package com.zzsn.clb.web.service.impl;
import com.zzsn.clb.web.mapper.entity.SubjectDataExt;
import com.zzsn.clb.web.mapper.SubjectDataExtMapper;
import com.zzsn.clb.web.service.ISubjectDataExtService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
/**
* @Description: 文章扩展表
* @Author: jeecg-boot
* @Date: 2023-02-22
* @Version: V1.0
*/
@Service
public class SubjectDataExtServiceImpl extends ServiceImpl<SubjectDataExtMapper, SubjectDataExt> implements ISubjectDataExtService {
}
package com.zzsn.common;
public class Constants {
//处理后的专题资讯信息存储索引
public final static String ES_DATA_FOR_SUBJECT = "subjectdatabase";
}
package com.zzsn.utils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class ExcelExportUtil {
/**
* 读取excel数据
*
* @param firstRow 第一行有用数据(0表示第一行)
* @param columnNum 有用数据的总列数
* @return java.util.List<java.util.List < java.lang.String>>
*/
public static List<List<String>> readExcel(HttpServletRequest request, Integer firstRow, Integer columnNum) throws Exception {
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
List<List<String>> dataList = new ArrayList<>();
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
MultipartFile file = entity.getValue();// 获取上传文件对象
FileInputStream is = (FileInputStream) file.getInputStream();
//获取整个excel
XSSFWorkbook hb = new XSSFWorkbook(is);
int sheets = hb.getNumberOfSheets();
for (int i = 0; i < sheets; i++) {
XSSFSheet sheet = hb.getSheetAt(i);
//第一行
int firstRowNum = sheet.getFirstRowNum();
//最后一行
int lastRowNum = sheet.getPhysicalNumberOfRows();
for (int j = firstRowNum + firstRow; j < lastRowNum; j++) {
//获取行
XSSFRow row = sheet.getRow(j);
if (row != null) {
List<String> list = new ArrayList<>();
for (int m = 0; m < columnNum; m++) {
String data = ExcelExportUtil.getValue(row.getCell(m)).trim();
list.add(data);
}
dataList.add(list);
}
}
}
}
return dataList;
}
/**
* 读取本地excel数据
*
* @param firstRow 第一行有用数据(0表示第一行)
* @param columnNum 有用数据的总列数
* @return java.util.List<java.util.List < java.lang.String>>
*/
public static List<List<String>> readLocalExcel(String path, Integer firstRow, Integer columnNum) throws Exception {
List<List<String>> dataList = new ArrayList<>();
File file = new File(path);
FileInputStream is = new FileInputStream(file.getAbsolutePath());
//获取整个excel
XSSFWorkbook hb = new XSSFWorkbook(is);
int sheets = hb.getNumberOfSheets();
for (int i = 0; i < sheets; i++) {
XSSFSheet sheet = hb.getSheetAt(i);
//第一行
int firstRowNum = sheet.getFirstRowNum();
//最后一行
int lastRowNum = sheet.getPhysicalNumberOfRows();
for (int j = firstRowNum + firstRow; j < lastRowNum; j++) {
//获取行
XSSFRow row = sheet.getRow(j);
if (row != null) {
List<String> list = new ArrayList<>();
for (int m = 0; m < columnNum; m++) {
String data = ExcelExportUtil.getValue(row.getCell(m)).trim();
list.add(data);
}
dataList.add(list);
}
}
}
return dataList;
}
public static String getValue(XSSFCell xssfCell) {
if (xssfCell == null || xssfCell.toString().trim().equals("")) {
return "";
}
CellType cellType = xssfCell.getCellType();
/* if (cellType == CellType.NUMERIC) {
return xssfCell.getStringCellValue();
}*/
if (cellType == CellType.NUMERIC) {
if(HSSFDateUtil.isCellDateFormatted(xssfCell)){
return TimeUtil.getDateString(xssfCell.getDateCellValue());
}
DecimalFormat df = new DecimalFormat("0");
return df.format(xssfCell.getNumericCellValue());
}
return xssfCell.getStringCellValue();
}
/**
* 获取标题栏样式
*
* @param workbook
* @return
*/
private static XSSFCellStyle getHeaderStyle(XSSFWorkbook workbook) {
// 生成一个样式
XSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setFillForegroundColor(IndexedColors.SKY_BLUE.index);
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
// style.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00"));
// 生成一个字体
XSSFFont font = workbook.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 9);
// 把字体应用到当前的样式
style.setFont(font);
return style;
}
/**
* 获取字符串型内容栏样式
*
* @return
*/
private static XSSFCellStyle getRowStrStyle(XSSFWorkbook workbook) {
// 生成一个样式
XSSFCellStyle style = workbook.createCellStyle();
// 设置这些样式
style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN);
style.setAlignment(HorizontalAlignment.CENTER);
// 生成一个字体
XSSFFont font = workbook.createFont();
font.setColor(IndexedColors.BLACK.index);
font.setFontHeightInPoints((short) 9);
font.setBold(true);
// 把字体应用到当前的样式
style.setFont(font);
return style;
}
private static OutputStream getOutputStream(String fileName, HttpServletResponse response) throws Exception {
fileName = URLEncoder.encode(fileName, "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf8");
response.setHeader("Content-Disposition", "attachment;filename=" + fileName + ".xlsx");
return response.getOutputStream();
}
public static List<List<String>> readExcel(String path) throws Exception {
List<List<String>> dataList = new ArrayList<>();
File file = new File(path);
FileInputStream is = new FileInputStream(file.getAbsolutePath());
//获取整个excel
XSSFWorkbook hb = new XSSFWorkbook(is);
//获取所有表单
int sheets = hb.getNumberOfSheets();
for (int m = 0; m < sheets; m++) {
//获取表单
XSSFSheet sheet = hb.getSheetAt(m);
//第一行
int firstRowNum = sheet.getFirstRowNum();
//最后一行
int lastRowNum = sheet.getPhysicalNumberOfRows();
for (int j = firstRowNum + 1; j < 6; j++) {
//获取行
XSSFRow row = sheet.getRow(j);
if (row != null) {
// short firstCellNum = row.getFirstCellNum();
// int lastCellNum = row.getPhysicalNumberOfCells();
List<String> list = new ArrayList<>();
for (int i = 1; i < 2; i++) {
String value = getValue(row.getCell(i));
list.add(value.trim());
}
dataList.add(list);
}
}
break;
}
return dataList;
}
//多个sheet
public static void exportExcelData(XSSFWorkbook workbook, int sheetNum, List<String> keyList, List<List<String>> rows, String sheetName) {
Sheet sheet = workbook.createSheet();
//多个sheet
workbook.setSheetName(sheetNum, sheetName);
sheet.setDefaultColumnWidth(20);
sheet.setDefaultRowHeight((short) 400);
XSSFCellStyle titleStyle = ExcelExportUtil.getHeaderStyle(workbook);
XSSFCellStyle rowStrStyle = ExcelExportUtil.getRowStrStyle(workbook);
// 产生表格标题行
Row row = sheet.createRow(0);
row.setHeight((short) 400);
Cell cell;
List<String> colData = new ArrayList<>(keyList);
for (int i = 0; i < colData.size(); i++) {
cell = row.createCell(i, CellType.STRING);
cell.setCellStyle(titleStyle);
cell.setCellValue(new XSSFRichTextString(colData.get(i)));
}
// 数据行
for (int m = 0; m < rows.size(); m++) {
List<String> rowData = rows.get(m);
row = sheet.createRow(m + 1);
row.setHeight((short) 400);
int i = 0;
for (String rowDatum : rowData) {
createCell(rowStrStyle, row, i, rowDatum);
i++;
}
}
}
private static void createCell(XSSFCellStyle rowStrStyle, Row row, int index, String value) {
Cell cell = row.createCell(index, CellType.STRING);
cell.setCellStyle(rowStrStyle);
cell.setCellValue(value);
}
}
package com.zzsn.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TimeUtil {
static SimpleDateFormat format;
private static Pattern patDate0 = Pattern.compile("\\d+-\\d{1,2}-\\d+");
private static Pattern patDate1 = Pattern.compile("\\d+[-\\s/年月日]\\d{1,2}-\\d+", Pattern.CASE_INSENSITIVE);
private static Pattern patDate2 = Pattern.compile("\\d+\\s+[A-Z][a-z]+\\s+\\d+");
private static Pattern patDate3 = Pattern.compile("[A-Z][a-z.]+\\s+\\d{1,2},\\s+\\d+");
private static Pattern patDate4 = Pattern.compile("\\d+年\\d+月\\d+日");
private static Pattern patDate4_1 = Pattern.compile("\\d+年\\d+月\\d+号");
private static Pattern patDate5 = Pattern.compile("\\d+/\\d{1,2}/\\d+");
private static Pattern patDate6 = Pattern.compile("\\d+\\.\\d+\\.\\d+");
private static Date thresholdDate = null;
private static SimpleDateFormat formatter0 = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat formatter0_1 = new SimpleDateFormat("yy-MM-dd");
private static SimpleDateFormat formatter2 = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH);
private static SimpleDateFormat formatter3_1 = new SimpleDateFormat("MMM dd, yyyy", Locale.ENGLISH);
private static SimpleDateFormat formatter3_2 = new SimpleDateFormat("MMM. dd, yyyy", Locale.ENGLISH);
private static SimpleDateFormat formatter4 = new SimpleDateFormat("yyyy年MM月dd");
private static SimpleDateFormat formatter5_1 = new SimpleDateFormat("yyyy/MM/dd");
private static SimpleDateFormat formatter5_2 = new SimpleDateFormat("dd/MM/yyyy");
private static SimpleDateFormat formatter5_4 = new SimpleDateFormat("yy/MM/dd");
private static SimpleDateFormat formatter5_3 = new SimpleDateFormat("dd/MM/yy");
private static SimpleDateFormat formatter6 = new SimpleDateFormat("yyyy.MM.dd");
private static SimpleDateFormat formatter6_1 = new SimpleDateFormat("dd.MM.yyyy");
public static String dateToString(Date date) {
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return TimeUtil.format.format(date);
}
public static String getPublishDate(String raw) {
if (raw == null) {
return null;
}
Date date = transDate(raw);
if (date != null) {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("Asia/Shanghai"));
c.setTime(date);
Pattern p = Pattern.compile("(\\d{1,2})[:|:](\\d{1,2})([:|:]\\d{1,2}){0,1}");
Matcher m = p.matcher(raw);
while (m.find()) {
String hour = m.group(1);
if (hour != null) {
c.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hour));
}
String minute = m.group(2);
if (minute != null) {
c.set(Calendar.MINUTE, Integer.parseInt(minute));
}
String second = m.group(3);
if (second != null) {
c.set(Calendar.SECOND, Integer.parseInt(second.replaceAll("[::]", "")));
}
}
return format(c.getTime(), "yyyy-MM-dd");
} else {
return null;
}
}
private static String format(Date d, String format) {
if (d == null)
return "";
SimpleDateFormat myFormatter = new SimpleDateFormat(format);
return myFormatter.format(d);
}
private static Date transDate(String content) {
try {
Matcher dateMatcher = null;
Date date = null;
if (((dateMatcher = patDate0.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 0)) != null))
|| ((dateMatcher = patDate1.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 1)) != null))
|| ((dateMatcher = patDate2.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 2)) != null))
|| ((dateMatcher = patDate3.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 3)) != null))
|| ((dateMatcher = patDate4.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 4)) != null))
|| ((dateMatcher = patDate4_1.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 4)) != null))
|| ((dateMatcher = patDate5.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 5)) != null))
|| ((dateMatcher = patDate6.matcher(content)).find() && ((date = transDate(dateMatcher.group(), 6)) != null))
) {
return date;
}
return null;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static Date transDate(String source, int type) {
try {
if (thresholdDate == null) {
thresholdDate = formatter0.parse("1970-01-01");
}
Date date = null;
switch (type) {
case 0:
date = formatter0.parse(source);
if (date.before(thresholdDate)) {
date = formatter0_1.parse(source);
if (date.before(thresholdDate)) {
return null;
}
}
break;
case 1:
//date = formatter1.parse(source);
break;
case 2:
date = formatter2.parse(source);
break;
case 3:
try {
date = formatter3_1.parse(source);
} catch (Exception e) {
date = null;
}
if (date == null) {
date = formatter3_2.parse(source);
}
break;
case 4:
date = formatter4.parse(source);
break;
case 5:
try {
date = formatter5_1.parse(source);
} catch (Exception e) {
date = null;
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter5_2.parse(source);
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter5_3.parse(source);
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter5_4.parse(source);
}
break;
case 6:
try {
date = formatter6.parse(source);
} catch (ParseException e) {
date = null;
}
if ((date == null) || (date.before(thresholdDate))) {
date = formatter6_1.parse(source);
}
break;
}
if ((date != null) && (date.before(thresholdDate))) {
return null;
}
return date;
} catch (Exception e) {
return null;
}
}
/**
* 获取前7天的时间
* @param date
* @return
*/
public static String beforeWeek(Date date){
format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Calendar c = Calendar.getInstance();
//设置为指定日期
c.setTime(date);
c.add(Calendar.DATE,-7);
Date time = c.getTime();
return format.format(time);
}
/**
* 获取前30天的时间
* @param date
* @return
*/
public static String beforeMonth(Date date){
format = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
//设置为指定日期
c.setTime(date);
c.add(Calendar.DATE,-30);
return format.format(c.getTime()) + " 00:00:00";
}
public static String getDateString(Date date) {
format = new SimpleDateFormat("yyyy-MM-dd");
return TimeUtil.format.format(date);
}
public static Date StringToDate(String dateString) throws ParseException {
format = new SimpleDateFormat("yyyy-MM-dd");
return format.parse(dateString);
}
public static String dateConvert(String dateString) throws ParseException {
format = new SimpleDateFormat("MM/dd/yyyy");
Date parse = format.parse(dateString);
return getDateString(parse);
}
/**
* 获取指定某一天的开始时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public static Long getDailyStartTime(Long timeStamp, String timeZone) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone(timeZone));
calendar.setTimeInMillis(timeStamp);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis();
}
/**
* 获取指定某一天的结束时间戳
*
* @param timeStamp 毫秒级时间戳
* @param timeZone 如 GMT+8:00
* @return
*/
public static Long getDailyEndTime(Long timeStamp, String timeZone) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TimeZone.getTimeZone(timeZone));
calendar.setTimeInMillis(timeStamp);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
calendar.set(Calendar.MILLISECOND, 999);
return calendar.getTimeInMillis();
}
/**
* 判断两个时间是否为同一天
* @param date1
* @param date2
* @return
*/
public static boolean isSameDay(final Date date1, final Date date2) {
if(date1 == null || date2 == null) {
return false;
}
final Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
final Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
return isSame(cal1, cal2);
}
private static boolean isSame(final Calendar cal1, final Calendar cal2) {
if (cal1 == null || cal2 == null) {
return false;
}
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
}
}
package com.zzsn.utils;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class UDateUtils {
/**
* @param
* @Description 根据当前日期获取本季度第一天
* @Throws
* @Return java.util.Date
* @Date 2021-08-31 15:37:11
* @Author WangKun
**/
public static Date getCurrentQuarterStartTime() {
Calendar c = Calendar.getInstance();
int currentMonth = c.get(Calendar.MONTH) + 1;
SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
Date now = null;
try {
if (currentMonth <= 3)
c.set(Calendar.MONTH, 0);
else if (currentMonth <= 6)
c.set(Calendar.MONTH, 3);
else if (currentMonth <= 9)
c.set(Calendar.MONTH, 6);
else if (currentMonth <= 12)
c.set(Calendar.MONTH, 9);
c.set(Calendar.DATE, 1);
now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
} catch (Exception e) {
e.printStackTrace();
}
return now;
}
/**
* @param
* @Description 根据当前日期获取本季度最后一天
* @Throws
* @Return java.util.Date
* @Date 2021-08-31 15:30:23
* @Author WangKun
**/
public static Date getCurrentQuarterEndTime() {
Calendar cal = Calendar.getInstance();
cal.setTime(getCurrentQuarterStartTime());
cal.add(Calendar.MONTH, 2);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
cal.set(Calendar.MILLISECOND, 999);
return cal.getTime();
}
}
...@@ -25,63 +25,11 @@ spring: ...@@ -25,63 +25,11 @@ spring:
group: clb-common group: clb-common
refresh: true refresh: true
extension-configs[1]: extension-configs[1]:
data‐id: clb-common.yaml data‐id: ${spring.application.name}.yaml
group: clb-common group: clb-service
refresh: true refresh: true
discovery: discovery:
namespace: @config.namespace@ namespace: @config.namespace@
server-addr: @config.server-addr@ server-addr: @config.server-addr@
watch: watch:
enabled: true enabled: true
#调用企业微信
wechat:
#企业Id
# corpid: ww187217d77e086f26
corpid: wwb740436999b352d1
#应用私钥
# corpsecret: HCZiXELtruFLkKloV6oGzgkIJjdbFcnwQ8dt2F7jAXU
corpsecret: BXd67p291P2WNiUczw_h8rq-5_2SooIphrHsOw3KGOM
#通讯录私钥
# txlsecret: PfTu5mlzpMG3czuR7NzsOSj79rcQJg6sDp3fOyduTTE
txlsecret: O36wWk8oM_GY98FuyTKX0kKYEgCeN4Rdo4zPDALcWmY
#应用ID
# agentId: 1000002
agentId: 1000019
#获取token地址
accessTokenUrl: https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=CORPID&corpsecret=CORPSECRET
#发送消息地址
sendMessageUrl: https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=
#用户 所有人 ,可指定人员 例如 WangPeng|ZhangShuo123
userId: "@all"
# #获取用户id地址
getUseridUrl: https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=
# #获取访问用户身份
# getUserInfoUrl: https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&code=CODE
# #获取企业的jsapi_ticket
# getJsapiTicketUrl: https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=ACCESS_TOKEN
# #获取部门列表地址(企业微信api地址)
getDepartmentListUrl: https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=
# #获取企业成员地址(企业微信api地址)
getUserListUrl: https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token=
task:
cron:
#专题预警每天1点开始执行
subject: 0 9 1 * * ?
#信息源预警每天 1点执行
infosource: 0 20 1 * * ?
#从es采集库中统计每个信息源当天每小采集量,一小时跑一次
staticByHour: 0 3 */1 * * ?
#统计前7天的采集量,每天 1点执行
staticByDays: 0 10 1 * * ?
#定时发送微信消息
sendWechatMsg: 0 0 8 * * ?
#fdfs:
# so-timeout: 1501 # 读取时间
# connect-timeout: 11601 #连接超时时间
# thumb-image: #缩略图
# height: 60
# width: 60
# tracker-list:
# 114.115.215.96:22122
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论