package cn.com.do1.component.dynamicinfo.dynamicinfo.service.impl;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import cn.com.do1.common.exception.ExceptionCenter;
import cn.com.do1.common.util.DateUtil;
import cn.com.do1.component.addressbook.contact.service.ITargetService;
import cn.com.do1.component.addressbook.contact.util.BaseTargetUtil;
import cn.com.do1.component.addressbook.contact.vo.*;
import cn.com.do1.component.core.WxqyhAppContext;
import cn.com.do1.component.dynamicinfo.dynamicinfo.model.*;
import cn.com.do1.component.dynamicinfo.dynamicinfo.util.DynamicCommentUtil;
import cn.com.do1.component.dynamicinfo.dynamicinfo.util.DynamicUtil;
import cn.com.do1.component.dynamicinfo.dynamicinfo.vo.*;
import cn.com.do1.component.dynamicinfomanage.dynamicinfomanage.util.DynamicinfomanageUtil;
import cn.com.do1.component.dynamicinfomanage.dynamicinfomanage.util.NewsUtil;
import cn.com.do1.component.log.operationlog.util.LogOperation;
import cn.com.do1.component.qiweipublicity.experienceapplication.util.MatchAgentUtil;
import cn.com.do1.component.uploadfile.imageupload.vo.TbFileMediaVO;
import cn.com.do1.component.util.*;
import cn.com.do1.component.util.jedis.AgentBillCountQueue;
import cn.com.do1.component.util.memcached.CacheWxqyhObject;
import cn.com.do1.component.util.org.OrgUtil;
import cn.com.do1.component.util.vo.AgentCountVO;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import cn.com.do1.common.dac.Pager;
import cn.com.do1.common.exception.BaseException;
import cn.com.do1.common.exception.NonePrintException;
import cn.com.do1.common.framebase.dqdp.BaseService;
import cn.com.do1.common.util.AssertUtil;
import cn.com.do1.common.util.string.StringUtil;
import cn.com.do1.component.addressbook.contact.model.ExtOrgPO;
import cn.com.do1.component.addressbook.contact.model.TbQyUserInfoPO;
import cn.com.do1.component.addressbook.contact.service.IContactService;
import cn.com.do1.component.dynamicinfo.dynamicinfo.dao.IDynamicinfoDAO;
import cn.com.do1.component.dynamicinfo.dynamicinfo.dao.IDynamicinfoInsideReadOnlyDAO;
import cn.com.do1.component.dynamicinfo.dynamicinfo.dao.IDynamicinfoReadOnlyDAO;
import cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService;
import cn.com.do1.component.dynamicinfomanage.dynamicinfomanage.dao.IDynamicinfomanageDAO;
import cn.com.do1.component.dynamicinfomanage.dynamicinfomanage.service.IDynamicinfomanageService;
import cn.com.do1.component.dynamicinfomanage.dynamicinfomanage.util.BirthAndEntryUtil;
import cn.com.do1.component.qiweiredpack.qiweiredpack.service.IQiweiredpackService;
import cn.com.do1.component.qiweiredpack.qiweiredpack.ui.RedpackSettingParam;
import cn.com.do1.component.systemmgr.org.service.IOrgService;
import cn.com.do1.component.uploadfile.imageupload.service.IFileMediaService;
import cn.com.do1.component.wxcgiutil.WxAgentUtil;
import cn.com.do1.component.wxcgiutil.WxMessageUtil;
import cn.com.do1.component.wxcgiutil.message.NewsMessageVO;
//已看-ok
@Service("dynamicinfoService")
public class DynamicinfoServiceImpl extends BaseService implements IDynamicinfoService {
private final static transient Logger logger = LoggerFactory.getLogger(DynamicinfoServiceImpl.class);
private IDynamicinfoDAO dynamicinfoDAO;
private IContactService contactService;
private IOrgService orgService;
private IFileMediaService fileMediaService;
private IDynamicinfoReadOnlyDAO dynamicinfoReadOnlyDAO;
private IDynamicinfoInsideReadOnlyDAO dynamicinfoInsideReadOnlyDAO;
private Map<String, Object> params;
private ITargetService targetService;
@Resource(name = "targetService")
public void setTargetService(ITargetService targetService) {
this.targetService = targetService;
}
@Resource
public void setDynamicinfoInsideReadOnlyDAO(
IDynamicinfoInsideReadOnlyDAO dynamicinfoInsideReadOnlyDAO) {
this.dynamicinfoInsideReadOnlyDAO = dynamicinfoInsideReadOnlyDAO;
}
@Resource
public void setDynamicinfoReadOnlyDAO(IDynamicinfoReadOnlyDAO dynamicinfoReadOnlyDAO) {
this.dynamicinfoReadOnlyDAO = dynamicinfoReadOnlyDAO;
}
@Resource(name = "dynamicinfomanageService")
private IDynamicinfomanageService dynamicinfomanageService;
public IDynamicinfomanageService getDynamicinfomanageService() {
return dynamicinfomanageService;
}
public void setDynamicinfomanageService(
IDynamicinfomanageService dynamicinfomanageService) {
this.dynamicinfomanageService = dynamicinfomanageService;
}
@Resource(name = "qiweiredpackService")
private IQiweiredpackService qiweiredpackService;
public IQiweiredpackService getQiweiredpackService() {
return qiweiredpackService;
}
public void setQiweiredpackService(IQiweiredpackService qiweiredpackService) {
this.qiweiredpackService = qiweiredpackService;
}
private IDynamicinfomanageDAO dynamicinfomanageDAO;
@Resource
public void setDynamicinfomanageDAO(IDynamicinfomanageDAO dynamicinfomanageDAO) {
this.dynamicinfomanageDAO = dynamicinfomanageDAO;
setDAO(dynamicinfomanageDAO);
}
@Resource
public void setDynamicinfoDAO(IDynamicinfoDAO dynamicinfoDAO) {
this.dynamicinfoDAO = dynamicinfoDAO;
}
@Resource(name = "fileMediaService")
public void setFileMediaService(IFileMediaService fileMediaService) {
this.fileMediaService = fileMediaService;
}
@Override
public List<TbXyhDynamicInfoImagesPO> getImages(TbXyhDynamicinfoPO dynamicInfo) throws Exception, BaseException {
if (null == dynamicInfo) {
return Collections.<TbXyhDynamicInfoImagesPO>emptyList();
}
String sql = "select path from tb_xyh_dynamic_info_images where dynamic_info_id = :dynamicInfoId order by sort_num";
dynamicinfoDAO.preparedSql(sql);
dynamicinfoDAO.setPreValue("dynamicInfoId", dynamicInfo.getDynamicInfoId());
List<TbXyhDynamicInfoImagesPO> images = dynamicinfoDAO.getList(TbXyhDynamicInfoImagesPO.class);
return images != null ? images : Collections.<TbXyhDynamicInfoImagesPO>emptyList();
}
private final static String getPageDynamicInfoComments_sql = "SELECT a.comment_id,a.CREATOR as user_id,a.person_name,a.head_pic,a.CONTENT," +
"a.create_time,a.dynamicinfo_id,a.COMMENT_STATUS,a.type, a.is_pass_review, a.audit_person, a.audit_id, a.audit_time" +
" from tb_xyh_dynamicinfo_comment a" +
" where 1=1" +
" and a.dynamicinfo_id =:diId" +
" and a.is_pass_review = 0" +
" order by a.create_time desc";
private final static String getPageDynamicInfoComments_countSql = "select count(1) " +
" from tb_xyh_dynamicinfo_comment a" +
" where 1=1" +
" and a.dynamicinfo_id =:diId" +
" and a.is_pass_review = 0";
@Override
public Pager getPageDynamicInfoComments(TbXyhDynamicinfoPO po, Pager pager) {
try {
pager = dynamicinfoDAO.pageSearchByField(DynamicInfoCommentVO.class, getPageDynamicInfoComments_countSql, getPageDynamicInfoComments_sql,
Collections.<String, Object>singletonMap("diId", po.getDynamicInfoId()), pager);
if (pager != null && pager.getTotalRows() > 0) {
List<DynamicInfoCommentVO> list = (List<DynamicInfoCommentVO>) pager.getPageData();
for (DynamicInfoCommentVO vo : list) {
if ("1".equals(vo.getCommentStatus())) {
vo.setContent("该条评论已删除");
}
}
}
return getPageCommentInfo(pager);
} catch (SQLException e) {
logger.error("getPageDynamicInfoComments error: " + e);
throw new RuntimeException(e);
} catch (Exception e) {
logger.error("getPageDynamicInfoComments error: " + e);
throw new RuntimeException(e);
} catch (BaseException e) {
logger.error("getPageDynamicInfoComments error: " + e);
throw new RuntimeException(e);
}
}
@Override
public Pager getPageDynamicInfoComments(TbXyhDynamicinfoPO po, Pager pager,Integer isCommentReviewer, String userId) {
try {
/**
* 1.如果该公告所属类有评论审批人
* (1)如果是自己是该类的评论审核人,则可以看到所有评论
* (2)如果不是,则只能看到”已通过”的评论
* 2.如果该公告所属类没有评论审批人,可以看到所有评论
*/
Map<String, Object> searchMap = new HashMap<String, Object>();
searchMap.put("orgId", po.getOrgId());
searchMap.put("dynamicinfoId", po.getDynamicInfoId());
searchMap.put("userId", userId);
searchMap.put("dynamicTypeId", po.getDynamicTypeId());
pager = dynamicinfoDAO.pageSearchComment(searchMap, pager);
if (pager != null && pager.getTotalRows() > 0) {
List<DynamicInfoCommentVO> list = (List<DynamicInfoCommentVO>) pager.getPageData();
for (DynamicInfoCommentVO vo : list) {
if ("1".equals(vo.getCommentStatus())) {
vo.setContent("该条评论已删除");
}
}
}
return getPageCommentInfo(pager);
} catch (SQLException e) {
logger.error("getPageDynamicInfoComments error: " + e);
ExceptionCenter.addAndPrintException(e, "getPageDynamicInfoComments", "getPageDynamicInfoComments");
throw new RuntimeException(e);
} catch (Exception e) {
logger.error("getPageDynamicInfoComments error: " + e);
ExceptionCenter.addAndPrintException(e, "getPageDynamicInfoComments", "getPageDynamicInfoComments");
throw new RuntimeException(e);
} catch (BaseException e) {
logger.error("getPageDynamicInfoComments error: " + e);
ExceptionCenter.addAndPrintException(e, "getPageDynamicInfoComments", "getPageDynamicInfoComments");
throw new RuntimeException(e);
}
}
private final static String getPageDynamicInfoComments_hasmore_sql = "select a.comment_id, a.CREATOR as user_id, a.person_name,a.head_pic,a.content,a.create_time,a.COMMENT_STATUS,a.dynamicinfo_id,a.type " +
" from tb_xyh_dynamicinfo_comment a" +
" where dynamicinfo_id=:diId" +
" and a.create_time <:lastDynamicInfoCreateTime" +
" order by create_time desc";
private final static String getPageDynamicInfoComments_hasmore_countSql = "select count(1)" +
" from tb_xyh_dynamicinfo_comment a" +
" where dynamicinfo_id=:diId" +
" and a.create_time <:lastDynamicInfoCreateTime";
@Override
public Pager getPageDynamicInfoComments(TbXyhDynamicinfoCommentPO lastComment, int pageSize) throws Exception, BaseException {
Map<String, Object> params = new HashMap<String, Object>();
params.put("diId", lastComment.getDynamicinfoId());
params.put("lastDynamicInfoCreateTime", lastComment.getCreateTime());
Pager pager = dynamicinfoDAO.pageSearchByField(DynamicInfoCommentVO.class, getPageDynamicInfoComments_hasmore_countSql, getPageDynamicInfoComments_hasmore_sql, params, new Pager(pageSize));
return getPageCommentInfo(pager);
}
private Pager getPageCommentInfo(Pager pager) throws Exception, BaseException {
Collection<?> data = pager.getPageData();
if (data == null) pager.setPageData(Collections.emptyList());
else {
List<Map<String, Object>> commentInfos = new ArrayList<Map<String, Object>>();
for (Object o : data) {
commentInfos.add(initCommentInfo((DynamicInfoCommentVO) o));
}
pager.setPageData(commentInfos);
}
return pager;
}
private Map<String, Object> initCommentInfo(DynamicInfoCommentVO vo) {
Map<String, Object> commentInfo = new HashMap<String, Object>();
commentInfo.put("userId", vo.getUserId());
commentInfo.put("personName", vo.getPersonName());
commentInfo.put("content", vo.getContent());
commentInfo.put("time", TimeHelper.getFriendlyDesc(vo.getCreateTime()));
commentInfo.put("dynamicinfoId", vo.getDynamicinfoId());
commentInfo.put("commentId", vo.getCommentId());
commentInfo.put("commentStatus", vo.getCommentStatus());
commentInfo.put("headPic", vo.getHeadPic());
commentInfo.put("type", vo.getType());
commentInfo.put("isPassReview", vo.getIsPassReview());
commentInfo.put("auditPerson", vo.getAuditPerson());
return commentInfo;
}
@Override
public void increaseCommentCount(TbXyhDynamicinfoPO po, int increaseCount) {
try {
String sql = "update tb_xyh_dynamicinfo set comment_count = comment_count + :increaseCount where dynamic_info_id = :id";
dynamicinfoDAO.preparedSql(sql);
dynamicinfoDAO.setPreValue("increaseCount", increaseCount);
dynamicinfoDAO.setPreValue("id", po.getDynamicInfoId());
dynamicinfoDAO.executeUpdate();
} catch (SQLException e) {
logger.error("increaseCommentCount error: " + e);
throw new RuntimeException(e);
}
}
/**
* 设置新闻公告的类型
* @param paramMap
* @param orgId
* @param dynamicType
* @throws Exception
* @throws BaseException
*/
private void setSearchParamDynamicType(Map<String, Object> paramMap, String orgId, String dynamicType, String belongAgent)throws Exception, BaseException {
//未选任何类型,则搜dynamicTypeId最靠前的
if("1".equals(dynamicType)) {
List<TbDynamicinfoChangetypeVO> typeList = dynamicinfomanageService.getDynamicType(orgId, DynamicinfomanageUtil.IS_FOR_VIEW, belongAgent);
if (!AssertUtil.isEmpty(typeList) && typeList.size() > 0) {
paramMap.put("dynamicType", typeList.get(0).getId().toString());
}
}else if(! AssertUtil.isEmpty(dynamicType)){
paramMap.put("dynamicType", dynamicType);
}
}
@Override
public Pager getPageDynamicInfoByType(TbXyhDynamicinfoPO lastDynamicInfo, Pager pager, String schType) throws Exception, BaseException {
Map<String, Object> params = new HashMap<String, Object>();
params.put("belongAgent", lastDynamicInfo.getBelongAgent());
setSearchParamDynamicType(params, lastDynamicInfo.getOrgId(), lastDynamicInfo.getDynamicType(), lastDynamicInfo.getBelongAgent());
if (null!=lastDynamicInfo.getIsPassReview()) {
params.put("isPassReview", lastDynamicInfo.getIsPassReview());
}
//设置状态
if ("0".equals(lastDynamicInfo.getStatus())) {
params.put("status", "草稿");
} else if ("1".equals(lastDynamicInfo.getStatus())) {
params.put("status", "发布");
} else {
//设置奇葩的状态,保证搜索不超出范围
params.put("status", "其它");
}
String userId = lastDynamicInfo.getCreator();
if (AssertUtil.isEmpty(userId)) {
throw new NonePrintException("2001", "登录人信息为空");
}
TbQyUserInfoVO userInfoVO = contactService.findUserInfoByUserId(userId);
if (userInfoVO == null) {
throw new NonePrintException("2001", "登录人的信息为空");
}
params.put("orgId", userInfoVO.getOrgId());
params.put("creator", userId);
if (!StringUtil.isNullEmpty(lastDynamicInfo.getTitle())) {
params.put("title", "%" + lastDynamicInfo.getTitle() + "%");
}
if (DynamicinfomanageUtil.TYPE_UNREAD.equals(schType)) {
if(!AssertUtil.isEmpty(userInfoVO.getCreateTime())) {
params.put("beginTime", userInfoVO.getCreateTime());
}
//上一次一键已阅的时间
TbXyhDynamicBatchReadTimePO batchReadTimePO = dynamicinfoDAO.getBatchReadTimeByCreator(userInfoVO.getOrgId(), userInfoVO.getUserId(), lastDynamicInfo.getBelongAgent());
if(! AssertUtil.isEmpty(batchReadTimePO)) {
params.put("lastBatchReadTime", batchReadTimePO.getLastBatchReadTime());
}
}
//设置搜索类型
params.put("schType", schType);
//最新公告的搜索特殊处理
if (null != lastDynamicInfo.getSendType() && 99 == lastDynamicInfo.getSendType()) {
params.put("sendType1", 1);
params.put("sendType2", 2);
}
//给用户返回查询目标对象的md5加密字段 guoquanhui 20180921
List<String> userMd5TgTp = BaseTargetUtil.getUserMd5TgTp(userInfoVO.getOrgId(), userInfoVO.getUserId());
params.put("mdfiveTgTp", userMd5TgTp);
return getPageDynamicinfo(dynamicinfoDAO.getPageDynamicInfo(params, pager));
}
@Override
public Integer getMyWaitDynamicTotal(TbXyhDynamicinfoPO lastDynamicInfo, String schType, Date createTime, String belongAgent) throws Exception, BaseException {
Map<String, Object> params = new HashMap<String, Object>();
params.put("belongAgent", belongAgent);
//2015-4-14 lishengtao
//修改搜索条件,判断类型是否为空
if (!AssertUtil.isEmpty(lastDynamicInfo.getDynamicType())) {
params.put("dynamicType", lastDynamicInfo.getDynamicType());
}
if (!AssertUtil.isEmpty(lastDynamicInfo.getIsEnable())) {
params.put("isEnable", lastDynamicInfo.getIsEnable());
}
//设置状态
params.put("status", "发布");
String userId = lastDynamicInfo.getCreator();
if (AssertUtil.isEmpty(userId)) {
logger.info("getPageDynamicInfoByType :获取不到userId");
throw new BaseException("获取不到userId");
}
TbQyUserInfoVO userInfoVO = contactService.findUserInfoByUserId(userId);
if (userInfoVO == null) {
logger.info("getPageDynamicInfoByType :登录人的信息为空 ");
throw new BaseException("登录人的信息为空");
}
params.put("orgId", userInfoVO.getOrgId());
params.put("creator", userId);
params.put("beginTime", createTime);
//设置搜索类型
params.put("schType", schType);
//获取上一次一键已阅的时间
TbXyhDynamicBatchReadTimePO batchReadTimePO = dynamicinfoDAO.getBatchReadTimeByCreator(userInfoVO.getOrgId(), userInfoVO.getUserId(), belongAgent);
if(! AssertUtil.isEmpty(batchReadTimePO)){
params.put("lastBatchReadTime", batchReadTimePO.getLastBatchReadTime());
}
//给用户返回查询目标对象的md5加密字段 guoquanhui 20180921
List<String> userMd5TgTp = BaseTargetUtil.getUserMd5TgTp(userInfoVO.getOrgId(), userInfoVO.getUserId());
params.put("mdfiveTgTp", userMd5TgTp);
return dynamicinfoDAO.getMyWaitDynamicTotal(params);
}
private Pager getPageDynamicinfo(Pager pager) throws Exception, BaseException {
List<DynamicInfoVO> data = (List<DynamicInfoVO>) pager.getPageData();
if (data != null && data.size() > 0) {
DqdpOrgVO orgVO = WxqyhAppContext.getOrgExtInfo(data.get(0).getOrgId());
for (DynamicInfoVO vo : data) {
if (AssertUtil.isEmpty(vo.getPersonName())) {
vo.setPersonName(orgVO.getOrgName());
}
if (AssertUtil.isEmpty(vo.getHeadPic())) {
vo.setHeadPic(orgVO.getLogo());
}
}
}
return pager;
}
@Override
public DynamicInfoVO getTbXyhDynamicinfoVOByPO(TbXyhDynamicinfoPO po) throws Exception, BaseException {
DynamicInfoVO vo = new DynamicInfoVO();
vo.setDynamicInfoId(po.getDynamicInfoId());
vo.setTitle(po.getTitle());
vo.setSummary(po.getSummary());
vo.setCreator(po.getCreator());
//vo.setContent(po.getContent());
vo.setAccessAddress(po.getAccessAddress());
vo.setCoverImage(po.getCoverImage());
//vo.setContentType(po.getContentType());
vo.setSource(po.getSource());
vo.setStatus(po.getStatus());
vo.setIsSecret(po.getIsSecret());
vo.setIsTop(po.getIsTop());
//guoquanhui 不是第一次发布的动态,需要返回上一次编辑人的名字
if(po.getLastEditTime().getTime() != po.getPublishTime().getTime()) {
//编辑人是手机端编辑的
TbQyUserInfoVO lastEditorPersonPO = contactService.findUserInfoByUserId(po.getLastEditor());
if (AssertUtil.isEmpty(lastEditorPersonPO)) {
//编辑人是后台编辑的
UserOrgVO manager = OrgUtil.getOrgByUserId(po.getLastEditor());
if (!AssertUtil.isEmpty(manager)) {
vo.setLastEditorPersonName(manager.getPersonName());
}
} else {
vo.setLastEditorPersonName(lastEditorPersonPO.getPersonName());
}
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = po.getPublishTime();
Date currentDate = new Date();
String dateStr = formatter.format(date);
String currentDateStr = formatter.format(currentDate);
if (dateStr.equals(currentDateStr)) {
formatter = new SimpleDateFormat("HH:mm");
vo.setPublishTime(formatter.format(po.getPublishTime()));
} else {
vo.setPublishTime(formatter.format(po.getPublishTime()));
}
vo.setPublisher(po.getPublisher());
vo.setPublishTime(formatter.format(po.getPublishTime()));
vo.setViewCount(po.getViewCount());
vo.setCommentCount(po.getCommentCount());
vo.setSendType(po.getSendType());
vo.setPersonName(po.getPersonName());
vo.setWxUserId(po.getWxUserId());
vo.setHeadPic(po.getHeadPic());
vo.setDepartmentId(po.getDepartmentId());
vo.setDepartmentName(po.getDepartmentName());
vo.setPraise(po.getPraise());
return vo;
}
public List<NewsXyhPraisePO> getPraiseById(String id) throws Exception, BaseException {
return dynamicinfoDAO.getPraiseById(id);
}
@Override
public DynamicInfoVO getDynamicinfoDetailVOByPO(TbXyhDynamicinfoPO po, TbXyhDynamicinfoExtVO dynamicinfoExtVO) throws Exception, BaseException {
DynamicInfoVO vo = new DynamicInfoVO();
vo.setDynamicInfoId(po.getDynamicInfoId());
vo.setTitle(po.getTitle());
vo.setSummary(po.getSummary());
//2017-01-03 guoquanhui 输出正文
vo.setContent(searchEditorContent(po));
vo.setCreator(po.getCreator());
vo.setAccessAddress(po.getAccessAddress());
vo.setCoverImage(po.getCoverImage());
vo.setContentType(po.getContentType());
vo.setSource(po.getSource());
vo.setStatus(po.getStatus());
vo.setViewCount(po.getViewCount());
vo.setCommentCount(po.getCommentCount());
vo.setLastEditor(po.getLastEditor());
vo.setOrgId(po.getOrgId());
vo.setRanges(po.getRanges());
//获取公告的目标对象 guoquanhui 20180920
BaseTargetRefVO targetRefVO =DynamicinfomanageUtil.getTargetRefByRefId(po.getDynamicInfoId());
vo.setSendTarget(targetRefVO.getUserIds());
vo.setDepartids(targetRefVO.getDeptIds());
vo.setDynamicType(po.getDynamicType());
vo.setIsComment(po.getIsComment());
vo.setIsTiming(po.getIsTiming());
if (!AssertUtil.isEmpty(po.getTimingTime())) {
vo.setTimingTime(DateUtil.format(po.getTimingTime(), DateUtil.DATE_TIME_PATTERN));
}
if (!AssertUtil.isEmpty(po.getSendTime())) {
vo.setTimingTime(DateUtil.format(po.getSendTime(), DateUtil.DATE_TIME_PATTERN));
}
vo.setSendRes(po.getSendRes());
vo.setPersonName(po.getPersonName());
vo.setHeadPic(po.getHeadPic());
vo.setWxUserId(po.getWxUserId());
vo.setDepartmentId(po.getDepartmentId());
vo.setDepartmentName(po.getDepartmentName());
vo.setIsManager(po.getIsManager());
vo.setIsSuperAdminUpdate(po.getIsSuperAdminUpdate());
vo.setIsDisplayCoverImage(po.getIsDisplayCoverImage());
vo.setIsSecret(po.getIsSecret());
vo.setIsTop(po.getIsTop());
vo.setContentImage(po.getContentImage());
vo.setExt2(po.getExt2());
vo.setIsSendMsg(po.getIsSendMsg());
vo.setSendType(po.getSendType());
vo.setVoiceId(po.getVoiceId());
//guoquanhui 20181102 发布人优先显示【新闻作者】,否则显示对应的人名
if(!AssertUtil.isEmpty(dynamicinfoExtVO) && !AssertUtil.isEmpty(dynamicinfoExtVO.getAuthorName())) {
vo.setPublisher(dynamicinfoExtVO.getAuthorName());
}else{
if(AssertUtil.isEmpty(po.getPublisher())) {
vo.setPublisher(po.getPersonName()); //草稿时
}else {
UserOrgVO userOrgVO = contactService.getUserOrgVOByUserName(po.getPublisher());
if (AssertUtil.isEmpty(userOrgVO)) { //手机端发布的
vo.setPublisher(po.getPersonName());
}else{ //后台发布的
vo.setPublisher(userOrgVO.getPersonName());
}
}
}
//guoquanhui 不是第一次发布的动态,需要返回上一次编辑人的名字
if(!AssertUtil.isEmpty(po.getPublishTime()) && po.getLastEditTime().getTime() > po.getPublishTime().getTime()) {
//编辑人是手机端编辑的
TbQyUserInfoVO lastEditorPersonPO = contactService.findUserInfoByUserId(po.getLastEditor());
if (AssertUtil.isEmpty(lastEditorPersonPO)) {
//编辑人是后台编辑的
UserOrgVO manager = OrgUtil.getOrgByUserId(po.getLastEditor());
if (!AssertUtil.isEmpty(manager)) {
vo.setLastEditorPersonName(manager.getPersonName());
}
} else {
vo.setLastEditorPersonName(lastEditorPersonPO.getPersonName());
}
}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
vo.setCreateTime(formatter.format(po.getCreateTime()));
vo.setValidityTime(formatter.format(po.getValidityTime()));
vo.setLastEditTime(formatter.format(po.getLastEditTime()));
if(!AssertUtil.isEmpty(po.getPublishTime())) {
vo.setPublishTime(formatter.format(po.getPublishTime()));
}
//增加【将封面图片显示在正文中】开关字段选项 maquanyang 2015-6-9
if (!AssertUtil.isEmpty(po.getIsOpen())) {
vo.setIsOpen(po.getIsOpen().toString());
}
vo.setPraise(po.getPraise());
vo.setIsDisplayCoverImage(po.getIsDisplayCoverImage());
vo.setIsRedpack(po.getIsRedpack());//红包字段
vo.setMergePeopleCount(po.getMergePeopleCount());
vo.setIsSendTodo(po.getIsSendTodo());
vo.setBuildUnreadStatus(po.getBuildUnreadStatus());
vo.setIsEnable(po.getIsEnable());
if (!AssertUtil.isEmpty(po.getShareComment())) {
vo.setShareComment(po.getShareComment().toString());
}
vo.setMsgType(po.getMsgType());
vo.setThirdPartUrl(po.getThirdPartUrl());
vo.setThirdPartTips(po.getThirdPartTips());
vo.setDynamicTypeId(po.getDynamicTypeId());
vo.setIsPassReview(po.getIsPassReview());
TbQyDynamicAuditPO auditPO = dynamicinfoDAO.getAuditByDynamicCommentId(po.getDynamicInfoId(), po.getOrgId());
if(! AssertUtil.isEmpty(auditPO)) {
vo.setAuditId(auditPO.getAuditId());
vo.setAuditPerson(auditPO.getAuditPerson());
vo.setAuditTime(auditPO.getAuditTime());
}
vo.setIsWatermark(po.getIsWatermark());
if(!AssertUtil.isEmpty(po.getCoverImage())) {
List<TbFileMediaVO> coverImages = fileMediaService.getMediaByPaths(new String[]{po.getCoverImage()}, po.getOrgId());
if (!AssertUtil.isEmpty(coverImages)) {
vo.setCoverImageName(coverImages.get(0).getFileName());
}
}
return vo;
}
@Override
public Pager getPublishPageDynamicInfo(Pager pager) {
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("status", "发布");
return dynamicinfoDAO.getPagePublishDynamicInfo(params, pager);
} catch (SQLException e) {
logger.error("getPublishPageDynamicInfo error: " + e);
throw new RuntimeException(e);
}
}
@Override
public Pager getPageDynamicInfo(TbXyhDynamicinfoPO lastDynamicInfo, Pager pager) throws Exception, BaseException {
Map<String, Object> params = new HashMap<String, Object>();
//params.put("lastDynamicInfoPublishTime", lastDynamicInfo.getPublishTime());
//params.put("status", lastDynamicInfo.getStatus());
/*
* 2015-4-14 李盛滔 修改搜索条件,判断类型是否为空
*/
if (!AssertUtil.isEmpty(lastDynamicInfo.getDynamicType())) {
params.put("dynamicType", lastDynamicInfo.getDynamicType());
}
//设置状态
if ("0".equals(lastDynamicInfo.getStatus())) {
params.put("status", "草稿");
} else if ("1".equals(lastDynamicInfo.getStatus())) {
params.put("status", "发布");
} else {
//设置奇葩的状态,保证搜索不超出范围
params.put("status", "其它");
}
/*
* 孙青海修改目标用户
*/
String userId = lastDynamicInfo.getCreator();
if (AssertUtil.isEmpty(userId)) {
logger.info("getPageDynamicInfoByType :获取不到userId");
throw new BaseException("获取不到userId");
}
TbQyUserInfoVO userInfoVO = contactService.findUserInfoByUserId(userId);
if (userInfoVO == null) {
logger.info("getPageDynamicInfoByType :登录人的信息为空 ");
throw new BaseException("登录人的信息为空");
}
params.put("orgId", userInfoVO.getOrgId());
params.put("creator", userId);
if (!StringUtil.isNullEmpty(lastDynamicInfo.getTitle())) {
params.put("title", "%" + lastDynamicInfo.getTitle() + "%");
}
//给用户返回查询目标对象的md5加密字段 guoquanhui 20180921
List<String> userMd5TgTp = BaseTargetUtil.getUserMd5TgTp(userInfoVO.getOrgId(), userInfoVO.getUserId());
params.put("mdfiveTgTp", userMd5TgTp);
return getPageDynamicinfo(dynamicinfoDAO.getPageDynamicInfo(params, pager));
}
@Override
public Pager getPublishPageDynamicInfo(TbXyhDynamicinfoPO lastDynamicInfo, int pageSize) {
try {
Map<String, Object> params = new HashMap<String, Object>();
params.put("status", "发布");
params.put("lastDynamicInfoPublishTime", lastDynamicInfo.getPublishTime());
return dynamicinfoDAO.getPagePublishDynamicInfo(params, new Pager(pageSize));
} catch (SQLException e) {
logger.error("getPublishPageDynamicInfo error: " + e);
throw new RuntimeException(e);
}
}
@Override
public void delDynamicInfoImages(TbXyhDynamicinfoPO po) {
try {
String sql = "delete from tb_xyh_dynamic_info_images where dynamic_info_id = :diId";
dynamicinfoDAO.preparedSql(sql);
dynamicinfoDAO.setPreValue("diId", po.getDynamicInfoId());
dynamicinfoDAO.executeUpdate();
} catch (SQLException e) {
logger.error("delDynamicInfoImages error: " + e);
throw new RuntimeException(e);
}
}
public void setPraise(UserInfoVO userVO, String id,boolean isAgentCount) throws Exception, BaseException {
TbXyhDynamicinfoPO dynamicinfoPO = this.searchByPk(TbXyhDynamicinfoPO.class, id);
if (null == dynamicinfoPO) {
throw new NonePrintException("2001", "动态不存在或已被删除");
}
NewsXyhPraisePO praisePO = dynamicinfoDAO.getPraisePOByUserId(userVO.getUserId().trim(), id.trim());
if (null == praisePO) {
praisePO = new NewsXyhPraisePO();
praisePO.setNPraiseId(UUID.randomUUID().toString());
praisePO.setDynamicInfoId(id);
praisePO.setCreateTime(new Date());
praisePO.setCreator(userVO.getUserId());
praisePO.setPersonName(userVO.getPersonName());
praisePO.setDepartmentId(userVO.getDeptIdsForRedundancy());
praisePO.setDepartmentName(userVO.getDeptFullNamesForRedundancy());
praisePO.setWxUserId(userVO.getWxUserId());
praisePO.setHeadPic(userVO.getHeadPic());
this.insertPO(praisePO, false);//点赞
if (AssertUtil.isEmpty(dynamicinfoPO.getPraise())) {
dynamicinfoPO.setPraise(0);
}
dynamicinfoPO.setPraise(dynamicinfoPO.getPraise() + 1);
this.updatePO(dynamicinfoPO, false);
//添加发单统计
if(isAgentCount){
setAgentCount(userVO,AgentBillCountQueue.COMMENT,1);
}
} else {
this.delPO(praisePO);//取消点赞
if (!AssertUtil.isEmpty(dynamicinfoPO.getPraise()) && dynamicinfoPO.getPraise() > 0) {
dynamicinfoPO.setPraise(dynamicinfoPO.getPraise() - 1);
this.updatePO(dynamicinfoPO, false);
}
}
}
/**
* 人资”员工关怀“发单统计
* @param userInfoVO
* @param billOrComment
* @param count
* @author leiyingbin
* @2018-09-05
*/
private void setAgentCount(UserInfoVO userInfoVO,int billOrComment, int count){
try{
AgentCountVO agentCountVO = new AgentCountVO();
agentCountVO.setCorpId(userInfoVO.getCorpId());
agentCountVO.setOrgId(userInfoVO.getOrgId());
agentCountVO.setUserId(userInfoVO.getUserId());
agentCountVO.setDepartId(userInfoVO.getDeptIds());
agentCountVO.setDepartFullName(userInfoVO.getDeptFullNames());
agentCountVO.setAgentCode(WxAgentUtil.getHrmanagementCode());
agentCountVO.setAgentBillType("care_staff");
agentCountVO.setCount(count);
agentCountVO.setBillOrComment(billOrComment);
agentCountVO.setCreateTime(DateUtil.formartCurrentDateTime());
AgentBillCountQueue.saveAgentBillQueue(agentCountVO);
}catch (Exception e){
ExceptionCenter.addException(e,"员工关怀发单统计出错 @leiyingbin","");
}
}
@Override
public void sendCommentMsg(TbXyhDynamicinfoPO dynamicPO, TbXyhDynamicinfoCommentPO po, UserInfoVO userInfoVO, String userIds, String type) throws Exception, BaseException {
/**
* 1.如果属于需要审批的类
* (1)若自己也是审核人中一员,执行2
* (2)若自己不是审核人,推送消息给审批人,评论PO的isPassReview为“待审核”
* 2.如果不需要审核,则评论PO的isPassReview为“已通过”,增加评论数
* (1)若艾特人,则推送消息
*/
po.setDynamicTypeId(dynamicPO.getDynamicTypeId());
//该公告所属的类绑定的审批人
List<TbXhyDynamicReviewerVO> reviewerList = dynamicinfomanageDAO.getReviewers(dynamicPO.getDynamicTypeId(), DynamicinfomanageUtil.COMMENT_REVIEWER, dynamicPO.getOrgId());
//是否需要发送审批消息
boolean isNeedAudit = dynamicinfomanageService.isNeedAudit(userInfoVO.getUserId(), reviewerList);
if (isNeedAudit) {
NewsUtil.sendToCommentReviewer(dynamicPO.getTitle(), po, userInfoVO.getCorpId(), reviewerList, dynamicPO.getOrgId(), dynamicPO.getBelongAgent());
po.setIsPassReview(DynamicinfomanageUtil.WAIT_REVIEW);
} else {
po.setIsPassReview(DynamicinfomanageUtil.PASS_REVIEW);
increaseCommentCount(dynamicPO, 1);//增加评论数
commentPublish(po, userInfoVO.getUserId(), userIds, type, dynamicPO);
}
}
@Override
public void addDynamic(TbXyhDynamicinfoCommentPO comment, UserInfoVO userInfoVO, String userIds, String type) throws Exception, BaseException {
String userId = userInfoVO.getUserId();
comment.setCreateTime(new Date());
comment.setCreator(userId);
comment.setOrgId(userInfoVO.getOrgId());
/**
* @author lishengtao
* 2015-4-22
* 插入冗余数据
*/
UserInfoVO userRedundancyInfoVO = contactService.getUserInfoNoCacheByUserId(comment.getCreator());
comment.setPersonName(userRedundancyInfoVO.getPersonName());
comment.setHeadPic(userRedundancyInfoVO.getHeadPic());
comment.setDepartmentId(userRedundancyInfoVO.getDeptIds());
comment.setDepartmentName(userRedundancyInfoVO.getDepartmentNames());
comment.setWxUserId(userRedundancyInfoVO.getWxUserId());
comment.setType(type);
comment.setUserStr(userIds);
TbXyhDynamicinfoPO tbXyhDynamicinfoPO = this.searchByPk(TbXyhDynamicinfoPO.class, comment.getDynamicinfoId());
if (null == tbXyhDynamicinfoPO) {
throw new NonePrintException("20001", "动态不存在或已不删除!");
}
//审批or直接发送评论
sendCommentMsg(tbXyhDynamicinfoPO, comment, userInfoVO, userIds, type);
insertPO(comment, false);
//QiWeiUtil.addUserPoint(QiWeiUserPoint.COMMENT.value(), userId, QiWeiUserPoint.COMMENT.why());
}
/**
* 新增回复
* @param replycomment
* @param userInfoVO
* @param userIds
* @param type
* @throws Exception
* @throws BaseException
*/
@Override
public void addCommentReply(DynamicInfoReplyCommentVO replycomment,UserInfoVO userInfoVO,String userIds, String type) throws Exception, BaseException{
TbXyhDynamicinfoPO tbXyhDynamicinfoPO = this.searchByPk(TbXyhDynamicinfoPO.class, replycomment.getDynamicinfoId());
if (null == tbXyhDynamicinfoPO) {
throw new NonePrintException("20001", "动态不存在或已不删除!");
}
replycomment.setDynamicTypeId(tbXyhDynamicinfoPO.getDynamicTypeId());
//审批or直接发送评论
sendReplyCommentMsg(tbXyhDynamicinfoPO, replycomment, userInfoVO, userIds, type);
insertPO(replycomment, false);
}
@Override
public void sendReplyCommentMsg(TbXyhDynamicinfoPO dynamicPO, DynamicInfoReplyCommentVO po, UserInfoVO userInfoVO, String userIds, String type) throws Exception, BaseException {
/**
* 1.如果属于需要审批的类
* (1)若自己也是审核人中一员,执行2
* (2)若自己不是审核人,推送消息给审批人,评论PO的isPassReview为“待审核”
* 2.如果不需要审核,则评论PO的isPassReview为“已通过”,增加评论数
* (1)若艾特人,则推送消息
*/
po.setDynamicTypeId(dynamicPO.getDynamicTypeId());
//该公告所属的类绑定的审批人
List<TbXhyDynamicReviewerVO> reviewerList = dynamicinfomanageDAO.getReviewers(dynamicPO.getDynamicTypeId(), DynamicinfomanageUtil.COMMENT_REVIEWER, dynamicPO.getOrgId());
//是否需要发送审批消息
boolean isNeedAudit = dynamicinfomanageService.isNeedAudit(userInfoVO.getUserId(), reviewerList);
if (isNeedAudit) {
NewsUtil.sendToReplyCommentReviewer(dynamicPO.getTitle(), po, userInfoVO.getCorpId(), reviewerList, dynamicPO.getOrgId(), dynamicPO.getBelongAgent());
po.setIsPassReview(DynamicinfomanageUtil.WAIT_REVIEW);
} else {
po.setIsPassReview(DynamicinfomanageUtil.PASS_REVIEW);
increaseCommentCount(dynamicPO, 1);//增加评论数
replyCommentPublish(po, userInfoVO.getUserId(), userIds, type, dynamicPO);
}
}
/**
* 评论回复人,发布消息
*
* @param comment
* @param userId
* @param userIds
* @param type
* @param tbXyhDynamicinfoPO
* @throws Exception
* @throws BaseException
* @@author guoquanhui
* @Date 2017/7/18
*/
private void replyCommentPublish(
DynamicInfoReplyCommentVO comment, String userId, String userIds,
String type, TbXyhDynamicinfoPO tbXyhDynamicinfoPO
) throws Exception, BaseException {
if (!StringUtil.isNullEmpty(userIds)) {
String[] commentUsers = userIds.split("\\|");
//String userIdsStr="";
TbQyUserInfoVO sendUser = contactService.findUserInfoByUserId(userId);
if (sendUser == null) {
return;
}
StringBuffer send = new StringBuffer();
for (String commentUser : commentUsers) {
TbQyUserInfoVO userVO = contactService.findUserInfoByUserId(commentUser);
if (userVO == null || !sendUser.getOrgId().equals(userVO.getOrgId())) {
continue;
}
if ("-1".equals(userVO.getUserStatus())) {
continue;
}
if (comment.getContent().indexOf("@" + userVO.getPersonName()) < 0) {
//评论里没找到此用户id对应的@人名内容
send.append("|" + userVO.getWxUserId());
TbDynamicinfoCommentExtPO inputExt = new TbDynamicinfoCommentExtPO();
inputExt.setCommentId(comment.getCommentId());
inputExt.setUserId(commentUser);
inputExt.setCreateTime(new Date());
inputExt.setCreatePerson(userId);
insertPO(inputExt, true);
//记录常用联系人 by:oyl/2014/7/4
contactService.updateCommonUser(sendUser.getUserId(), userVO.getUserId(), 1);
send.deleteCharAt(0);
}else if(userVO != null){
send.append(userVO.getWxUserId());
TbDynamicinfoCommentExtPO inputExt = new TbDynamicinfoCommentExtPO();
inputExt.setCommentId(comment.getCommentId());
inputExt.setUserId(commentUser);
inputExt.setCreateTime(new Date());
inputExt.setCreatePerson(userId);
insertPO(inputExt, true);
//记录常用联系人 by:oyl/2014/7/4
contactService.updateCommonUser(sendUser.getUserId(), userVO.getUserId(), 1);
}
}
if (send.length() > 0) {
//发送消息
String content = comment.getContent();
content = EmojiUtil.replaceEmoji(content, true, 30);
String message = "";
if ("1".equals(type)) {
message = "「" + tbXyhDynamicinfoPO.getTitle() + "」有新评论啦:" + content;
} else if ("2".equals(type)) {
message = "「" + tbXyhDynamicinfoPO.getTitle() + "」有新评论啦:" + sendUser.getPersonName() + "发布了一张图片";
}
//xiangdejun
//send news message.
//20140609
ExtOrgPO orgPO = contactService.searchByPk(ExtOrgPO.class, sendUser.getOrgId());
WxMsgVO wxMsgVO = new WxMsgVO();
wxMsgVO.setId(tbXyhDynamicinfoPO.getDynamicInfoId());
wxMsgVO.setPersonName(sendUser.getPersonName());
wxMsgVO.setTitlePre(WxMessageUtil.getPartyDynamicTitlePre(tbXyhDynamicinfoPO.getOrgId(), tbXyhDynamicinfoPO.getDynamicTypeId(), tbXyhDynamicinfoPO.getBelongAgent()));
wxMsgVO.setDescription(message);
NewsMessageVO newsMessageVO = WxMessageUtil.newsMessageVO.clone();
newsMessageVO.setTouser(send.toString());
newsMessageVO.setDuration("0");
newsMessageVO.setCorpId(orgPO.getCorpId());
newsMessageVO.setAgentCode(tbXyhDynamicinfoPO.getBelongAgent());
newsMessageVO.setOrgId(orgPO.getOrganizationId());
WxMessageUtil.formatMsgInfo(newsMessageVO,NewsUtil.MSGKEY_TOCOMMENT,wxMsgVO);
WxMessageUtil.sendNewsMessage(newsMessageVO);
}
}
}
/**
* 评论艾特人,发布消息
*
* @param comment
* @param userId
* @param userIds
* @param type
* @param tbXyhDynamicinfoPO
* @throws Exception
* @throws BaseException
* @@author guoquanhui
* @Date 2017/7/18
*/
private void commentPublish(
TbXyhDynamicinfoCommentPO comment, String userId, String userIds,
String type, TbXyhDynamicinfoPO tbXyhDynamicinfoPO
) throws Exception, BaseException {
if (!StringUtil.isNullEmpty(userIds)) {
String[] commentUsers = userIds.split("\\|");
//String userIdsStr="";
TbQyUserInfoVO sendUser = contactService.findUserInfoByUserId(userId);
if (sendUser == null) {
return;
}
StringBuffer send = new StringBuffer();
for (String commentUser : commentUsers) {
TbQyUserInfoVO userVO = contactService.findUserInfoByUserId(commentUser);
if (userVO == null || !sendUser.getOrgId().equals(userVO.getOrgId())) {
continue;
}
if ("-1".equals(userVO.getUserStatus())) {
continue;
}
if (comment.getContent().indexOf("@" + userVO.getPersonName()) < 0) {
//评论里没找到此用户id对应的@人名内容
continue;
}
send.append("|" + userVO.getWxUserId());
TbDynamicinfoCommentExtPO inputExt = new TbDynamicinfoCommentExtPO();
inputExt.setCommentId(comment.getCommentId());
inputExt.setUserId(commentUser);
inputExt.setCreateTime(new Date());
inputExt.setCreatePerson(userId);
insertPO(inputExt, true);
//记录常用联系人 by:oyl/2014/7/4
contactService.updateCommonUser(sendUser.getUserId(), userVO.getUserId(), 1);
}
if (send.length() > 0) {
send.deleteCharAt(0);
//发送消息
String content = comment.getContent();
content = EmojiUtil.replaceEmoji(content, true, 30);
String message = "";
if ("1".equals(type)) {
message = "「" + tbXyhDynamicinfoPO.getTitle() + "」有新评论啦:" + content;
} else if ("2".equals(type)) {
message = "「" + tbXyhDynamicinfoPO.getTitle() + "」有新评论啦:" + sendUser.getPersonName() + "发布了一张图片";
}
//xiangdejun
//send news message.
//20140609
ExtOrgPO orgPO = contactService.searchByPk(ExtOrgPO.class, sendUser.getOrgId());
WxMsgVO wxMsgVO = new WxMsgVO();
wxMsgVO.setId(tbXyhDynamicinfoPO.getDynamicInfoId());
wxMsgVO.setPersonName(sendUser.getPersonName());
wxMsgVO.setTitlePre(WxMessageUtil.getPartyDynamicTitlePre(tbXyhDynamicinfoPO.getOrgId(), tbXyhDynamicinfoPO.getDynamicTypeId(), tbXyhDynamicinfoPO.getBelongAgent()));
wxMsgVO.setDescription(message);
NewsMessageVO newsMessageVO = WxMessageUtil.newsMessageVO.clone();
newsMessageVO.setTouser(send.toString());
newsMessageVO.setDuration("0");
newsMessageVO.setCorpId(orgPO.getCorpId());
newsMessageVO.setAgentCode(tbXyhDynamicinfoPO.getBelongAgent());
newsMessageVO.setOrgId(orgPO.getOrganizationId());
WxMessageUtil.formatMsgInfo(newsMessageVO,NewsUtil.MSGKEY_TOCOMMENT,wxMsgVO);
WxMessageUtil.sendNewsMessage(newsMessageVO);
}
}
}
@Override
public TbXyhDynamicinfoPO delDynamicInfoComment(String commentId) throws Exception, BaseException {
TbXyhDynamicinfoCommentPO po = this.searchByPk(TbXyhDynamicinfoCommentPO.class, commentId);
if (null != po) {
this.delPO(po);
TbXyhDynamicinfoPO dynamicinfo = this.searchByPk(TbXyhDynamicinfoPO.class, po.getDynamicinfoId());
//审批通过的评论,删除时才更新评论数
if (null != dynamicinfo) {
if(DynamicinfomanageUtil.PASS_REVIEW.equals(po.getIsPassReview())) {
dynamicinfo.setCommentCount(dynamicinfo.getCommentCount()-1);
this.increaseCommentCount(dynamicinfo, -1);
}
return dynamicinfo;
}
}
return null;
}
private String[] getUserIds(List<TbQyUserInfoPO> list) {
String persons = "";
String userIds[] = null;
if (list != null && list.size() > 0) {
int length = list.size();
int max = Configuration.WX_SEND_USER_MAX;//微信单次发送的最多人员
if (length < max) {
userIds = new String[1];
for (TbQyUserInfoPO tbQyUserInfoPO : list) {
persons += "|" + tbQyUserInfoPO.getUserId();
}
userIds[0] = persons.replaceFirst("\\|", "");
} else {
userIds = new String[length / max + 1];
//循环发送给所有用户
for (int i = 0; i < length; i++) {
persons += "|" + list.get(i).getUserId();
//如果已经达到了最大允许发送的用户数,即刻进行发送,并将发送目标人员置为空
if ((i + 1) % max == 0) {
userIds[(i + 1) / max - 1] = persons.replaceFirst("\\|", "");
persons = "";
}
}
//如果最后一组人员不为空,发送最后一组
if (persons.length() > 0) {
userIds[length / max] = persons.replaceFirst("\\|", "");
}
}
}
return userIds;
}
@Override
public Pager getBackPageDynamicInfo(Map<String, Object> searchMap,
Pager pager) throws Exception, BaseException {
return dynamicinfoDAO.getBackPageDynamicInfo(searchMap, pager);
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#insetTempLate(cn.com.do1.component.dynamicinfo.dynamicinfo.model.TbXyhDynamicinfoBtemplatePO, java.lang.String)
*/
@Override
public void insetTempLate(
TbXyhDynamicinfoBrithdaytemplatePO po,
String imgurl, String type
, RedpackSettingParam redpackSettingVO
, UserOrgVO user) throws Exception, BaseException {
if ("0".equals(type)) {
po.setCreateTime(new Date());
this.insertPO(po, false);
} else {
this.updatePO(po, false);
//处理图片数据
contactService.delPicListByGroupId(po.getId(), po.getCreator());
}
//插入图片
if (!"".equals(imgurl) && imgurl != null) {
String[] images = imgurl.split(",");
contactService.insertPicAttach(po.getId(), po.getCreator(), po.getOrgId(), images);
}
//保存生日红包模板
qiweiredpackService.saveRedpackSetting(redpackSettingVO, user);
}
public IContactService getContactService() {
return contactService;
}
@Resource(name = "contactService")
public void setContactService(IContactService contactService) {
this.contactService = contactService;
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#getBirthdayTemp(java.lang.String)
*/
@Override
public TbXyhDynamicinfoBrithdaytemplatePO getBirthdayTemp(String orgId)
throws Exception, BaseException {
return dynamicinfoDAO.getBirthdayTemp(orgId);
}
public IOrgService getOrgService() {
return orgService;
}
public void setOrgService(IOrgService orgService) {
this.orgService = orgService;
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#getUserByPersonId(java.lang.String)
*/
// @Override
// public TbDqdpUserVO getUserByPersonId(String substring) throws Exception,
// BaseException {
// return dynamicinfoDAO.getBackPageDynamicInfo(substring);
// }
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#getViewCount(java.lang.String)
*/
@Override
public List<TbXyhDynamicinfoViewcountPO> getViewCount(String id, String type) throws Exception, BaseException {
return dynamicinfoDAO.getViewCount(id, type);
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#ajaxSearchRead(java.util.Map, cn.com.do1.common.dac.Pager)
*/
//---需改造,liaojiaming分库查看-已改,2018.09.29
@Override
public Pager ajaxSearchRead(Map<String, Object> searchMap, Pager pager)
throws Exception, BaseException {
Pager viewCount = dynamicinfoDAO.getViewCount(searchMap, pager);
if(AssertUtil.isEmpty(viewCount) || AssertUtil.isEmpty(viewCount.getPageData())){
return viewCount;
}
List<TbXyhDynamicinfoViewcountVO> pageData = (List<TbXyhDynamicinfoViewcountVO>) viewCount.getPageData();
String[] userIds = getUserIdArray(pageData); //根据pager返回userIds
Map<String, TbQyUserInfoVO> userMap = getUserMapByIds(userIds); //根据userIds返回userMap
for (TbXyhDynamicinfoViewcountVO vo : pageData) { //设置手机号
TbQyUserInfoVO userInfoVO = userMap.get(vo.getUserId());
if(!AssertUtil.isEmpty(userInfoVO)){
vo.setMobile(userInfoVO.getMobile());
}
}
return viewCount;
}
/**
* @throws Exception
* @throws BaseException
* @Author:liaojiaming
* @Description:根据userIds 返回Map<string,user>
* @Date:17:29 2018/10/9
*/
private Map<String, TbQyUserInfoVO> getUserMapByIds(String[] userIds) throws Exception, BaseException {
List<TbQyUserInfoVO> allUserInfo = contactService.getAllUserInfoByIds(userIds);
if(AssertUtil.isEmpty(allUserInfo)){
return new HashedMap();
}
Map<String,TbQyUserInfoVO> userMap = new HashedMap();
for (TbQyUserInfoVO userVO : allUserInfo) {
userMap.put(userVO.getUserId(),userVO);
}
return userMap;
}
/**
* @throws Exception
* @throws BaseException
* @Author:liaojiaming
* @Description:根据集合,返回userId数组
* @Date:17:25 2018/10/9
*/
private String[] getUserIdArray(List<TbXyhDynamicinfoViewcountVO> pageData) {
if(AssertUtil.isEmpty(pageData)){
return null;
}
String[] userIds = new String[pageData.size()];
for (int i = 0; i < pageData.size(); i++) {
TbXyhDynamicinfoViewcountVO vo = pageData.get(i);
String userId = vo.getUserId();
userIds[i] = userId;
}
return userIds;
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#ajaxSearchRead(java.util.Map)
*/
//---需改造,liaojiaming分库查看-已改,2018.09.29(疑是废弃)
@Override
public List<TbXyhDynamicinfoViewcountVO> ajaxSearchRead(
Map<String, Object> searchMap) throws Exception, BaseException {
List<TbXyhDynamicinfoViewcountVO> viewCount = dynamicinfoDAO.getViewCount(searchMap);
if(AssertUtil.isEmpty(viewCount)){
return viewCount;
}
String[] userIds = getUserIdArray(viewCount); //根据pager返回userIds
Map<String, TbQyUserInfoVO> userMap = getUserMapByIds(userIds); //根据userIds返回userMap
for (TbXyhDynamicinfoViewcountVO vo : viewCount) { //设置手机号
TbQyUserInfoVO userInfoVO = userMap.get(vo.getUserId());
if(!AssertUtil.isEmpty(userInfoVO)){
vo.setMobile(userInfoVO.getMobile());
}
}
return viewCount;
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#ajaxSearchReadForExport(java.util.Map)
*/
//---需改造,liaojiaming分库查看-已改,2018.09.29
@Override
public List<TbXyhDynamicinfoViewcountVO> ajaxSearchReadForExport(
Map<String, Object> searchMap) throws Exception, BaseException {
List<TbXyhDynamicinfoViewcountVO> list = dynamicinfoReadOnlyDAO.ajaxSearchReadForExport(searchMap);
if(AssertUtil.isEmpty(list)){
return list;
}
String[] userIds = getUserIdArray(list); //根据pager返回userIds
Map<String, TbQyUserInfoVO> userMap = getUserMapByIds(userIds); //根据userIds返回userMap
for (TbXyhDynamicinfoViewcountVO vo : list) { //设置手机号
TbQyUserInfoVO userInfoVO = userMap.get(vo.getUserId());
if(!AssertUtil.isEmpty(userInfoVO)){
vo.setMobile(userInfoVO.getMobile());
}
}
return list;
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#getViewCountByUser(java.lang.String, java.lang.String)
*/
@Override
public TbXyhDynamicinfoViewcountPO getViewCountByUser(String userId,
String id) throws Exception, BaseException {
return dynamicinfoDAO.getViewCountByUser(userId, id);
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#updateTiming(java.lang.String, java.lang.String)
*/
@Override
public void updateTiming(String id, String orgId) throws Exception,
BaseException {
dynamicinfoDAO.updateTiming(id, orgId);
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#batchDeleteDynamicinfoPO(java.lang.String, java.lang.String[])
*/
@Override
public void batchDeleteDynamicinfoPO(String userId, String[] ids)
throws Exception, BaseException {
if (ids == null || ids.length == 0) {
return;
}
UserOrgVO userInfoVO = contactService.getOrgByUserId(userId);
if (userInfoVO == null) {
logger.error("获取登录人" + userId + "orgId的信息为空");
throw new BaseException("新增人的信息为空");
}
for (String id : ids) {
TbXyhDynamicinfoPO po = dynamicinfoDAO.searchByPk(TbXyhDynamicinfoPO.class, id);
if (!userInfoVO.getOrgId().equals(po.getOrgId())) {
//throw new BaseException("无法删除不是本机构下的数据");
continue;
} else {
//删除附件文件
fileMediaService.delMediaByGroupId(po.getDynamicInfoId(), po.getOrgId());
dynamicinfoDAO.delete(po);
LogOperation.insertDel(userId, userInfoVO.getUserName(), "删除新闻公告:" + po.getTitle(), po.getBelongAgent(), userInfoVO.getOrgId());
}
}
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#getDynamicType(java.lang.String)
*/
@Override
public List<TbXyhDynamicinfoChangetypePO> getDynamicType(String orgId, String idDefault)
throws Exception, BaseException {
return dynamicinfoDAO.getDynamicType(orgId, idDefault);
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#delType(java.lang.String)
*/
@Override
public void delType(String orgId) throws Exception, BaseException {
dynamicinfoDAO.delType(orgId);
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#updateCommentByDqdp(java.lang.String, java.lang.String)
*/
@Override
public void updateCommentByDqdp(String commentId, UserOrgVO userOrgVO)
throws Exception, BaseException {
//2016-3-21 lishengtao 修改为直接删除
TbXyhDynamicinfoCommentPO po = this.searchByPk(TbXyhDynamicinfoCommentPO.class, commentId);
if (po == null) {
throw new NonePrintException("1999", "评论已被删除");
}
TbXyhDynamicinfoPO dynamicinfo = this.searchByPk(TbXyhDynamicinfoPO.class, po.getDynamicinfoId());
if (null == dynamicinfo) {
throw new NonePrintException("1001", "动态已不存在");
}
MatchAgentUtil.validPartyAuth(dynamicinfo.getBelongAgent(), userOrgVO); //验证党建信息
dynamicinfomanageDAO.delete(po);//删除评论
increaseCommentCount(dynamicinfo, -1);//修改评论数
}
@Override
public void increaseViewCount(TbXyhDynamicinfoPO po, int increaseCount)
throws Exception, BaseException {
dynamicinfoDAO.increaseViewCount(po, increaseCount);
}
@Override
public String batchDeleteDynamicinfoPO(String[] ids, UserOrgVO userOrgVO, String belongAgent)
throws Exception, BaseException {
/**
* 因为需要删除对应的评论,图片,附件等的数据,所以逐条新闻公告删除
*/
StringBuilder rMsg = new StringBuilder("");
StringBuilder operateStr = new StringBuilder("");
if (ids != null && ids.length > 0) {
rMsg.append("");
List<String> list = Arrays.asList(ids);
List<String> successList = new ArrayList<String>();
Map<String, Object> params;
TbXyhDynamicinfoPO po;
int failCount = 0;
for (String id : list) {
po = this.searchByPk(TbXyhDynamicinfoPO.class, id);
if (po == null) {
rMsg.append(id + ":新闻公告不存在;");
failCount = failCount + 1;
continue;
}
if (!userOrgVO.getOrgId().equals(po.getOrgId())) {
rMsg.append(po.getTitle() + ":无法删除不是本机构下的数据");
failCount = failCount + 1;
continue;
}
MatchAgentUtil.validPartyAuth(po.getBelongAgent(), userOrgVO); //验证党建信息
operateStr.append(po.getTitle() + ";");
successList.add(id);
this.delReferenceInfo(po);
/*//删除评论:包括评论图片
this.delAllCommentByDynamicId(po.getDynamicInfoId(),po.getOrgId());
//删除对应的媒体数据:附件、编辑器图片、封面图片
fileMediaService.delMediaByGroupId(po.getDynamicInfoId(), po.getOrgId());
//删除图片:图片表的图片
this.delAllImagesByDynamicId(po.getDynamicInfoId());
//删除阅读数据
dynamicinfomanageDAO.delAllViewByDynamicId(po.getDynamicInfoId());
//删除生日/入职祝福被祝福者的信息
dynamicinfomanageDAO.delBlessAndEntryUserInfo(po.getDynamicInfoId());
//删除主表新闻公告
dynamicinfoDAO.delete(po);*/
}
if (successList.size() > 0) {
String[] targetIds = new String[successList.size()];
for (int i = 0; i < successList.size(); i++) {
targetIds[i] = (String) successList.get(i);
}
LogOperation.insertOperationLog(userOrgVO.getUserName(), userOrgVO.getPersonName(), "删除新闻公告:" + operateStr.toString(), LogOperation.DEL_TYPE, belongAgent, userOrgVO.getOrgId(), "操作成功");
}
if (failCount == 0) {
rMsg.append("删除成功");
}
//实时统计机构空间
//fileMediaService.updateFileStatisticByOrgId(userOrgVO.getOrgId());
} else {
rMsg.append("没有可删除的数据!");
}
return rMsg.toString();
}
@Override
public String batchDelDynamic(String ids, UserInfoVO userInfoVO, String belongAgent)
throws Exception, BaseException {
StringBuilder rMsg = new StringBuilder("");
StringBuilder operateStr = new StringBuilder("");
if (!AssertUtil.isEmpty(ids)) {
rMsg.append("");
String idArray[] = ids.split("#");
List<String> list = Arrays.asList(idArray);
List<String> successList = new ArrayList<String>();
TbXyhDynamicinfoPO po;
int failCount = 0;
for (String id : list) {
po = this.searchByPk(TbXyhDynamicinfoPO.class, id);
if (po == null) {
rMsg.append(id + ":改动态已不存在。");
failCount = failCount + 1;
continue;
}
if (!userInfoVO.getUserId().equals(po.getCreator())) {
rMsg.append(po.getTitle() + ":不能删除非自己创建的动态");
failCount = failCount + 1;
continue;
}
operateStr.append(po.getTitle() + ";");
successList.add(id);
/**
* 因为要同时删除公告一级内容,所以一个一个删除
*/
//删除评论
this.delAllImagesByDynamicId(po.getDynamicInfoId());
//删除对应的媒体数据:附件、编辑器图片、封面图片
fileMediaService.delMediaByGroupId(po.getDynamicInfoId(), po.getOrgId());
//删除图片:包括封面,文本编辑器的图片,评论图片等等
this.delAllImagesByDynamicId(po.getDynamicInfoId());
//删除阅读数据
dynamicinfomanageDAO.delAllViewByDynamicId(po.getDynamicInfoId());
//删除扩展表
dynamicinfomanageDAO.delDynamicinfoContentExt(po.getDynamicInfoId());
//删除主表新闻公告
dynamicinfoDAO.delete(po);
}
if (successList.size() > 0) {
String[] targetIds = new String[successList.size()];
for (int i = 0; i < successList.size(); i++) {
targetIds[i] = (String) successList.get(i);
}
LogOperation.insertDel(userInfoVO.getUserId(), userInfoVO.getPersonName(), "删除动态:" + operateStr.toString(), belongAgent, userInfoVO.getOrgId());
}
if (failCount == 0) {
rMsg.append("删除成功!");
}
//实时统计机构空间
//fileMediaService.updateFileStatisticByOrgId(userInfoVO.getOrgId());
} else {
rMsg.append("没有可删除的数据!");
}
return rMsg.toString();
}
@Override
public TbXyhDynamicinfoEntrytemplatePO getEntryTemp(String orgId, String ext2)
throws Exception, BaseException {
return dynamicinfoDAO.getEntryTemp(orgId, ext2);
}
@Override
public TbXyhDynamicinfoEntrytemplatePO getEntryTempInfo(String orgId)
throws Exception, BaseException {
//获取机构自定义的模板
TbXyhDynamicinfoEntrytemplatePO tbXyhDynamicinfoEntrytemplatePO = dynamicinfoDAO.getEntryTempByOrgId(orgId);
if (AssertUtil.isEmpty(tbXyhDynamicinfoEntrytemplatePO)) {
//如果为空,获取默认模板
tbXyhDynamicinfoEntrytemplatePO = dynamicinfoDAO.getEntryTempByOrgIdType();
} else {
//如果不为空,判断是不是使用默认模板
if (tbXyhDynamicinfoEntrytemplatePO.getExt2().equals("0")) {
//使用模板模板
//2016-2-3 lishengtao 将自定义模板的对外属性赋值到默认模板
int isOpen = 0;
if (!AssertUtil.isEmpty(tbXyhDynamicinfoEntrytemplatePO.getIsOpen())) {
isOpen = tbXyhDynamicinfoEntrytemplatePO.getIsOpen();
}
tbXyhDynamicinfoEntrytemplatePO = dynamicinfoDAO.getEntryTempByOrgIdType();
tbXyhDynamicinfoEntrytemplatePO.setIsOpen(isOpen);
}
}
return tbXyhDynamicinfoEntrytemplatePO;
}
@Override
public TbXyhDynamicinfoEntrytemplatePO getMorenTemplate()
throws Exception, BaseException {
TbXyhDynamicinfoEntrytemplatePO tbXyhDynamicinfoEntrytemplatePO = dynamicinfoDAO.getEntryTempByOrgIdType();
return tbXyhDynamicinfoEntrytemplatePO;
}
public TbXyhDynamicinfoEntrytemplatePO getZhouNian(String orgId)
throws Exception, BaseException {
//return dynamicinfoDAO.getEntryTemp(orgId);
return null;
}
@Override
public void insetEntryTempLate(TbXyhDynamicinfoEntrytemplatePO po, String imgurlNews,
String imgurlZhuFu
, RedpackSettingParam redpackSettingVO, UserOrgVO user) throws Exception, BaseException {
po.setCreator(user.getUserName());
po.setUpdateTime(new Date());
po.setOrgId(user.getOrgId());
//获取原来的模板数据
TbXyhDynamicinfoEntrytemplatePO oldTemplate = this.getEntryTempByOrgId(po.getOrgId());
if (null == oldTemplate) {
//新增
po.setId(UUID.randomUUID().toString());
po.setIsRemind(BlessAndEntrySwitch.SWICH_OFF.stringValue());//默认不提醒
po.setCreateTime(new Date());
this.insertPO(po, false);
} else {
//编辑
po.setUpdateTime(new Date());
po.setId(oldTemplate.getId());
this.updatePO(po, false);
}
if (BirthAndEntryUtil.useCustomTemplate.equals(po.getExt2())) {
//自定义模板需要验证的信息
if (StringUtil.isNullEmpty(imgurlZhuFu)) {
throw new NonePrintException("2001", "图片数量必须在1到10张");
}
if (StringUtil.isNullEmpty(imgurlNews)) {
throw new NonePrintException("2001", "图片数量必须在1到10张");
}
String[] imagesZhuFu = imgurlZhuFu.split(",");
if (imagesZhuFu.length > 10) {
throw new NonePrintException("2001", "图片数量必须在1到10张");
}
String[] images = imgurlNews.split(",");
if (images.length > 10) {
throw new NonePrintException("2001", "图片数量必须在1到10张");
}
//处理图片数据
contactService.delPicListByGroupId(po.getId(), po.getCreator());
//插入图片
if (!"".equals(imgurlZhuFu) && imgurlZhuFu != null) {
String[] imgurlZhuFus = imgurlZhuFu.split(",");
contactService.insertPicAttachZhouNian(po.getId(), po.getCreator(), po.getOrgId(), imgurlZhuFus, "1");
}
if (!"".equals(imgurlNews) && imgurlNews != null) {
String[] imgurlNewS = imgurlNews.split(",");
contactService.insertPicAttachZhouNian(po.getId(), po.getCreator(), po.getOrgId(), imgurlNewS, "0");
}
}
//保存生日红包模板
qiweiredpackService.saveRedpackSetting(redpackSettingVO, user);
}
@Override
public void delAllCommentByDynamicId(String dynamicId, String orgId) throws Exception,
BaseException {
//dynamicinfomanageDAO.delAllCommentByDynamicId(dynamicId);//只删除关联
/**
* 删除评论数据
* 删除media数据
* 删除物理文件
*/
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("dynamicId", dynamicId);
//paramMap.put("type", "2");//图片评论
List<TbXyhDynamicinfoCommentPO> commentList = dynamicinfomanageDAO.getDynamicCommentList(paramMap);
if (null != commentList && commentList.size() > 0) {
for (TbXyhDynamicinfoCommentPO po : commentList) {
if ("2".equals(po.getType()) && !AssertUtil.isEmpty(po.getContent())) {
//删除media
fileMediaService.delMediaByPath(po.getContent(), orgId);
}
//删除本数据
this.delPO(po);
}
}
}
@Override
public void delAllImagesByDynamicId(String dynamicId) throws Exception,
BaseException {
/**
* 删除图片有复制的问题,这里记录到组中删除
*/
dynamicinfomanageDAO.delAllImagesByDynamicId(dynamicId);//只删除关联
}
@Override
public TbXyhDynamicinfoEntrytemplatePO getEntryTempByOrgId(String orgId)
throws Exception, BaseException {
return dynamicinfoDAO.getEntryTempByOrgId(orgId);
}
/* (非 Javadoc)
* @see cn.com.do1.component.dynamicinfo.dynamicinfo.service.IDynamicinfoService#exportDynamicList(java.util.Map)
*/
@Override
public List<ExportDynamicPO> exportDynamicList(Map<String, Object> params)
throws Exception, BaseException {
if(! AssertUtil.isEmpty(params) && DynamicinfomanageUtil.DYNAMIC_TYPE_BLESS.equals(params.get("dynamicType"))){
params.remove("dynamicType");
params.put("sendType", NewsUtil.SEND_TYPE_NORMAL_NEWS);
}
//获取需要导出的报表po
List<ExportDynamicPO> exportList = dynamicinfoReadOnlyDAO.exportDynamicList(params);
List<String> dynamicIdList = new ArrayList<String>();
Map<String, StringBuffer> paramMap = new HashMap<String, StringBuffer>();
/**
* 遍历报表PoList,存储公告id,
* 100条一批, 查看扩展表,拼接正文,
* 存入Map(key为公告id,value为正文)
*/
if (!AssertUtil.isEmpty(exportList)) {
int i = 1;
for (ExportDynamicPO exportDynamicPO : exportList) {
dynamicIdList.add(exportDynamicPO.getDynamicInfoId());
if (i % DynamicinfomanageUtil.REPORT_BATCH == 0) {
getExportContentToMap(dynamicIdList, paramMap);
i = 1;
dynamicIdList.clear();
} else {
i++;
}
}
if (i > 1) {
getExportContentToMap(dynamicIdList, paramMap);
}
}
//遍历报表poList,根据公告id,将正文set入报表的content
if (!AssertUtil.isEmpty(paramMap)) {
for (ExportDynamicPO exportDynamicPO : exportList) {
if(! AssertUtil.isEmpty(exportDynamicPO.getDynamicInfoId())) {
exportDynamicPO.setContent(paramMap.get(exportDynamicPO.getDynamicInfoId()).toString());
}
}
}
return exportList;
}
@Override
public void getExportContentToMap(List<String> dynamicIdList, Map<String, StringBuffer> paramMap) throws Exception, BaseException {
Map<String, Object> searchMap = new HashMap<String, Object>();
if (!AssertUtil.isEmpty(dynamicIdList)) {
//根据公告id, 查找扩展表相关content
searchMap.put("dynamicInfoIds", ListUtil.toArrays(dynamicIdList));
List<TbXyhDynamicInfoContentExtPO> contentList = dynamicinfoDAO.getContentExtLists(searchMap);
//拼接正文,存入map
if (!AssertUtil.isEmpty(contentList)) {
for (TbXyhDynamicInfoContentExtPO contentPO : contentList) {
if (paramMap.containsKey(contentPO.getDynamicInfoId())) {
paramMap.get(contentPO.getDynamicInfoId()).append(contentPO.getContent());
} else {
paramMap.put(contentPO.getDynamicInfoId(), new StringBuffer(contentPO.getContent()));
}
}
}
}
}
@Override
public Pager getNextDynamic(Map<String, Object> searchMap, Pager pager, String belongAgent)
throws Exception, BaseException {
if (DynamicinfomanageUtil.TYPE_ADD.equals(searchMap.get("schType"))) {//我的动态
searchMap.remove("dynamicType");
} else {
String orgId = (String) searchMap.get("orgId");
String dynamicType = (String) searchMap.get("dynamicType");
if (DynamicinfomanageUtil.TYPE_UNREAD.equals(searchMap.get("schType"))) {//未阅
searchMap.remove("dynamicType");
TbQyUserInfoVO userInfo = contactService.findUserInfoByUserId((String) searchMap.get("creator"));
searchMap.put("beginTime", userInfo.getCreateTime());
} else {
setSearchParamDynamicType(searchMap, orgId, dynamicType, belongAgent);
}
//给用户返回查询目标对象的md5加密字段 guoquanhui 20180921
List<String> userMd5TgTp = BaseTargetUtil.getUserMd5TgTp(orgId, (String)searchMap.get("creator"));
searchMap.put("mdfiveTgTp", userMd5TgTp);
}
searchMap.put("belongAgent", belongAgent);
return dynamicinfoDAO.getNextDynamic(searchMap, pager);
}
@Override
public List<DynamicTaskInfoVO> getSendNewsTask(String status)
throws Exception, BaseException {
return dynamicinfoDAO.getSendNewsTask("1");
}
@Override
public List<TbXyhDynamicinfoBrithdaytemplatePO> getTbXyhDynamicinfoBrithdaytemplatePOList(
Map<String, Object> paramMap) throws Exception, BaseException {
return dynamicinfoInsideReadOnlyDAO.getTbXyhDynamicinfoBrithdaytemplatePOList(paramMap);
}
@Override
public List<BlessAndEntryUserInfoPO> getBlessAndEntryUserInfoPOList(Map<String, Object> searchMap) throws Exception, BaseException {
return dynamicinfoDAO.getBlessAndEntryUserInfoPOList(searchMap);
}
@Override
public void addBlessAndEntryUserInfoPOList(List<BlessAndEntryUserInfoPO> list) throws Exception, BaseException {
if (list.size() > 0) {
dynamicinfoDAO.execBatchInsert(list);
}
}
@Override
public void delReferenceInfo(TbXyhDynamicinfoPO po) throws Exception, BaseException {
//删除评论:包括评论图片
this.delAllCommentByDynamicId(po.getDynamicInfoId(), po.getOrgId());
//删除对应的媒体数据:附件、编辑器图片、封面图片
fileMediaService.delMediaByGroupId(po.getDynamicInfoId(), po.getOrgId());
//删除图片:图片表的图片
this.delAllImagesByDynamicId(po.getDynamicInfoId());
//删除阅读数据
dynamicinfomanageDAO.delAllViewByDynamicId(po.getDynamicInfoId());
//删除生日/入职祝福被祝福者的信息
dynamicinfomanageDAO.delBlessAndEntryUserInfo(po.getDynamicInfoId());
//删除点赞数据
dynamicinfomanageDAO.delPraiseByDynamicId(po.getDynamicInfoId());
//删除主表新闻公告
dynamicinfoDAO.delete(po);
//删除正文扩展表
dynamicinfomanageDAO.delDynamicinfoContentExt(po.getDynamicInfoId());
//删除目标对象表 guoquanhui 20180920
dynamicinfomanageDAO.delDynamicTargetsByRefId(po.getDynamicInfoId());
//删除未阅表 guoquanhui 20180920
targetService.delTargetUserByGroupId(po.getDynamicInfoId(), 0);
//删除新闻公告扩展表 guoquanhui 20181101
dynamicinfomanageDAO.delDynamicinfoExtByDynamicId(po.getDynamicInfoId());
}
@Override
public String searchEditorContent(TbXyhDynamicinfoPO tbXyhDynamicinfoPO) throws Exception, BaseException {
String tempContent = "";
if (Configuration.READ_EDITOR_SWITCH == 1) {
//用扩展表数据
List<TbXyhDynamicInfoContentExtPO> list = dynamicinfoDAO.getDynamicinfoContentExt(tbXyhDynamicinfoPO.getDynamicInfoId());
StringBuffer sb = new StringBuffer();
if (list != null && list.size() > 0) {
for (TbXyhDynamicInfoContentExtPO po : list) {
sb.append(po.getContent());
}
tempContent = sb.toString();
}
} else {
//用主表content数据
tempContent = tbXyhDynamicinfoPO.getContent();
}
return tempContent;
}
@Override
public int getDynamicContentExtCount(String dynamicInfoId) throws Exception, BaseException {
return dynamicinfoDAO.getDynamicContentExtCount(dynamicInfoId);
}
@Override
public File setExportDynamic(String[] header, List<ExportDynamicPO> list, String fileName) throws Exception, BaseException {
if (fileName == null || "".equals(fileName)) {
fileName = "exportForExcel.xls";
}
File file = new File(fileName);
FileOutputStream out = null;
out = new FileOutputStream(file);
Workbook writeWB = new SXSSFWorkbook(500);
Sheet sheet = writeWB.createSheet(fileName);
//设置表头
Row firstRow = sheet.createRow(0);
for (int col = 0; col < header.length; col++) {
firstRow.createCell(col).setCellValue(header[col]);
}
ExportDynamicPO exportDynamicPO;
Row dynamicRow;
String content;
String[] rowContent;
int lastIndex, rowNum;
//填充表格
for (int index = 0, firstIndex = 0; index < list.size(); index++) {
dynamicRow = sheet.createRow(firstIndex + 1);
exportDynamicPO = list.get(index);
//3w字符一行,切割content
content = exportDynamicPO.getContent();
rowContent = new String[content.length() / DynamicinfomanageUtil.REPORT_SECTION + 1];
lastIndex = 0;
if (!StringUtil.isNullEmpty(content) && content.length()>0) {
for (int i = 0; i < content.length(); i = i + DynamicinfomanageUtil.REPORT_SECTION, lastIndex++) {
if (content.length() < (i + DynamicinfomanageUtil.REPORT_SECTION)) {
rowContent[lastIndex] = content.substring(i);
} else {
rowContent[lastIndex] = content.substring(i, i + DynamicinfomanageUtil.REPORT_SECTION);
}
}
} else {
//20180128 修复导出错误,如果content为空的时候, lastIndex至少要加一行
//因为图片经过替换标签字符后,有可能为空,但是仍然要导出
lastIndex ++;
}
rowNum = lastIndex; //content所占表格的行数
lastIndex = rowNum + firstIndex; //content所占表格的最大行号
firstIndex = firstIndex + 1; //content所占表格的最小行号
//合并单元格
for (int i = 0, j = firstIndex; i < rowNum; i++, j++) {
if (i == 0) {
dynamicRow.createCell(0).setCellValue(exportDynamicPO.getTitle());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 0, 0));
dynamicRow.createCell(2).setCellValue(exportDynamicPO.getDynamicType());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 2, 2));
dynamicRow.createCell(3).setCellValue(exportDynamicPO.getPersonName());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 3, 3));
dynamicRow.createCell(4).setCellValue(exportDynamicPO.getViewCount());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 4, 4));
dynamicRow.createCell(5).setCellValue(exportDynamicPO.getCommentCount());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 5, 5));
dynamicRow.createCell(6).setCellValue(exportDynamicPO.getPraise());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 6, 6));
dynamicRow.createCell(7).setCellValue(exportDynamicPO.getUserPraise());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 7, 7));
dynamicRow.createCell(8).setCellValue(exportDynamicPO.getStatus());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 8, 8));
dynamicRow.createCell(9).setCellValue(exportDynamicPO.getCreateTime());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 9, 9));
dynamicRow.createCell(10).setCellValue(exportDynamicPO.getPublishTime());
sheet.addMergedRegion(new CellRangeAddress(firstIndex, lastIndex, 10, 10));
} else {
dynamicRow = sheet.createRow(j);
}
dynamicRow.createCell(1).setCellValue(rowContent[i]);
}
firstIndex = lastIndex;
}
writeWB.write(out);
out.close();
return file;
}
@Override
public Pager searchDynamicPraisePager(Map<String, Object> paramMap, Pager pager) throws Exception, BaseException {
return dynamicinfoDAO.searchDynamicPraisePager(paramMap, pager);
}
@Override
public NewsXyhPraisePO getPraisePOByUserId(String userId, String id) throws Exception, BaseException {
return dynamicinfoDAO.getPraisePOByUserId(userId, id);
}
@Override
public boolean getIsCreateTemplate(String orgId) throws Exception, BaseException {
return dynamicinfoDAO.getIsCreateTemplate(orgId);
}
@Override
public Integer isReviewer(String userId, String dynamicTypeId, Integer reviewerType, String orgId, String belongAgent) throws BaseException, Exception {
Integer count = dynamicinfomanageDAO.isReviewer(userId, dynamicTypeId, reviewerType, orgId, belongAgent);
if(count > 0){
return DynamicUtil.IS_REVIEWER;
}else{
return DynamicUtil.NOT_REVIEWER;
}
}
@Override
public List<String> getTypeIdsByUserId(String userId, Integer reviewType, String orgId, String belongAgent) throws Exception, BaseException {
List<String> list;
if (Configuration.IS_USE_MEMCACHED) {
list = (List<String>) CacheWxqyhObject.get(belongAgent, orgId, userId + "_review_" +reviewType);
if (AssertUtil.isEmpty(list)) {
list = dynamicinfomanageDAO.getTypeIdsByUserId(userId, reviewType, orgId, belongAgent);
if (list != null) {
CacheWxqyhObject.set(belongAgent, orgId, userId + "_review_" +reviewType, list);
}
}
} else {
list = dynamicinfomanageDAO.getTypeIdsByUserId(userId, reviewType, orgId, belongAgent);
if (list != null) {
CacheWxqyhObject.set(belongAgent, orgId, userId + "_review_" +reviewType, list);
}
}
return list;
}
@Override
public Pager getDynamicinfoByReviewType(Map<String, Object> searchMap, Pager pager) throws Exception, BaseException {
return dynamicinfomanageDAO.getDynamicinfoByReviewType(searchMap, pager);
}
@Override
public Pager getCommentByReviewType(Map<String, Object> searchMap, Pager pager) throws Exception, BaseException {
return dynamicinfomanageDAO.getCommentByReviewType(searchMap, pager);
}
/**
* 根据dynamicId或commentId删除审批人信息
* @param dynamicCommentIds
* @throws Exception
* @throws BaseException
* @@author guoquanhui
* @Date 2017/8/14
*/
private void delAuditByDynamicCommentIds(String[] dynamicCommentIds, String orgId)throws Exception, BaseException{
if(dynamicCommentIds.length == 0){
return;
}
Map<String, Object> searchMap = new HashMap<String, Object>();
searchMap.put("dynamicCommentIds", dynamicCommentIds);
searchMap.put("orgId", orgId);
dynamicinfoDAO.delAuditByDynamicCommentIds(searchMap);
}
@Override
public void auditDynamic(UserInfoVO user, String dynamicIds, Integer isPassReview, String belongAgent) throws Exception, BaseException {
String[] dynamicIdArr = dynamicIds.split("\\|");
List<TbXyhDynamicinfoPO> poList = this.searchByPks(TbXyhDynamicinfoPO.class, dynamicIdArr); //要被审核的动态
//审核人可以审核的类型
List<String> typeIds = this.getTypeIdsByUserId(user.getUserId(), DynamicinfomanageUtil.DYNAMIC_REVIEWER, user.getOrgId(), belongAgent);
String ids = StringUtils.join(typeIds, ",");
//审核人可以审核的动态
List<TbXyhDynamicinfoPO> auditDynamicList = new ArrayList<TbXyhDynamicinfoPO>();
for (TbXyhDynamicinfoPO po : poList) {
if (ids.contains(po.getDynamicTypeId())) {
auditDynamicList.add(po);
}
}
if (!AssertUtil.isEmpty(auditDynamicList) && auditDynamicList.size() > 0) {
//删除所有审批人信息
this.delAuditByDynamicCommentIds(dynamicIdArr, user.getOrgId());
//更新审核状态并推送消息
this.updateDynamicStatus(auditDynamicList, isPassReview, user);
}
}
/**
* 更新审核状态并推送消息
* @param dynamicList
* @param isPassReivew
* @param user
* @throws Exception
* @throws BaseException
* @@author guoquanhui
* @Date 2017/7/18
*/
private void updateDynamicStatus(List<TbXyhDynamicinfoPO> dynamicList, Integer isPassReivew, UserInfoVO user) throws Exception, BaseException {
DqdpOrgVO dqdpOrgVO = OrgUtil.getOrgByOrgId(user.getOrgId());
//后台发送人
UserOrgVO userOrgVO = new UserOrgVO();
userOrgVO.setOrgId(dqdpOrgVO.getOrgId());
userOrgVO.setCorpId(dqdpOrgVO.getCorpId());
userOrgVO.setWxId(dqdpOrgVO.getWxId());
//手机端发送人
UserInfoVO userInfoVO = new UserInfoVO();
userInfoVO.setOrgId(dqdpOrgVO.getOrgId());
userInfoVO.setCorpId(dqdpOrgVO.getCorpId());
boolean isFirstSend;
String operation;
TbQyDynamicAuditPO auditPO;
TbQyDynamicAuditPO tbQyDynamicAuditPO = new TbQyDynamicAuditPO();
List<TbQyDynamicAuditPO> auditList = new ArrayList<TbQyDynamicAuditPO>();
for (TbXyhDynamicinfoPO po : dynamicList) {
//是不是同机构
if (!user.getOrgId().equals(po.getOrgId())) {
continue;
}
//如果已被审核就跳过
if (!DynamicinfomanageUtil.WAIT_REVIEW.equals(po.getIsPassReview())) {
continue;
}
//更新状态
po.setIsPassReview(isPassReivew);
/*po.setAuditId(user.getUserId());
po.setAuditPerson(user.getPersonName());
po.setAuditTime(new Date());*/
//审批人信息
auditPO = (TbQyDynamicAuditPO)tbQyDynamicAuditPO.clone();
auditPO.setId(UUID32.getID());
auditPO.setDynamicCommentId(po.getDynamicInfoId());
auditPO.setAuditId(user.getUserId());
auditPO.setAuditPerson(user.getPersonName());
auditPO.setAuditTime(new Date());
auditPO.setOrgId(user.getOrgId());
auditList.add(auditPO);
//审核通过,推送消息
if(DynamicinfomanageUtil.PASS_REVIEW.equals(isPassReivew)){
if (!DynamicinfomanageUtil.IS_TIMING_ON.equals(po.getIsTiming())
|| (DynamicinfomanageUtil.IS_TIMING_ON.equals(po.getIsTiming()) && DynamicinfomanageUtil.SEND_RES_HAS_SEND.equals(po.getSendRes()))) {
//如果(非定时任务) 或者 (如果是定时任务,且定时任务已经发布了)才能发消息
if (DynamicinfomanageUtil.IS_FIRST_SEND.equals(po.getIsFirstSend())) {
isFirstSend = true;
operation = DynamicinfomanageUtil.OPERATION_ADD.toString();
} else {
isFirstSend = false;
operation = DynamicinfomanageUtil.OPERATION_EDIT.toString();
}
logger.info("__________________send _________________________",po.getIsSendMsg());
if(DynamicinfomanageUtil.FROM_WEB.equals(po.getContentType())&&po.getIsSendMsg().equals("1")) { //后台消息发送方式
NewsUtil.sendDynamicMsg(DynamicinfomanageUtil.replaceDyPOToDyVO(po, null, true), userOrgVO, isFirstSend, false);
}else{//手机端消息发送方式
userInfoVO.setUserId(po.getCreator());
NewsUtil.sendDynamicMsg(DynamicinfomanageUtil.replaceDyPOToDyVO(po, null, true), userInfoVO, operation, DynamicinfomanageUtil.PUBLISH_STATUS);
}
}
}
}
dynamicinfomanageDAO.execBatchUpdate(dynamicList);
if(! AssertUtil.isEmpty(auditList)){
dynamicinfomanageDAO.execBatchInsert(auditList);
}
}
@Override
public void auditComment(UserInfoVO user, String commentIds, Integer isPassReview, String belongAgent) throws Exception, BaseException {
String[] commentIdArr = commentIds.split("\\|");
List<TbXyhDynamicinfoCommentPO> poList = this.searchByPks(TbXyhDynamicinfoCommentPO.class, commentIdArr); //要被审核的动态
//审核人可以审核的评论类型
List<String> typeIds = this.getTypeIdsByUserId(user.getUserId(), DynamicinfomanageUtil.COMMENT_REVIEWER, user.getOrgId(), belongAgent);
String ids = StringUtils.join(typeIds, ",");
//审核人可以审核的评论
List<TbXyhDynamicinfoCommentPO> auditCommentList = new ArrayList<TbXyhDynamicinfoCommentPO>();
Set<String> auditDynamicIds = new HashSet<String>(); //评论中涉及到的dynamicId
Map<String, String> commentDynamicMap = new HashMap<String, String>();//commentId与dynamicId
for (TbXyhDynamicinfoCommentPO po : poList) {
if (ids.contains(po.getDynamicTypeId())) {
auditCommentList.add(po);
auditDynamicIds.add(po.getDynamicinfoId());
commentDynamicMap.put(po.getCommentId(), po.getDynamicinfoId());
}
}
if (!AssertUtil.isEmpty(auditCommentList) && auditCommentList.size() > 0) {
//删除所有审批人信息
this.delAuditByDynamicCommentIds(commentIdArr, user.getOrgId());
//更新审核状态并推送消息
this.updateCommentStatus(auditCommentList, auditDynamicIds,commentDynamicMap, isPassReview, user);
}
}
@Override
public Integer countDynamicAuditNumber(List<String> typeIds, String orgId, Integer isPassReview) throws Exception, BaseException{
return dynamicinfomanageDAO.countDynamicAuditNumber(typeIds, orgId, isPassReview);
}
@Override
public Integer countCommentAuditNumber(List<String> typeIds, String orgId, Integer isPassReview) throws Exception, BaseException {
return dynamicinfomanageDAO.countCommentAuditNumber(typeIds, orgId, isPassReview);
}
/**
* 更新审核状态并推送消息
* @param commentList
* @param isPassReivew
* @param user
* @throws Exception
* @throws BaseException
* @@author guoquanhui
* @Date 2017/7/18
*/
private void updateCommentStatus(List<TbXyhDynamicinfoCommentPO> commentList,Set<String> auditDynamicIds, Map<String, String> commentDynamicMap, Integer isPassReivew, UserInfoVO user) throws Exception, BaseException {
List<String> delIdList = new ArrayList<String>();
Map<String, TbXyhDynamicinfoPO> dynamicinfoMap = new HashMap<String, TbXyhDynamicinfoPO>();//dynamicId与dynamicPO
List<TbXyhDynamicinfoPO> dynamicinfoList = this.searchByPks(TbXyhDynamicinfoPO.class, auditDynamicIds.toArray());
if(AssertUtil.isEmpty(dynamicinfoList)){
return;
}
for(TbXyhDynamicinfoPO dynamicinfoPO : dynamicinfoList){
dynamicinfoMap.put(dynamicinfoPO.getDynamicInfoId(), dynamicinfoPO);
}
TbXyhDynamicinfoPO dynamicPO;
TbQyDynamicAuditPO auditPO;
TbQyDynamicAuditPO tbQyDynamicAuditPO = new TbQyDynamicAuditPO();
List<TbQyDynamicAuditPO> auditList = new ArrayList<TbQyDynamicAuditPO>();
for (TbXyhDynamicinfoCommentPO po : commentList) {
//是不是同机构
if (!user.getOrgId().equals(po.getOrgId())) {
continue;
}
//如果已被审核就提示
if (!DynamicinfomanageUtil.WAIT_REVIEW.equals(po.getIsPassReview())) {
continue;
}
//更新状态
po.setIsPassReview(isPassReivew);
/* po.setAuditId(user.getUserId());
po.setAuditPerson(user.getPersonName());
po.setAuditTime(new Date());*/
String dynamicId = commentDynamicMap.get(po.getCommentId());
dynamicPO = dynamicinfoMap.get(dynamicId);
if(DynamicinfomanageUtil.PASS_REVIEW.equals(isPassReivew)){//审核通过,推送消息,动态的commentCount + 1
commentPublish(po, po.getCreator(), po.getUserStr(), po.getType(), dynamicPO);
dynamicPO.setCommentCount(dynamicPO.getCommentCount() + 1);
//审批人信息
auditPO = (TbQyDynamicAuditPO)tbQyDynamicAuditPO.clone();
auditPO.setId(UUID32.getID());
auditPO.setDynamicCommentId(po.getCommentId());
auditPO.setAuditId(user.getUserId());
auditPO.setAuditPerson(user.getPersonName());
auditPO.setAuditTime(new Date());
auditPO.setOrgId(user.getOrgId());
auditList.add(auditPO);
}else if(DynamicinfomanageUtil.NOT_PASS_REVIEW.equals(isPassReivew)){ //审核不通过,删除这条评论
delIdList.add(po.getCommentId());
}
}
dynamicinfomanageDAO.execBatchUpdate(commentList);
//更新dynamic的commentCount
dynamicinfoList = new ArrayList<TbXyhDynamicinfoPO>(dynamicinfoMap.values());
dynamicinfomanageDAO.execBatchUpdate(dynamicinfoList);
if(! AssertUtil.isEmpty(delIdList) && delIdList.size() > 0){
this.batchDel(TbXyhDynamicinfoCommentPO.class, ListUtil.toArrays(delIdList));
}
if(! AssertUtil.isEmpty(auditList)){
dynamicinfomanageDAO.execBatchInsert(auditList);
}
}
@Override
public void initDefaultType(String orgId) throws Exception,BaseException {
//获取默认类型
List<TbXyhDynamicinfoChangetypePO> typeList = getDynamicType(null, DynamicUtil.IS_DEFAULT);
//对于每个orgId分别插入各自的默认类型
TbXyhDynamicinfoChangetypePO initTypePO;
List<TbXyhDynamicinfoChangetypePO> initTypeList = new ArrayList<TbXyhDynamicinfoChangetypePO>();
for(TbXyhDynamicinfoChangetypePO typePO : typeList) {
initTypePO = (TbXyhDynamicinfoChangetypePO) typePO.clone();
initTypePO.setId(UUID32.getID());
initTypePO.setOrgId(orgId);
initTypePO.setCreator(DynamicinfomanageUtil.INIT_CREATOR);
initTypePO.setIsDefault(DynamicinfomanageUtil.NOT_DEFAULT_TYPE);
initTypePO.setCreateTime(new Date());
initTypePO.setBelongAgent(WxAgentUtil.getDynamicCode());
initTypeList.add(initTypePO);
}
if(! AssertUtil.isEmpty(initTypeList) && initTypeList.size() > 0){
dynamicinfomanageDAO.execBatchInsert(initTypeList);
}
}
@Override
public boolean getIsDefaultType(String orgId, String belongAgent) throws Exception, BaseException {
return dynamicinfoDAO.getIsDefaultType(orgId, belongAgent);
}
@Override
public void updateAuditStatusByIds(Map<String, Object> paramMap) throws Exception, BaseException {
dynamicinfoDAO.updateAuditStatusByIds(paramMap);
}
@Override
public List<DynamicTaskInfoVO> getSendNewsRemindTask() throws Exception, BaseException {
return dynamicinfoDAO.getSendNewsRemindTask();
}
@Override
public Pager ajaxTemplateNews(UserInfoVO user, Map<String, Object> searchMap, Pager pager) throws Exception, BaseException {
//给用户返回查询目标对象的md5加密字段 guoquanhui 20180921
List<String> userMd5TgTp = BaseTargetUtil.getUserMd5TgTp(user.getOrgId(), user.getUserId());
searchMap.put("mdfiveTgTp", userMd5TgTp);
pager = dynamicinfoDAO.ajaxTemplateNews(searchMap, pager);
List<DynamicInfoVO> dynamicInfoVOList = (List<DynamicInfoVO>) pager.getPageData();
if (AssertUtil.isEmpty(dynamicInfoVOList)) {
return pager;
}
DqdpOrgVO orgVO = WxqyhAppContext.getOrgExtInfo(dynamicInfoVOList.get(0).getOrgId());
//过滤出dynamicInfoIdList
List<String> dynamicInfoIdList = dynamicInfoVOList.parallelStream().map(DynamicInfoVO::getDynamicInfoId).collect(Collectors.toList());
//根据dynamicInfoIds获取点赞人名称列表
List<NewsXyhPraisePO> praiseNameList = dynamicinfoReadOnlyDAO.getPraiseNamesByDynamicinfoIds(dynamicInfoIdList);
//获取当前用户对应的点赞信息
List<NewsXyhPraisePO> userPraisePOList = dynamicinfoReadOnlyDAO.getDynamicPraisePOListByUserId(user.getUserId(), dynamicInfoIdList);
assemblePraisePO(orgVO, dynamicInfoVOList, praiseNameList, userPraisePOList);
return pager;
}
/**
* 组装点赞参数
*/
public static void assemblePraisePO(DqdpOrgVO orgVO, List<DynamicInfoVO> dynamicInfoVOList, List<NewsXyhPraisePO> praisePOList, List<NewsXyhPraisePO> userPraisePOList) {
//点赞人名称
Map<String, String> praiseNameMap = Maps.newHashMap();
Map<String, NewsXyhPraisePO> userPraiseMap = Maps.newHashMap();
if (!AssertUtil.isEmpty(praisePOList)){
praisePOList.forEach( x -> praiseNameMap.put(x.getDynamicInfoId(),x.getPersonName()));
}
if (!AssertUtil.isEmpty(userPraisePOList)) {
userPraisePOList.forEach( x -> userPraiseMap.put(x.getDynamicInfoId(),x));
}
for (DynamicInfoVO vo : dynamicInfoVOList) {
if (AssertUtil.isEmpty(vo.getPersonName())) {
vo.setPersonName(orgVO.getOrgName());
}
if (AssertUtil.isEmpty(vo.getHeadPic())) {
vo.setHeadPic(orgVO.getLogo());
}
if (praiseNameMap.containsKey(vo.getDynamicInfoId())) {
//设置点赞人名称
String praiseNames = praiseNameMap.get(vo.getDynamicInfoId());
vo.setPraiseNames(NewsUtil.PARISE_NAME_SIZE > praiseNames.length() ? praiseNames : praiseNames.substring(0, NewsUtil.PARISE_NAME_SIZE));
}
if(userPraiseMap.containsKey(vo.getDynamicInfoId())){
//当前用户点过赞
vo.setHasPraise(true);
}
}
}
@Override
public void batchRead(UserInfoVO user, String belongAgent) throws Exception, BaseException {
Map<String, Object> searchMap = new HashMap<String, Object>();
searchMap.put("orgId", user.getOrgId());
searchMap.put("creator", user.getUserId());
searchMap.put("beginTime", DateUtil.parse(user.getCreateTime(), "yyyy-MM-dd HH:mm:ss"));
//给用户返回查询目标对象的md5加密字段 guoquanhui 20180921
List<String> userMd5TgTp = BaseTargetUtil.getUserMd5TgTp(user.getOrgId(), user.getUserId());
searchMap.put("mdfiveTgTp", userMd5TgTp);
//获取该用户上一次一键已阅的时间, 并更新时间
TbXyhDynamicBatchReadTimePO batchReadTimePO = dynamicinfoDAO.getBatchReadTimeByCreator(user.getOrgId(), user.getUserId(), belongAgent);
if(AssertUtil.isEmpty(batchReadTimePO)){
batchReadTimePO = new TbXyhDynamicBatchReadTimePO();
batchReadTimePO.setId(UUID32.getID());
batchReadTimePO.setOrgId(user.getOrgId());
batchReadTimePO.setCreator(user.getUserId());
batchReadTimePO.setLastBatchReadTime(new Date());
batchReadTimePO.setBelongAgent(belongAgent);
this.insertPO(batchReadTimePO, false);
}else{
searchMap.put("lastBatchReadTime", batchReadTimePO.getLastBatchReadTime());
batchReadTimePO.setLastBatchReadTime(new Date());
this.updatePO(batchReadTimePO, false);
}
//未阅新闻id
searchMap.put("belongAgent", belongAgent);
List<String> dynamicIdList = dynamicinfoDAO.batchRead(searchMap);
if(! AssertUtil.isEmpty(dynamicIdList)){
//删除未阅目标对象
targetService.delTargetUser(ListUtil.toArrays(dynamicIdList), user.getUserId(), DynamicinfomanageUtil.OPERATION_ADD);
}
}
@Override
public List<TbXyhDynamicinfoPO> getInitDynamicInfo(Map<String, Object> params) throws SQLException {
return dynamicinfoDAO.getInitDynamicInfo(params);
}
@Override
public Integer getDraftNum(UserInfoVO user, String belongAgent) throws Exception, BaseException {
return dynamicinfoInsideReadOnlyDAO.getDraftNum(user, belongAgent);
}
@Override
public Integer getBlessOrEntryCount(String orgId, Integer sendType) throws Exception, BaseException {
if(AssertUtil.isEmpty(orgId)||AssertUtil.isEmpty(sendType)){
return null;
}
return dynamicinfoReadOnlyDAO.getBlessOrEntryCount(orgId,sendType);
}
@Override
public boolean getIsCreateEntryTemplate(String orgId) throws Exception, BaseException {
return dynamicinfoDAO.getIsCreateEntryTemplate(orgId);
}
@Override
public List<HrDynamicInfoCommentVO> ajaxCommentNews(String orgId, String userId, String status) throws Exception, BaseException {
if (AssertUtil.isAnyEmpty(orgId, userId)) {
return Lists.newArrayList();
}
Map<String, Object> paramsMap = Maps.newHashMap();
paramsMap.put("orgId", orgId);
paramsMap.put("creator", userId);
paramsMap.put("status", status);
//获取当前用户的祝福可见范围
List<String> userMd5TgTp = BaseTargetUtil.getUserMd5TgTp(orgId, userId);
paramsMap.put("mdfiveTgTp", userMd5TgTp);
paramsMap.put("count", NewsUtil.DYNAMICINFO_COUNT);
//根据可见范围获取最新4条被祝福评论数据
List<HrDynamicInfoCommentVO> commentVOList = dynamicinfoReadOnlyDAO.ajaxCommentNews(paramsMap);
if (AssertUtil.isEmpty(commentVOList)) {
return Lists.newArrayList();
}
List<String> dynamicInfoIdList = commentVOList.parallelStream().map(HrDynamicInfoCommentVO::getDynamicinfoId).collect(Collectors.toList());
//根据dynamicInfoIds,orgId查找被祝福者列表
List<BlessAndEntryUserInfoVO> userList = dynamicinfoReadOnlyDAO.getUserListByDynamicinfoIds(dynamicInfoIdList, orgId);
if (AssertUtil.isEmpty(userList)) {
return Lists.newArrayList();
}
DynamicCommentUtil.setCommentTitle(commentVOList, userList);
return commentVOList;
}
@Override
public List<TbXyhDynamicinfoPO> getDynamicInfoToSendList(Map<String, Object> searchValue) throws Exception, BaseException {
return dynamicinfoReadOnlyDAO.getDynamicInfoToSendList(searchValue);
}
@Override
public List<BlessAndEntryUserInfoVO> getUserListByDynamicinfoIds(Collection<String> dynamicInfoIdList, String orgId) throws Exception, BaseException{
return dynamicinfoReadOnlyDAO.getUserListByDynamicinfoIds(dynamicInfoIdList, orgId);
}
@Override
public Pager getWaitSendSummary(Integer status, Pager pager) throws Exception, BaseException {
return dynamicinfoReadOnlyDAO.getWaitSendSummary(status, pager);
}
@Override
public void delBlessSummary(Integer status, String createTime) throws Exception, BaseException {
if(AssertUtil.isAllNotEmpty(status, createTime)){
dynamicinfoDAO.delBlessSummary(status, createTime);
}
}
@Override
public Pager getPageDynamicInfoCommentList(TbXyhDynamicinfoPO po, Pager pager) throws Exception, BaseException {
if(AssertUtil.isEmpty(po)){
return new Pager();
}
pager = dynamicinfoDAO.getPageDynamicInfoCommentList(po.getDynamicInfoId(), pager);
if (pager != null && pager.getTotalRows() > 0) {
List<DynamicInfoCommentVO> list = (List<DynamicInfoCommentVO>) pager.getPageData();
Iterator<DynamicInfoCommentVO> iterator = list.iterator();
while (iterator.hasNext()){
if ("1".equals(iterator.next().getCommentStatus())) {
iterator.remove();
}
}
}
return pager;
}
@Override
public void batchAddBlessSummary(List<TbHrBlessSummaryPO> blessSummaryPOList) throws Exception, BaseException {
if(!AssertUtil.isEmpty(blessSummaryPOList)){
dynamicinfoDAO.execBatchInsert(blessSummaryPOList);
}
}
@Override
public void batchUpdateBlessSummary(List<TbHrBlessSummaryPO> blessSummaryPOList) throws Exception, BaseException {
if (!AssertUtil.isEmpty(blessSummaryPOList)) {
dynamicinfoDAO.execBatchUpdate(blessSummaryPOList);
}
}
// @Override
// public void insertPOList(List<TbXyhDynamicinfoPO> list) throws Exception, BaseException {
// dynamicinfoDAO.execBatchInsert(list);
// }
/**
* 获取关注某种动态类型的用户id
* @param params
* @throws Exception
* @throws BaseException
* @@author chenjifeng
* @Date 2018/8/10
*/
@Override
public List<TbXyhDynamictypeFollowPO> getDynamictypeFollow(Map<String, Object> params)throws Exception, BaseException{
return dynamicinfoDAO.getDynamictypeFollow(params);
}
/**
* 通过用户id获取是否关注某种动态类型
* @param userId
* @throws Exception
* @throws BaseException
* @@author chenjifeng
* @Date 2018/8/10
*/
@Override
public List<TbXyhDynamictypeFollowextPO> getDynamicFollowbyUserId(String userId)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicFollowbyUserId(userId);
}
/**
* 通过用户id获取是否关注某种动态类型
* @param userId
* @throws Exception
* @throws BaseException
* @@author chenjifeng
* @Date 2018/8/10
*/
@Override
public String getDynamicFollowbyUserIdandTypeId(String userId,String typeId)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicFollowbyUserIdandTypeId(userId,typeId);
}
@Override
public void insertDynamicFollow(TbXyhDynamictypeFollowPO dynamictypeFollow)throws Exception, BaseException{
insertPO(dynamictypeFollow,true);
}
@Override
public long[] updateDynamicFollow(Map<String, Object> paramMap)throws Exception, BaseException{
return dynamicinfoDAO.updateDynamicFollow(paramMap);
}
/**
* 通过用户id获取所有动态类型及动态详情、是否关注、已阅数
* @param userId
* @throws Exception
* @throws BaseException
* @@author chenruishan
* @Date 2018/8/10
*/
@Override
public List<DynamicInfoTypeVO> getDynamicTypebyUserid(String userId,String belongAgent)throws Exception, BaseException
{
return dynamicinfoDAO.getDynamicTypebyUserid(userId,belongAgent);
}
/**
* 获取所有类型下新闻总数
* @param belongAgent
* @throws Exception
* @throws BaseException
* @@author chenjifeng
* @Date 2018/8/10
*/
@Override
public List<DynamicInfoTypeReadVO> getTypeSumRead(String belongAgent)throws Exception, BaseException{
return dynamicinfoDAO.getTypeSumRead(belongAgent);
}
/**
* 获取新闻首页轮播图
* @throws Exception
* @throws BaseException
* @@author chenjifeng
* @Date 2018/8/10
*/
@Override
public List<DynamicCoverVO> getDynamicCover()throws Exception, BaseException{
return dynamicinfoDAO.getDynamicCover();
}
/**
* 通过标题获取新闻列表
* @throws Exception
* @throws BaseException
* @@author chenjifeng
* @Date 2018/8/10
*/
@Override
public List<DynamicListVO> getDynamicbyTitle(String title)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicbyTitle(title);
}
/**
* 查询新闻详情by id
* @throws Exception
* @throws BaseException
* @@author chenjifeng
* @Date 2018/8/10
*/
@Override
public DynamicListVO getDynamicbyId(String id)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicbyId(id);
}
/**
* 插入收藏
* @param tbXyhDynamicCollectPO
* @throws Exception
* @throws BaseException
*/
@Override
public void insertDynamicCollect(TbXyhDynamicCollectPO tbXyhDynamicCollectPO)throws Exception, BaseException{
insertPO(tbXyhDynamicCollectPO,true);
}
/**
* 查询某人收藏的新闻
* @throws Exception
* @throws BaseException
*/
@Override
public Pager getDynamicCollectPager(String userid,String DYNAMIC_ID,Pager pager)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicCollectPager(userid,DYNAMIC_ID,pager);
}
@Override
public List<TbXyhDynamicCollectPO> getDynamicCollectbyUserId (String userid,String DYNAMIC_ID)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicCollectbyUserId(userid,DYNAMIC_ID);
}
/**
* 通过新闻类型id 获取新闻列表
* @param typeid
* @return
* @throws Exception
* @throws BaseException
*/
@Override
public Pager getDynamicPagerbyTypeId (String typeid,Pager pager,String userid,List<String> userMd5TgTp)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicPagerbyTypeId ( typeid, pager,userid,userMd5TgTp );
}
/**
*获取新闻列表
* @param userid
* @return
* @throws Exception
* @throws BaseException
*/
@Override
public Pager getDynamicbyPager (String userid,String typeid,String title,Pager pager ,List<String> userMd5TgTp)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicbyPager ( userid, typeid, title, pager,userMd5TgTp);
}
/**
*获取新闻类型详情及关注数
* @param typeid
* @return
* @throws Exception
* @throws BaseException
*/
@Override
public List<DynamicTypeVO> getDynamicType(String typeid)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicType(typeid);
}
/**
*获取新闻类型详情及关注数
* @param userid
* @return
* @throws Exception
* @throws BaseException
*/
@Override
public List<DynamicTypeFollowVO> getDynamicTypeByUserId(String userid)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicTypeByUserId(userid);
}
@Override
public void CancelCollection(String userId,String dynamicid)throws Exception, BaseException{
dynamicinfoDAO.CancelCollection(userId,dynamicid);
}
@Override
public List<DynamicVO> getDynamicTypeListByUserId(String userid)throws Exception, BaseException{
return dynamicinfoDAO.getDynamicTypeListByUserId(userid);
}
}