🐛 修正后台创建标签失败问题

This commit is contained in:
ronger 2020-02-15 15:13:12 +08:00
parent 164e0376ed
commit 2d24f698ff
4 changed files with 33 additions and 8 deletions

View File

@ -42,4 +42,6 @@ public class Tag implements Serializable,Cloneable {
private Date createdTime; private Date createdTime;
/** 更新时间 */ /** 更新时间 */
private Date updatedTime; private Date updatedTime;
/** 保留标签 */
private String tagReservation;
} }

View File

@ -15,5 +15,5 @@ public interface TagMapper extends Mapper<Tag> {
Integer deleteUnusedTag(); 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);
} }

View File

@ -11,12 +11,14 @@ import com.rymcu.vertical.web.api.exception.BaseApiException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Condition;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -87,15 +89,35 @@ public class TagServiceImpl extends AbstractService<Tag> implements TagService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Map saveTag(Tag tag) { public Map saveTag(Tag tag) {
Integer result = 0; Integer result = 0;
Map map = new HashMap(1);
if (tag.getIdTag() == null) { if (tag.getIdTag() == null) {
tag.setCreatedTime(new Date()); if (StringUtils.isBlank(tag.getTagTitle())) {
tag.setUpdatedTime(tag.getCreatedTime()); map.put("message","标签名不能为空!");
result = tagMapper.insertSelective(tag); return map;
} else {
Condition tagCondition = new Condition(Tag.class);
tagCondition.createCriteria().andCondition("tag_title =", tag.getTagTitle());
List<Tag> 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 { } else {
tag.setUpdatedTime(new Date()); 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) { if (result == 0) {
map.put("message","操作失败!"); map.put("message","操作失败!");
} else { } else {

View File

@ -13,6 +13,7 @@
<id column="tag_view_count" property="tagViewCount"/> <id column="tag_view_count" property="tagViewCount"/>
<id column="tag_article_count" property="tagArticleCount"/> <id column="tag_article_count" property="tagArticleCount"/>
<id column="tag_ad" property="tagAd"/> <id column="tag_ad" property="tagAd"/>
<id column="tag_reservation" property="tagReservation"/>
<id column="tag_show_side_ad" property="tagShowSideAd"/> <id column="tag_show_side_ad" property="tagShowSideAd"/>
<id column="created_time" property="createdTime"/> <id column="created_time" property="createdTime"/>
<id column="updated_time" property="updatedTime"/> <id column="updated_time" property="updatedTime"/>
@ -24,10 +25,10 @@
insert into vertical_user_tag (id_tag,id_user,type,created_time,updated_time) values (#{idTag},#{idUser},#{type},sysdate(),sysdate()) insert into vertical_user_tag (id_tag,id_user,type,created_time,updated_time) values (#{idTag},#{idUser},#{type},sysdate(),sysdate())
</insert> </insert>
<update id="update"> <update id="update">
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}
</update> </update>
<delete id="deleteUnusedTag"> <delete id="deleteUnusedTag">
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);
</delete> </delete>
<select id="selectCountTagArticleById" resultType="java.lang.Integer"> <select id="selectCountTagArticleById" resultType="java.lang.Integer">
select count(*) from vertical_tag_article where id_tag = #{idTag} and id_article = #{idArticle} select count(*) from vertical_tag_article where id_tag = #{idTag} and id_article = #{idArticle}