package com.product.administration.service;
|
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import com.alibaba.druid.util.StringUtils;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.product.administration.config.CmnConst;
|
import com.product.core.config.CoreConst;
|
import com.product.core.dao.BaseDao;
|
import com.product.core.entity.DataTableEntity;
|
import com.product.core.entity.FieldMetaEntity;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.exception.BaseException;
|
import com.product.core.service.support.AbstractBaseService;
|
import com.product.core.service.support.QueryFilterService;
|
import com.product.core.spring.context.SpringMVCContextHolder;
|
import com.product.core.websocket.service.WebsocketMesssageServiceThread;
|
import com.product.util.BaseUtil;
|
|
@Component
|
public class AnnouncementService extends AbstractBaseService {
|
@Autowired
|
public QueryFilterService queryFilterService;
|
@Autowired
|
public BaseDao baseDao;
|
private final String COOPERATE_URL = "16209107146651641w21286";
|
|
public String addAnnouncement(FieldSetEntity fse) throws BaseException {
|
fse.setValue("publish_status", 0);
|
fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
|
fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
|
return baseDao.add(fse);
|
}
|
|
public boolean releaseAnnouncement(FieldSetEntity fse) throws BaseException {
|
fse.setValue("publish_status", 1);
|
int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
|
String user_name = SpringMVCContextHolder.getCurrentUser().getUser_name();
|
fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
|
fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
|
String[] extentArr = fse.getString("extent").split(",");
|
DataTableEntity dt = new DataTableEntity();
|
for (int i = 0; i < extentArr.length; i++) {
|
FieldSetEntity fs = new FieldSetEntity();
|
FieldMetaEntity metaEntity = new FieldMetaEntity();
|
metaEntity.setTableName(new Object[]{CmnConst.product_oa_ANNOUNCEMENT_ROLE});
|
fs.setMeta(metaEntity);
|
fs.setValue("user_id", extentArr[i]);
|
fs.setValue("status", 0);
|
fs.setValue("announcement_uuid", fse.getString("uuid"));
|
dt.addFieldSetEntity(fs);
|
}
|
fse.addSubDataTable(dt);
|
String uuid = "";
|
if (StringUtils.isEmpty(fse.getUUID())) {
|
uuid = baseDao.add(fse);
|
} else {
|
boolean update = baseDao.update(fse);
|
if (update) {
|
uuid = fse.getUUID();
|
}
|
}
|
WebsocketMesssageServiceThread.getInstance().appendMessage(fse.getString("extent"), "[公告]" + user_name + "发布了《" + fse.getString("title") + "》公告", "[公告]" + user_name + "发布了《" + fse.getString("title") + "》公告",
|
user_id, "1", COOPERATE_URL + "?" + CoreConst.UUID + "=" + uuid + "&news=1", CmnConst.product_oa_ANNOUNCEMENT, fse.getUUID(), user_id, 0, 0);
|
|
return !StringUtils.isEmpty(uuid);
|
}
|
|
public boolean remindAnnouncement(FieldSetEntity fs) throws BaseException {
|
FieldSetEntity fse = baseDao.getFieldSetEntity(CmnConst.product_oa_ANNOUNCEMENT, fs.getUUID(), false);
|
String user_name = SpringMVCContextHolder.getCurrentUser().getUser_name();
|
int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
|
WebsocketMesssageServiceThread.getInstance().appendMessage(fs.getString("extent"), "[公告]" + user_name + "提醒你查看公告《" + fse.getString("title") + "》", "[公告]" + user_name + "提醒你查看公告《" + fse.getString("title") + "》",
|
user_id, "1", COOPERATE_URL + "?" + CoreConst.UUID + "=" + fs.getUUID() + "&news=1", CmnConst.product_oa_ANNOUNCEMENT, fse.getUUID(), user_id, 0, 0);
|
|
return !StringUtils.isEmpty(fs.getUUID());
|
}
|
|
public boolean updateAnnouncement(FieldSetEntity fse) throws BaseException {
|
fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
|
fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
|
return baseDao.update(fse);
|
}
|
|
public FieldSetEntity getAnnouncement(FieldSetEntity fse) throws BaseException {
|
return baseDao.getFieldSetEntity(CmnConst.product_oa_ANNOUNCEMENT, fse.getString("uuid"), false);
|
}
|
|
public DataTableEntity listAnnouncement(FieldSetEntity fse) throws BaseException {
|
String queryFilter = "";
|
if (!BaseUtil.dataTableIsEmpty(fse.getSubDataTable("systemSeniorQueryString"))) {
|
queryFilter = " and " + queryFilterService.getQueryFilter(fse);
|
}
|
DataTableEntity dt = baseDao.listTable(CmnConst.product_oa_ANNOUNCEMENT, "publish_status=0 " + queryFilter, new Object[]{},
|
new Object[]{}, " created_utc_datetime desc ", fse.getInteger("pagesize"), fse.getInteger("cpage"));
|
baseDao.loadPromptData(dt);
|
return dt;
|
}
|
|
public DataTableEntity listAnnouncementRelease(FieldSetEntity fse) throws BaseException {
|
String queryFilter = "";
|
if (!BaseUtil.dataTableIsEmpty(fse.getSubDataTable("systemSeniorQueryString"))) {
|
queryFilter = " and " + queryFilterService.getQueryFilter(fse);
|
}
|
DataTableEntity dt = baseDao.listTable(CmnConst.product_oa_ANNOUNCEMENT, "publish_status=1" + queryFilter, new Object[]{},
|
new Object[]{}, " created_utc_datetime desc ", fse.getInteger("pagesize"), fse.getInteger("cpage"));
|
baseDao.loadPromptData(dt);
|
return dt;
|
}
|
|
public DataTableEntity listAnnouncementReceive(FieldSetEntity fse) throws BaseException {
|
String queryFilter = "";
|
if (!BaseUtil.dataTableIsEmpty(fse.getSubDataTable("systemSeniorQueryString"))) {
|
queryFilter = " and " + queryFilterService.getQueryFilter(fse);
|
}
|
int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
|
String id = "," + user_id + ",";
|
String type = "";
|
if (!StringUtils.isEmpty(fse.getString("type"))) {
|
type = " and type='" + fse.getString("type") + "'";
|
}
|
DataTableEntity dt = baseDao.listTable(CmnConst.product_oa_ANNOUNCEMENT,
|
"publish_status=1 and concat(',',extent,',') like '%" + id + "%'" + type + queryFilter, new Object[]{},
|
new Object[]{}, CmnConst.CREATED_UTC_DATETIME + " desc", fse.getInteger("pagesize"), fse.getInteger("cpage"));
|
baseDao.loadPromptData(dt);
|
|
return dt;
|
}
|
|
public JSONArray treeAnnouncementType(FieldSetEntity fse) throws BaseException {
|
|
//封装公告类别树结构
|
DataTableEntity dictDt = baseDao.listTable(CmnConst.PRODUCT_SYS_DICT, "dict_name='" + CmnConst.ANNOUNCEMENT_TYPE + "'");
|
JSONArray menus = new JSONArray();
|
JSONObject parent_menu = new JSONObject();
|
parent_menu.put("dict_label", "公告类别");
|
parent_menu.put("dict_value", "0");
|
JSONArray sub = new JSONArray();
|
for (int i = 0; i < dictDt.getRows(); i++) {
|
FieldSetEntity fs = dictDt.getFieldSetEntity(i);
|
JSONObject submen = BaseUtil.fieldSetEntityToJson(fs);
|
sub.add(submen);
|
}
|
parent_menu.put("children", sub);
|
menus.add(parent_menu);
|
return menus;
|
}
|
// public DataTableEntity announcementRoleList(FieldSetEntity fse) throws BaseException {
|
// int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
|
// String id = "," + user_id + ",";
|
// DataTableEntity dt = baseDao.listTable(CmnConst.product_oa_ANNOUNCEMENT,
|
// "WHERE concat(',',extent,',') like '%" + id + "%'");
|
// baseDao.loadPromptData(dt);
|
// return dt;
|
// }
|
|
public boolean delAnnouncement(FieldSetEntity fse) throws BaseException {
|
String[] uuid = fse.getString("uuid").split(",");
|
return baseDao.delete(CmnConst.product_oa_ANNOUNCEMENT, uuid);
|
}
|
|
public FieldSetEntity findAnnouncement(FieldSetEntity fse) throws BaseException {
|
// FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.product_oa_ANNOUNCEMENT, fse.getString("uuid"), false);
|
String sqlfs = "SELECT *,(SELECT user_name FROM " + CmnConst.PRODUCT_SYS_USERS + " WHERE user_id=a.created_by)created_by_save,(SELECT user_name FROM " + CmnConst.PRODUCT_SYS_USERS + " WHERE user_id=a.updated_by)updated_by_save from " + CmnConst.product_oa_ANNOUNCEMENT + " a WHERE uuid=?";
|
FieldSetEntity fs = baseDao.getFieldSetEntityBySQL(sqlfs, new String[]{fse.getString("uuid")}, false);
|
String sql = "SELECT b.user_id user_id,b.show_name show_name,c.org_level_name,a.status FROM " + CmnConst.product_oa_ANNOUNCEMENT_ROLE + " a LEFT JOIN product_sys_staffs b on a.user_id=b.user_id LEFT JOIN product_sys_org_levels c on b.dept_uuid=c.uuid WHERE a.announcement_uuid=?";
|
DataTableEntity dt = baseDao.listTable(sql, new String[]{fs.getUUID()});
|
fs.addSubDataTable(dt);
|
fs.setValue("number", dt.getRows());
|
int a = 0;
|
for (int i = 0; i < dt.getRows(); i++) {
|
if (dt.getInt(i, "status") == 1) {
|
a++;
|
}
|
}
|
fs.setValue("readNum", a);
|
return fs;
|
}
|
|
public boolean readAnnouncementRemind(FieldSetEntity fs) throws BaseException {
|
FieldSetEntity fse = baseDao.getFieldSetEntity(CmnConst.product_oa_ANNOUNCEMENT, fs.getUUID(), false);
|
String expiration_date = fse.getString("expiration_date");
|
|
SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd");
|
String current_time = tempDate.format(new Date());
|
int compareTo = 0;
|
if (expiration_date != null) {
|
compareTo = current_time.compareTo(expiration_date);
|
}
|
String user_name = SpringMVCContextHolder.getCurrentUser().getUser_name();
|
int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
|
if (compareTo <= 0 && fse.getInteger("status") == 1) {
|
WebsocketMesssageServiceThread.getInstance().appendMessage(fse.getString("created_by"), "[提醒]" + user_name + "已读了《" + fse.getString("title") + "》公告", "[提醒]" + user_name + "已读了《" + fse.getString("title") + "》公告",
|
user_id, "1", null, null, null, user_id, 0, 0);
|
}
|
return baseDao.executeUpdate("update product_oa_announcement_role set status=1 where user_id=? and announcement_uuid=?",
|
new String[]{"" + user_id, fse.getString("uuid")});
|
|
}
|
|
public DataTableEntity listAnnouncementGateway(FieldSetEntity fs) throws BaseException {
|
//当前人uuid
|
int user_id = SpringMVCContextHolder.getCurrentUser().getUser_id();
|
String id = "," + user_id + ",";
|
DataTableEntity dt = baseDao.listTable(CmnConst.product_oa_ANNOUNCEMENT,
|
"publish_status=1 and concat(',',extent,',') like '%" + id + "%'", new Object[]{},
|
new Object[]{}, CmnConst.CREATED_UTC_DATETIME + " desc", 5, 1);
|
baseDao.loadPromptData(dt);
|
// DataTableEntity dt = baseDao.listTable(CmnConst.product_oa_ANNOUNCEMENT, "publish_status=1 and created_by=?", new Object[]{user_id}, new Object[]{}, CmnConst.CREATED_UTC_DATETIME + " desc", 5, 1);
|
// baseDao.loadPromptData(dt);
|
return dt;
|
}
|
// public static String emojiConvert1(String str)
|
// throws UnsupportedEncodingException {
|
// String patternString = "([\\x{10000}-\\x{10ffff}\ud800-\udfff])";
|
// Pattern pattern = Pattern.compile(patternString);
|
// Matcher matcher = pattern.matcher(str);
|
// StringBuffer sb = new StringBuffer();
|
// while(matcher.find()) {
|
// try {
|
// matcher.appendReplacement(
|
// sb,
|
// "[["
|
// + URLEncoder.encode(matcher.group(1),
|
// "UTF-8") + "]]");
|
// } catch(UnsupportedEncodingException e) {
|
// throw e;
|
// }
|
// }
|
// matcher.appendTail(sb);
|
// return sb.toString();
|
// }
|
}
|