微信模块迁移
This commit is contained in:
@ -23,6 +23,11 @@
|
||||
<artifactId>wx-java-pay-spring-boot-starter</artifactId>
|
||||
<version>3.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang</groupId>
|
||||
<artifactId>yshop-common</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.github.binarywang</groupId>-->
|
||||
<!-- <artifactId>wx-java-miniapp-spring-boot-starter</artifactId>-->
|
||||
|
@ -0,0 +1,72 @@
|
||||
package co.yixiang.mp.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import co.yixiang.mp.domain.YxArticle;
|
||||
import co.yixiang.mp.service.YxArticleService;
|
||||
import co.yixiang.mp.service.dto.YxArticleQueryCriteria;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
@Api(tags = "YxArticle管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class YxArticleController {
|
||||
|
||||
@Autowired
|
||||
private YxArticleService yxArticleService;
|
||||
|
||||
|
||||
@ApiOperation(value = "查询YxArticle")
|
||||
@GetMapping(value = "/yxArticle")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXARTICLE_ALL','YXARTICLE_SELECT')")
|
||||
public ResponseEntity getYxArticles(YxArticleQueryCriteria criteria, Pageable pageable){
|
||||
return new ResponseEntity(yxArticleService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "新增YxArticle")
|
||||
@PostMapping(value = "/yxArticle")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXARTICLE_ALL','YXARTICLE_CREATE')")
|
||||
public ResponseEntity create(@Validated @RequestBody YxArticle resources){
|
||||
resources.setAddTime(DateUtil.now());
|
||||
return new ResponseEntity(yxArticleService.create(resources),HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "修改YxArticle")
|
||||
@PutMapping(value = "/yxArticle")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXARTICLE_ALL','YXARTICLE_EDIT')")
|
||||
public ResponseEntity update(@Validated @RequestBody YxArticle resources){
|
||||
yxArticleService.update(resources);
|
||||
return new ResponseEntity(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "删除YxArticle")
|
||||
@DeleteMapping(value = "/yxArticle/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXARTICLE_ALL','YXARTICLE_DELETE')")
|
||||
public ResponseEntity delete(@PathVariable Integer id){
|
||||
yxArticleService.delete(id);
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "发布文章")
|
||||
@GetMapping(value = "/yxArticle/publish/{id}")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXARTICLE_ALL','YXARTICLE_DELETE')")
|
||||
public ResponseEntity publish(@PathVariable Integer id){
|
||||
//todo
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package co.yixiang.mp.controller;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxCache;
|
||||
import co.yixiang.mp.service.YxCacheService;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
@Api(tags = "YxCache管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class YxCacheController {
|
||||
|
||||
@Autowired
|
||||
private YxCacheService yxCacheService;
|
||||
|
||||
@Autowired
|
||||
private WxMpService wxService;
|
||||
|
||||
|
||||
@ApiOperation(value = "查询菜单")
|
||||
@GetMapping(value = "/yxCache")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXCACHE_ALL','YXCACHE_SELECT')")
|
||||
public ResponseEntity getYxCaches(){
|
||||
return new ResponseEntity(yxCacheService.findById("wechat_menus"),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "创建菜单")
|
||||
@PostMapping(value = "/yxCache")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXCACHE_ALL','YXCACHE_CREATE')")
|
||||
public ResponseEntity create( @RequestBody String jsonStr){
|
||||
//if(StrUtil.isNotEmpty(jsonStr)) throw new BadRequestException("演示环境禁止操作");
|
||||
JSONObject jsonObject = JSON.parseObject(jsonStr);
|
||||
String jsonButton = jsonObject.get("buttons").toString();
|
||||
YxCache yxCache = new YxCache();
|
||||
Boolean isExist = yxCacheService.isExist("wechat_menus");
|
||||
WxMenu menu = JSONObject.parseObject(jsonStr,WxMenu.class);
|
||||
if(isExist){
|
||||
yxCache.setKey("wechat_menus");
|
||||
yxCache.setResult(jsonButton);
|
||||
yxCacheService.update(yxCache);
|
||||
}else {
|
||||
yxCache.setKey("wechat_menus");
|
||||
yxCache.setResult(jsonButton);
|
||||
yxCache.setAddTime(OrderUtil.getSecondTimestampTwo());
|
||||
yxCacheService.create(yxCache);
|
||||
}
|
||||
|
||||
|
||||
//创建菜单
|
||||
try {
|
||||
wxService.getMenuService().menuDelete();
|
||||
wxService.getMenuService().menuCreate(menu);
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return new ResponseEntity(HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package co.yixiang.mp.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import co.yixiang.mp.domain.YxWechatReply;
|
||||
import co.yixiang.mp.service.YxWechatReplyService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
@Api(tags = "YxWechatReply管理")
|
||||
@RestController
|
||||
@RequestMapping("api")
|
||||
public class YxWechatReplyController {
|
||||
|
||||
@Autowired
|
||||
private YxWechatReplyService yxWechatReplyService;
|
||||
|
||||
|
||||
@ApiOperation(value = "查询")
|
||||
@GetMapping(value = "/yxWechatReply")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXWECHATREPLY_ALL','YXWECHATREPLY_SELECT')")
|
||||
public ResponseEntity getYxWechatReplys(){
|
||||
return new ResponseEntity(yxWechatReplyService.isExist("subscribe"),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "新增自动回复")
|
||||
@PostMapping(value = "/yxWechatReply")
|
||||
@PreAuthorize("hasAnyRole('ADMIN','YXWECHATREPLY_ALL','YXWECHATREPLY_CREATE')")
|
||||
public ResponseEntity create(@RequestBody String jsonStr){
|
||||
JSONObject jsonObject = JSON.parseObject(jsonStr);
|
||||
YxWechatReply yxWechatReply = new YxWechatReply();
|
||||
YxWechatReply isExist = yxWechatReplyService.isExist(jsonObject.get("key").toString());
|
||||
yxWechatReply.setKey(jsonObject.get("key").toString());
|
||||
yxWechatReply.setStatus(Integer.valueOf(jsonObject.get("status").toString()));
|
||||
yxWechatReply.setData(jsonObject.get("data").toString());
|
||||
yxWechatReply.setType(jsonObject.get("type").toString());
|
||||
if(ObjectUtil.isNull(isExist)){
|
||||
yxWechatReplyService.create(yxWechatReply);
|
||||
}else{
|
||||
yxWechatReply.setId(isExist.getId());
|
||||
yxWechatReplyService.update(yxWechatReply);
|
||||
}
|
||||
|
||||
return new ResponseEntity(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
103
yshop-mp/src/main/java/co/yixiang/mp/domain/YxArticle.java
Normal file
103
yshop-mp/src/main/java/co/yixiang/mp/domain/YxArticle.java
Normal file
@ -0,0 +1,103 @@
|
||||
package co.yixiang.mp.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="yx_article")
|
||||
public class YxArticle implements Serializable {
|
||||
|
||||
// 文章管理ID
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
// 分类id
|
||||
@Column(name = "cid")
|
||||
private String cid;
|
||||
|
||||
// 文章标题
|
||||
@Column(name = "title",nullable = false)
|
||||
private String title;
|
||||
|
||||
// 文章作者
|
||||
@Column(name = "author")
|
||||
private String author;
|
||||
|
||||
@Column(name = "content")
|
||||
private String content;
|
||||
|
||||
// 文章图片
|
||||
@Column(name = "image_input",nullable = false)
|
||||
private String imageInput;
|
||||
|
||||
// 文章简介
|
||||
@Column(name = "synopsis")
|
||||
private String synopsis;
|
||||
|
||||
// 文章分享标题
|
||||
@Column(name = "share_title")
|
||||
private String shareTitle;
|
||||
|
||||
// 文章分享简介
|
||||
@Column(name = "share_synopsis")
|
||||
private String shareSynopsis;
|
||||
|
||||
// 浏览次数
|
||||
@Column(name = "visit")
|
||||
private String visit;
|
||||
|
||||
// 排序
|
||||
@Column(name = "sort",nullable = false)
|
||||
private Integer sort;
|
||||
|
||||
// 原文链接
|
||||
@Column(name = "url")
|
||||
private String url;
|
||||
|
||||
// 状态
|
||||
@Column(name = "status",nullable = false)
|
||||
private Integer status;
|
||||
|
||||
// 添加时间
|
||||
@Column(name = "add_time",nullable = false)
|
||||
private String addTime;
|
||||
|
||||
// 是否隐藏
|
||||
@Column(name = "hide",nullable = false)
|
||||
private Integer hide;
|
||||
|
||||
// 管理员id
|
||||
@Column(name = "admin_id",nullable = false)
|
||||
private Integer adminId;
|
||||
|
||||
// 商户id
|
||||
@Column(name = "mer_id")
|
||||
private Integer merId;
|
||||
|
||||
// 产品关联id
|
||||
@Column(name = "product_id",nullable = false)
|
||||
private Integer productId;
|
||||
|
||||
// 是否热门(小程序)
|
||||
@Column(name = "is_hot",nullable = false)
|
||||
private Integer isHot;
|
||||
|
||||
// 是否轮播图(小程序)
|
||||
@Column(name = "is_banner",nullable = false)
|
||||
private Integer isBanner;
|
||||
|
||||
public void copy(YxArticle source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
38
yshop-mp/src/main/java/co/yixiang/mp/domain/YxCache.java
Normal file
38
yshop-mp/src/main/java/co/yixiang/mp/domain/YxCache.java
Normal file
@ -0,0 +1,38 @@
|
||||
package co.yixiang.mp.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="yx_cache")
|
||||
public class YxCache implements Serializable {
|
||||
|
||||
|
||||
@Id
|
||||
@Column(name = "`key`")
|
||||
private String key;
|
||||
|
||||
// 缓存数据
|
||||
@Column(name = "result")
|
||||
private String result;
|
||||
|
||||
// 缓存时间
|
||||
@Column(name = "add_time")
|
||||
private Integer addTime;
|
||||
|
||||
public void copy(YxCache source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package co.yixiang.mp.domain;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name="yx_wechat_reply")
|
||||
public class YxWechatReply implements Serializable {
|
||||
|
||||
// 微信关键字回复id
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
// 关键字
|
||||
@Column(name = "`key`",unique = true,nullable = false)
|
||||
private String key;
|
||||
|
||||
// 回复类型
|
||||
@Column(name = "type",nullable = false)
|
||||
private String type;
|
||||
|
||||
// 回复数据
|
||||
@Column(name = "data",nullable = false)
|
||||
private String data;
|
||||
|
||||
// 0=不可用 1 =可用
|
||||
@Column(name = "status",nullable = false)
|
||||
private Integer status;
|
||||
|
||||
// 是否隐藏
|
||||
@Column(name = "hide",nullable = false)
|
||||
private Integer hide;
|
||||
|
||||
public void copy(YxWechatReply source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
}
|
@ -1,7 +1,13 @@
|
||||
package co.yixiang.mp.handler;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import co.yixiang.mp.domain.YxWechatReply;
|
||||
import co.yixiang.mp.service.YxWechatReplyService;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import co.yixiang.mp.builder.TextBuilder;
|
||||
@ -16,14 +22,35 @@ import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
@Component
|
||||
public class SubscribeHandler extends AbstractHandler {
|
||||
|
||||
@Autowired
|
||||
private YxWechatReplyService yxWechatReplyService;
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
|
||||
Map<String, Object> context, WxMpService weixinService,
|
||||
WxSessionManager sessionManager) throws WxErrorException {
|
||||
|
||||
|
||||
//System.out.println("wxMessage:"+wxMessage);
|
||||
//System.out.println("context:"+context);
|
||||
|
||||
YxWechatReply wechatReply = yxWechatReplyService.isExist("subscribe");
|
||||
if(ObjectUtil.isNull(wechatReply)){
|
||||
|
||||
}
|
||||
|
||||
|
||||
String str = JSONObject.parseObject(wechatReply.getData()).getString("content");
|
||||
try {
|
||||
return new TextBuilder().build("hello yshop", wxMessage, weixinService);
|
||||
//String str = new String(wechatReply.getData().getBytes(),"utf-8");
|
||||
WxMpXmlOutMessage msg= WxMpXmlOutMessage.TEXT()
|
||||
.content(str)
|
||||
.fromUser(wxMessage.getToUser())
|
||||
.toUser(wxMessage.getFromUser())
|
||||
.build();
|
||||
//System.out.println(msg);
|
||||
return msg;
|
||||
//return new TextBuilder().build(str, wxMessage, weixinService);
|
||||
} catch (Exception e) {
|
||||
this.logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package co.yixiang.mp.repository;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxArticle;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
public interface YxArticleRepository extends JpaRepository<YxArticle, Integer>, JpaSpecificationExecutor {
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package co.yixiang.mp.repository;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxCache;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
public interface YxCacheRepository extends JpaRepository<YxCache, String>, JpaSpecificationExecutor {
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package co.yixiang.mp.repository;
|
||||
|
||||
import co.yixiang.mp.domain.YxWechatReply;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
public interface YxWechatReplyRepository extends JpaRepository<YxWechatReply, Integer>, JpaSpecificationExecutor {
|
||||
|
||||
/**
|
||||
* findByKey
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
YxWechatReply findByKey(String key);
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package co.yixiang.mp.service;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxArticle;
|
||||
import co.yixiang.mp.service.dto.YxArticleDTO;
|
||||
import co.yixiang.mp.service.dto.YxArticleQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
//@CacheConfig(cacheNames = "yxArticle")
|
||||
public interface YxArticleService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
Map<String,Object> queryAll(YxArticleQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
List<YxArticleDTO> queryAll(YxArticleQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(key = "#p0")
|
||||
YxArticleDTO findById(Integer id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
YxArticleDTO create(YxArticle resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void update(YxArticle resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void delete(Integer id);
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
package co.yixiang.mp.service;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxCache;
|
||||
import co.yixiang.mp.service.dto.YxCacheDTO;
|
||||
import co.yixiang.mp.service.dto.YxCacheQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
//@CacheConfig(cacheNames = "yxCache")
|
||||
public interface YxCacheService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
Map<String,Object> queryAll(YxCacheQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
List<YxCacheDTO> queryAll(YxCacheQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(key = "#p0")
|
||||
YxCacheDTO findById(String key);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
YxCacheDTO create(YxCache resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void update(YxCache resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param key
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void delete(String key);
|
||||
|
||||
boolean isExist(String key);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package co.yixiang.mp.service;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxWechatReply;
|
||||
import co.yixiang.mp.service.dto.YxWechatReplyDTO;
|
||||
import co.yixiang.mp.service.dto.YxWechatReplyQueryCriteria;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
//@CacheConfig(cacheNames = "yxWechatReply")
|
||||
public interface YxWechatReplyService {
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
Map<String,Object> queryAll(YxWechatReplyQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable
|
||||
List<YxWechatReplyDTO> queryAll(YxWechatReplyQueryCriteria criteria);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@Cacheable(key = "#p0")
|
||||
YxWechatReplyDTO findById(Integer id);
|
||||
|
||||
/**
|
||||
* 创建
|
||||
* @param resources
|
||||
* @return
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
YxWechatReplyDTO create(YxWechatReply resources);
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param resources
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void update(YxWechatReply resources);
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @param id
|
||||
*/
|
||||
//@CacheEvict(allEntries = true)
|
||||
void delete(Integer id);
|
||||
|
||||
YxWechatReply isExist(String key);
|
||||
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
package co.yixiang.mp.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
@Data
|
||||
public class YxArticleDTO implements Serializable {
|
||||
|
||||
// 文章管理ID
|
||||
private Integer id;
|
||||
|
||||
// 分类id
|
||||
private String cid;
|
||||
|
||||
// 文章标题
|
||||
private String title;
|
||||
|
||||
// 文章作者
|
||||
private String author;
|
||||
|
||||
// 文章图片
|
||||
private String imageInput;
|
||||
|
||||
// 文章简介
|
||||
private String synopsis;
|
||||
|
||||
private String content;
|
||||
|
||||
// 文章分享标题
|
||||
private String shareTitle;
|
||||
|
||||
// 文章分享简介
|
||||
private String shareSynopsis;
|
||||
|
||||
// 浏览次数
|
||||
private String visit;
|
||||
|
||||
// 排序
|
||||
private Integer sort;
|
||||
|
||||
// 原文链接
|
||||
private String url;
|
||||
|
||||
// 状态
|
||||
private Integer status;
|
||||
|
||||
// 添加时间
|
||||
private String addTime;
|
||||
|
||||
// 是否隐藏
|
||||
private Integer hide;
|
||||
|
||||
// 管理员id
|
||||
private Integer adminId;
|
||||
|
||||
// 商户id
|
||||
private Integer merId;
|
||||
|
||||
// 产品关联id
|
||||
private Integer productId;
|
||||
|
||||
// 是否热门(小程序)
|
||||
private Integer isHot;
|
||||
|
||||
// 是否轮播图(小程序)
|
||||
private Integer isBanner;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package co.yixiang.mp.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
@Data
|
||||
public class YxArticleQueryCriteria{
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package co.yixiang.mp.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
@Data
|
||||
public class YxCacheDTO implements Serializable {
|
||||
|
||||
private String key;
|
||||
|
||||
// 缓存数据
|
||||
private String result;
|
||||
|
||||
// 缓存时间
|
||||
private Integer addTime;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package co.yixiang.mp.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
@Data
|
||||
public class YxCacheQueryCriteria{
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package co.yixiang.mp.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
@Data
|
||||
public class YxWechatReplyDTO implements Serializable {
|
||||
|
||||
// 微信关键字回复id
|
||||
private Integer id;
|
||||
|
||||
// 关键字
|
||||
private String key;
|
||||
|
||||
// 回复类型
|
||||
private String type;
|
||||
|
||||
// 回复数据
|
||||
private String data;
|
||||
|
||||
// 0=不可用 1 =可用
|
||||
private Integer status;
|
||||
|
||||
// 是否隐藏
|
||||
private Integer hide;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package co.yixiang.mp.service.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
@Data
|
||||
public class YxWechatReplyQueryCriteria{
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package co.yixiang.mp.service.impl;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxArticle;
|
||||
import co.yixiang.mp.repository.YxArticleRepository;
|
||||
import co.yixiang.mp.service.YxArticleService;
|
||||
import co.yixiang.mp.service.dto.YxArticleDTO;
|
||||
import co.yixiang.mp.service.dto.YxArticleQueryCriteria;
|
||||
import co.yixiang.mp.service.mapper.YxArticleMapper;
|
||||
import co.yixiang.utils.OrderUtil;
|
||||
import co.yixiang.utils.PageUtil;
|
||||
import co.yixiang.utils.QueryHelp;
|
||||
import co.yixiang.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class YxArticleServiceImpl implements YxArticleService {
|
||||
|
||||
@Autowired
|
||||
private YxArticleRepository yxArticleRepository;
|
||||
|
||||
@Autowired
|
||||
private YxArticleMapper yxArticleMapper;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(YxArticleQueryCriteria criteria, Pageable pageable){
|
||||
Page<YxArticle> page = yxArticleRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(yxArticleMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<YxArticleDTO> queryAll(YxArticleQueryCriteria criteria){
|
||||
return yxArticleMapper.toDto(yxArticleRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YxArticleDTO findById(Integer id) {
|
||||
Optional<YxArticle> yxArticle = yxArticleRepository.findById(id);
|
||||
ValidationUtil.isNull(yxArticle,"YxArticle","id",id);
|
||||
return yxArticleMapper.toDto(yxArticle.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public YxArticleDTO create(YxArticle resources) {
|
||||
resources.setAddTime(String.valueOf(OrderUtil.getSecondTimestampTwo()));
|
||||
return yxArticleMapper.toDto(yxArticleRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(YxArticle resources) {
|
||||
Optional<YxArticle> optionalYxArticle = yxArticleRepository.findById(resources.getId());
|
||||
ValidationUtil.isNull( optionalYxArticle,"YxArticle","id",resources.getId());
|
||||
YxArticle yxArticle = optionalYxArticle.get();
|
||||
yxArticle.copy(resources);
|
||||
yxArticleRepository.save(yxArticle);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Integer id) {
|
||||
yxArticleRepository.deleteById(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package co.yixiang.mp.service.impl;
|
||||
|
||||
|
||||
import co.yixiang.mp.domain.YxCache;
|
||||
import co.yixiang.mp.repository.YxCacheRepository;
|
||||
import co.yixiang.mp.service.YxCacheService;
|
||||
import co.yixiang.mp.service.dto.YxCacheDTO;
|
||||
import co.yixiang.mp.service.dto.YxCacheQueryCriteria;
|
||||
import co.yixiang.mp.service.mapper.YxCacheMapper;
|
||||
import co.yixiang.utils.PageUtil;
|
||||
import co.yixiang.utils.QueryHelp;
|
||||
import co.yixiang.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class YxCacheServiceImpl implements YxCacheService {
|
||||
|
||||
@Autowired
|
||||
private YxCacheRepository yxCacheRepository;
|
||||
|
||||
@Autowired
|
||||
private YxCacheMapper yxCacheMapper;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(YxCacheQueryCriteria criteria, Pageable pageable){
|
||||
Page<YxCache> page = yxCacheRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(yxCacheMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<YxCacheDTO> queryAll(YxCacheQueryCriteria criteria){
|
||||
return yxCacheMapper.toDto(yxCacheRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YxCacheDTO findById(String key) {
|
||||
Optional<YxCache> yxCache = yxCacheRepository.findById(key);
|
||||
ValidationUtil.isNull(yxCache,"YxCache","key",key);
|
||||
return yxCacheMapper.toDto(yxCache.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExist(String key) {
|
||||
Optional<YxCache> yxCache = yxCacheRepository.findById(key);
|
||||
if(!yxCache.isPresent()){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public YxCacheDTO create(YxCache resources) {
|
||||
//resources.setKey(IdUtil.simpleUUID());
|
||||
return yxCacheMapper.toDto(yxCacheRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(YxCache resources) {
|
||||
Optional<YxCache> optionalYxCache = yxCacheRepository.findById(resources.getKey());
|
||||
ValidationUtil.isNull( optionalYxCache,"YxCache","id",resources.getKey());
|
||||
YxCache yxCache = optionalYxCache.get();
|
||||
yxCache.copy(resources);
|
||||
yxCacheRepository.save(yxCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(String key) {
|
||||
yxCacheRepository.deleteById(key);
|
||||
}
|
||||
}
|
@ -0,0 +1,93 @@
|
||||
package co.yixiang.mp.service.impl;
|
||||
|
||||
import co.yixiang.exception.EntityExistException;
|
||||
import co.yixiang.mp.domain.YxWechatReply;
|
||||
import co.yixiang.mp.repository.YxWechatReplyRepository;
|
||||
import co.yixiang.mp.service.YxWechatReplyService;
|
||||
import co.yixiang.mp.service.dto.YxWechatReplyDTO;
|
||||
import co.yixiang.mp.service.dto.YxWechatReplyQueryCriteria;
|
||||
import co.yixiang.mp.service.mapper.YxWechatReplyMapper;
|
||||
import co.yixiang.utils.PageUtil;
|
||||
import co.yixiang.utils.QueryHelp;
|
||||
import co.yixiang.utils.ValidationUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
@Service
|
||||
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
|
||||
public class YxWechatReplyServiceImpl implements YxWechatReplyService {
|
||||
|
||||
@Autowired
|
||||
private YxWechatReplyRepository yxWechatReplyRepository;
|
||||
|
||||
@Autowired
|
||||
private YxWechatReplyMapper yxWechatReplyMapper;
|
||||
|
||||
@Override
|
||||
public Map<String,Object> queryAll(YxWechatReplyQueryCriteria criteria, Pageable pageable){
|
||||
Page<YxWechatReply> page = yxWechatReplyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(yxWechatReplyMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<YxWechatReplyDTO> queryAll(YxWechatReplyQueryCriteria criteria){
|
||||
return yxWechatReplyMapper.toDto(yxWechatReplyRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public YxWechatReplyDTO findById(Integer id) {
|
||||
Optional<YxWechatReply> yxWechatReply = yxWechatReplyRepository.findById(id);
|
||||
ValidationUtil.isNull(yxWechatReply,"YxWechatReply","id",id);
|
||||
return yxWechatReplyMapper.toDto(yxWechatReply.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public YxWechatReplyDTO create(YxWechatReply resources) {
|
||||
if(yxWechatReplyRepository.findByKey(resources.getKey()) != null){
|
||||
throw new EntityExistException(YxWechatReply.class,"key",resources.getKey());
|
||||
}
|
||||
return yxWechatReplyMapper.toDto(yxWechatReplyRepository.save(resources));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(YxWechatReply resources) {
|
||||
Optional<YxWechatReply> optionalYxWechatReply = yxWechatReplyRepository.findById(resources.getId());
|
||||
ValidationUtil.isNull( optionalYxWechatReply,"YxWechatReply","id",resources.getId());
|
||||
YxWechatReply yxWechatReply = optionalYxWechatReply.get();
|
||||
YxWechatReply yxWechatReply1 = null;
|
||||
yxWechatReply1 = yxWechatReplyRepository.findByKey(resources.getKey());
|
||||
if(yxWechatReply1 != null && !yxWechatReply1.getId().equals(yxWechatReply.getId())){
|
||||
throw new EntityExistException(YxWechatReply.class,"key",resources.getKey());
|
||||
}
|
||||
yxWechatReply.copy(resources);
|
||||
yxWechatReplyRepository.save(yxWechatReply);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delete(Integer id) {
|
||||
yxWechatReplyRepository.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public YxWechatReply isExist(String key) {
|
||||
YxWechatReply yxWechatReply = yxWechatReplyRepository.findByKey(key);
|
||||
|
||||
return yxWechatReply;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package co.yixiang.mp.service.mapper;
|
||||
|
||||
import co.yixiang.mapper.EntityMapper;
|
||||
|
||||
import co.yixiang.mp.domain.YxArticle;
|
||||
import co.yixiang.mp.service.dto.YxArticleDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-07
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface YxArticleMapper extends EntityMapper<YxArticleDTO, YxArticle> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package co.yixiang.mp.service.mapper;
|
||||
|
||||
import co.yixiang.mapper.EntityMapper;
|
||||
import co.yixiang.mp.domain.YxCache;
|
||||
import co.yixiang.mp.service.dto.YxCacheDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-06
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface YxCacheMapper extends EntityMapper<YxCacheDTO, YxCache> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package co.yixiang.mp.service.mapper;
|
||||
|
||||
import co.yixiang.mapper.EntityMapper;
|
||||
import co.yixiang.mp.domain.YxWechatReply;
|
||||
import co.yixiang.mp.service.dto.YxWechatReplyDTO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.ReportingPolicy;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* @date 2019-10-10
|
||||
*/
|
||||
@Mapper(componentModel = "spring",uses = {},unmappedTargetPolicy = ReportingPolicy.IGNORE)
|
||||
public interface YxWechatReplyMapper extends EntityMapper<YxWechatReplyDTO, YxWechatReply> {
|
||||
|
||||
}
|
Reference in New Issue
Block a user