wjt 1 year ago
parent 545eeaf71f
commit 2068d4ab5b

@ -21,6 +21,11 @@
<artifactId>cdp-tool-xhs-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.baiye</groupId>-->
<!-- <artifactId>cdp-task</artifactId>-->
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.baiye</groupId>
<artifactId>cdp-tool-xhs-core</artifactId>

@ -33,7 +33,7 @@ public class CityInfoController {
@PostMapping("/add")
@ApiOperation("导入城市")
@Inner(value = false)
public Result<Object> addCity(@RequestParam(value = "file", required = false) MultipartFile file) {
return cityInfoService.addCity(file);
public Result<Object> addCity(@RequestParam(value = "file", required = false) MultipartFile file, @RequestParam(value = "type") Integer type) {
return cityInfoService.addCity(file, type);
}
}

@ -0,0 +1,52 @@
package com.baiye.controller;
import com.baiye.annotation.Inner;
import com.baiye.core.base.api.Result;
import com.baiye.dto.LinkWatchDTO;
import com.baiye.service.LinkWatchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author wjt
* @date 2023/3/28
*/
@RestController
@RequestMapping("/link/watch")
@RequiredArgsConstructor
@Api(tags = "xhs定时统计")
public class LinkWatchController {
private final LinkWatchService linkWatchService;
@PostMapping("/create")
@ApiOperation("添加链接监听信息")
@Inner(value = false)
public Result<Object> create(@RequestBody @Validated LinkWatchDTO linkWatchDTO) {
return linkWatchService.create(linkWatchDTO);
}
@GetMapping("/query")
@ApiOperation("查看统计的链接列表")
@Inner(value = false)
public Result<Object> query() {
return linkWatchService.query();
}
@GetMapping("/report")
@ApiOperation("查看链接监听统计")
@Inner(value = false)
public Result<Object> report(@RequestParam("link") String link) {
return linkWatchService.report(link);
}
@GetMapping("/test")
@ApiOperation("查看链接监听统计")
@Inner(value = false)
public Result<Object> test(@RequestParam("link") String link, @RequestParam("param") String param) {
return Result.data(linkWatchService.test(link, param));
}
}

@ -1,59 +0,0 @@
package com.baiye.controller;
import cn.hutool.json.JSONUtil;
import com.baiye.core.base.api.Result;
import com.baiye.core.page.PageResult;
import com.baiye.dto.SourceDTO;
import com.baiye.query.SourceQuery;
import com.baiye.service.SourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
* @author jt
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/xhs/source")
@Api(tags = "小红书素材包管理")
public class ResourceController {
private final SourceService sourceService;
@GetMapping("/query")
@ApiOperation("资源包查询")
public PageResult querySource(SourceQuery sourceQuery, Pageable pageable) {
return sourceService.querySource(sourceQuery, pageable);
}
@PostMapping("/add")
@ApiOperation("新增素材包")
public Result<Object> addSource(@RequestParam(value = "file",required = false) MultipartFile file, @RequestParam("sourceDTO") String sourceDTO) {
return sourceService.addSource(file, JSONUtil.toBean(sourceDTO, SourceDTO.class));
}
@DeleteMapping("/delete")
@ApiOperation("删除素材包")
public Result<Object> deleteSource(@RequestParam(value = "id") Long id) {
return sourceService.deleteSource(id);
}
@GetMapping("/status")
@ApiOperation("修改素材包状态")
public Result<Object> changeStatus(@RequestParam(value = "id") Long id) {
return sourceService.changeStatus(id);
}
@GetMapping("/isRepeat")
@ApiOperation("验证名称重复")
public Result<Object> isRepeatSourceName(@RequestParam(value = "sourceName") String sourceName) {
Boolean repeatSourceName = sourceService.isRepeatSourceName(sourceName);
return Result.data(repeatSourceName);
}
}

@ -1,49 +0,0 @@
package com.baiye.controller;
import com.baiye.core.base.api.Result;
import com.baiye.dto.SourceOrganizeDTO;
import com.baiye.query.SourceOrganizeQuery;
import com.baiye.service.SourceOrganizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* @author jt
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/xhs/source/organize")
@Api(tags = "小红书资源组管理")
public class ResourceOrganizeController {
private final SourceOrganizeService sourceOrganizeService;
@GetMapping("/query")
@ApiOperation("资源组管理")
public Result<Object> querySourceOrganize(SourceOrganizeQuery sourceOrganizeQuery) {
return sourceOrganizeService.querySourceOrganize(sourceOrganizeQuery);
}
@PostMapping("/add")
@ApiOperation("新增组")
public Result<Object> addSourceOrganize(@RequestBody @Validated SourceOrganizeDTO sourceOrganizeDTO) {
return sourceOrganizeService.addSourceOrganize(sourceOrganizeDTO);
}
@DeleteMapping("/delete")
private Result<Object> deleteSourceOrganize(Long id) {
return sourceOrganizeService.deleteSourceOrganize(id);
}
@GetMapping("/isRepeat")
@ApiOperation("验证名称重复")
public Result<Object> isRepeatSourceName(@RequestParam(value = "sourceOrganizeName") String sourceOrganizeName) {
Boolean repeatSourceName = sourceOrganizeService.isRepeatSourceOrganizeName(sourceOrganizeName);
return Result.data(repeatSourceName);
}
}

@ -1,51 +0,0 @@
package com.baiye.controller;
import com.baiye.core.base.api.Result;
import com.baiye.dto.OperateVariableDTO;
import com.baiye.dto.SourceVariableDTO;
import com.baiye.query.SourceVariableQuery;
import com.baiye.service.ResourceVariableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @author jt
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/xhs/source/variable")
@Api(tags = "小红书资源变量管理")
public class ResourceVariableController {
private final ResourceVariableService resourceVariableService;
@GetMapping("/query")
@ApiOperation("查询变量")
public Result<Object> queryResourceVariable(SourceVariableQuery sourceVariableQuery) {
return resourceVariableService.queryResourceVariable(sourceVariableQuery);
}
@PostMapping("/add")
@ApiOperation("新增变量")
public Result<Object> addResourceVariable(@RequestBody @Validated OperateVariableDTO operateVariableDTO) {
return resourceVariableService.addResourceVariable(operateVariableDTO);
}
@DeleteMapping("/delete")
@ApiOperation("删除变量")
public Result<Object> deleteResourceVariable(Long id) {
return resourceVariableService.deleteResourceVariable(id);
}
// @PostMapping("/update")
// @ApiOperation("修改变量")
// public Result<Object> updateResourceVariable(@RequestBody List<SourceVariableDTO> sourceVariableDTO) {
// return resourceVariableService.updateResourceVariable(sourceVariableDTO);
// }
}

@ -1,38 +0,0 @@
package com.baiye.controller;
import com.baiye.annotation.Inner;
import com.baiye.core.base.api.Result;
import com.baiye.dto.SmartWriteDTO;
import com.baiye.service.SmartWriteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
/**
* @author jt
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/xhs/smart")
@Api(tags = "小红书智能文案")
public class SmartWriteController {
private final SmartWriteService smartWriteService;
@PostMapping("/create")
@ApiOperation("智能文案生成")
public Result<Object> smartCreate(@RequestBody SmartWriteDTO smartWriteDTO) {
return smartWriteService.smartCreate(smartWriteDTO);
}
@PostMapping("/write")
@ApiOperation("智能文案导出")
public void smartWrite(HttpServletResponse response, @RequestBody SmartWriteDTO smartWriteDTO) {
smartWriteService.smartWrite(response, smartWriteDTO);
}
}

@ -1,12 +1,13 @@
package com.baiye.dao;
import com.baiye.entity.Source;
import com.baiye.entity.LinkReport;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author jt
* @author wjt
* @date 2023/3/31
*/
@Mapper
public interface SourceMapper extends BaseMapper<Source> {
public interface LinkReportMapper extends BaseMapper<LinkReport> {
}

@ -0,0 +1,17 @@
package com.baiye.dao;
import com.baiye.entity.LinkWatch;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author wjt
* @date 2023/3/28
*/
@Mapper
public interface LinkWatchMapper extends BaseMapper<LinkWatch> {
void insertAll(@Param("list") List<LinkWatch> list);
}

@ -0,0 +1,18 @@
package com.baiye.dao;
import com.baiye.entity.LinkWatch;
import com.baiye.entity.SchedulingJob;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author wjt
* @date 2023/3/30
*/
@Mapper
public interface SchedulingJobMapper extends BaseMapper<SchedulingJob> {
void insertAll(@Param("list") List<SchedulingJob> list);
}

@ -1,12 +0,0 @@
package com.baiye.dao;
import com.baiye.entity.SourceOrganize;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author jt
*/
@Mapper
public interface SourceOrganizeMapper extends BaseMapper<SourceOrganize> {
}

@ -1,21 +0,0 @@
package com.baiye.dao;
import com.baiye.entity.Template;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author jt
*/
@Mapper
public interface TemplateMapper extends BaseMapper<Template> {
/**
*
*
* @param list
*/
void insertAll(@Param("list") List<Template> list);
}

@ -1,30 +0,0 @@
package com.baiye.dao;
import com.baiye.dto.SourceVariableDTO;
import com.baiye.entity.Variable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* @author jt
*/
@Mapper
public interface VariableMapper extends BaseMapper<Variable> {
/**
*
*
* @param list
*/
void insertAll(@Param("list") List<Variable> list);
/**
*
*
* @param list
*/
void updateBatch(@Param("list") List<SourceVariableDTO> list);
}

@ -0,0 +1,31 @@
package com.baiye.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author wjt
* @date 2023/3/28
*/
@Data
public class LinkWatchDTO {
@NotNull
@ApiModelProperty("类型 1-笔记 2-博主")
private Integer type;
@NotNull
@ApiModelProperty("链接 数组")
private List<String> links;
@NotNull
@ApiModelProperty("定时频率 1-一次 2-半小时 3-一小时 4-六小时 5-十二小时")
private Integer reportFrequency;
@NotNull
@ApiModelProperty(" 统计周期 1-一次 2-1天 3-7天 4-15天 5-30天")
private Integer reportPeriod;
}

@ -1,37 +0,0 @@
package com.baiye.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.core.parameters.P;
import java.util.List;
/**
* @author jt
*/
@Data
public class SmartWriteDTO {
@ApiModelProperty(value = "手动写入的标题")
private String title;
@ApiModelProperty(value = "传入的标题素材包Id")
private List<Long> sourceId;
@ApiModelProperty(value = "是否智能生成")
private Boolean isCreate;
@ApiModelProperty(value = "文字素材包id")
private List<Long> wordSources;
@ApiModelProperty(value = "图片素材包id")
private List<Long> pictureSources;
@ApiModelProperty(value = "redis缓存的key")
private String redisKey;
@ApiModelProperty(value = "导出的文案数量")
private Integer num;
}

@ -1,14 +0,0 @@
package com.baiye.dto;
import lombok.Data;
/**
* @author jt
*/
@Data
public class SmartWriteExportDTO {
private String title;
private String content;
private String picTrue;
}

@ -1,53 +0,0 @@
package com.baiye.dto;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
* @author jt
*/
@Data
public class SourceDTO {
/**
* id
*/
@ApiModelProperty(value = "素材包id 为空就是新增")
private Long id;
@NotNull
@ApiModelProperty(value = "素材包名称")
private String sourceName;
@ApiModelProperty(value = "素材描述")
private String sourceRemark;
@NotNull
@ApiModelProperty(value = "素材类型 1-图片 2-文字 3-文字模板")
private Integer sourceType;
@NotNull
@ApiModelProperty(value = "组id")
private Long organizeId;
@ApiModelProperty(value = "素材模板")
private List<String> templateContent;
@ApiModelProperty(value = "文字变量对象")
private List<VariableTemplateContentDTO> variableTemplateContentDTO;
@ApiModelProperty(value = "需要删除的模板id")
private List<Long> deleteTemplateIds;
@Data
public static class VariableTemplateContentDTO {
@ApiModelProperty(value = "文字变量模板")
private String variableTemplateContent;
@ApiModelProperty(value = "变量")
private List<SourceVariableDTO> sourceVariableDTO;
}
}

@ -1,21 +0,0 @@
package com.baiye.dto;
import com.baiye.core.constant.AddGroup;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author jt
*/
@Data
public class SourceOrganizeDTO {
@ApiModelProperty(value = "组名")
@NotNull(groups = AddGroup.class)
private String organizeName;
@ApiModelProperty(value = "组描述")
private String organizeRemark;
}

@ -1,28 +0,0 @@
package com.baiye.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author jt
*/
@Data
public class SourceVariableDTO {
@ApiModelProperty(value = "变量id")
private Long id;
@NotNull
@ApiModelProperty(value = "序号")
private String number;
@NotNull
@ApiModelProperty(value = "模板id")
private Long templateId;
@NotNull
@ApiModelProperty(value = "变量内容")
private String variableContent;
}

@ -19,13 +19,18 @@ import java.util.Date;
@ApiOperation("城市信息")
public class CityInfo implements Serializable {
@TableId
@ApiModelProperty(value = "")
private String id;
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "nid")
private String nid;
@ApiModelProperty(value = "城市")
private String city;
@ApiModelProperty(value = "1-xhs ")
private Integer type;
@ApiModelProperty(value = "创建人")
private String createBy;

@ -11,26 +11,30 @@ import java.io.Serializable;
import java.util.Date;
/**
* @author jt
* @author wjt
* @date 2023/3/28
*/
@Data
@TableName("tb_source_organize")
@ApiOperation("资源 素材包 组")
public class SourceOrganize implements Serializable {
@TableName("tb_link_report")
@ApiOperation("链接统计信息")
public class LinkReport implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "ID", hidden = true)
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "组名称")
private String organizeName;
@ApiModelProperty(value = "链接")
private String link;
@ApiModelProperty(value = "组描述")
private String organizeRemark;
@ApiModelProperty(value = "收藏数")
private Integer collectNum;
@ApiModelProperty(value = "点赞数")
private Integer likeNum;
@ApiModelProperty(value = "评论数")
private Integer commentNum;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人")
private Long createBy;
}

@ -0,0 +1,42 @@
package com.baiye.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author wjt
* @date 2023/3/28
*/
@Data
@TableName("tb_link_watch")
@ApiOperation("链接监听信息")
public class LinkWatch implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "链接")
private String link;
@ApiModelProperty(value = "类型 1-笔记 2-博主信息")
private Integer type;
@ApiModelProperty(value = "状态 0-false 1-true")
private Integer status;
@ApiModelProperty(value = "定时频率 1-一次 2-半小时 3-一小时 4-六小时 5-十二小时")
private Integer reportFrequency;
@ApiModelProperty(value = "统计周期 1-一次 2-1天 3-7天 4-15天 5-30天")
private Integer reportPeriod;
@ApiModelProperty(value = "创建时间")
private Date createTime;
}

@ -0,0 +1,43 @@
package com.baiye.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author wjt
* @date 2023/3/30
*/
@Data
@TableName("tb_scheduling_job")
public class SchedulingJob implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "id")
private Long id;
@ApiModelProperty(value = "任务名")
private String jobName;
@ApiModelProperty(value = "表达式")
private String cron;
@ApiModelProperty(value = "参数 ")
private String jobParameter;
@ApiModelProperty(value = "执行实例类路径")
private String jobClass;
@ApiModelProperty(value = "状态 0-false 1-true")
private Integer status;
@ApiModelProperty(value = "创建时间")
private Date createTime;
}

@ -1,69 +0,0 @@
package com.baiye.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* @author jt
*/
@Data
@TableName("tb_source")
@ApiOperation("资源 素材包")
public class Source implements Serializable {
private static final long serialVersionUID = -7281246000750520229L;
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
@ApiModelProperty(value = "素材包名称")
private String sourceName;
@ApiModelProperty(value = "类型 1-文字模板 2-图片 3-文字变量模板")
private Integer sourceType;
@ApiModelProperty(value = "素材包描述")
private String sourceRemark;
@ApiModelProperty(value = "素材组id")
private Long organizeId;
@ApiModelProperty(value = "状态 0-停用 1-启用")
private Integer status;
@ApiModelProperty(value = "状态改变时间 0-停用 1-启用 默认启用")
private Date statusTime;
@ApiModelProperty(value = "创建人")
private Long createBy;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@TableField(exist = false)
@ApiModelProperty(value = "时间处理回显")
private String useTime;
@TableField(exist = false)
@ApiModelProperty(value = "模板回显")
private List<Template> templateContent;
@TableField(exist = false)
@ApiModelProperty(value = "组名回显")
private String organizeName;
@TableField(exist = false)
@ApiModelProperty(value = "创建人")
private String createName;
}

@ -1,39 +0,0 @@
package com.baiye.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author jt
*/
@Data
@TableName("tb_template")
@ApiOperation("模板")
public class Template implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
@ApiModelProperty(value = "素材包id")
private Long sourceId;
@ApiModelProperty(value = "模板内容")
private String templateContent;
@ApiModelProperty(value = "类型 1-文字模板 2-图片 3-文字变量模板")
private int templateType;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人")
private Long createBy;
}

@ -1,40 +0,0 @@
package com.baiye.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;
/**
* @author jt
*/
@Data
@TableName("tb_variable")
@ApiOperation("变量库")
public class Variable implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
@ApiModelProperty(value = "ID", hidden = true)
private Long id;
@ApiModelProperty(value = "变量序号")
private String number;
@ApiModelProperty(value = "模板id")
private Long templateId;
@ApiModelProperty(value = "变量内容")
private String variableContent;
@ApiModelProperty(value = "创建时间")
private Date createTime;
@ApiModelProperty(value = "创建人")
private Long createBy;
}

@ -0,0 +1,33 @@
package com.baiye.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* @author wjt
* @date 2023/3/31
*/
@Getter
@RequiredArgsConstructor
public enum LinkWatchFrequencyEnum {
/**
*
*/
ONE(1, "即时一次"),
THIRTY_MINUTE(2, "半小时一次"),
ONE_HOUR(3, "一小时一次"),
SIX_HOUR(4, "六小时一次"),
TWELVE_HOUR(5, "十二小时一次"),
;
private final Integer key;
private final String value;
public static String findValue(Integer key) {
for (LinkWatchFrequencyEnum linkWatchEnum : LinkWatchFrequencyEnum.values()) {
if (key.equals(linkWatchEnum.key)) {
return linkWatchEnum.getValue();
}
}
return "";
}
}

@ -0,0 +1,33 @@
package com.baiye.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
/**
* @author wjt
* @date 2023/3/31
*/
@Getter
@RequiredArgsConstructor
public enum LinkWatchPeriodEnum {
/**
*
*/
ONE(1, "即时一次"),
ONE_DAY(2, "持续监控1天"),
SEVEN_DAY(3, "持续监控7天"),
FIFTEEN_DAY(4, "持续监控15天"),
THIRTY_DAY(5, "持续监控30天"),
;
private final Integer key;
private final String value;
public static String findValue(Integer key) {
for (LinkWatchPeriodEnum linkWatchPeriodEnum : LinkWatchPeriodEnum.values()) {
if (key.equals(linkWatchPeriodEnum.key)) {
return linkWatchPeriodEnum.getValue();
}
}
return "";
}
}

@ -1,23 +0,0 @@
package com.baiye.query;
import com.baiye.annotation.Query;
import com.baiye.annotation.type.SelectType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author jt
*/
@Data
public class SourceOrganizeQuery {
@TableId(type = IdType.INPUT)
@ApiModelProperty(value = "资源组id")
private Long id;
@Query(type = SelectType.INNER_LIKE)
@ApiModelProperty(value = "组名称")
private String organizeName;
}

@ -1,38 +0,0 @@
package com.baiye.query;
import com.baiye.annotation.Query;
import com.baiye.annotation.type.SelectType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.util.List;
/**
* @author jt
*/
@Data
public class SourceQuery {
@TableId(type = IdType.INPUT)
@ApiModelProperty(value = "素材包id")
private Long id;
@Query(type = SelectType.INNER_LIKE)
@ApiModelProperty(value = "素材包名称")
private String sourceName;
@Query(type = SelectType.INNER_LIKE)
@ApiModelProperty(value = "类型 1-文字模板 2-图片 3-文字变量模板")
private String sourceType;
@Query
@ApiModelProperty(value = "组id")
private Long organizeId;
@ApiModelProperty(value = "排序")
private Boolean timeSort;
}

@ -1,36 +0,0 @@
package com.baiye.query;
import com.baiye.annotation.Query;
import com.baiye.annotation.type.SelectType;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author jt
*/
@Data
public class SourceVariableQuery {
/**
* id
*/
@TableId(type = IdType.INPUT)
@ApiModelProperty(value = "变量id")
private Long id;
/**
*
*/
@Query
@ApiModelProperty(value = "序号")
private String number;
/**
*
*/
@Query
@ApiModelProperty(value = "模板id")
private Long templateId;
}

@ -1,50 +0,0 @@
package com.baiye.request;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author jt
*/
@Component
public class RequestBaiDuApi {
private final static String ACCESS_TOKEN = "24.acf7f7d6cc7aa4c4d1cd21414d4447d8.2592000.1679125865.282335-30477410";
public List<String> requestApi(String doc) {
List<String> list = new ArrayList<>();
String url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/titlepredictor?access_token=" + ACCESS_TOKEN + "&charset=UTF-8";
Map<String, String> map = new HashMap<>(1);
map.put("doc", doc);
String httpResponse = sendCallReq(JSONUtil.toJsonStr(map), url);
JSONObject json = JSONUtil.parseObj(httpResponse);
if (json.getJSONArray("reference_titles") != null) {
JSONArray referenceTitles = json.getJSONArray("reference_titles");
for (int i = 0; i < referenceTitles.size(); i++) {
JSONObject jsonObject = referenceTitles.getJSONObject(i);
String title = jsonObject.getStr("title");
list.add(title);
}
}
return list;
}
private String sendCallReq(String json, String url) {
return HttpRequest.post(url).
header("Content-Type", "application/json").
header("Accept", "application/json").
body(json).
execute().
body();
}
}

@ -0,0 +1,39 @@
package com.baiye.util;
/**
* @author wjt
* @date 2023/3/29
*/
public class CronUtil {
/**
* @param rate 01234
* @param cycle
*/
public static String createLoopCronExpression(int rate, int cycle) {
String cron = "";
switch (rate) {
case 0:
cron = "0/" + cycle + " * * * * ?";
break;
case 1:
cron = "0 0/" + cycle + " * * * ?";
break;
case 2:
cron = "0 0 0/" + cycle + " * * ?";
break;
case 3:
cron = "0 0 0 1/" + cycle + " * ?";
break;
case 4:
cron = "0 0 0 1 1/" + cycle + " ? ";
break;
case 5:
cron = "0 0 " + cycle + " * * ?";
break;
default:
cron = "0/1 * * * * ?";
break;
}
return cron;
}
}

@ -15,6 +15,11 @@
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.baiye</groupId>
<artifactId>cdp-task</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.baiye</groupId>
<artifactId>cdp-tool-xhs-core</artifactId>

@ -0,0 +1,41 @@
package com.baiye.job;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baiye.dao.SchedulingJobMapper;
import com.baiye.entity.SchedulingJob;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.Job;
import com.example.serive.impl.JobServiceImpl;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
/**
* @author wjt
* @date 2023/3/30
* zookeeper
*/
@Component
@Order(value = 1)
public class InitialJobTask extends JobServiceImpl implements ApplicationRunner {
@Resource
private SchedulingJobMapper schedulingJobMapper;
@Override
public void run(ApplicationArguments args) throws Exception {
List<SchedulingJob> schedulingJobs = schedulingJobMapper.selectList(new QueryWrapper<SchedulingJob>().eq("status", "1"));
if (CollUtil.isNotEmpty(schedulingJobs)) {
for (SchedulingJob schedulingJob : schedulingJobs) {
Job job = new Job();
BeanUtil.copyProperties(schedulingJob, job);
addJob(job);
}
}
}
}

@ -0,0 +1,29 @@
package com.baiye.job;
import com.baiye.service.LinkWatchService;
import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
/**
* @author wjt
* @date 2023/3/30
*/
@Slf4j
@Component
public class LinkWatchJob implements SimpleJob {
@Resource
private LinkWatchService linkWatchService;
@Override
public void execute(ShardingContext shardingContext) {
String jobParameter = shardingContext.getJobParameter();
linkWatchService.carryReport(jobParameter);
}
}

@ -11,5 +11,5 @@ public interface CityInfoService {
String queryCity(String nid);
Result<Object> addCity(MultipartFile file);
Result<Object> addCity(MultipartFile file, Integer type);
}

@ -0,0 +1,21 @@
package com.baiye.service;
import com.baiye.core.base.api.Result;
import com.baiye.dto.LinkWatchDTO;
/**
* @author wjt
* @date 2023/3/28
*/
public interface LinkWatchService {
Result<Object> create(LinkWatchDTO linkWatchDTO);
Result<Object> report(String link);
Result<Object> query();
void carryReport(String link);
String test(String link,String param);
}

@ -1,46 +0,0 @@
package com.baiye.service;
import com.baiye.core.base.api.Result;
import com.baiye.dto.OperateVariableDTO;
import com.baiye.query.SourceVariableQuery;
/**
* @author jt
*/
public interface ResourceVariableService {
/**
*
*
* @param sourceVariableQuery
* @return
*/
Result<Object> queryResourceVariable(SourceVariableQuery sourceVariableQuery);
/**
*
*
* @param operateVariableDTO
* @return
*/
Result<Object> addResourceVariable(OperateVariableDTO operateVariableDTO);
/**
*
*
* @param id
* @return
*/
Result<Object> deleteResourceVariable(Long id);
/**
*
*
* @param sourceVariableDTO
* @return
*/
// Result<Object> updateResourceVariable(List<SourceVariableDTO> sourceVariableDTO);
}

@ -1,29 +0,0 @@
package com.baiye.service;
import com.baiye.core.base.api.Result;
import com.baiye.dto.SmartWriteDTO;
import javax.servlet.http.HttpServletResponse;
/**
* @author jt
*/
public interface SmartWriteService {
/**
*
*
* @param smartWriteDTO
* @return
*/
Result<Object> smartCreate(SmartWriteDTO smartWriteDTO);
/**
*
*
* @param response
* @param smartWriteDTO
*
*/
void smartWrite(HttpServletResponse response, SmartWriteDTO smartWriteDTO);
}

@ -1,51 +0,0 @@
package com.baiye.service;
import com.baiye.core.base.api.Result;
import com.baiye.dto.SourceOrganizeDTO;
import com.baiye.entity.SourceOrganize;
import com.baiye.query.SourceOrganizeQuery;
/**
* @author jt
*/
public interface SourceOrganizeService {
/**
*
*
* @param sourceOrganizeQuery
* @return
*/
Result<Object> querySourceOrganize(SourceOrganizeQuery sourceOrganizeQuery);
/**
*
*
* @param sourceOrganizeDTO
* @return
*/
Result<Object> addSourceOrganize(SourceOrganizeDTO sourceOrganizeDTO);
/**
*
*
* @param id
* @return
*/
Result<Object> deleteSourceOrganize(Long id);
/**
*
*
* @param id
* @return
*/
SourceOrganize queryOrganize(Long id);
/**
*
*
* @param sourceOrganizeName
* @return
*/
Boolean isRepeatSourceOrganizeName(String sourceOrganizeName);
}

@ -1,55 +0,0 @@
package com.baiye.service;
import com.baiye.core.base.api.Result;
import com.baiye.core.page.PageResult;
import com.baiye.dto.SourceDTO;
import com.baiye.query.SourceQuery;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
/**
* @author jt
*/
public interface SourceService {
/**
*
*
* @param sourceQuery
* @param pageable
* @return
*/
PageResult querySource(SourceQuery sourceQuery, Pageable pageable);
/**
*
*
* @param file
* @param sourceDTO
* @return
*/
Result<Object> addSource(MultipartFile file, SourceDTO sourceDTO);
/**
*
*
* @param id
* @return
*/
Result<Object> deleteSource(Long id);
/**
*
*
* @param id
* @return
*/
Result<Object> changeStatus(Long id);
/**
*
*
* @param name
* @return
*/
Boolean isRepeatSourceName(String name);
}

@ -29,7 +29,6 @@ import java.util.*;
@Slf4j
public class CityInfoServiceImpl extends ServiceImpl<CityInfoMapper, CityInfo> implements CityInfoService {
private final CityInfoMapper cityInfoMapper;
@Override
public String queryCity(String nid) {
CityInfo cityInfo = cityInfoMapper.selectById(nid);
@ -40,10 +39,10 @@ public class CityInfoServiceImpl extends ServiceImpl<CityInfoMapper, CityInfo> i
}
@Override
public Result<Object> addCity(MultipartFile file) {
public Result<Object> addCity(MultipartFile file, Integer type) {
try {
String type = FileUtil.getExtensionName(file.getOriginalFilename());
boolean contain = Arrays.asList(DefaultFileTypeConstants.EXCEL).contains(type);
String fileType = FileUtil.getExtensionName(file.getOriginalFilename());
boolean contain = Arrays.asList(DefaultFileTypeConstants.EXCEL).contains(fileType);
if (contain) {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<List<Object>> read = reader.read();
@ -53,8 +52,9 @@ public class CityInfoServiceImpl extends ServiceImpl<CityInfoMapper, CityInfo> i
CityInfo cityInfo = new CityInfo();
String nid = objects.get(0).toString();
String city = objects.get(1).toString();
cityInfo.setId(nid);
cityInfo.setNid(nid);
cityInfo.setCity(city);
cityInfo.setType(type);
cityInfo.setCreateBy(null);
cityInfo.setCreateTime(DateUtil.date());
cityInfos.add(cityInfo);

@ -0,0 +1,168 @@
package com.baiye.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import com.baiye.BadRequestException;
import com.baiye.core.base.api.Result;
import com.baiye.dao.LinkReportMapper;
import com.baiye.dao.LinkWatchMapper;
import com.baiye.dao.SchedulingJobMapper;
import com.baiye.dto.LinkWatchDTO;
import com.baiye.entity.LinkReport;
import com.baiye.entity.LinkWatch;
import com.baiye.entity.SchedulingJob;
import com.baiye.enums.LinkWatchFrequencyEnum;
import com.baiye.enums.LinkWatchPeriodEnum;
import com.baiye.service.ArticleService;
import com.baiye.service.LinkWatchService;
import com.baiye.util.CronUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.entity.Job;
import com.example.serive.impl.JobServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author wjt
* @date 2023/3/28
*/
@Service
@RequiredArgsConstructor
public class LinkWatchServiceImpl extends JobServiceImpl implements LinkWatchService {
private final LinkWatchMapper linkWatchMapper;
private final SchedulingJobMapper schedulingJobMapper;
private final ArticleService articleService;
private final LinkReportMapper linkReportMapper;
@Override
@Transactional(rollbackOn = Exception.class)
public Result<Object> create(LinkWatchDTO linkWatchDTO) {
List<LinkWatch> list = new ArrayList<>();
List<SchedulingJob> listJob = new ArrayList<>();
for (String s : linkWatchDTO.getLinks()) {
//查看是否重复
LinkWatch linkWatch1 = linkWatchMapper.selectOne(new QueryWrapper<LinkWatch>().eq("link", s));
if (ObjectUtil.isNotNull(linkWatch1)) {
continue;
}
LinkWatch linkWatch = new LinkWatch();
BeanUtil.copyProperties(linkWatchDTO, linkWatch);
linkWatch.setLink(s);
linkWatch.setStatus(1);
linkWatch.setCreateTime(DateUtil.date());
list.add(linkWatch);
//处理cron表达式
if (linkWatch.getReportFrequency() != 1 && linkWatch.getReportPeriod() != 1) {
//todo ==1 即时处理一次 单独处理 carryReport(s);
//创建定时任务对象
Job job = new Job();
job.setJobName("LinkWatchJob" + RandomUtil.randomString(6));
job.setCron(dealTaskCron(linkWatch.getReportFrequency()));
job.setJobParameter(s);
job.setJobClass("com.baiye.job.LinkWatchJob");
//zookeeper中注入
addJob(job);
//持久化
// SchedulingJob schedulingJob = new SchedulingJob();
// BeanUtil.copyProperties(job, schedulingJob);
// schedulingJob.setStatus(1);
// schedulingJob.setCreateTime(DateUtil.date());
// listJob.add(schedulingJob);
} else {
carryReport(s);
}
}
if (CollUtil.isNotEmpty(list)) {
linkWatchMapper.insertAll(list);
}
if (CollUtil.isNotEmpty(listJob)) {
schedulingJobMapper.insertAll(listJob);
}
return Result.success();
}
@Override
public Result<Object> report(String link) {
Map<String, Object> map = new HashMap<>();
//统计情况
List<LinkReport> link1 = linkReportMapper.selectList(new QueryWrapper<LinkReport>().eq("link", link));
if (CollUtil.isEmpty(link1)) {
return Result.data(map);
}
//监控情况
LinkWatch linkWatch = linkWatchMapper.selectOne(new QueryWrapper<LinkWatch>().eq("link", link));
String value = LinkWatchFrequencyEnum.findValue(linkWatch.getReportFrequency());
String value1 = LinkWatchPeriodEnum.findValue(linkWatch.getReportPeriod());
map.put("report", link1);
map.put("creatTime",DateUtil.formatChineseDate(linkWatch.getCreateTime(), false,false)+""+DateUtil.format(linkWatch.getCreateTime(),"HH:mm:ss"));
map.put("param", value + "," + value1);
map.put("firstTime",DateUtil.formatChineseDate(link1.get(0).getCreateTime(), false,false)+""+DateUtil.format(linkWatch.getCreateTime(),"HH:mm:ss"));
return Result.data(map);
}
@Override
public Result<Object> query() {
return Result.data(linkWatchMapper.selectList(new QueryWrapper<LinkWatch>().eq("status", 1)));
}
/**
*
*
* @param link
*/
@Override
public void carryReport(String link) {
// Map<String, String> articleContent = articleService.getArticleContentByUrl(link);
// String likeNum = articleContent.get("likeNum");
// String collectNum = articleContent.get("collectNum");
// String commentNum = articleContent.get("commentNum");
String likeNum = "100";
String collectNum = "60";
String commentNum = "120";
LinkReport linkReport = new LinkReport();
linkReport.setLink(link);
linkReport.setCollectNum(Integer.valueOf(collectNum));
linkReport.setCommentNum(Integer.valueOf(commentNum));
linkReport.setLikeNum(Integer.valueOf(likeNum));
linkReport.setCreateTime(DateUtil.date());
}
private static String dealTaskCron(Integer reportFrequency) {
switch (reportFrequency) {
case 2:
return CronUtil.createLoopCronExpression(1, 30);
case 3:
return CronUtil.createLoopCronExpression(2, 1);
case 4:
return CronUtil.createLoopCronExpression(2, 6);
case 5:
return CronUtil.createLoopCronExpression(2, 12);
default:
throw new BadRequestException("请输入正确的统计频率");
}
}
@Override
public String test(String link, String param) {
Job job = new Job();
job.setJobName("LinkWatchJob-" + RandomUtil.randomString(6));
job.setCron("0/5 * * * * ? ");
job.setJobParameter(param);
job.setJobClass("com.baiye.job.LinkWatchJob");
//zookeeper中注入
addJob(job);
return "成功";
}
}

@ -1,66 +0,0 @@
package com.baiye.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.baiye.core.base.api.Result;
import com.baiye.dao.VariableMapper;
import com.baiye.dto.OperateVariableDTO;
import com.baiye.entity.Variable;
import com.baiye.query.SourceVariableQuery;
import com.baiye.service.ResourceVariableService;
import com.baiye.util.QueryHelpUtils;
import com.baiye.util.SecurityUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author jt
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class ResourceVariableServiceImpl implements ResourceVariableService {
private final VariableMapper variableMapper;
@Override
public Result<Object> queryResourceVariable(SourceVariableQuery sourceVariableQuery) {
QueryWrapper<Variable> queryWrapper = QueryHelpUtils.getWrapper(sourceVariableQuery, Variable.class);
List<Variable> sources = variableMapper.selectList(queryWrapper);
return Result.data(sources);
}
@Override
public Result<Object> addResourceVariable(OperateVariableDTO operateVariableDTO) {
if (CollUtil.isNotEmpty(operateVariableDTO.getDeleteIds())) {
variableMapper.deleteBatchIds(operateVariableDTO.getDeleteIds());
}
if (CollUtil.isNotEmpty(operateVariableDTO.getSourceVariableDTO())) {
List<Variable> variables = JSONUtil.toList(JSONUtil.toJsonStr(operateVariableDTO.getSourceVariableDTO()), Variable.class);
variables.forEach(item -> {
item.setCreateTime(DateUtil.date());
item.setCreateBy(SecurityUtils.getCurrentUserId());
});
variableMapper.insertAll(variables);
}
return Result.success("操作成功");
}
@Override
public Result<Object> deleteResourceVariable(Long id) {
variableMapper.deleteById(id);
return Result.success("操作成功");
}
//
// @Override
// @Transactional(rollbackOn = Exception.class)
// public Result<Object> updateResourceVariable(List<SourceVariableDTO> sourceVariable) {
// variableMapper.updateBatch(sourceVariable);
// return Result.success("操作成功");
// }
}

@ -1,256 +0,0 @@
package com.baiye.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.poi.word.Word07Writer;
import com.baiye.core.base.api.Result;
import com.baiye.core.util.RedisUtils;
import com.baiye.dao.TemplateMapper;
import com.baiye.dao.VariableMapper;
import com.baiye.dto.SmartWriteDTO;
import com.baiye.entity.Template;
import com.baiye.entity.Variable;
import com.baiye.BadRequestException;
import com.baiye.properties.FileProperties;
import com.baiye.service.SmartWriteService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hankcs.hanlp.HanLP;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author jt
*/
@Service
@Slf4j
@RequiredArgsConstructor
public class SmartWriteServiceImpl implements SmartWriteService {
private final TemplateMapper templateMapper;
private final VariableMapper variableMapper;
private final RedisUtils redisUtils;
private final FileProperties properties;
@Override
public Result<Object> smartCreate(SmartWriteDTO smartWriteDTO) {
List<Long> wordSources = smartWriteDTO.getWordSources();
List<String> templateList = new ArrayList<>();
List<Template> templates = new ArrayList<>();
for (Long id : wordSources) {
// id 为素材包id
//通过id获取文字模板
templates.addAll(templateMapper.selectList(new QueryWrapper<Template>().eq("source_id", id)));
}
if (CollUtil.isEmpty(templates)) {
return Result.fail("文字模板为空");
}
for (Template template : templates) {
int templateType = template.getTemplateType();
if (templateType == 1) {
templateList.add(template.getTemplateContent());
continue;
}
//变量模板
if (templateType == 3) {
Long id = template.getId();
String templateContent = template.getTemplateContent();
List<Variable> variables = variableMapper.selectList(new QueryWrapper<Variable>().eq("template_id", id));
if (CollUtil.isEmpty(variables)) {
continue;
}
Map<String, String> mapByNumber = variables.stream().collect(Collectors.toMap(Variable::getNumber, Variable::getVariableContent));
List<String> deal = new ArrayList<>();
int count = (templateContent + " ").split("&v&").length - 1;
if (count == 1) {
deal = deal(mapByNumber, templateContent);
} else if (count == 0) {
deal.add(templateContent);
} else {
Map<String, String[]> map = new HashMap<>(4);
//切割变量
for (String key : mapByNumber.keySet()) {
String s = mapByNumber.get(key);
String[] split = s.split("\\\\");
map.put(key, split);
}
String collect = String.join("", map.keySet());
deal = letterCombinations(collect, map, templateContent.replace("&v&", "{}"));
}
templateList.addAll(deal);
}
}
String redisKey = RandomUtil.randomString(8);
redisUtils.set(redisKey, templateList, 60 * 60);
Map<String, Object> data = new HashMap<>(1);
data.put("redisKey", redisKey);
data.put("num", templateList.size());
return Result.data(data);
}
@Override
public void smartWrite(HttpServletResponse response, SmartWriteDTO smartWriteDTO) {
Random rand = new Random();
Object value = redisUtils.get(smartWriteDTO.getRedisKey());
if (value == null) {
throw new BadRequestException("超时操作,请重新生成物料");
}
List<String> templateList = JSONUtil.toList(JSONUtil.toJsonStr(value), String.class);
Collections.shuffle(templateList);
int num = smartWriteDTO.getNum();
if (num > templateList.size()) {
num = templateList.size();
}
//需要生成文案的文字模板
List<String> randomSeries = templateList.subList(0, num);
//获取图片地址
List<Template> picTrueTemplates = new ArrayList<>();
List<String> picTrues = new ArrayList<>();
if (CollUtil.isNotEmpty(smartWriteDTO.getPictureSources())) {
for (Long id : smartWriteDTO.getPictureSources()) {
// id 为素材包id
//通过id获取文字模板
picTrueTemplates.addAll(templateMapper.selectList(new QueryWrapper<Template>().eq("source_id", id)));
picTrues = picTrueTemplates.stream().map(Template::getTemplateContent).collect(Collectors.toList());
}
}
//写文件
Word07Writer writer = new Word07Writer();
for (String templateContent : randomSeries) {
if (CollUtil.isNotEmpty(picTrues)) {
//添加图片
getFile(picTrues, writer, rand);
}
// 添加段落(标题)
if (smartWriteDTO.getSourceId() != null) {
List<Long> sourceIds = smartWriteDTO.getSourceId();
List<Template> templates = new ArrayList<>();
for (Long id : sourceIds) {
templates.addAll(templateMapper.selectList(new QueryWrapper<Template>().eq("source_id", id)));
}
List<String> titles = templates.stream().map(Template::getTemplateContent).collect(Collectors.toList());
String title = getTitle(titles, smartWriteDTO.getIsCreate(), templateContent);
writer.addText(new Font("方正小标宋简体", Font.PLAIN, 36), title);
}
// 添加段落(正文)
writer.addText(new Font("宋体", Font.PLAIN, 22), templateContent);
}
try {
//输出到页面下载
ServletOutputStream os = response.getOutputStream();
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
String fileName = "write.docx";
response.setHeader("Content-Disposition", "attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
writer.flush(os);
os.close();
} catch (IOException e) {
e.printStackTrace();
}
writer.close();
}
private void getFile(List<String> picTrues, Word07Writer writer, Random rand) {
if (CollUtil.isNotEmpty(picTrues)) {
String path = picTrues.get(rand.nextInt(picTrues.size()));
File file = FileUtil.file(properties.getPath().getAvatar() + path);
try {
writer.addPicture(file, 350, 250);
} catch (Exception e) {
log.error("图片地址不存在:{}", path);
picTrues.removeIf(s -> s.equals(path));
getFile(picTrues, writer, rand);
}
}
}
private String getTitle(List<String> titles, Boolean isCreate, String templateContent) {
Random rand = new Random();
String title = titles.get(rand.nextInt(titles.size()));
String[] split = title.split("&v&");
if (isCreate) {
if (split.length > 1) {
List<String> mainIdea = getMainIdea(templateContent, split.length - 1);
return StrUtil.format(title.replace("&v&", "{}"), mainIdea.toArray());
}
return title;
} else {
if (split.length <= 1) {
return title;
} else {
titles.removeIf(s -> s.equals(title));
getTitle(titles, false, templateContent);
}
}
return null;
}
public static List<String> deal(Map<String, String> mapByNumber, String text) {
List<String> list = new ArrayList<>();
String[] split = null;
for (String value : mapByNumber.values()) {
split = value.split("\\\\");
}
if (split != null) {
for (String s : split) {
String replace = text.replace("&v&", s);
list.add(replace);
}
}
return list;
}
public static List<String> letterCombinations(String digits, Map<String, String[]> phoneMap, String text) {
List<String> combinations = new ArrayList<>();
if (digits.length() == 0) {
return combinations;
}
backtrack(combinations, phoneMap, text, digits, 0, new StringBuffer());
return combinations;
}
public static void backtrack(List<String> combinations, Map<String, String[]> phoneMap, String text, String digits, int index, StringBuffer combination) {
if (index == digits.length()) {
String[] split = combination.toString().split("");
String format = StrUtil.format(text, CollUtil.toList(split).toArray());
combinations.add(format);
} else {
String string = String.valueOf(index + 1);
String[] strings = phoneMap.get(string);
for (String s : strings) {
combination.append(s);
backtrack(combinations, phoneMap, digits, text, index + 1, combination);
combination.deleteCharAt(index);
}
}
}
/**
*
*
* @param content
* @param size
*/
public List<String> getMainIdea(String content, Integer size) {
return HanLP.extractKeyword(content, size);
}
}

@ -1,67 +0,0 @@
package com.baiye.service.impl;
import com.baiye.core.base.api.Result;
import com.baiye.dao.SourceOrganizeMapper;
import com.baiye.dto.SourceOrganizeDTO;
import com.baiye.entity.SourceOrganize;
import com.baiye.BadRequestException;
import com.baiye.query.SourceOrganizeQuery;
import com.baiye.service.SourceOrganizeService;
import com.baiye.util.QueryHelpUtils;
import com.baiye.util.SecurityUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
* @author jt
*/
@Service
@RequiredArgsConstructor
public class SourceOrganizeServiceImpl implements SourceOrganizeService {
private final SourceOrganizeMapper sourceOrganizeMapper;
@Override
public Result<Object> querySourceOrganize(SourceOrganizeQuery sourceOrganizeQuery) {
QueryWrapper<SourceOrganize> queryWrapper = QueryHelpUtils.getWrapper(sourceOrganizeQuery, SourceOrganize.class);
List<SourceOrganize> sourceOrganizes = sourceOrganizeMapper.selectList(queryWrapper);
return Result.data(sourceOrganizes);
}
@Override
public Result<Object> addSourceOrganize(SourceOrganizeDTO sourceOrganizeDTO) {
Boolean repeatSourceOrganizeName = isRepeatSourceOrganizeName(sourceOrganizeDTO.getOrganizeName());
if (repeatSourceOrganizeName) {
throw new BadRequestException("名称重复");
}
SourceOrganize sourceOrganize = new SourceOrganize();
sourceOrganize.setOrganizeName(sourceOrganizeDTO.getOrganizeName());
sourceOrganize.setOrganizeRemark(sourceOrganizeDTO.getOrganizeRemark());
sourceOrganize.setCreateTime(new Date());
sourceOrganize.setCreateBy(SecurityUtils.getCurrentUserId());
sourceOrganizeMapper.insert(sourceOrganize);
return Result.success("新增成功");
}
@Override
public Result<Object> deleteSourceOrganize(Long id) {
sourceOrganizeMapper.deleteById(id);
return Result.success("删除成功");
}
@Override
public Boolean isRepeatSourceOrganizeName(String name) {
Integer organizeName = sourceOrganizeMapper.selectCount(new QueryWrapper<SourceOrganize>().eq("organize_name", name));
return organizeName > 0;
}
@Override
@Cacheable(cacheNames = "sourceOrganizeCache", key = "#id")
public SourceOrganize queryOrganize(Long id) {
return sourceOrganizeMapper.selectById(id);
}
}

@ -1,351 +0,0 @@
package com.baiye.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.BetweenFormatter;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baiye.core.base.api.Result;
import com.baiye.core.page.PageResult;
import com.baiye.dao.SourceMapper;
import com.baiye.dao.TemplateMapper;
import com.baiye.dao.VariableMapper;
import com.baiye.dto.SourceDTO;
import com.baiye.dto.SourceVariableDTO;
import com.baiye.entity.Source;
import com.baiye.entity.SourceOrganize;
import com.baiye.entity.Template;
import com.baiye.entity.Variable;
import com.baiye.BadRequestException;
import com.baiye.feign.UserFeignService;
import com.baiye.query.SourceQuery;
import com.baiye.service.SourceOrganizeService;
import com.baiye.service.SourceService;
import com.baiye.util.PageUtils;
import com.baiye.util.QueryHelpUtils;
import com.baiye.util.SecurityUtils;
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.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.transaction.Transactional;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author jt
*/
@Service
@RequiredArgsConstructor
@Slf4j
public class SourceServiceImpl implements SourceService {
private final SourceMapper sourceMapper;
private final TemplateMapper templateMapper;
private final VariableMapper variableMapper;
private final SourceOrganizeService sourceOrganizeService;
private final UserFeignService userFeignService;
@Override
public PageResult querySource(SourceQuery sourceQuery, Pageable pageable) {
if (sourceQuery.getTimeSort() == null) {
sourceQuery.setTimeSort(false);
}
Page<Source> page = PageUtils.startPageAndSort(pageable);
QueryWrapper<Source> queryWrapper = Objects.requireNonNull(QueryHelpUtils.getWrapper(sourceQuery, Source.class)).orderBy(true, sourceQuery.getTimeSort(), "create_time", "status_time");
IPage<Source> selectPage = sourceMapper.selectPage(page, queryWrapper);
for (Source source : selectPage.getRecords()) {
Date statusTime = source.getStatusTime();
String formatBetween = DateUtil.formatBetween(statusTime, DateUtil.date(), BetweenFormatter.Level.MINUTE);
source.setUseTime(formatBetween);
List<Template> templates = templateMapper.selectList(new QueryWrapper<Template>().eq("source_id", source.getId()));
source.setTemplateContent(templates);
SourceOrganize sourceOrganize = sourceOrganizeService.queryOrganize(source.getOrganizeId());
source.setOrganizeName(sourceOrganize.getOrganizeName());
Long createBy = source.getCreateBy();
source.setCreateName(findById(createBy));
}
return PageResult.success(selectPage.getTotal(), selectPage.getPages(), selectPage.getRecords());
}
@Override
@Transactional(rollbackOn = Exception.class)
public Result<Object> addSource(MultipartFile file, SourceDTO sourceDTO) {
Boolean repeatSourceName = isRepeatSourceName(sourceDTO.getSourceName());
if (sourceDTO.getSourceType() == null || sourceDTO.getOrganizeId() == null) {
throw new BadRequestException("素材包类型或分组不能为空");
}
Source source = new Source();
// id不为空则是修改, id为空则是新增
if (sourceDTO.getId() == null) {
if (repeatSourceName) {
throw new BadRequestException("名称重复");
}
source.setSourceName(sourceDTO.getSourceName());
source.setSourceRemark(sourceDTO.getSourceRemark());
source.setSourceType(sourceDTO.getSourceType());
source.setCreateBy(SecurityUtils.getCurrentUserId());
source.setCreateTime(new Date());
source.setStatus(1);
source.setStatusTime(new Date());
source.setOrganizeId(sourceDTO.getOrganizeId());
sourceMapper.insert(source);
} else {
source.setSourceName(sourceDTO.getSourceName());
source.setId(sourceDTO.getId());
source.setSourceRemark(sourceDTO.getSourceRemark());
source.setOrganizeId(sourceDTO.getOrganizeId());
source.setSourceType(sourceDTO.getSourceType());
sourceMapper.updateById(source);
}
//图片素材
if (sourceDTO.getSourceType() == 2) {
if (CollUtil.isNotEmpty(sourceDTO.getTemplateContent()) && sourceDTO.getTemplateContent().size() > 0) {
List<Template> list = new ArrayList<>();
for (String pic : sourceDTO.getTemplateContent()) {
Template template = new Template();
template.setSourceId(source.getId());
template.setTemplateContent(pic);
template.setTemplateType(source.getSourceType());
template.setCreateTime(new Date());
template.setCreateBy(SecurityUtils.getCurrentUserId());
list.add(template);
}
templateMapper.insertAll(list);
}
} else if (sourceDTO.getSourceType() == 3) {
//文字变量模板
addSourceByVariable(sourceDTO, source.getId(), source.getSourceType(), file);
} else {
//文字素材 和标题模板
addSourceByWord(sourceDTO, source.getId(), source.getSourceType(), file);
}
if (CollUtil.isNotEmpty(sourceDTO.getDeleteTemplateIds())) {
templateMapper.deleteBatchIds(sourceDTO.getDeleteTemplateIds());
if (sourceDTO.getSourceType() == 3) {
for (Long templateId : sourceDTO.getDeleteTemplateIds()) {
QueryWrapper<Variable> wrapper = new QueryWrapper<Variable>().in("template_id", templateId);
variableMapper.delete(wrapper);
}
}
}
return Result.success("操作成功");
}
@Override
@Transactional(rollbackOn = Exception.class)
public Result<Object> deleteSource(Long id) {
Source source = sourceMapper.selectById(id);
//模板
List<Template> templates = templateMapper.selectList(new QueryWrapper<Template>().eq("source_id", id));
if (CollUtil.isNotEmpty(templates)) {
List<Long> templateIds = templates.stream().map(Template::getId).collect(Collectors.toList());
if (source.getSourceType() == 3 && CollUtil.isNotEmpty(templateIds)) {
for (Long templateId : templateIds) {
QueryWrapper<Variable> wrapper = new QueryWrapper<Variable>().in("template_id", templateId);
variableMapper.delete(wrapper);
}
}
templateMapper.deleteBatchIds(templateIds);
}
sourceMapper.deleteById(id);
return Result.success();
}
@Override
public Result<Object> changeStatus(Long id) {
Source source = sourceMapper.selectById(id);
source.setSourceType(source.getSourceType() == 0 ? 1 : 0);
source.setStatusTime(DateUtil.date());
sourceMapper.updateById(source);
return Result.success();
}
/**
*
*
* @param sourceDTO
* @param sourceId
*/
private void addSourceByWord(SourceDTO sourceDTO, Long sourceId, Integer type, MultipartFile file) {
List<Template> list = new ArrayList<>();
if (CollUtil.isNotEmpty(sourceDTO.getTemplateContent())) {
for (String con : sourceDTO.getTemplateContent()) {
if (StrUtil.isBlank(con)) {
throw new BadRequestException("模板不能为空");
}
Template template = new Template();
template.setSourceId(sourceId);
template.setTemplateType(type);
template.setTemplateContent(con);
template.setCreateTime(new Date());
template.setCreateBy(SecurityUtils.getCurrentUserId());
list.add(template);
}
}
//解析文件
if (ObjectUtil.isNotNull(file) && file.getSize() > 0) {
try {
int lastIndexOf = Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf(".");
String nameFormat = file.getOriginalFilename().substring(lastIndexOf + 1);
if ("xlsx".equals(nameFormat) || "xls".equals(nameFormat)) {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<List<Object>> read = reader.read(1, reader.getRowCount());
for (List<Object> objects : read) {
String number = String.valueOf(objects.get(0));
if (StrUtil.isBlank(number)) {
throw new BadRequestException("文件上传失败,模板不能为空");
}
Template template = new Template();
template.setSourceId(sourceId);
template.setTemplateType(type);
template.setTemplateContent(number);
template.setCreateTime(new Date());
template.setCreateBy(SecurityUtils.getCurrentUserId());
list.add(template);
}
}
} catch (Exception e) {
log.error("读取文件错误:{}", e.getMessage());
throw new BadRequestException("读取文件错误");
}
}
if (CollUtil.isNotEmpty(list)) {
templateMapper.insertAll(list);
}
}
/**
*
*
* @param sourceDTO
* @param sourceId
* @param type
*/
private void addSourceByVariable(SourceDTO sourceDTO, Long sourceId, Integer type, MultipartFile file) {
List<Variable> list = new ArrayList<>();
if (CollUtil.isNotEmpty(sourceDTO.getVariableTemplateContentDTO())) {
for (SourceDTO.VariableTemplateContentDTO con : sourceDTO.getVariableTemplateContentDTO()) {
//变量
List<SourceVariableDTO> sourceVariableDTO = con.getSourceVariableDTO();
//模板
String variableTemplateContent = con.getVariableTemplateContent();
if (StrUtil.isBlank(variableTemplateContent)) {
throw new BadRequestException("模板不能为空");
}
Template template = new Template();
template.setSourceId(sourceId);
template.setTemplateType(type);
template.setTemplateContent(variableTemplateContent);
template.setCreateTime(new Date());
template.setCreateBy(SecurityUtils.getCurrentUserId());
templateMapper.insert(template);
int count = (variableTemplateContent+ " ").split("&v&").length - 1;
if (count > 0) {
if (CollUtil.isEmpty(sourceVariableDTO)) {
throw new BadRequestException("模板变量不能为空");
}
//判断模板占位符和变量是否一致
if (count != sourceVariableDTO.size()) {
throw new BadRequestException("模板占位符和模板变量数量不一致,模板为" + variableTemplateContent);
}
for (SourceVariableDTO sourceVariable : sourceVariableDTO) {
if (sourceVariable.getNumber() == null || sourceVariable.getVariableContent() == null) {
throw new BadRequestException("变量的序号和变量内容不能为空,模板为" + variableTemplateContent);
}
Variable variable = new Variable();
variable.setVariableContent(sourceVariable.getVariableContent());
variable.setNumber(sourceVariable.getNumber());
variable.setTemplateId(template.getId());
variable.setCreateTime(new Date());
variable.setCreateBy(SecurityUtils.getCurrentUserId());
list.add(variable);
}
}
}
}
//解析文件
if (ObjectUtil.isNotNull(file) && file.getSize() > 0) {
try {
int lastIndexOf = Objects.requireNonNull(file.getOriginalFilename()).lastIndexOf(".");
String nameFormat = file.getOriginalFilename().substring(lastIndexOf + 1);
if ("xlsx".equals(nameFormat) || "xls".equals(nameFormat)) {
ExcelReader reader = ExcelUtil.getReader(file.getInputStream());
List<List<Object>> read = reader.read();
for (int index = 1; index < read.size(); index++) {
// for (List<Object> objects : read) {
List<Object> objects = read.get(index);
String variableContent = String.valueOf(objects.get(0));
if (StrUtil.isBlank(variableContent)) {
throw new BadRequestException("文件上传失败,变量模板不能为空");
}
//判断变量模板的变量数量
int count = (variableContent+ " ").split("&v&").length - 1;
if (count != objects.size()-1) {
throw new BadRequestException("文件上传失败,模板占位符和模板变量数量不一致,模板为" + variableContent);
}
Template template = new Template();
template.setSourceId(sourceId);
template.setTemplateType(type);
template.setTemplateContent(variableContent);
template.setCreateTime(new Date());
template.setCreateBy(SecurityUtils.getCurrentUserId());
templateMapper.insert(template);
if (count > 0) {
for (int i = 1; i < objects.size(); i++) {
if (StrUtil.isEmpty(objects.get(i).toString())) {
throw new BadRequestException("变量内容不能为空,模板为" + variableContent);
}
Variable variable = new Variable();
variable.setVariableContent(objects.get(i).toString());
variable.setNumber(String.valueOf(i));
variable.setTemplateId(template.getId());
variable.setCreateTime(new Date());
variable.setCreateBy(SecurityUtils.getCurrentUserId());
list.add(variable);
}
}
}
}
} catch (Exception e) {
throw new BadRequestException("读取文件错误:" + e.getMessage());
}
}
if (CollUtil.isNotEmpty(list)) {
variableMapper.insertAll(list);
}
}
@Override
public Boolean isRepeatSourceName(String name) {
Integer organizeName = sourceMapper.selectCount(new QueryWrapper<Source>().eq("source_name", name));
return organizeName > 0;
}
// @Cacheable(key = "'id:' + #p0")
@Cacheable(cacheNames = "userName", key = "'userId:' + #id")
public String findById(Long id) {
String body = userFeignService.queryByUserId(id).getBody();
if (StrUtil.isNotBlank(body)) {
return body;
}
return null;
}
}

@ -0,0 +1,4 @@
elasticjob:
zookeeper:
namespace: springboot-elasticjob
server-list: localhost:2181

@ -0,0 +1,13 @@
<?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.baiye.dao.LinkWatchMapper">
<insert id="insertAll">
insert into tb_link_watch (id,link,type,status,report_frequency,report_period,create_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id}, #{item.link},#{item.type},#{item.status},#{item.reportFrequency},#{item.reportPeriod},#{item.createTime})
</foreach>
</insert>
</mapper>

@ -0,0 +1,14 @@
<?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.baiye.dao.SchedulingJobMapper">
<insert id="insertAll">
insert into tb_scheduling_job (id,job_name,cron,job_parameter,job_class,status,create_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id},
#{item.jobName},#{item.cron},#{item.jobParameter},#{item.jobClass},#{item.status},#{item.createTime})
</foreach>
</insert>
</mapper>

@ -1,6 +0,0 @@
<?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.baiye.dao.SourceMapper">
</mapper>

@ -1,23 +0,0 @@
<?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.baiye.dao.TemplateMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.baiye.entity.Template">
<id column="id" property="id"/>
<result column="source_id" property="sourceId"/>
<result column="template_content" property="templateContent"/>
<result column="template_type" property="templateType"/>
<result column="create_time" property="createTime"/>
<result column="create_by" property="createBy"/>
</resultMap>
<insert id="insertAll">
insert into tb_template (id,source_id,template_content,template_type,create_time,create_by)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id},
#{item.sourceId},#{item.templateContent},#{item.templateType},#{item.createTime},#{item.createBy})
</foreach>
</insert>
</mapper>

@ -1,40 +0,0 @@
<?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.baiye.dao.VariableMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="com.baiye.entity.Variable">
<id column="id" property="id"/>
<result column="number" property="number"/>
<result column="template_id" property="templateId"/>
<result column="variable_content" property="variableContent"/>
<result column="create_time" property="createTime"/>
<result column="create_by" property="createBy"/>
</resultMap>
<insert id="insertAll">
insert into tb_variable (id,number,template_id,variable_content,create_time,create_by)
values
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id}, #{item.number},#{item.templateId},#{item.variableContent},#{item.createTime},#{item.createBy})
</foreach>
</insert>
<update id="updateBatch">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update tb_variable
<set>
<if test="item.number != null and item.number != ''">
number = #{item.number},
</if>
<if test="item.templateId != null'">
template_id = #{itemTemplateId},
</if>
<if test="item.variableContent != null and item.variableContent != ''">
variable_content = #{item.variableContent},
</if>
</set>
where id = #{item.id}
</foreach>
</update>
</mapper>
Loading…
Cancel
Save