6 changed files with 252 additions and 1 deletions
@ -0,0 +1,63 @@
|
||||
package com.mh.user.controller; |
||||
|
||||
import com.mh.common.http.HttpResult; |
||||
import com.mh.common.page.PageRequest; |
||||
import com.mh.common.page.PageResult; |
||||
import com.mh.user.entity.KnowledgeDataEntity; |
||||
import com.mh.user.service.KnowledgeDataService; |
||||
import io.jsonwebtoken.lang.Assert; |
||||
import org.springframework.validation.annotation.Validated; |
||||
import org.springframework.web.bind.annotation.*; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 知识库管理 |
||||
* @date 2024-06-26 14:39:24 |
||||
*/ |
||||
@RestController |
||||
@RequestMapping("/knowledge") |
||||
public class KnowledgeDataController { |
||||
|
||||
@Resource |
||||
private KnowledgeDataService knowledgeDataService; |
||||
|
||||
@GetMapping("/query") |
||||
public HttpResult queryKnowledgeData(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize) { |
||||
PageRequest pageRequest = new PageRequest(); |
||||
pageRequest.setPageNum(pageNum); |
||||
pageRequest.setPageSize(pageSize); |
||||
return HttpResult.ok(knowledgeDataService.queryKnowledgeData(pageRequest)); |
||||
} |
||||
|
||||
@GetMapping("/{id}") |
||||
public HttpResult detail(@PathVariable(name = "id") Long id) { |
||||
KnowledgeDataEntity knowledgeData = knowledgeDataService.getById(id); |
||||
Assert.notNull(knowledgeData, "该文章已被删除"); |
||||
return HttpResult.ok(knowledgeData); |
||||
} |
||||
|
||||
@PostMapping("/update") |
||||
public HttpResult updateData(@Validated @RequestBody KnowledgeDataEntity knowledgeData) { |
||||
try { |
||||
knowledgeDataService.updateData(knowledgeData); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
return HttpResult.ok(); |
||||
} |
||||
|
||||
@PostMapping("/insert") |
||||
public HttpResult insertKnowledgeData(@Validated @RequestBody KnowledgeDataEntity knowledgeData) { |
||||
try { |
||||
knowledgeDataService.insertKnowledgeData(knowledgeData); |
||||
} catch (Exception e) { |
||||
throw new RuntimeException(e); |
||||
} |
||||
return HttpResult.ok(); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,38 @@
|
||||
package com.mh.user.entity; |
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat; |
||||
import lombok.Data; |
||||
|
||||
import javax.validation.constraints.NotBlank; |
||||
import java.io.Serializable; |
||||
import java.util.Date; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 知识库管理 |
||||
* @date 2024-06-26 14:18:28 |
||||
*/ |
||||
@Data |
||||
public class KnowledgeDataEntity implements Serializable { |
||||
|
||||
private Long id; |
||||
|
||||
@NotBlank(message = "标题不能为空") |
||||
private String title; |
||||
|
||||
@NotBlank(message = "摘要不能为空") |
||||
private String description; |
||||
|
||||
@NotBlank(message = "内容不能为空") |
||||
private String content; |
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
||||
private Date createTime; |
||||
|
||||
private Integer status; |
||||
|
||||
private String remark; |
||||
|
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.mh.user.mapper; |
||||
|
||||
import com.mh.user.entity.KnowledgeDataEntity; |
||||
import org.apache.ibatis.annotations.*; |
||||
|
||||
import java.util.List; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 知识库管理 |
||||
* @date 2024-06-26 14:21:47 |
||||
*/ |
||||
@Mapper |
||||
public interface KnowledgeDataMapper { |
||||
|
||||
@Insert("insert into knowledge_data(title,description,content,create_time,status,remark) " + |
||||
" values(#{title},#{description},#{content},getDate(),#{status},#{remark})") |
||||
void insertKnowledgeData(KnowledgeDataEntity knowledgeData); |
||||
|
||||
@Results({ |
||||
@Result(column = "id",property = "id" ), |
||||
@Result(column = "title", property = "title"), |
||||
@Result(column = "description", property = "description"), |
||||
@Result(column = "content", property = "content"), |
||||
@Result(column = "create_time", property = "createTime"), |
||||
@Result(column = "status", property = "status"), |
||||
@Result(column = "remark", property = "remark") |
||||
}) |
||||
@Select("select id,title,description,content,create_time,status,remark from knowledge_data order by create_time desc") |
||||
List<KnowledgeDataEntity> findPage(); |
||||
|
||||
@Update("<script>" + |
||||
" update knowledge_data set " + |
||||
" <if test='title!=null'> title = #{title} </if>" + |
||||
" <if test='description!=null'> , description = #{description} </if>" + |
||||
" <if test='content!=null'> , content = #{content} </if>" + |
||||
" <if test='createTime!=null'> , create_time = #{createTime} </if>" + |
||||
" <if test='status!=null'> , status = #{status} </if>" + |
||||
" <if test='remark!=null'> , remark = #{remark} </if>" + |
||||
" where id = #{id} " + |
||||
"</script>") |
||||
void updateData(KnowledgeDataEntity knowledgeData); |
||||
|
||||
@Results({ |
||||
@Result(column = "id",property = "id" ), |
||||
@Result(column = "title", property = "title"), |
||||
@Result(column = "description", property = "description"), |
||||
@Result(column = "content", property = "content"), |
||||
@Result(column = "create_time", property = "createTime"), |
||||
@Result(column = "status", property = "status"), |
||||
@Result(column = "remark", property = "remark") |
||||
}) |
||||
@Select("select id,title,description,content,create_time,status,remark from knowledge_data where id = #{id} order by create_time desc") |
||||
KnowledgeDataEntity getById(@Param("id") Long id); |
||||
} |
@ -0,0 +1,23 @@
|
||||
package com.mh.user.service; |
||||
|
||||
import com.mh.common.page.PageRequest; |
||||
import com.mh.common.page.PageResult; |
||||
import com.mh.user.entity.KnowledgeDataEntity; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 知识库服务 |
||||
* @date 2024-06-26 14:32:06 |
||||
*/ |
||||
public interface KnowledgeDataService { |
||||
|
||||
void insertKnowledgeData(KnowledgeDataEntity knowledgeData); |
||||
|
||||
PageResult queryKnowledgeData(PageRequest pageRequest); |
||||
|
||||
void updateData(KnowledgeDataEntity knowledgeData); |
||||
|
||||
KnowledgeDataEntity getById(Long id); |
||||
} |
@ -0,0 +1,47 @@
|
||||
package com.mh.user.service.impl; |
||||
|
||||
import com.github.pagehelper.PageHelper; |
||||
import com.mh.common.page.ColumnFilter; |
||||
import com.mh.common.page.MybatisPageHelper; |
||||
import com.mh.common.page.PageRequest; |
||||
import com.mh.common.page.PageResult; |
||||
import com.mh.user.entity.KnowledgeDataEntity; |
||||
import com.mh.user.mapper.KnowledgeDataMapper; |
||||
import com.mh.user.service.KnowledgeDataService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
|
||||
/** |
||||
* @author LJF |
||||
* @version 1.0 |
||||
* @project CHWS |
||||
* @description 知识库服务实现类 |
||||
* @date 2024-06-26 14:33:20 |
||||
*/ |
||||
@Service |
||||
public class KnowledgeDataServiceImpl implements KnowledgeDataService { |
||||
|
||||
@Resource |
||||
private KnowledgeDataMapper knowledgeDataMapper; |
||||
|
||||
@Override |
||||
public void insertKnowledgeData(KnowledgeDataEntity knowledgeData) { |
||||
knowledgeDataMapper.insertKnowledgeData(knowledgeData); |
||||
} |
||||
|
||||
@Override |
||||
public PageResult queryKnowledgeData(PageRequest pageRequest) { |
||||
return MybatisPageHelper.findPage(pageRequest, knowledgeDataMapper); |
||||
} |
||||
|
||||
@Override |
||||
public void updateData(KnowledgeDataEntity knowledgeData) { |
||||
knowledgeDataMapper.updateData(knowledgeData); |
||||
} |
||||
|
||||
@Override |
||||
public KnowledgeDataEntity getById(Long id) { |
||||
return knowledgeDataMapper.getById(id); |
||||
} |
||||
} |
Loading…
Reference in new issue