From 2d24f698ffd2f91bfa3a832507057ee51d9f2634 Mon Sep 17 00:00:00 2001 From: ronger Date: Sat, 15 Feb 2020 15:13:12 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E6=AD=A3=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=A0=87=E7=AD=BE=E5=A4=B1=E8=B4=A5=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/vertical/entity/Tag.java | 2 ++ .../com/rymcu/vertical/mapper/TagMapper.java | 2 +- .../vertical/service/impl/TagServiceImpl.java | 32 ++++++++++++++++--- src/main/java/mapper/TagMapper.xml | 5 +-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/entity/Tag.java b/src/main/java/com/rymcu/vertical/entity/Tag.java index 24dba8f..b53e68a 100644 --- a/src/main/java/com/rymcu/vertical/entity/Tag.java +++ b/src/main/java/com/rymcu/vertical/entity/Tag.java @@ -42,4 +42,6 @@ public class Tag implements Serializable,Cloneable { private Date createdTime; /** 更新时间 */ private Date updatedTime; + /** 保留标签 */ + private String tagReservation; } diff --git a/src/main/java/com/rymcu/vertical/mapper/TagMapper.java b/src/main/java/com/rymcu/vertical/mapper/TagMapper.java index 64c7b14..dcd8d30 100644 --- a/src/main/java/com/rymcu/vertical/mapper/TagMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/TagMapper.java @@ -15,5 +15,5 @@ public interface TagMapper extends Mapper { Integer deleteUnusedTag(); - Integer update(@Param("idTag") Integer idTag, @Param("tagUri") String tagUri, @Param("tagIconPath") String tagIconPath, @Param("tagStatus") String tagStatus, @Param("tagDescription") String tagDescription); + Integer update(@Param("idTag") Integer idTag, @Param("tagUri") String tagUri, @Param("tagIconPath") String tagIconPath, @Param("tagStatus") String tagStatus, @Param("tagDescription") String tagDescription, @Param("tagReservation") String tagReservation); } diff --git a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java index d78b366..4c02be0 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/TagServiceImpl.java @@ -11,12 +11,14 @@ import com.rymcu.vertical.web.api.exception.BaseApiException; import org.apache.commons.lang.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import tk.mybatis.mapper.entity.Condition; import javax.annotation.Resource; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -87,15 +89,35 @@ public class TagServiceImpl extends AbstractService implements TagService { @Transactional(rollbackFor = Exception.class) public Map saveTag(Tag tag) { Integer result = 0; + + Map map = new HashMap(1); if (tag.getIdTag() == null) { - tag.setCreatedTime(new Date()); - tag.setUpdatedTime(tag.getCreatedTime()); - result = tagMapper.insertSelective(tag); + if (StringUtils.isBlank(tag.getTagTitle())) { + map.put("message","标签名不能为空!"); + return map; + } else { + Condition tagCondition = new Condition(Tag.class); + tagCondition.createCriteria().andCondition("tag_title =", tag.getTagTitle()); + List tags = tagMapper.selectByCondition(tagCondition); + if (!tags.isEmpty()) { + map.put("message","标签 '" + tag.getTagTitle() + "' 已存在!"); + return map; + } + } + Tag newTag = new Tag(); + newTag.setTagTitle(tag.getTagTitle()); + newTag.setTagUri(tag.getTagUri()); + newTag.setTagIconPath(tag.getTagIconPath()); + newTag.setTagStatus(tag.getTagStatus()); + newTag.setTagDescription(tag.getTagDescription()); + newTag.setTagReservation(tag.getTagReservation()); + newTag.setCreatedTime(new Date()); + newTag.setUpdatedTime(tag.getCreatedTime()); + result = tagMapper.insertSelective(newTag); } else { tag.setUpdatedTime(new Date()); - result = tagMapper.update(tag.getIdTag(),tag.getTagUri(),tag.getTagIconPath(),tag.getTagStatus(),tag.getTagDescription()); + result = tagMapper.update(tag.getIdTag(),tag.getTagUri(),tag.getTagIconPath(),tag.getTagStatus(),tag.getTagDescription(),tag.getTagReservation()); } - Map map = new HashMap(1); if (result == 0) { map.put("message","操作失败!"); } else { diff --git a/src/main/java/mapper/TagMapper.xml b/src/main/java/mapper/TagMapper.xml index 32baccd..4f4d437 100644 --- a/src/main/java/mapper/TagMapper.xml +++ b/src/main/java/mapper/TagMapper.xml @@ -13,6 +13,7 @@ + @@ -24,10 +25,10 @@ insert into vertical_user_tag (id_tag,id_user,type,created_time,updated_time) values (#{idTag},#{idUser},#{type},sysdate(),sysdate()) - update vertical_tag set tag_uri = #{tagUri}, tag_icon_path = #{tagIconPath}, tag_status = #{tagStatus}, tag_description = #{tagDescription} where id = #{idTag} + update vertical_tag set tag_uri = #{tagUri}, tag_icon_path = #{tagIconPath}, tag_status = #{tagStatus}, tag_description = #{tagDescription}, tag_reservation = #{tagReservation} where id = #{idTag} - delete from vertical_tag where id not in (select * from (select id_tag from vertical_tag_article vta left join vertical_article va on vta.id_article = va.id where va.id is not null) tmp); + delete from vertical_tag where tag_reservation = 0 and id not in (select * from (select id_tag from vertical_tag_article vta left join vertical_article va on vta.id_article = va.id where va.id is not null) tmp);