fixed commonWords

master
zhangjinli 2 years ago
parent df1c83aed2
commit d3f207fb0b

@ -0,0 +1,31 @@
package com.zh.project0512.mapper;
import com.zh.project0512.model.CommonWords;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zh.project0512.model.Tag;
import org.apache.ibatis.annotations.Update;
/**
* <p>
* Mapper
* </p>
*
* @author zh
* @since 2023-02-16
*/
public interface CommonWordsMapper extends BaseMapper<CommonWords> {
@Update("update commonWords set sortWeight = sortWeight + 1 where sortWeight <> 0;\n" +
"insert into commonWords ( title, creatAt,sortWeight) VALUES ( #{title}, #{creatAt},1 );")
void addWords(CommonWords words);
@Update("<script>" +
"update commonWords set sortWeight = -1 where sortWeight = #{origin};\n" +
"<if test='originHigherCurrent'> " +
"update commonWords set sortWeight = sortWeight + 1 where sortWeight &lt;&gt; 0 and sortWeight &gt;= #{current} and sortWeight &lt; #{origin};"+
"</if>" +
"<if test='!originHigherCurrent'> " +
"update commonWords set sortWeight = sortWeight - 1 where sortWeight &lt;&gt; 0 and sortWeight &gt; #{origin} and sortWeight &lt;= #{current};\n" +
"</if>" +
"update commonWords set sortWeight = #{current} where sortWeight = -1;" +
"</script>")
void updSort(int origin, int current, boolean originHigherCurrent);
}

@ -0,0 +1,56 @@
package com.zh.project0512.model;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* <p>
*
* </p>
*
* @author zh
* @since 2023-02-16
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("commonWords")
public class CommonWords extends Model {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
/**
*
*/
private String title;
@TableField("creatAt")
private LocalDateTime creatAt;
@TableField("updateAt")
private LocalDateTime updateAt;
/**
* :
*/
@TableField("sortWeight")
private Integer sortWeight;
/**
* :01
*/
@TableField("isDeleted")
private Integer isDeleted;
}

@ -0,0 +1,18 @@
package com.zh.project0512.service;
import com.zh.project0512.model.CommonWords;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zh.project0512.model.Tag;
/**
* <p>
*
* </p>
*
* @author zh
* @since 2023-02-16
*/
public interface ICommonWordsService extends IService<CommonWords> {
void addWords(CommonWords words);
void updSort(int origin, int current, boolean originHigherCurrent);
}

@ -0,0 +1,30 @@
package com.zh.project0512.serviceImpl;
import com.zh.project0512.mapper.TagMapper;
import com.zh.project0512.model.CommonWords;
import com.zh.project0512.mapper.CommonWordsMapper;
import com.zh.project0512.model.Tag;
import com.zh.project0512.service.ICommonWordsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* <p>
*
* </p>
*
* @author zh
* @since 2023-02-16
*/
@Service
public class CommonWordsServiceImpl extends ServiceImpl<CommonWordsMapper, CommonWords> implements ICommonWordsService {
@Autowired
private CommonWordsMapper commonWordsMapper;
public void addWords(CommonWords words){
commonWordsMapper.addWords(words);
}
public void updSort(int origin, int current, boolean originHigherCurrent) {
commonWordsMapper.updSort(origin, current, originHigherCurrent);
}
}
Loading…
Cancel
Save