sj
2 years ago
26 changed files with 752 additions and 14 deletions
@ -0,0 +1,26 @@ |
|||||||
|
package co.yixiang.app.modules.evaluation.param; |
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.Getter; |
||||||
|
import lombok.Setter; |
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 评测点赞和收藏表 查询参数对象 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author sj |
||||||
|
* @date 2022-10-19 |
||||||
|
*/ |
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@ApiModel("查询参数对象") |
||||||
|
public class YxStoreEvaluationRelationQueryParam { |
||||||
|
@NotBlank(message = "参数有误") |
||||||
|
@ApiModelProperty(value = "商品id",required=true) |
||||||
|
private String id; |
||||||
|
} |
@ -0,0 +1,40 @@ |
|||||||
|
package co.yixiang.modules.evaluation.domain; |
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDomain; |
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
import lombok.*; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 评测点赞和收藏表 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author sj |
||||||
|
* @since 2022-10-19 |
||||||
|
*/ |
||||||
|
|
||||||
|
@Getter |
||||||
|
@Setter |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
@Builder |
||||||
|
public class YxStoreEvaluationRelation extends BaseDomain { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Long id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户ID") |
||||||
|
private Long uid; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "评测ID") |
||||||
|
private Long evaluationId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "类型(收藏(collect)、点赞(like)、足迹(foot))") |
||||||
|
private String type; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,69 @@ |
|||||||
|
package co.yixiang.modules.evaluation.service; |
||||||
|
|
||||||
|
|
||||||
|
import co.yixiang.domain.PageResult; |
||||||
|
import co.yixiang.modules.evaluation.domain.YxStoreEvaluationRelation; |
||||||
|
import co.yixiang.modules.evaluation.service.dto.YxStoreEvaluationRelationDto; |
||||||
|
import co.yixiang.modules.evaluation.service.vo.YxStoreEvaluationRelationQueryVo; |
||||||
|
import co.yixiang.modules.product.service.dto.YxStoreProductRelationQueryCriteria; |
||||||
|
import org.springframework.data.domain.Pageable; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 评测收藏表 服务类 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author hupeng |
||||||
|
* @since 2019-10-23 |
||||||
|
*/ |
||||||
|
public interface YxEvaluationRelationService { |
||||||
|
/** |
||||||
|
* 是否收藏 |
||||||
|
* @param evaluationId 评测ID |
||||||
|
* @param uid 用户ID |
||||||
|
* @return Boolean |
||||||
|
*/ |
||||||
|
Boolean isEvaluationRelation(long evaluationId, long uid); |
||||||
|
|
||||||
|
/** |
||||||
|
*添加收藏 |
||||||
|
* @param evaluationId 评测id |
||||||
|
* @param uid 用户id |
||||||
|
*/ |
||||||
|
void addEvaluationRelation(long evaluationId,long uid); |
||||||
|
|
||||||
|
/** |
||||||
|
* 取消收藏 |
||||||
|
* @param evaluationId 评测id |
||||||
|
* @param uid 用户id |
||||||
|
*/ |
||||||
|
void delEvaluationRelation(long evaluationId,long uid); |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取用户收藏列表 |
||||||
|
* @param page page |
||||||
|
* @param limit limit |
||||||
|
* @param uid 用户id |
||||||
|
* @return list |
||||||
|
*/ |
||||||
|
List<YxStoreEvaluationRelationQueryVo> userCollectEvaluation(int page, int limit, Long uid, String type); |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 查询数据分页 |
||||||
|
* @param criteria 条件 |
||||||
|
* @param pageable 分页参数 |
||||||
|
* @return Map<String,Object> |
||||||
|
*/ |
||||||
|
PageResult<YxStoreEvaluationRelationDto> queryAll(YxStoreProductRelationQueryCriteria criteria, Pageable pageable); |
||||||
|
|
||||||
|
/** |
||||||
|
* 查询所有数据不分页 |
||||||
|
* @param criteria 条件参数 |
||||||
|
* @return List<YxStoreProductRelationDto> |
||||||
|
*/ |
||||||
|
List<YxStoreEvaluationRelation> queryAll(YxStoreProductRelationQueryCriteria criteria); |
||||||
|
|
||||||
|
} |
@ -0,0 +1,41 @@ |
|||||||
|
package co.yixiang.modules.evaluation.service.dto; |
||||||
|
|
||||||
|
import co.yixiang.modules.evaluation.domain.YxEvaluation; |
||||||
|
import co.yixiang.modules.product.domain.YxStoreProduct; |
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat; |
||||||
|
import lombok.Data; |
||||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
import java.sql.Timestamp; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class YxStoreEvaluationRelationDto implements Serializable { |
||||||
|
private Long id; |
||||||
|
|
||||||
|
/** 用户ID */ |
||||||
|
private Long uid; |
||||||
|
|
||||||
|
private String userName; |
||||||
|
|
||||||
|
/** 评测ID */ |
||||||
|
private Long evaluationId; |
||||||
|
|
||||||
|
private YxEvaluation evaluation; |
||||||
|
|
||||||
|
private YxStoreProduct product; |
||||||
|
|
||||||
|
/** 类型(收藏(collect)、点赞(like)) */ |
||||||
|
private String type; |
||||||
|
|
||||||
|
|
||||||
|
/** 添加时间 */ |
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
private Timestamp createTime; |
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
||||||
|
private Timestamp updateTime; |
||||||
|
|
||||||
|
private Integer isDel; |
||||||
|
} |
@ -0,0 +1,131 @@ |
|||||||
|
package co.yixiang.modules.evaluation.service.impl; |
||||||
|
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.exception.YshopException; |
||||||
|
import co.yixiang.common.service.impl.BaseServiceImpl; |
||||||
|
import co.yixiang.common.utils.QueryHelpPlus; |
||||||
|
import co.yixiang.domain.PageResult; |
||||||
|
import co.yixiang.dozer.service.IGenerator; |
||||||
|
import co.yixiang.modules.evaluation.domain.YxStoreEvaluationRelation; |
||||||
|
import co.yixiang.modules.evaluation.service.YxEvaluationRelationService; |
||||||
|
import co.yixiang.modules.evaluation.service.YxEvaluationService; |
||||||
|
import co.yixiang.modules.evaluation.service.dto.YxStoreEvaluationRelationDto; |
||||||
|
import co.yixiang.modules.evaluation.service.mapper.YxEvaluationRelationMapper; |
||||||
|
import co.yixiang.modules.evaluation.service.vo.YxStoreEvaluationRelationQueryVo; |
||||||
|
import co.yixiang.modules.product.service.dto.YxStoreProductRelationQueryCriteria; |
||||||
|
import co.yixiang.modules.user.service.YxUserService; |
||||||
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import com.github.pagehelper.PageInfo; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
import org.springframework.data.domain.Pageable; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.transaction.annotation.Transactional; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 评测点赞和收藏表 服务实现类 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author sj |
||||||
|
* @since 2022-10-19 |
||||||
|
*/ |
||||||
|
@Slf4j |
||||||
|
@Service |
||||||
|
@AllArgsConstructor |
||||||
|
@Transactional(rollbackFor = Exception.class) |
||||||
|
public class YxEvaluationRelationServiceImpl extends BaseServiceImpl<YxEvaluationRelationMapper, YxStoreEvaluationRelation> implements YxEvaluationRelationService { |
||||||
|
|
||||||
|
private final YxEvaluationRelationMapper yxEvaluationRelationMapper; |
||||||
|
private final YxEvaluationService yxEvaluationService; |
||||||
|
private final YxUserService userService; |
||||||
|
private final IGenerator generator; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* 是否收藏 |
||||||
|
* @param evaluationId 评测ID |
||||||
|
* @param uid 用户ID |
||||||
|
* @return Boolean |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public Boolean isEvaluationRelation(long evaluationId, long uid) { |
||||||
|
Long count = yxEvaluationRelationMapper |
||||||
|
.selectCount(Wrappers.<YxStoreEvaluationRelation>lambdaQuery() |
||||||
|
.eq(YxStoreEvaluationRelation::getUid,uid) |
||||||
|
.eq(YxStoreEvaluationRelation::getType,"collect") |
||||||
|
.eq(YxStoreEvaluationRelation::getEvaluationId,evaluationId)); |
||||||
|
if(count > 0) { |
||||||
|
return true; |
||||||
|
} |
||||||
|
|
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 添加收藏 |
||||||
|
* @param evaluationId 评测id |
||||||
|
* @param uid 用户id |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void addEvaluationRelation(long evaluationId, long uid) { |
||||||
|
if(isEvaluationRelation(evaluationId,uid)){ |
||||||
|
throw new YshopException("已收藏"); |
||||||
|
} |
||||||
|
YxStoreEvaluationRelation storeEvaluationRelation=YxStoreEvaluationRelation.builder() |
||||||
|
.evaluationId(evaluationId) |
||||||
|
.uid(uid) |
||||||
|
.build(); |
||||||
|
yxEvaluationRelationMapper.insert(storeEvaluationRelation); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 取消收藏 |
||||||
|
* @param evaluationId 评测id |
||||||
|
* @param uid 用户id |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public void delEvaluationRelation(long evaluationId, long uid) { |
||||||
|
YxStoreEvaluationRelation evaluationRelation =this.lambdaQuery() |
||||||
|
.eq(YxStoreEvaluationRelation::getEvaluationId,evaluationId) |
||||||
|
.eq(YxStoreEvaluationRelation::getUid,uid) |
||||||
|
.one(); |
||||||
|
if (evaluationRelation == null){ |
||||||
|
throw new YshopException("已取消"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* 获取用户收藏列表 |
||||||
|
* @param page page |
||||||
|
* @param limit limit |
||||||
|
* @param uid 用户id |
||||||
|
* @return list |
||||||
|
*/ |
||||||
|
@Override |
||||||
|
public List<YxStoreEvaluationRelationQueryVo> userCollectEvaluation(int page, int limit, Long uid, String type) { |
||||||
|
Page<YxStoreEvaluationRelation> pageModel = new Page<>(page, limit); |
||||||
|
List<YxStoreEvaluationRelationQueryVo> list = yxEvaluationRelationMapper.selectRelationList(pageModel,uid,type); |
||||||
|
return list; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public PageResult<YxStoreEvaluationRelationDto> queryAll(YxStoreProductRelationQueryCriteria criteria, Pageable pageable) { |
||||||
|
getPage(pageable); |
||||||
|
PageInfo<YxStoreEvaluationRelation> page = new PageInfo<>(queryAll(criteria)); |
||||||
|
PageResult<YxStoreEvaluationRelationDto> relationDtoPageResult = generator.convertPageInfo(page, YxStoreEvaluationRelationDto.class); |
||||||
|
relationDtoPageResult.getContent().forEach(i ->{ |
||||||
|
i.setEvaluation(yxEvaluationService.getById(i.getEvaluationId())); |
||||||
|
i.setUserName(userService.getYxUserById(i.getUid()).getNickname()); |
||||||
|
}); |
||||||
|
return relationDtoPageResult; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public List<YxStoreEvaluationRelation> queryAll(YxStoreProductRelationQueryCriteria criteria) { |
||||||
|
return baseMapper.selectList(QueryHelpPlus.getPredicate(YxStoreEvaluationRelation.class, criteria)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,33 @@ |
|||||||
|
package co.yixiang.modules.evaluation.service.mapper; |
||||||
|
|
||||||
|
|
||||||
|
import co.yixiang.common.mapper.CoreMapper; |
||||||
|
import co.yixiang.modules.evaluation.domain.YxStoreEvaluationRelation; |
||||||
|
import co.yixiang.modules.evaluation.service.vo.YxStoreEvaluationRelationQueryVo; |
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
||||||
|
import org.apache.ibatis.annotations.Param; |
||||||
|
import org.apache.ibatis.annotations.Select; |
||||||
|
import org.springframework.stereotype.Repository; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* <p> |
||||||
|
* 评测点赞和收藏表 Mapper 接口 |
||||||
|
* </p> |
||||||
|
* |
||||||
|
* @author sj |
||||||
|
* @since 2022-10-19 |
||||||
|
*/ |
||||||
|
@Repository |
||||||
|
public interface YxEvaluationRelationMapper extends CoreMapper<YxStoreEvaluationRelation> { |
||||||
|
|
||||||
|
|
||||||
|
@Select("select B.id pid,A.type as category,B.home_image as homeImage,A.id id," + |
||||||
|
"B.is_show as isShow" + |
||||||
|
" from yx_evaluation_relation A left join yx_evaluation B " + |
||||||
|
"on A.evaluation_id = B.id where A.type=#{type} and A.uid=#{uid} and A.is_del = 0 and B.is_del = 0 order by A.create_time desc") |
||||||
|
List<YxStoreEvaluationRelationQueryVo> selectRelationList(Page page, @Param("uid") Long uid, @Param("type") String type); |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
package co.yixiang.modules.evaluation.service.vo; |
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModelProperty; |
||||||
|
|
||||||
|
import java.util.Date; |
||||||
|
|
||||||
|
public class YxStoreEvaluationRelationQueryVo { |
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
private Long id; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "用户ID") |
||||||
|
private Long uid; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "商品ID") |
||||||
|
private Long productId; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "类型(收藏(collect") |
||||||
|
private String type; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "添加时间") |
||||||
|
private Date createTime; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "首页图片") |
||||||
|
private String homeImage; |
||||||
|
|
||||||
|
@ApiModelProperty(value = "是否显示") |
||||||
|
private Integer isShow; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,12 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class CardAction { |
||||||
|
private Integer type; |
||||||
|
private String url; |
||||||
|
private String appid; |
||||||
|
private String pagepath; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class EmphasisContent { |
||||||
|
/** 关键数据样式 "title":"100", |
||||||
|
"desc":"数据含义"*/ |
||||||
|
private String title; |
||||||
|
private String desc; |
||||||
|
} |
@ -0,0 +1,18 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
|
||||||
|
/** 二级标题+文本列表 type:0或不填代表是普通文本,1 代表跳转url,2 代表下载附件,3 代表@员工 |
||||||
|
keyname:二级标题、value:内容、url:链接 |
||||||
|
* */ |
||||||
|
@Data |
||||||
|
public class HorizontalContent { |
||||||
|
private String type; |
||||||
|
private String keyname; |
||||||
|
private String value; |
||||||
|
private String url; |
||||||
|
private String media_id; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
|
||||||
|
/** { |
||||||
|
"type":1, |
||||||
|
"url":"https://work.weixin.qq.com/?from=openApi", |
||||||
|
"title":"企业微信官网" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"type":2, |
||||||
|
"appid":"APPID", |
||||||
|
"pagepath":"PAGEPATH", |
||||||
|
"title":"跳转小程序" |
||||||
|
}*/ |
||||||
|
@Data |
||||||
|
public class Jump { |
||||||
|
private Integer type; |
||||||
|
private String appid; |
||||||
|
private String url; |
||||||
|
private String title; |
||||||
|
private String pagepath; |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,11 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class MainTitle { |
||||||
|
/** 模版卡片的主要内容 title:一级标题、desc:标题辅助信息*/ |
||||||
|
private String title; |
||||||
|
private String desc; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,22 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
|
||||||
|
/** 引用文献样式 |
||||||
|
* "type":1, |
||||||
|
"url":"https://work.weixin.qq.com/?from=openApi", |
||||||
|
"appid":"APPID", |
||||||
|
"pagepath":"PAGEPATH", |
||||||
|
"title":"引用文本标题", |
||||||
|
"quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"*/ |
||||||
|
@Data |
||||||
|
public class QuoteArea { |
||||||
|
private Integer type; |
||||||
|
private String url; |
||||||
|
private String appid; |
||||||
|
private String pagepath; |
||||||
|
private String title; |
||||||
|
private String quote_text; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import io.swagger.models.auth.In; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class Souce { |
||||||
|
/**卡片来源信息模板 icon_url:来源图片url、desc:描述、desc_color:颜色 0(默认) 灰色,1 黑色,2 红色,3 绿色 */ |
||||||
|
|
||||||
|
private String icon_url; |
||||||
|
private String desc; |
||||||
|
private Integer desc_color; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,62 @@ |
|||||||
|
package co.yixiang.modules.inform.domin; |
||||||
|
|
||||||
|
import co.yixiang.modules.inform.domin.*; |
||||||
|
import lombok.Data; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
@Data |
||||||
|
@Service |
||||||
|
public class TemplateCard { |
||||||
|
|
||||||
|
// /**消息类型*/
|
||||||
|
// private String msgtype ;
|
||||||
|
/** 模板卡片的模板类型*/ |
||||||
|
private String card_type; |
||||||
|
|
||||||
|
/**卡片来源信息模板 icon_url:来源图片url、desc:描述、desc_color:颜色 0(默认) 灰色,1 黑色,2 红色,3 绿色 */ |
||||||
|
private Souce source; |
||||||
|
|
||||||
|
/** 模版卡片的主要内容 title:一级标题、desc:标题辅助信息*/ |
||||||
|
private MainTitle main_title; |
||||||
|
|
||||||
|
/** 关键数据样式 "title":"100", |
||||||
|
"desc":"数据含义"*/ |
||||||
|
private EmphasisContent emphasis_content; |
||||||
|
|
||||||
|
/** 引用文献样式 |
||||||
|
* "type":1, |
||||||
|
"url":"https://work.weixin.qq.com/?from=openApi", |
||||||
|
"appid":"APPID", |
||||||
|
"pagepath":"PAGEPATH", |
||||||
|
"title":"引用文本标题", |
||||||
|
"quote_text":"Jack:企业微信真的很好用~\nBalian:超级好的一款软件!"*/ |
||||||
|
private QuoteArea quote_area; |
||||||
|
|
||||||
|
|
||||||
|
private String sub_title_text; |
||||||
|
|
||||||
|
/** 二级标题+文本列表 type:0或不填代表是普通文本,1 代表跳转url,2 代表下载附件,3 代表@员工 |
||||||
|
keyname:二级标题、value:内容、url:链接 |
||||||
|
* */ |
||||||
|
private ArrayList<HorizontalContent> horizontal_content_list; |
||||||
|
|
||||||
|
/** { |
||||||
|
"type":1, |
||||||
|
"url":"https://work.weixin.qq.com/?from=openApi", |
||||||
|
"title":"企业微信官网" |
||||||
|
}, |
||||||
|
{ |
||||||
|
"type":2, |
||||||
|
"appid":"APPID", |
||||||
|
"pagepath":"PAGEPATH", |
||||||
|
"title":"跳转小程序" |
||||||
|
}*/ |
||||||
|
private ArrayList<Jump> jump_list; |
||||||
|
|
||||||
|
/** 0 = 未购买 1 = 已购买 "type":1, |
||||||
|
"url":"https://work.weixin.qq.com/?from=openApi", |
||||||
|
"appid":"APPID", |
||||||
|
"pagepath":"PAGEPATH"*/ |
||||||
|
private CardAction card_action; |
||||||
|
} |
@ -0,0 +1,5 @@ |
|||||||
|
package co.yixiang.modules.inform.service; |
||||||
|
|
||||||
|
public interface SendMsgService { |
||||||
|
String inform(long orderId); |
||||||
|
} |
@ -0,0 +1,85 @@ |
|||||||
|
package co.yixiang.modules.inform.service.impl; |
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil; |
||||||
|
import co.yixiang.modules.inform.domin.*; |
||||||
|
import co.yixiang.modules.inform.service.SendMsgService; |
||||||
|
import co.yixiang.modules.order.service.YxStoreOrderService; |
||||||
|
import co.yixiang.modules.order.service.dto.YxStoreOrderDto; |
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import lombok.SneakyThrows; |
||||||
|
import org.apache.http.HttpStatus; |
||||||
|
import org.apache.http.client.methods.CloseableHttpResponse; |
||||||
|
import org.apache.http.client.methods.HttpPost; |
||||||
|
import org.apache.http.entity.StringEntity; |
||||||
|
import org.apache.http.impl.client.CloseableHttpClient; |
||||||
|
import org.apache.http.impl.client.HttpClients; |
||||||
|
import org.apache.http.util.EntityUtils; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
|
||||||
|
import java.text.SimpleDateFormat; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@Service |
||||||
|
public class SendMsgServiceImpl implements SendMsgService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private YxStoreOrderService yxStoreOrderService; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private TemplateCard templateCard; |
||||||
|
|
||||||
|
@SneakyThrows |
||||||
|
@Override |
||||||
|
public String inform(long orderId) { |
||||||
|
CloseableHttpClient httpClient = HttpClients.createDefault();//实例化对象
|
||||||
|
String webhook_url="https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a2f0f8c9-e406-4f6b-86e4-d6ac9e4df88e"; |
||||||
|
HttpPost httpPost=new HttpPost(webhook_url); |
||||||
|
httpPost.addHeader("Content-Type", "application/json; charset=utf-8"); |
||||||
|
|
||||||
|
TemplateCard templateCard=this.creatTemplatecard(orderId); |
||||||
|
Map<String, Object> param = new HashMap<>(); |
||||||
|
param.put("msgtype", "template_card"); |
||||||
|
param.put("template_card", JSONObject.parseObject(JSONUtil.toJsonStr(templateCard))); |
||||||
|
String jsonParam = JSONObject.toJSONString(param); |
||||||
|
|
||||||
|
StringEntity stringEntity=new StringEntity(jsonParam, "utf-8"); |
||||||
|
httpPost.setEntity(stringEntity); |
||||||
|
CloseableHttpResponse response=httpClient.execute(httpPost); |
||||||
|
// 发送成功接收返回值
|
||||||
|
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { |
||||||
|
String result = EntityUtils.toString(response.getEntity(), "utf-8"); |
||||||
|
System.out.println("发送微信机器人消息成功 " + result); |
||||||
|
return result; |
||||||
|
} else { |
||||||
|
System.out.println("发送微信机器人消息失败"); |
||||||
|
} |
||||||
|
// 关闭
|
||||||
|
httpClient.close(); |
||||||
|
response.close(); |
||||||
|
return "发送微信机器人消息失败"; |
||||||
|
} |
||||||
|
|
||||||
|
public TemplateCard creatTemplatecard(long orderId){ |
||||||
|
YxStoreOrderDto yxStoreOrderDto=yxStoreOrderService.getOrderDetailByOrderId(orderId); |
||||||
|
templateCard.setCard_type("text_notice"); |
||||||
|
templateCard.setSource(new Souce().setDesc("眼界甄选").setIcon_url("https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0").setDesc_color(0)); |
||||||
|
templateCard.setMain_title(new MainTitle().setTitle("有新的在线订单来啦").setDesc("订单号:"+orderId)); |
||||||
|
templateCard.setEmphasis_content(new EmphasisContent().setTitle(yxStoreOrderDto.getPayPrice().toString()).setDesc("订单总金额")); |
||||||
|
// templateCard.setQuote_area(new QuoteArea().setType(0).setUrl("").setAppid("APPID").setTitle("订单详情").setQuote_text("眼镜*1 0.01"));
|
||||||
|
templateCard.setSub_title_text("订单类型:"+yxStoreOrderDto.getPinkName());//订单类型
|
||||||
|
ArrayList<HorizontalContent> arrayList=new ArrayList<>(); |
||||||
|
arrayList.add(new HorizontalContent().setKeyname("下单地址").setValue(yxStoreOrderDto.getUserAddress())); |
||||||
|
arrayList.add(new HorizontalContent().setKeyname("下单时间").setValue(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(yxStoreOrderDto.getCreateTime()))); |
||||||
|
arrayList.add(new HorizontalContent().setKeyname("会员名称").setValue(yxStoreOrderDto.getRealName())); |
||||||
|
arrayList.add(new HorizontalContent().setKeyname("会员手机号").setValue(yxStoreOrderDto.getUserPhone())); |
||||||
|
templateCard.setHorizontal_content_list(arrayList); |
||||||
|
ArrayList<Jump> arrayList1=new ArrayList<>(); |
||||||
|
arrayList1.add(new Jump().setType(1).setUrl("https://work.weixin.qq.com/?from=openApi").setTitle("前去处理订单")); |
||||||
|
templateCard.setJump_list(arrayList1); |
||||||
|
templateCard.setCard_action(new CardAction().setType(1).setUrl("https://work.weixin.qq.com/?from=openApi")); |
||||||
|
return templateCard; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue