🐛 修正后台创建标签失败问题
This commit is contained in:
parent
164e0376ed
commit
2d24f698ff
@ -42,4 +42,6 @@ public class Tag implements Serializable,Cloneable {
|
||||
private Date createdTime;
|
||||
/** 更新时间 */
|
||||
private Date updatedTime;
|
||||
/** 保留标签 */
|
||||
private String tagReservation;
|
||||
}
|
||||
|
@ -15,5 +15,5 @@ public interface TagMapper extends Mapper<Tag> {
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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<Tag> 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<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 {
|
||||
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 {
|
||||
|
@ -13,6 +13,7 @@
|
||||
<id column="tag_view_count" property="tagViewCount"/>
|
||||
<id column="tag_article_count" property="tagArticleCount"/>
|
||||
<id column="tag_ad" property="tagAd"/>
|
||||
<id column="tag_reservation" property="tagReservation"/>
|
||||
<id column="tag_show_side_ad" property="tagShowSideAd"/>
|
||||
<id column="created_time" property="createdTime"/>
|
||||
<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>
|
||||
<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>
|
||||
<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>
|
||||
<select id="selectCountTagArticleById" resultType="java.lang.Integer">
|
||||
select count(*) from vertical_tag_article where id_tag = #{idTag} and id_article = #{idArticle}
|
||||
|
Loading…
Reference in New Issue
Block a user