package com.sinata.modular.system.controller;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.sinata.common.enums.EnumNoticeMessageType;
|
import com.sinata.core.base.controller.BaseController;
|
import com.sinata.core.common.annotion.BussinessLog;
|
import com.sinata.core.common.annotion.Permission;
|
import com.sinata.core.common.constant.factory.PageFactory;
|
import com.sinata.core.log.LogObjectHolder;
|
import com.sinata.core.util.ToolUtil;
|
import com.sinata.modular.member.model.MemMerchant;
|
import com.sinata.modular.member.model.MemUser;
|
import com.sinata.modular.member.service.IMemMerchantService;
|
import com.sinata.modular.member.service.IMemUserService;
|
import com.sinata.modular.system.model.TNotice;
|
import com.sinata.modular.system.model.TNoticeMessage;
|
import com.sinata.modular.system.service.ITNoticeMessageService;
|
import com.sinata.modular.system.service.ITNoticeService;
|
import com.sinata.modular.system.service.RedisTemplateService;
|
import org.apache.commons.collections.CollectionUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
/**
|
* 公告控制器
|
*/
|
@Controller
|
@RequestMapping("/tNotice")
|
public class TNoticeController extends BaseController {
|
|
private String PREFIX = "/system/tNotice/";
|
|
@Autowired
|
private ITNoticeService tNoticeService;
|
|
@Autowired
|
private RedisTemplateService redisTemplateService;
|
|
@Autowired
|
private ITNoticeMessageService itNoticeMessageService;
|
|
@Autowired
|
private IMemUserService iMemUserService;
|
|
@Autowired
|
private IMemMerchantService iMemMerchantService;
|
|
/**
|
* 跳转到公告首页
|
*/
|
@RequestMapping("")
|
public String index() {
|
return PREFIX + "tNotice.html";
|
}
|
|
/**
|
* 跳转到添加公告
|
*/
|
@RequestMapping("/tNotice_add")
|
public String tNoticeAdd() {
|
return PREFIX + "tNotice_add.html";
|
}
|
|
/**
|
* 跳转到修改公告
|
*/
|
@RequestMapping("/tNotice_update/{tNoticeId}")
|
public String tNoticeUpdate(@PathVariable Integer tNoticeId, Model model) {
|
TNotice tNotice = tNoticeService.selectById(tNoticeId);
|
model.addAttribute("item",tNotice);
|
LogObjectHolder.me().set(tNotice);
|
return PREFIX + "tNotice_edit.html";
|
}
|
|
/**
|
* 获取公告列表
|
*/
|
@RequestMapping(value = "/list")
|
@ResponseBody
|
public Object list(String title, Integer source, String beginTime, String endTime) {
|
Wrapper<TNotice> wrapper = new EntityWrapper<TNotice>().orderBy("id", false);
|
// 未删除的信息
|
wrapper.eq("is_delete", 0);
|
// 标题名称
|
if (ToolUtil.isNotEmpty(title)) {
|
wrapper.and().like("title", title);
|
}
|
// 状态搜索
|
if (ToolUtil.isNotEmpty(source) && source != -1) {
|
wrapper.and().eq("source", source);
|
}
|
// 创建时间
|
if (ToolUtil.isNotEmpty(beginTime)) {
|
wrapper.ge("create_time", beginTime + " 00:00:00");
|
}
|
if (ToolUtil.isNotEmpty(endTime)) {
|
wrapper.le("create_time", endTime + " 23:59:59");
|
}
|
// 物理分页
|
Page<TNotice> page = new PageFactory<TNotice>().defaultPage();
|
page = tNoticeService.selectPage(page,wrapper);
|
return super.packForBT(page);
|
}
|
|
/**
|
* 新增公告
|
*/
|
@Permission
|
@RequestMapping(value = "/add")
|
@ResponseBody
|
public Object add(TNotice tNotice) {
|
if (tNotice != null) {
|
tNotice.setIsDelete( 0);
|
if (ToolUtil.isNotEmpty(tNotice.getContent())) {
|
// H5页面代码包装(判断加上自适应代码)
|
tNotice.setContent(ToolUtil.h5Warpper(tNotice.getContent()));
|
}
|
tNotice.setCreateTime(new Date());
|
tNoticeService.insert(tNotice);
|
Thread thread = new Thread(new Runnable() {
|
@Override
|
public void run() {
|
//消息来源 1-全部用户,2-全部商家
|
if (tNotice.getSource().equals("1")){
|
List<Object> ids = iMemUserService.selectObjs(new EntityWrapper<MemUser>().setSqlSelect("id").eq("is_delete",0));
|
if (CollectionUtils.isNotEmpty(ids)){
|
List<TNoticeMessage> tNoticeMessages = new ArrayList<TNoticeMessage>();
|
tNoticeMessages.addAll(ids.stream().map(id->{
|
TNoticeMessage tNoticeMessage = new TNoticeMessage();
|
tNoticeMessage.setContent(tNotice.getTitle());
|
tNoticeMessage.setCreateTime(tNotice.getCreateTime());
|
tNoticeMessage.setIsDelete(0);
|
tNoticeMessage.setIsRead(0);
|
tNoticeMessage.setOtherId(tNotice.getId().toString());
|
tNoticeMessage.setShowImg(tNotice.getCoverPlan());
|
tNoticeMessage.setUserId(new Integer(id.toString()));
|
tNoticeMessage.setType(EnumNoticeMessageType.NOTICE.index);
|
tNoticeMessage.setUserType(1);
|
return tNoticeMessage;
|
}).collect(Collectors.toList()));
|
itNoticeMessageService.insertList(tNoticeMessages);
|
}
|
}else{
|
List<Object> ids = iMemMerchantService.selectObjs(new EntityWrapper<MemMerchant>().setSqlSelect("id").eq("is_delete",0));
|
if (CollectionUtils.isNotEmpty(ids)){
|
List<TNoticeMessage> tNoticeMessages = new ArrayList<TNoticeMessage>();
|
tNoticeMessages = ids.stream().map(id->{
|
TNoticeMessage tNoticeMessage = new TNoticeMessage();
|
tNoticeMessage.setContent(tNotice.getTitle());
|
tNoticeMessage.setCreateTime(tNotice.getCreateTime());
|
tNoticeMessage.setIsDelete(0);
|
tNoticeMessage.setIsRead(0);
|
tNoticeMessage.setOtherId(tNotice.getId().toString());
|
tNoticeMessage.setShowImg(tNotice.getCoverPlan());
|
tNoticeMessage.setUserId(new Integer(id.toString()));
|
tNoticeMessage.setType(EnumNoticeMessageType.NOTICE.index);
|
tNoticeMessage.setUserType(2);
|
return tNoticeMessage;
|
}).collect(Collectors.toList());
|
itNoticeMessageService.insertList(tNoticeMessages);
|
}
|
}
|
}
|
});
|
thread.start();
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 删除/批量删除
|
*/
|
@Permission
|
@ResponseBody
|
@BussinessLog(value = "删除/批量删除")
|
@RequestMapping(value = "/delete")
|
public Object delete(@RequestParam String ids) {
|
// 逻辑删除
|
tNoticeService.updateForSet("is_delete = 1", new EntityWrapper<TNotice>().in("id", ids.split(",")));
|
//删除公告信息
|
this.itNoticeMessageService.delete(new EntityWrapper<TNoticeMessage>().in("other_id",ids).eq("type",EnumNoticeMessageType.NOTICE.index));
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改公告
|
*/
|
@RequestMapping(value = "/update")
|
@ResponseBody
|
public Object update(TNotice tNotice) {
|
if (tNotice != null) {
|
if (ToolUtil.isNotEmpty(tNotice.getContent())) {
|
// H5页面代码包装(判断加上自适应代码)
|
tNotice.setContent(ToolUtil.h5Warpper(tNotice.getContent()));
|
}
|
tNoticeService.updateById(tNotice);
|
//消息来源 1-全部用户,2-全部商家
|
if (tNotice.getSource().equals("1")){
|
List<Object> ids = this.iMemUserService.selectObjs(new EntityWrapper<MemUser>().setSqlSelect("id").eq("is_delete",0));
|
if (CollectionUtils.isNotEmpty(ids)){
|
List<TNoticeMessage> tNoticeMessages = new ArrayList<TNoticeMessage>();
|
tNoticeMessages.addAll(ids.stream().map(id->{
|
TNoticeMessage tNoticeMessage = new TNoticeMessage();
|
tNoticeMessage.setContent(tNotice.getTitle());
|
tNoticeMessage.setCreateTime(tNotice.getCreateTime());
|
tNoticeMessage.setIsDelete(0);
|
tNoticeMessage.setIsRead(0);
|
tNoticeMessage.setOtherId(tNotice.getId().toString());
|
tNoticeMessage.setShowImg(tNotice.getCoverPlan());
|
tNoticeMessage.setUserId(new Integer(id.toString()));
|
tNoticeMessage.setType(EnumNoticeMessageType.NOTICE.index);
|
tNoticeMessage.setUserType(1);
|
return tNoticeMessage;
|
}).collect(Collectors.toList()));
|
this.itNoticeMessageService.insertList(tNoticeMessages);
|
}
|
|
}else{
|
List<Object> ids = this.iMemMerchantService.selectObjs(new EntityWrapper<MemMerchant>().setSqlSelect("id").eq("is_delete",0));
|
if (CollectionUtils.isNotEmpty(ids)){
|
List<TNoticeMessage> tNoticeMessages = new ArrayList<TNoticeMessage>();
|
tNoticeMessages.addAll(ids.stream().map(id->{
|
TNoticeMessage tNoticeMessage = new TNoticeMessage();
|
tNoticeMessage.setContent(tNotice.getTitle());
|
tNoticeMessage.setCreateTime(tNotice.getCreateTime());
|
tNoticeMessage.setIsDelete(0);
|
tNoticeMessage.setIsRead(0);
|
tNoticeMessage.setOtherId(tNotice.getId().toString());
|
tNoticeMessage.setShowImg(tNotice.getCoverPlan());
|
tNoticeMessage.setUserId(new Integer(id.toString()));
|
tNoticeMessage.setType(EnumNoticeMessageType.NOTICE.index);
|
tNoticeMessage.setUserType(2);
|
return tNoticeMessage;
|
}).collect(Collectors.toList()));
|
this.itNoticeMessageService.insertList(tNoticeMessages);
|
}
|
|
}
|
}
|
return SUCCESS_TIP;
|
}
|
|
/**
|
* 修改公告状态
|
*/
|
@RequestMapping(value = "/updateState")
|
@ResponseBody
|
public Object updateState(@RequestParam Integer tNoticeId) {
|
TNotice obj = tNoticeService.selectById(tNoticeId);
|
if (obj != null) {
|
if(obj.getIsTop() == 0) {
|
obj.setIsTop(1);
|
} else {
|
obj.setIsTop(0);
|
}
|
tNoticeService.updateById(obj);
|
}
|
return SUCCESS_TIP;
|
}
|
|
|
/**
|
* 公告详情
|
*/
|
@RequestMapping(value = "/detail/{tNoticeId}")
|
@ResponseBody
|
public Object detail(@PathVariable("tNoticeId") Integer tNoticeId) {
|
return tNoticeService.selectById(tNoticeId);
|
}
|
}
|