Commit b309f0a1 authored by Quxl's avatar Quxl

x

parent 3e90dd3b
package com.egolm.film.api.service;
import java.util.List;
import java.util.Map;
import com.egolm.common.jdbc.Page;
public interface NewsService {
List<Map<String, Object>> queryList(Page page);
void merge(Object obj);
void batchSave(List<?> objs);
Map<String, Object> queryById(Integer id);
}
package com.egolm.film.api.service.impl;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
import com.egolm.film.api.service.NewsService;
@Service
public class NewsServiceImpl implements NewsService {
@Autowired
JdbcTemplate jdbcTemplate;
@Override
public List<Map<String, Object>> queryList(Page page) {
return jdbcTemplate.limit("select ns.*, a.realname creator_name from fc_news ns left join fc_admin a on a.adminid = ns.creator", page);
}
@Override
public void merge(Object obj) {
jdbcTemplate.merge(obj);
}
@Override
public void batchSave(List<?> objs) {
jdbcTemplate.batchSave(objs);
}
@Override
public Map<String, Object> queryById(Integer id) {
return jdbcTemplate.queryForMap("select * from fc_news where id = ?", id);
}
}
package com.egolm.film.api.web.admin;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import com.egolm.film.api.service.AdminTokenService;
import com.egolm.film.api.service.NewsService;
import com.egolm.film.bean.Fc_news;
import com.egolm.film.bean.Fc_news_sender;
import com.egolm.film.model.LoginToken;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api
@Controller
@RequestMapping("admin/news")
public class AdminNewsController {
@Autowired
AdminTokenService tokenService;
@Autowired
NewsService service;
@ResponseBody
@PostMapping("list")
@ApiOperation("公告列表查询")
public Object list(Long index, Long limit) {
index = index == null ? 1 : index;
limit = limit == null ? 20 : limit;
Page page = new Page(index, limit);
List<Map<String, Object>> list = service.queryList(page);
return Rjx.jsonOk().setData(list).setPage(page);
}
@ResponseBody
@PostMapping("saveOrUpdate")
@ApiOperation("公告保存")
@ApiImplicitParams({
@ApiImplicitParam(paramType="query", name="id", value="ID"),
@ApiImplicitParam(paramType="query", name="type", value="消息类型(HTML, TEXT)"),
@ApiImplicitParam(paramType="query", name="title", value="消息标题"),
@ApiImplicitParam(paramType="query", name="content", value="消息内容"),
@ApiImplicitParam(paramType="query", name="level", value="消息级别 (0,1,2,3,4...自定义)"),
})
public Object save(Integer id, String type, String title, String content, Integer level) {
Date now = new Date();
LoginToken loginToken = tokenService.getToken();
Integer adminid = (Integer)loginToken.getId();
Fc_news news = new Fc_news();
news.setId(id);
news.setType(type);
news.setTitle(title);
news.setContent(content);
news.setLevel(level);
if(id == null) {
news.setCreator(adminid);
news.setCreate_time(now);
news.setUpdater(adminid);
news.setLast_update_time(now);
} else {
news.setUpdater(adminid);
news.setLast_update_time(now);
}
service.merge(news);
return Rjx.jsonOk();
}
@ResponseBody
@PostMapping("send")
@ApiOperation("消息发送")
@ApiImplicitParams({
@ApiImplicitParam(paramType="query", name="id", value="消息ID"),
@ApiImplicitParam(paramType="query", name="user_id", value="用户ID", allowMultiple=true),
@ApiImplicitParam(paramType="query", name="user_group_id", value="用户组ID", allowMultiple=true),
})
public Object send(Integer id, Integer[] user_id, Integer[] user_group_id) {
Date now = new Date();
LoginToken loginToken = tokenService.getToken();
Integer adminid = (Integer)loginToken.getId();
List<Fc_news_sender> senders = new ArrayList<Fc_news_sender>();
for(Integer uid : user_id) {
Fc_news_sender sender = new Fc_news_sender();
sender.setNews_id(id);
sender.setUser_id(uid);
sender.setSender(adminid);
sender.setSend_time(now);
senders.add(sender);
}
for(Integer gid : user_group_id) {
Fc_news_sender sender = new Fc_news_sender();
sender.setNews_id(id);
sender.setUser_group_id(gid);
sender.setSender(adminid);
sender.setSend_time(now);
senders.add(sender);
}
service.batchSave(senders);
return Rjx.jsonOk();
}
@ResponseBody
@PostMapping("getById")
@ApiOperation("消息详情查询")
@ApiImplicitParams({
@ApiImplicitParam(paramType="query", name="id", value="消息ID"),
})
public Object getById(Integer id) {
Map<String, Object> map = service.queryById(id);
return Rjx.jsonOk().setData(map);
}
}
package com.egolm.film.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Entity(name="fc_news")
public class Fc_news implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(11)")
private Integer id;
@Column(columnDefinition="varchar(64) COMMENT '消息类型 TEXT,HTML'")
private String type;
@Column(columnDefinition="varchar(255) COMMENT '标题'")
private String title;
@Column(columnDefinition="longtext COMMENT '内容'")
private String content;
@Column(columnDefinition="int(11) COMMENT '级别 0,1,2,3,4,5自定义'")
private Integer level;
@Column(columnDefinition="int(11) COMMENT '创建人'")
private Integer creator;
@Column(columnDefinition="datetime COMMENT '创建时间'")
private Date create_time;
@Column(columnDefinition="int(11) COMMENT '最后修改人'")
private Integer updater;
@Column(columnDefinition="datetime COMMENT '最后修改时间'")
private Date last_update_time;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setType(String type) {
this.type = type;
}
public String getType() {
return type;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitle() {
return title;
}
public void setContent(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setLevel(Integer level) {
this.level = level;
}
public Integer getLevel() {
return level;
}
public void setCreator(Integer creator) {
this.creator = creator;
}
public Integer getCreator() {
return creator;
}
public void setCreate_time(Date create_time) {
this.create_time = create_time;
}
public Date getCreate_time() {
return create_time;
}
public void setUpdater(Integer updater) {
this.updater = updater;
}
public Integer getUpdater() {
return updater;
}
public void setLast_update_time(Date last_update_time) {
this.last_update_time = last_update_time;
}
public Date getLast_update_time() {
return last_update_time;
}
}
package com.egolm.film.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
@Entity(name="fc_news_read")
public class Fc_news_read implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(11)")
private Integer news_id;
@Id
@Column(columnDefinition="int(11)")
private Integer user_id;
public void setNews_id(Integer news_id) {
this.news_id = news_id;
}
public Integer getNews_id() {
return news_id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public Integer getUser_id() {
return user_id;
}
}
package com.egolm.film.bean;
import javax.persistence.Entity;
import javax.persistence.Column;
import javax.persistence.Id;
import java.util.Date;
@Entity(name="fc_news_sender")
public class Fc_news_sender implements java.io.Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(columnDefinition="int(11)")
private Integer news_id;
@Id
@Column(columnDefinition="int(11)")
private Integer user_id;
@Id
@Column(columnDefinition="int(11)")
private Integer user_group_id;
@Column(columnDefinition="int(11) COMMENT '发送人'")
private Integer sender;
@Column(columnDefinition="datetime COMMENT '发送时间'")
private Date send_time;
public void setNews_id(Integer news_id) {
this.news_id = news_id;
}
public Integer getNews_id() {
return news_id;
}
public void setUser_id(Integer user_id) {
this.user_id = user_id;
}
public Integer getUser_id() {
return user_id;
}
public void setUser_group_id(Integer user_group_id) {
this.user_group_id = user_group_id;
}
public Integer getUser_group_id() {
return user_group_id;
}
public void setSender(Integer sender) {
this.sender = sender;
}
public Integer getSender() {
return sender;
}
public void setSend_time(Date send_time) {
this.send_time = send_time;
}
public Date getSend_time() {
return send_time;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment