Commit 110011d6 by 阮思源

Merge branch 'feat-1002526' into 'master'

【1002526】发送邮件提醒

See merge request rays/pcloud-book!520
parents 12fa46cf 4df649e3
package com.pcloud.book.custom.biz;
import com.pcloud.book.custom.dto.CustomPlanEmailDto;
import com.pcloud.book.custom.entity.CustomPlanEmail;
import com.pcloud.common.page.PageBeanNew;
import java.util.List;
/**
* 邮件提醒(CustomPlanEmail)表服务接口
*
* @author zyq
* @since 2020-03-06 13:04:25
*/
public interface CustomPlanEmailBiz {
/**
* 通过ID查询单条数据
*
* @param customPlanId
* @return 实例对象
*/
CustomPlanEmailDto getCustomPlanEmailByPlanId(Integer customPlanId);
/**
* 分页查询
*/
PageBeanNew getList(Integer currentPage, Integer numPerPage);
/**
* 新增数据
*
* @param customPlanEmailDto 实例对象
* @return 主键
*/
Long sendCustomPlanEmail(CustomPlanEmailDto customPlanEmailDto);
}
\ No newline at end of file
package com.pcloud.book.custom.biz.impl;
import com.google.common.collect.Lists;
import com.pcloud.book.custom.biz.CustomPlanBiz;
import com.pcloud.book.custom.dto.CustomPlanEmailDto;
import com.pcloud.book.custom.entity.CustomPlan;
import com.pcloud.book.custom.entity.CustomPlanEmail;
import com.pcloud.book.custom.dao.CustomPlanEmailDao;
import com.pcloud.book.custom.biz.CustomPlanEmailBiz;
import com.pcloud.common.core.aspect.ParamLog;
import com.pcloud.common.core.biz.MessageBiz;
import com.pcloud.common.core.dto.SendEmailDto;
import com.pcloud.common.page.PageBeanNew;
import com.pcloud.common.page.PageParam;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.utils.DateNewUtils;
import com.pcloud.common.utils.ListUtils;
import com.pcloud.common.utils.NumberUtil;
import com.pcloud.common.utils.string.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 邮件提醒(CustomPlanEmail)表服务实现类
*
* @author zyq
* @since 2020-03-06 13:04:25
*/
@Service("customPlanEmailBiz")
public class CustomPlanEmailBizImpl implements CustomPlanEmailBiz {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomPlanEmailBizImpl.class);
@Autowired
private CustomPlanEmailDao customPlanEmailDao;
@Autowired
private CustomPlanBiz customPlanBiz;
@Autowired
private MessageBiz messageBiz;
@Override
@ParamLog("通过ID查询单条数据")
public CustomPlanEmailDto getCustomPlanEmailByPlanId(Integer customPlanId) {
CustomPlanEmailDto customPlanEmailDto = new CustomPlanEmailDto();
customPlanEmailDto.setEmailList(Lists.newArrayList());
CustomPlanEmail customPlanEmail = customPlanEmailDao.getCustomPlanEmailByPlanId(customPlanId);
if(customPlanEmail == null){
return customPlanEmailDto;
}
BeanUtils.copyProperties(customPlanEmail, customPlanEmailDto);
customPlanEmailDto.setEmailList(Lists.newArrayList(customPlanEmail.getEmails().split(";")));
return customPlanEmailDto;
}
@Override
@ParamLog("查询多条数据")
public PageBeanNew getList(Integer currentPage, Integer numPerPage) {
PageBeanNew pageBeanNew = customPlanEmailDao.listPageNew(new PageParam(currentPage, numPerPage), null, "getList");
List recordList = pageBeanNew.getRecordList();
if (ListUtils.isEmpty(recordList)){
return pageBeanNew;
}
// 加载其它数据
return pageBeanNew;
}
@Override
@ParamLog("发送邮件提醒")
public Long sendCustomPlanEmail(CustomPlanEmailDto customPlanEmailDto) {
if( !NumberUtil.isNumber(customPlanEmailDto.getCustomPlanId()) && customPlanEmailDto.getCustomPlanId() > 0){
throw new BizException(BizException.DB_SELECTONE_IS_NULL.getCode(),"panId不能为空");
}
if(customPlanEmailDto.getEmailList() == null || customPlanEmailDto.getEmailList().size() <= 0
|| customPlanEmailDto.getEmailList().stream().filter(x-> StringUtil.isNotEmpty(x)).count() == 0){
throw new BizException(BizException.PARAM_IS_NULL.getCode(),"请填写邮箱");
}
CustomPlan customPlan = customPlanBiz.getCustomPlanById(customPlanEmailDto.getCustomPlanId());
if(customPlan == null){
throw new BizException(BizException.DB_SELECTONE_IS_NULL.getCode(),"方案不存在,无法发送邮件");
}
CustomPlanEmail customPlanEmail = new CustomPlanEmail();
BeanUtils.copyProperties(customPlanEmailDto, customPlanEmail);
customPlanEmail.setEmails(String.join(";",customPlanEmailDto.getEmailList()));
customPlanEmailDao.insert(customPlanEmail);
customPlanEmailDto.setId(customPlanEmail.getId());
sendEmail(customPlanEmailDto, customPlan);
return customPlanEmail.getId();
}
@ParamLog("发送方案邮件提醒")
private void sendEmail(CustomPlanEmailDto customPlanEmailDto, CustomPlan customPlan) {
try {
SendEmailDto sendEmailDto = new SendEmailDto();
sendEmailDto.setTypeCode("custom_plan_email_remind");
Map<String, Object> content = new HashMap<>();
content.put("planNumber", customPlan.getPlanNumber());
content.put("planName", customPlan.getPlanName());
content.put("createUserName", customPlan.getCreateUserName());
content.put("planDescription", customPlan.getDescription());
content.put("planH5Url", customPlan.getH5Url());
content.put("robotClassifyName", customPlanEmailDto.getPcloudRobotClassifyName());
content.put("robotId", customPlanEmailDto.getRobotId());
content.put("userWxId", customPlanEmailDto.getUserWxId());
content.put("description", customPlanEmailDto.getDescription());
sendEmailDto.setContent(content);
for(String email : customPlanEmailDto.getEmailList()){
sendEmailDto.setToEmail(email);
messageBiz.sendEmail(sendEmailDto);
}
} catch (Exception e) {
LOGGER.error("发送方案邮件提醒出错:" + e.getMessage(), e);
}
}
}
\ No newline at end of file
package com.pcloud.book.custom.dao;
import com.pcloud.book.custom.entity.CustomPlanEmail;
import com.pcloud.common.core.dao.BaseDao;
import java.util.List;
/**
* 邮件提醒(CustomPlanEmail)表数据库访问层
*
* @author zyq
* @since 2020-03-06 13:04:22
*/
public interface CustomPlanEmailDao extends BaseDao<CustomPlanEmail> {
CustomPlanEmail getCustomPlanEmailByPlanId(Integer customPlanId);
}
\ No newline at end of file
package com.pcloud.book.custom.dao.impl;
import com.pcloud.book.custom.entity.CustomPlanEmail;
import com.pcloud.book.custom.dao.CustomPlanEmailDao;
import com.pcloud.common.core.dao.BaseDaoImpl;
import org.springframework.stereotype.Repository;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 邮件提醒(CustomPlanEmail)表数据库访问层
*
* @author zyq
* @since 2020-03-06 13:04:24
*/
@Repository("customPlanEmailDaoImpl")
public class CustomPlanEmailDaoImpl extends BaseDaoImpl<CustomPlanEmail> implements CustomPlanEmailDao {
@Override
public CustomPlanEmail getCustomPlanEmailByPlanId(Integer customPlanId) {
return super.getSqlSession().selectOne(getStatement("getCustomPlanEmailByPlanId"), customPlanId);
}
}
\ No newline at end of file
package com.pcloud.book.custom.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* 邮件提醒(CustomPlanEmail)实体类
*
* @author zyq
* @since 2020-03-06 13:04:22
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CustomPlanEmailDto implements Serializable {
@ApiModelProperty("主键")
private Long id;
@ApiModelProperty("方案id")
private Integer customPlanId;
@ApiModelProperty("邮件")
private List<String> emailList;
@ApiModelProperty("邮件补充内容")
private String description;
@ApiModelProperty("小睿wxId")
private String robotId;
@ApiModelProperty("分类名称")
private String pcloudRobotClassifyName;
@ApiModelProperty("用户微信id")
private String userWxId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
}
\ No newline at end of file
package com.pcloud.book.custom.entity;
import java.util.Date;
import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.pcloud.common.entity.BaseEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 邮件提醒(CustomPlanEmail)实体类
*
* @author zyq
* @since 2020-03-06 13:59:25
*/
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CustomPlanEmail extends BaseEntity {
private static final long serialVersionUID = -65823605833429988L;
@ApiModelProperty("主键")
private Long id;
@ApiModelProperty("方案id")
private Integer customPlanId;
@ApiModelProperty("邮件")
private String emails;
@ApiModelProperty("邮件补充内容")
private String description;
@ApiModelProperty("小睿wxId")
private String robotId;
@ApiModelProperty("分类名称")
private String pcloudRobotClassifyName;
@ApiModelProperty("用户微信id")
private String userWxId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
}
\ No newline at end of file
package com.pcloud.book.custom.facade; package com.pcloud.book.custom.facade;
import com.pcloud.book.custom.biz.CustomPlanBiz; import com.pcloud.book.custom.biz.CustomPlanBiz;
import com.pcloud.book.custom.biz.CustomPlanEmailBiz;
import com.pcloud.book.custom.dto.CustomPlanEmailDto;
import com.pcloud.book.custom.entity.CustomPlan; import com.pcloud.book.custom.entity.CustomPlan;
import com.pcloud.book.custom.vo.CustomPlanModuleVO; import com.pcloud.book.custom.vo.CustomPlanModuleVO;
import com.pcloud.book.custom.vo.EditCustomPlanModuleVO; import com.pcloud.book.custom.vo.EditCustomPlanModuleVO;
import com.pcloud.book.timecontrol.vo.CreateSelfPlanVO; import com.pcloud.book.timecontrol.vo.CreateSelfPlanVO;
import com.pcloud.common.dto.ResponseDto; import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.PermissionException;
import com.pcloud.common.utils.SessionUtil;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
...@@ -19,6 +24,8 @@ public class CustomPlanFacade { ...@@ -19,6 +24,8 @@ public class CustomPlanFacade {
@Autowired @Autowired
private CustomPlanBiz customPlanBiz; private CustomPlanBiz customPlanBiz;
@Autowired
private CustomPlanEmailBiz customPlanEmailBiz;
@ApiOperation("创建定制方案") @ApiOperation("创建定制方案")
@PostMapping("createCustomPlan") @PostMapping("createCustomPlan")
...@@ -101,4 +108,20 @@ public class CustomPlanFacade { ...@@ -101,4 +108,20 @@ public class CustomPlanFacade {
return new ResponseDto<>(customPlanBiz.getShortLinkUrl(appId, productId, linkUrl)); return new ResponseDto<>(customPlanBiz.getShortLinkUrl(appId, productId, linkUrl));
} }
@ApiOperation("发送邮件提醒")
@PostMapping("sendCustomPlanEmail")
public ResponseDto<?> sendCustomPlanEmail(@RequestHeader("token") String token, @RequestBody CustomPlanEmailDto customPlanEmailDto)
throws BizException, PermissionException {
SessionUtil.getToken4Redis(token);
return new ResponseDto<>(customPlanEmailBiz.sendCustomPlanEmail(customPlanEmailDto));
}
@ApiOperation("获取最后一次发送的邮件提醒")
@GetMapping("getCustomPlanEmailByPlanId")
public ResponseDto<?> getCustomPlanEmailByPlanId(@RequestHeader("token") String token, @RequestParam Integer customPlanId)
throws BizException, PermissionException {
SessionUtil.getToken4Redis(token);
return new ResponseDto<>(customPlanEmailBiz.getCustomPlanEmailByPlanId(customPlanId));
}
} }
<?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.pcloud.book.custom.dao.impl.CustomPlanEmailDaoImpl">
<resultMap id="BaseResultMap" type="com.pcloud.book.custom.entity.CustomPlanEmail">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="custom_plan_id" property="customPlanId" jdbcType="INTEGER"/>
<result column="emails" property="emails" jdbcType="VARCHAR"/>
<result column="description" property="description" jdbcType="VARCHAR"/>
<result column="robot_id" property="robotId" jdbcType="VARCHAR"/>
<result column="pcloud_robot_classify_name" property="pcloudRobotClassifyName" jdbcType="VARCHAR"/>
<result column="user_wx_id" property="userWxId" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<sql id="Base_Column_List">
id, custom_plan_id, emails, description, robot_id, pcloud_robot_classify_name, user_wx_id, create_time
</sql>
<select id="getById" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM custom_plan_email
WHERE id = #{id}
</select>
<select id="getCustomPlanEmailByPlanId" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM custom_plan_email
WHERE custom_plan_id = #{customPlanId}
ORDER BY id DESC
LIMIT 0,1
</select>
<select id="getList" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM custom_plan_email
</select>
<insert id="insert" keyProperty="id" useGeneratedKeys="true">
INSERT INTO custom_plan_email(
custom_plan_id,
emails,
description,
robot_id,
pcloud_robot_classify_name,
user_wx_id,
create_time
) VALUES (
#{customPlanId, jdbcType=INTEGER},
#{emails, jdbcType=VARCHAR},
#{description, jdbcType=VARCHAR},
#{robotId, jdbcType=VARCHAR},
#{pcloudRobotClassifyName, jdbcType=VARCHAR},
#{userWxId, jdbcType=VARCHAR},
NOW()
)
</insert>
<insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
INSERT INTO custom_plan_email (
custom_plan_id,
emails,
description,
robot_id,
pcloud_robot_classify_name,
user_wx_id,
create_time
) VALUES
<foreach collection="list" item="item" separator=",">
(
#{item.customPlanId, jdbcType=INTEGER},
#{item.emails, jdbcType=VARCHAR},
#{item.description, jdbcType=VARCHAR},
#{item.robotId, jdbcType=VARCHAR},
#{item.pcloudRobotClassifyName, jdbcType=VARCHAR},
#{item.userWxId, jdbcType=VARCHAR},
NOW()
)
</foreach>
</insert>
<!--通过主键修改数据-->
<update id="update">
UPDATE custom_plan_email
<set>
<if test="customPlanId != null">
custom_plan_id = #{customPlanId},
</if>
<if test="emails != null and emails != ''">
emails = #{emails},
</if>
<if test="description != null and description != ''">
description = #{description},
</if>
<if test="robotId != null and robotId != ''">
robot_id = #{robotId},
</if>
<if test="pcloudRobotClassifyName != null and pcloudRobotClassifyName != ''">
pcloud_robot_classify_name = #{pcloudRobotClassifyName},
</if>
<if test="userWxId != null and userWxId != ''">
user_wx_id = #{userWxId},
</if>
<if test="createTime != null">
create_time = #{createTime},
</if>
</set>
WHERE id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
DELETE FROM custom_plan_email where id = #{id}
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment