实现后台发布公告

This commit is contained in:
F嘉阳
2018-03-06 09:59:59 +08:00
parent dd4caf9fd4
commit 8507283a40
8 changed files with 139 additions and 8 deletions

View File

@@ -5,7 +5,7 @@
<groupId>com.fjy</groupId>
<artifactId>spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>V2.4 RC2</version>
<packaging>jar</packaging>
<name>spring</name>

View File

@@ -12,10 +12,8 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.text.SimpleDateFormat;
import java.util.*;
import static com.fjy.spring.constant.GlobalConstant.USER_SESSION_KEY;
@@ -53,6 +51,9 @@ public class DataController {
@Autowired
private VersionService versionService;
@Autowired
private AdminService adminService;
@Resource
private HttpServletRequest httpServletRequest;
@@ -183,6 +184,25 @@ public class DataController {
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")
public boolean addOneVersion(TbVersion version){
//log.info(version.toString());

View 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;
}

View File

@@ -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> {
}

View File

@@ -1,7 +1,9 @@
package com.fjy.spring.service;
import com.fjy.spring.domain.TbAdmin;
import com.fjy.spring.domain.VAdmin;
import com.fjy.spring.repository.TbAdminRepository;
import com.fjy.spring.repository.VAdminRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -12,7 +14,14 @@ public class AdminService {
@Autowired
private TbAdminRepository adminRepository;
@Autowired
private VAdminRepository vAdminRepository;
public Optional<TbAdmin> findAdminById(Integer id){
return adminRepository.findByUserid(id);
}
public Optional<VAdmin> findAdminByUserId(Integer id){
return vAdminRepository.findById(id);
}
}

View File

@@ -17,4 +17,7 @@ public class NoticeService {
return noticeRepository.findAll();
}
public TbNotice addOne(TbNotice notice){
return noticeRepository.save(notice);
}
}

View File

@@ -1,6 +1,9 @@
var Main = {
data() {
return {
NoticeForm: {
content: ''
},
activeIndex: '1',
form: {
content: '',
@@ -61,6 +64,25 @@ var Main = {
})
},
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) {
return getRootPath_web()+"/home/moreUpload?rename=false";
},
@@ -81,6 +103,50 @@ var Main = {
},
onSubmit() {
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;
}
});
}
}
}

View File

@@ -35,12 +35,13 @@
</el-row>
<el-row>
<h4>发布公告</h4>
<el-form :model="form">
<el-form :model="NoticeForm" ref="NoticeForm">
<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-button type="primary" @click="onSubmit">添加</el-button>
<el-button type="primary" @click="submitForm('NoticeForm')">添加</el-button>
</el-form-item>
</el-form>
</el-row>