实现后台发布公告
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>com.fjy</groupId>
|
<groupId>com.fjy</groupId>
|
||||||
<artifactId>spring</artifactId>
|
<artifactId>spring</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>V2.4 RC2</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>spring</name>
|
<name>spring</name>
|
||||||
|
|||||||
@@ -12,10 +12,8 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
|
||||||
|
|
||||||
@@ -53,6 +51,9 @@ public class DataController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private VersionService versionService;
|
private VersionService versionService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdminService adminService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private HttpServletRequest httpServletRequest;
|
private HttpServletRequest httpServletRequest;
|
||||||
|
|
||||||
@@ -183,6 +184,25 @@ public class DataController {
|
|||||||
return noticeService.findAll();
|
return noticeService.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/home/admin/addNotice")
|
||||||
|
public boolean addNotice(String content){
|
||||||
|
TbUser user= (TbUser)httpServletRequest.getSession().getAttribute(USER_SESSION_KEY);
|
||||||
|
TbNotice notice = new TbNotice();
|
||||||
|
Date date = new Date();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateNowStr = sdf.format(date);
|
||||||
|
Optional<VAdmin> vAdmin = adminService.findAdminByUserId(user.getColuserid());
|
||||||
|
if (vAdmin.isPresent()){
|
||||||
|
VAdmin admin = vAdmin.get();
|
||||||
|
notice.setAdminid(admin.getAdminid());
|
||||||
|
notice.setIssueTime(dateNowStr);
|
||||||
|
notice.setNoticeContent(content);
|
||||||
|
return noticeService.addOne(notice)!=null;
|
||||||
|
}else
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/home/admin/addoneversion")
|
@PostMapping("/home/admin/addoneversion")
|
||||||
public boolean addOneVersion(TbVersion version){
|
public boolean addOneVersion(TbVersion version){
|
||||||
//log.info(version.toString());
|
//log.info(version.toString());
|
||||||
|
|||||||
25
src/main/java/com/fjy/spring/domain/VAdmin.java
Normal file
25
src/main/java/com/fjy/spring/domain/VAdmin.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.fjy.spring.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.Immutable;
|
||||||
|
import org.hibernate.annotations.Subselect;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Immutable
|
||||||
|
@Subselect("SELECT * FROM v_admin")
|
||||||
|
@Data
|
||||||
|
public class VAdmin {
|
||||||
|
@Id
|
||||||
|
@Column(name = "coluserid")
|
||||||
|
private Integer userid;
|
||||||
|
|
||||||
|
private Integer adminid;
|
||||||
|
|
||||||
|
private String coltime;
|
||||||
|
|
||||||
|
private String colname;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.fjy.spring.repository;
|
||||||
|
|
||||||
|
import com.fjy.spring.domain.VAdmin;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface VAdminRepository extends JpaRepository<VAdmin,Integer> {
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.fjy.spring.service;
|
package com.fjy.spring.service;
|
||||||
|
|
||||||
import com.fjy.spring.domain.TbAdmin;
|
import com.fjy.spring.domain.TbAdmin;
|
||||||
|
import com.fjy.spring.domain.VAdmin;
|
||||||
import com.fjy.spring.repository.TbAdminRepository;
|
import com.fjy.spring.repository.TbAdminRepository;
|
||||||
|
import com.fjy.spring.repository.VAdminRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -12,7 +14,14 @@ public class AdminService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private TbAdminRepository adminRepository;
|
private TbAdminRepository adminRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VAdminRepository vAdminRepository;
|
||||||
|
|
||||||
public Optional<TbAdmin> findAdminById(Integer id){
|
public Optional<TbAdmin> findAdminById(Integer id){
|
||||||
return adminRepository.findByUserid(id);
|
return adminRepository.findByUserid(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<VAdmin> findAdminByUserId(Integer id){
|
||||||
|
return vAdminRepository.findById(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,7 @@ public class NoticeService {
|
|||||||
return noticeRepository.findAll();
|
return noticeRepository.findAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TbNotice addOne(TbNotice notice){
|
||||||
|
return noticeRepository.save(notice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
var Main = {
|
var Main = {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
NoticeForm: {
|
||||||
|
content: ''
|
||||||
|
},
|
||||||
activeIndex: '1',
|
activeIndex: '1',
|
||||||
form: {
|
form: {
|
||||||
content: '',
|
content: '',
|
||||||
@@ -61,6 +64,25 @@ var Main = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
openNotiSuccess(title, content) {
|
||||||
|
this.$notify({
|
||||||
|
title: title,
|
||||||
|
message: content,
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
},
|
||||||
|
openNotiError(title, content) {
|
||||||
|
this.$notify.error({
|
||||||
|
title: title,
|
||||||
|
message: content
|
||||||
|
});
|
||||||
|
},
|
||||||
|
openSuccess(content) {
|
||||||
|
this.$message({
|
||||||
|
message: content,
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
},
|
||||||
uploadURL(row) {
|
uploadURL(row) {
|
||||||
return getRootPath_web()+"/home/moreUpload?rename=false";
|
return getRootPath_web()+"/home/moreUpload?rename=false";
|
||||||
},
|
},
|
||||||
@@ -81,6 +103,50 @@ var Main = {
|
|||||||
},
|
},
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
console.log('submit!');
|
console.log('submit!');
|
||||||
|
},submitForm(formName) {
|
||||||
|
this.$refs[formName].validate((valid) => {
|
||||||
|
let that = this;
|
||||||
|
if (valid) {
|
||||||
|
axios({
|
||||||
|
url: getRootPath_web()+'/home/admin/addNotice',
|
||||||
|
method: 'post',
|
||||||
|
data: {
|
||||||
|
content: this.$refs.content.value
|
||||||
|
},
|
||||||
|
transformRequest: [function (data) {
|
||||||
|
// Do whatever you want to transform the data
|
||||||
|
let ret = ''
|
||||||
|
for (let it in data) {
|
||||||
|
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}],
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
}).then(function (response) {
|
||||||
|
console.log(response.data);
|
||||||
|
if (response.data===true){
|
||||||
|
//that.$refs[formName].submit;
|
||||||
|
//return true;
|
||||||
|
that.openNotiSuccess("成功", "发布成功!")
|
||||||
|
}else if (response.data===false){
|
||||||
|
that.openNotiError("失败", "发布失败!");
|
||||||
|
}else {
|
||||||
|
that.openNotiError("错误", response.data.message);
|
||||||
|
}
|
||||||
|
}).catch(function (error) {
|
||||||
|
console.log(error);
|
||||||
|
that.openNotiError("错误", "服务器错误!");
|
||||||
|
});
|
||||||
|
//console.log(this.$refs.content.value)
|
||||||
|
//this.$options.methods.openNotiSuccess.bind(this)();
|
||||||
|
//alert('submit!');
|
||||||
|
} else {
|
||||||
|
console.log('error submit!!');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,13 @@
|
|||||||
</el-row>
|
</el-row>
|
||||||
<el-row>
|
<el-row>
|
||||||
<h4>发布公告</h4>
|
<h4>发布公告</h4>
|
||||||
<el-form :model="form">
|
<el-form :model="NoticeForm" ref="NoticeForm">
|
||||||
<el-form-item label="公告内容">
|
<el-form-item label="公告内容">
|
||||||
<el-input v-model="form.content" placeholder="公告内容" type="textarea"></el-input>
|
<el-input v-model="NoticeForm.content" placeholder="公告内容" type="textarea"
|
||||||
|
name="content" ref="content"></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" @click="onSubmit">添加</el-button>
|
<el-button type="primary" @click="submitForm('NoticeForm')">添加</el-button>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|||||||
Reference in New Issue
Block a user