实现后台发布公告
This commit is contained in:
@@ -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());
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,7 @@ public class NoticeService {
|
||||
return noticeRepository.findAll();
|
||||
}
|
||||
|
||||
public TbNotice addOne(TbNotice notice){
|
||||
return noticeRepository.save(notice);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user