每周总结
本周完成了一个简单的小测试:
河北省科技政策查询系统
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title</title>
<link rel="stylesheet" href="plugins/element-ui/index.css">
<link rel="stylesheet" href="plugins/layui-v2.7.6/layui/css/layui.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
<style>
body{
float: left;
}
#left{
width: 10%;
float: left;
}
#right{
width:87%;
margin-left: 200px;
}
.right-top{
text-align: center;
height: 50px;
}
.right-content{
margin-top: 5px;
margin-left: 5px;
width: available;
height: available;
float: left;
}
.right-content-left{
width: 10%;
height: available;
float: left;
}
.right-content-right{
width:75%;
height:available ;
float: left;
margin-left: 150px;
}
#text1{
width:80px;
margin-left: 30px;
font-size: 15px;
height: available;
}
.filter-container .el-button,.filter-container .el-input__inner{
padding: 0 15px;
height: 34px;
line-height: 34px;
}
</style>
</head>
<body class="hold-transition">
<div id="app">
<div id="left">
<ul class="layui-nav layui-nav-tree layui-nav-side">
<li class="layui-nav-item"><a href="">科技文档管理</a></li>
<li class="layui-nav-item"><a href="">系统设置</a></li>
</ul>
</div>
<div id="right">
<div class="right-top layui-card">
<div class="right-top-title"><img src="images/LOGO.png" width="40" height="40" alt="logo"><span style="font-size:25px;color: #01aaed;font-weight: bold;margin-left: 15px;">科技政策查询系统</span></div>
</div>
<div class="right-content">
<div class="right-content-left">
<div class="layui-card" id="text1">图解政策</div>
<div id="tree" style="font-size: 15px;">
<el-tree
:data="typeTree"
nodeKey="id"
:props="children"
default-expand-all
@node-click="handleNodeClick"
v-model="type"
>
</el-tree>
</div>
</div>
<div class="right-content-right">
<div class="filter-container">
<el-form
ref="dataAddForm"
:model="formData"
:rules="rules"
label-position="right"
label-width="100px"
>
<div class="app-container">
<div class="box">
<div class="filter-container">
政策名称
<el-input
placeholder="请输入政策名称"
v-model="formData.name"
style="width: 150px"
class="filter-item"
></el-input>
发文字号
<el-input
placeholder="发文字号"
v-model="formData.document"
style="width: 100px"
class="filter-item"
></el-input>
发文机构
<el-input
placeholder="发文机构"
v-model="formData.organ"
style="width: 100px"
class="filter-item"
></el-input>
全文检索
<el-input
placeholder="全文检索"
v-model="formData.text"
style="width: 100px"
class="filter-item">
</el-input>
<el-button @click="handleQuery()" class="dalfBut">查询</el-button>
</div>
</div>
</div>
</el-form>
</div>
<el-table size="middle" :data="policyList" stripe highlight-current-row>
<el-table-column prop="name" align="center" label="政策名称"></el-table-column>
<el-table-column prop="organ" align="center" label="发文机构"></el-table-column>
<el-table-column prop="pubdata" align="center" label="发布日期"></el-table-column>
<el-table-column prop="type" align="center" label="政策分类"></el-table-column>
<el-table-column laybel="操作" align="center">
<template slot-scope="scope">
<el-button type="primary" size="mini" @click="read(scope.row)">查看</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
class="pageList"
:page-sizes="[3,5,10,15,20,30]"
:page-size="pageSize"
layout="total,sizes,prev,pager,next,jumper"
:total="counts"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
></el-pagination>
</div>
<!-- 政策查看层-->
<div class="add-form">
<el-dialog title="政策内容" width="90%" :visible.sync="dialogVisible">
<div><el-input v-html="text" type="textarea"></el-input></div>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="dialogVisible = false">确 定</el-button>
</span>
</el-dialog>
</span>
</div>
</div>
</div>
</div>
</div>
<script src="plugins/vue/vue.js"></script>
<script src="plugins/element-ui/index.js"></script>
<script src="plugins/axios/axios.min.js"></script>
<script>
var vue = new Vue({
el:'#app',
data:{
counts:0,
page:1,
pageSize:3,
dialogVisible:false,
type:'',
policyList:[],
text:{},
typeTree:{},
formData:{
'name':'',
'document':'',
'organ':'',
'text':'',
}
},
created(){
// this.getType();
this.getAllPolicies()
this.getAllType()
},
methods:{
handleNodeClick(data) {
axios.get("/type/"+data.label).then((res)=>{
this.policyList = res.data
})
},
getAllPolicies(){
const params = {
'page': this.page,
'pageSize': this.pageSize
}
axios({ url:'/policy/page',method:'get',params}).then((res)=>{
this.policyList = res.data.records;
this.counts = res.data.total
})
},
read(row){
console.log(row);
this.dialogVisible=true
axios.get("/policy/"+row.id).then((res)=>{
this.text=res.data.text
})
},
handleQuery(){
const params = {
'page': this.page,
'pageSize': this.pageSize,
'policy': this.formData
}
axios({url:'/policy/page1',method:'post',params}).then((res)=>{
this.policyList = res.data.records;
this.counts = res.data.total
})
},
getAllType() {
axios.get("/type").then((res)=>{
this.typeTree = res.data;
})
},
handleSizeChange(val){
this.pageSize = val
this.getAllPolicies();
},
handleCurrentChange(val){
this.pageSize = val
this.getAllPolicies();
}
},
mounted(){
}
})
</script>
</body>
</html>
Controller设计
package com.rsh.doc.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rsh.doc.domain.Policy;
import com.rsh.doc.mapper.PolicyMapper;
import com.rsh.doc.service.PolicyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/policy")
public class PolicyController {
@Autowired
private PolicyService policyService;
@Autowired
private PolicyMapper policyMapper;
@GetMapping("/page")
public Page<Policy> getAll(int page,int pageSize){
System.out.println(page+","+pageSize);
Page<Policy> pagePolicy = new Page<>(page,pageSize);
LambdaQueryWrapper<Policy> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByAsc(Policy::getId);
policyService.page(pagePolicy, queryWrapper);
System.out.println(pagePolicy);
return pagePolicy;
}
@GetMapping("/{id}")
public Policy getOne(@PathVariable Integer id){
System.out.println(id);
Policy policy = policyService.getOne(id);
return policy;
}
@PostMapping("/page1")
@ResponseBody
public Page<Policy> selectByConditions(int page,int pageSize,@RequestBody Policy policy){
System.out.println(page+","+pageSize);
Page<Policy> pagePolicy = new Page<>(page,pageSize);
System.out.println(policy);
LambdaQueryWrapper<Policy> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.like(policy.getName() != null,Policy::getName,policy.getName());
lambdaQueryWrapper.like(policy.getDocument() != null,Policy::getDocument,policy.getDocument());
lambdaQueryWrapper.like(policy.getOrgan() != null,Policy::getOrgan,policy.getOrgan());
lambdaQueryWrapper.like(policy.getText() != null,Policy::getText,policy.getText());
policyService.page(pagePolicy,lambdaQueryWrapper);
System.out.println(pagePolicy);
return pagePolicy;
}
}
package com.rsh.doc.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.rsh.doc.domain.Policy;
import com.rsh.doc.domain.Type;
import com.rsh.doc.dto.TypeTree;
import com.rsh.doc.service.TypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/type")
public class TypeController {
@Autowired
private TypeService typeService;
@GetMapping
public List<TypeTree> getTrees(){
return typeService.getTypeAll();
}
@GetMapping("/{label}")
public List<Policy> getPolicy(@PathVariable String label){
System.out.println(label);
List<Policy> policyList = typeService.getTypeWithPolicy(label);
return policyList;
}
}
service和Impl设计
package com.rsh.doc.service;
import com.rsh.doc.domain.Policy;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* @author 15251
* @description 针对表【policy】的数据库操作Service
* @createDate 2022-10-26 20:51:29
*/
public interface PolicyService extends IService<Policy> {
public List<Policy> getAll();
public Policy getOne(Integer id);
}
package com.rsh.doc.service;
import com.rsh.doc.domain.Policy;
import com.rsh.doc.domain.Type;
import com.baomidou.mybatisplus.extension.service.IService;
import com.rsh.doc.dto.TypeTree;
import java.util.List;
/**
* @author 15251
* @description 针对表【type】的数据库操作Service
* @createDate 2022-10-26 20:52:16
*/
public interface TypeService extends IService<Type> {
public List<TypeTree> getTypeAll();
public List<Policy> getTypeWithPolicy(String label);
}
package com.rsh.doc.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rsh.doc.domain.Policy;
import com.rsh.doc.service.PolicyService;
import com.rsh.doc.mapper.PolicyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @author 15251
* @description 针对表【policy】的数据库操作Service实现
* @createDate 2022-10-26 20:51:29
*/
@Service
public class PolicyServiceImpl extends ServiceImpl<PolicyMapper, Policy>
implements PolicyService{
@Autowired
private PolicyMapper policyMapper;
public List<Policy> getAll(){
return policyMapper.getAll();
}
@Override
public Policy getOne(Integer id) {
return policyMapper.getByIdPolicy(id);
}
}
package com.rsh.doc.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rsh.doc.domain.Policy;
import com.rsh.doc.domain.Type;
import com.rsh.doc.dto.TypeDto;
import com.rsh.doc.dto.TypeTree;
import com.rsh.doc.mapper.PolicyMapper;
import com.rsh.doc.service.PolicyService;
import com.rsh.doc.service.TypeService;
import com.rsh.doc.mapper.TypeMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.xml.ws.soap.Addressing;
import java.util.ArrayList;
import java.util.List;
/**
* @author 15251
* @description 针对表【type】的数据库操作Service实现
* @createDate 2022-10-26 20:52:16
*/
@Service
public class TypeServiceImpl extends ServiceImpl<TypeMapper, Type>
implements TypeService{
@Autowired
PolicyMapper policyMapper;
@Autowired
private TypeMapper typeMapper;
@Autowired
private PolicyService policyService;
@Override
public List<Policy> getTypeWithPolicy(String label) {
String s = StringUtils.substringBefore(label, "(");
System.out.println(s);
List<Policy> list = policyMapper.getAllByType(s);
return list;
}
public List<TypeTree> getTypeAll(){
List<Integer> typeNum = policyMapper.getTypeNum();
LambdaQueryWrapper<Type> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.orderByAsc(Type::getTypeId);
List<Type> list = this.list(queryWrapper);
List<TypeDto> dtoList = new ArrayList<>();
for(int i = 0 ; i < list.size() ; i++){
TypeDto typeDto = new TypeDto();
BeanUtils.copyProperties(list.get(i),typeDto);
typeDto.setId(i+1);
if(!typeDto.getTypeId().substring(2,4).equals("00")){
for(int j = 0 ; j < list.size() ; j++){
if( list.get(j).getTypeId().equals(typeDto.getTypeId().substring(0,2)+"00")){
typeDto.setPId(j+1);
}
}
}else {
typeDto.setPId(0);
}
dtoList.add(typeDto);
}
System.out.println(typeToTree(typeNum,dtoList,0));
return typeToTree(typeNum,dtoList,0);
}
private List<TypeTree> typeToTree(List<Integer> typeNumList,List<TypeDto> dtoList,int pid){
List<TypeTree> typeTrees = new ArrayList<>();
for(int i = 0 ; i < dtoList.size() ; i++){
TypeDto typeDto = dtoList.get(i);
if(dtoList.get(i).getPId() == pid){
TypeTree typeTree = new TypeTree();
typeTree.setId(typeDto.getId());
typeTree.setLabel(typeDto.getType()+"("+typeNumList.get(i)+")");
typeTree.setChildren(typeToTree(typeNumList,dtoList,typeDto.getId()));
typeTrees.add(typeTree);
}
}
return typeTrees;
}
}
mapper设计
package com.rsh.doc.mapper;
import com.rsh.doc.domain.Policy;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
/**
* @author 15251
* @description 针对表【policy】的数据库操作Mapper
* @createDate 2022-10-26 20:51:29
* @Entity com.rsh.doc.domain.Policy
*/
@Mapper
public interface PolicyMapper extends BaseMapper<Policy> {
@Select("SELECT COUNT(*) FROM policy GROUP BY TYPE")
public List<Integer> getTypeNum();
@Select("SELECT * FROM policy")
public List<Policy> getAll();
@Select("SELECT * FROM policy WHERE id=#{id}")
public Policy getByIdPolicy(Integer id);
@Select("SELECT * FROM policy where type=#{type}")
public List<Policy> getAllByType(String type);
}
package com.rsh.doc.mapper;
import com.rsh.doc.domain.Type;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* @author 15251
* @description 针对表【type】的数据库操作Mapper
* @createDate 2022-10-26 20:52:16
* @Entity com.rsh.doc.domain.Type
*/
@Mapper
public interface TypeMapper extends BaseMapper<Type> {
}
dto与domain设计
package com.rsh.doc.dto;
import com.rsh.doc.domain.Type;
import lombok.Data;
@Data
public class TypeDto extends Type {
private int id;
private int pId;
private String type;
private String typeId;
}
package com.rsh.doc.dto;
import lombok.Data;
import java.util.List;
@Data
public class TypeTree {
private int id;
private String label;
private List<TypeTree> children;
}
package com.rsh.doc.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
*
* @TableName policy
*/
@Data
@TableName(value ="policy")
public class Policy implements Serializable {
/**
*
*/
@TableId(type = IdType.AUTO)
private Long id;
/**
* 政策名称
*/
private String name;
/**
* 政策分类
*/
private String type;
/**
* 发文字号
*/
private String document;
/**
* 制定机关
*/
private String organ;
/**
*
*/
private Date pubdata;
private String text;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
}
package com.rsh.doc.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
/**
*
* @TableName type
*/
@TableName(value ="type")
public class Type implements Serializable {
/**
*
*/
@TableId
private String typeId;
/**
*
*/
private String type;
@TableField(exist = false)
private static final long serialVersionUID = 1L;
/**
*
*/
public String getTypeId() {
return typeId;
}
/**
*
*/
public void setTypeId(String typeId) {
this.typeId = typeId;
}
/**
*
*/
public String getType() {
return type;
}
/**
*
*/
public void setType(String type) {
this.type = type;
}
@Override
public boolean equals(Object that) {
if (this == that) {
return true;
}
if (that == null) {
return false;
}
if (getClass() != that.getClass()) {
return false;
}
Type other = (Type) that;
return (this.getTypeId() == null ? other.getTypeId() == null : this.getTypeId().equals(other.getTypeId()))
&& (this.getType() == null ? other.getType() == null : this.getType().equals(other.getType()));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((getTypeId() == null) ? 0 : getTypeId().hashCode());
result = prime * result + ((getType() == null) ? 0 : getType().hashCode());
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", typeId=").append(typeId);
sb.append(", type=").append(type);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
}
还有软件需求与分析中的结构设计,功能设计,数据设计,还有个什么设计我给忘了。每个设计怎么实现等复习时在写吧。

浙公网安备 33010602011771号