最近的一些修改 #7

Merged
xiaohai2271 merged 37 commits from dev into master 2020-08-01 21:26:46 +08:00
4 changed files with 55 additions and 8 deletions
Showing only changes of commit 9c949576aa - Show all commits

View File

@@ -58,6 +58,7 @@ public enum ResponseEnum {
DATA_HAS_EXIST(7020, "数据已存在"),
//其他
APPLY_LINK_NO_ADD_THIS_SITE(7200, "暂未在您的网站中抓取到本站链接"),
//提交更新之前,没有获取数据/,
DID_NOT_GET_THE_DATA(8020, "非法访问"),

View File

@@ -25,6 +25,10 @@ public class PartnerSite {
private Boolean delete = false;
private String email;
private Boolean notification;
public PartnerSite() {
}

View File

@@ -7,15 +7,20 @@ import cn.celess.blog.entity.request.LinkApplyReq;
import cn.celess.blog.entity.request.LinkReq;
import cn.celess.blog.exception.MyException;
import cn.celess.blog.mapper.PartnerMapper;
import cn.celess.blog.service.MailService;
import cn.celess.blog.service.PartnerSiteService;
import cn.celess.blog.util.HttpUtil;
import cn.celess.blog.util.RegexUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;
import javax.validation.constraints.Email;
import java.util.Date;
import java.util.List;
/**
@@ -26,6 +31,11 @@ import java.util.List;
public class PartnerSiteServiceImpl implements PartnerSiteService {
@Autowired
PartnerMapper partnerMapper;
@Autowired
MailService mailService;
private static final String SITE_NAME = "小海博客";
private static final String SITE_URL = "celess.cn";
private static final String SITE_EMAIL = "a@celess.cn";
@Override
public PartnerSite create(LinkReq reqBody) {
@@ -118,6 +128,32 @@ public class PartnerSiteServiceImpl implements PartnerSiteService {
|| StringUtils.isEmpty(linkApplyReq.getLinkUrl())) {
throw new MyException(ResponseEnum.PARAMETERS_ERROR);
}
if (RegexUtil.emailMatch(linkApplyReq.getEmail())) {
throw new MyException(ResponseEnum.PARAMETERS_EMAIL_ERROR);
}
if (RegexUtil.urlMatch(linkApplyReq.getLinkUrl()) || RegexUtil.urlMatch(linkApplyReq.getUrl())
|| (!StringUtils.isEmpty(linkApplyReq.getIconPath()) && RegexUtil.urlMatch(linkApplyReq.getIconPath()))) {
throw new MyException(ResponseEnum.PARAMETERS_URL_ERROR);
}
if (StringUtils.isEmpty(linkApplyReq.getIconPath())) {
linkApplyReq.setIconPath("");
}
String resp = HttpUtil.getAfterRendering(linkApplyReq.getLinkUrl());
assert resp != null;
if (resp.contains(SITE_URL)) {
PartnerSite ps = new PartnerSite();
BeanUtils.copyProperties(linkApplyReq, ps);
ps.setOpen(false);
partnerMapper.insert(ps);
SimpleMailMessage smm = new SimpleMailMessage();
smm.setSubject("友链申请");
smm.setText("有一条友链申请,[\n" + linkApplyReq.toString() + "\n]");
smm.setTo(SITE_EMAIL);
smm.setSentDate(new Date());
mailService.send(smm);
} else {
throw new MyException(ResponseEnum.APPLY_LINK_NO_ADD_THIS_SITE);
}
return null;
}
}

View File

@@ -9,20 +9,26 @@
<result column="l_icon_path" property="iconPath"/>
<result column="l_desc" property="desc"/>
<result column="is_delete" property="delete"/>
<result column="l_email" property="email"/>
<result column="l_notification" property="notification"/>
</resultMap>
<insert id="insert" parameterType="cn.celess.blog.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, is_delete)
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, false)
insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, l_email, l_notification, is_delete)
values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, #{email}, #{notification}, false)
</insert>
<update id="update" parameterType="cn.celess.blog.entity.PartnerSite">
update links set
update links
<trim prefix="set" suffixOverrides=",">
<if test="open!=null">l_is_open=#{open},</if>
<if test="iconPath!=null">l_icon_path=#{iconPath},</if>
<if test="desc!=null">l_desc=#{desc},</if>
<if test="url!=null">l_url=#{url},</if>
<if test="name!=null">l_name=#{name}</if>
<if test="name!=null">l_name=#{name},</if>
<if test="notification!=null">l_notification=#{notification},</if>
<if test="email!=null">l_email=#{email}</if>
</trim>
where l_id=#{id}
</update>