use of com.bc.pmpheep.back.po.MaterialContact in project pmph by BCSquad.
the class MaterialExtraServiceImpl method noticePublished.
@Override
public Integer noticePublished(Long materialId, List<Long> orgIds, String sessionId) throws CheckedServiceException, IOException {
if (CollectionUtil.isEmpty(orgIds)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "机构为空");
}
// 防止网络延迟重复提交
Set<Long> newOrgIdSet = new HashSet<>();
newOrgIdSet.addAll(orgIds);
List<Long> listOrgIds = new ArrayList<Long>(newOrgIdSet.size());
listOrgIds.addAll(newOrgIdSet);
// 获取当前用户
PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
if (ObjectUtil.isNull(pmphUser)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
}
Integer count = 0;
List<MaterialOrg> materialOrgList = new ArrayList<MaterialOrg>(listOrgIds.size());
// 根据教材ID查询教材-机构关联表
List<Long> OrgIds = materialOrgService.getListMaterialOrgByMaterialId(materialId);
if (CollectionUtil.isEmpty(OrgIds)) {
// 为空,初次发布
for (Long orgId : listOrgIds) {
materialOrgList.add(new MaterialOrg(materialId, orgId));
}
count = materialOrgService.addMaterialOrgs(materialOrgList);
if (count > 0) {
systemMessageService.materialSend(materialId, listOrgIds, pmphUser, false);
/*以下向主任和项目编辑发送微信推送*/
// 企业微信推送对象的微信id集合
Set<String> touserOpenidSet = new HashSet<String>();
List<Long> useridList = new ArrayList<Long>();
String touser = "";
Set<String> touserIdSet = new HashSet<String>();
String contactUserNamesStr = "";
String projectEditorNamesStr = "";
List<MaterialContact> materialContactList = materialContactService.listMaterialContactByMaterialId(materialId);
List<MaterialProjectEditorVO> materialProjectEditorVOList = materialProjectEditorService.listMaterialProjectEditors(materialId);
Material material = materialService.getMaterialById(materialId);
// 获取主任
PmphUser director = pmphUserService.get(material.getDirector());
// 主任加入企业微信推送对象集合
touserOpenidSet.add(director.getOpenid());
useridList.add(director.getId());
for (MaterialProjectEditorVO materialProjectEditorVO : materialProjectEditorVOList) {
projectEditorNamesStr += materialProjectEditorVO.getRealname() + ",";
PmphUser projectEditorUser = pmphUserService.get(materialProjectEditorVO.getEditorId());
// 项目编辑加入企业微信推送对象集合
touserOpenidSet.add(projectEditorUser.getOpenid());
useridList.add(projectEditorUser.getId());
}
for (MaterialContact materialContact : materialContactList) {
contactUserNamesStr += materialContact.getContactUserName() + ",";
}
projectEditorNamesStr = projectEditorNamesStr.substring(0, projectEditorNamesStr.lastIndexOf(",") > 0 ? projectEditorNamesStr.lastIndexOf(",") : projectEditorNamesStr.length());
contactUserNamesStr = contactUserNamesStr.substring(0, contactUserNamesStr.lastIndexOf(",") > 0 ? contactUserNamesStr.lastIndexOf(",") : contactUserNamesStr.length());
String msg1 = director.getRealname() + "已被选为“" + material.getMaterialName() + "”的主任。";
String msg2 = projectEditorNamesStr + "已被选为“" + material.getMaterialName() + "”的项目编辑。";
String msg3 = contactUserNamesStr + "已被选为“" + material.getMaterialName() + "”的联系人。";
touserOpenidSet.remove(null);
touser = touserOpenidSet.toString();
if (touserOpenidSet.size() > 0) {
wxqyUserService.sendTextMessage("0", "0", touser, "", "", "text", msg1, (short) 0, "");
wxqyUserService.sendTextMessage("0", "0", touser, "", "", "text", msg2, (short) 0, "");
wxqyUserService.sendTextMessage("0", "0", touser, "", "", "text", msg3, (short) 0, "");
}
wxSendMessageService.batchInsertWxMessage(msg1, 0, useridList, "0", "0", "");
wxSendMessageService.batchInsertWxMessage(msg2, 0, useridList, "0", "0", "");
wxSendMessageService.batchInsertWxMessage(msg3, 0, useridList, "0", "0", "");
}
} else {
// 不为空
// 新选中的机构
List<Long> newOrgIds = new ArrayList<Long>();
for (Long orgId : listOrgIds) {
if (!OrgIds.contains(orgId)) {
newOrgIds.add(orgId);
materialOrgList.add(new MaterialOrg(materialId, orgId));
}
}
List<Long> i1 = new ArrayList<>();
// 当前提交
i1.addAll(listOrgIds);
List<Long> i2 = new ArrayList<>();
// 以保存
i2.addAll(OrgIds);
List<Long> i3 = new ArrayList<>();
for (Long i : i2) {
if (!i1.contains(i)) {
i3.add(i);
}
}
if (CollectionUtil.isEmpty(materialOrgList)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA, CheckedExceptionResult.ILLEGAL_PARAM, "当前选中的学校已收到消息,无需要再次发送");
}
if (CollectionUtil.isNotEmpty(materialOrgList)) {
count = materialOrgService.addMaterialOrgs(materialOrgList);
if (count > 0) {
systemMessageService.materialSend(materialId, newOrgIds, pmphUser, false);
}
}
}
CmsContent cmsContent = cmsContentService.getCmsContentByMaterialId(materialId);
if (ObjectUtil.notNull(cmsContent)) {
// throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL_EXTRA,
// CheckedExceptionResult.NULL_PARAM, "没有找到对应的教材通知信息");
cmsContentService.updateCmsContent(new CmsContent(cmsContent.getId(), true, false, Const.CMS_AUTHOR_STATUS_2, // authUserId
0L, // 为0代表系统审核
DateUtil.formatTimeStamp("yyyy-MM-dd HH:mm:ss", DateUtil.getCurrentTime())));
}
count = materialService.updateMaterial(new Material(materialId, true), sessionId);
return count;
}
use of com.bc.pmpheep.back.po.MaterialContact in project pmph by BCSquad.
the class MigrationStageFour method transferMaterialContact.
protected void transferMaterialContact() {
String sql = "select " + "a.linkerid linkerid, " + "b.new_pk materid, " + "c.new_pk userid, " + "c.username username, " + "a.linkphone linkphone, " + "a.email email, " + "a.orderno orderno " + "from teach_material_linker a " + "LEFT JOIN teach_material b on b.materid = a.materid " + "LEFT JOIN sys_user c on c.userid = a.userid " + "where 1=1 ";
// 获取到所有数据表
String tableName = "teach_material_linker";
// 增加new_pk字段
JdbcHelper.addColumn(tableName);
List<Map<String, Object>> materialContactList = JdbcHelper.getJdbcTemplate().queryForList(sql);
List<Map<String, Object>> excel = new LinkedList<>();
Map<String, Object> result = new LinkedHashMap<>();
int count = 0;
int correctCount = 0;
int[] state = { 0, 0, 0, 0, 0, 0 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
// 模块名称
excptionList.add(new Object[] { "教材联系人" });
// 模块标题
excptionList.add(new Object[] { "所属教材名称", "问题", "原因分析", "处理方式" });
int excptionListOldSize = excptionList.size();
for (Map<String, Object> object : materialContactList) {
String linkId = (String) object.get("linkerid");
StringBuilder exception = new StringBuilder();
Long materid = (Long) object.get("materid");
String matername = (materid == null ? "" : materialService.getMaterialNameById(materid));
if (ObjectUtil.isNull(materid)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("教材id为空。"));
excel.add(object);
excptionList.add(new Object[] { matername, "找不到对应的教材", "新建的教材被删除", "不导入该条数据" });
if (state[0] == 0) {
reason.append("找不到教材的唯一标识。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
Long userid = (Long) object.get("userid");
if (ObjectUtil.isNull(userid)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("联系人id为空。"));
excel.add(object);
excptionList.add(new Object[] { matername, "找不到对应的联系人", " ", "不导入该条数据" });
if (state[1] == 0) {
reason.append("找不到教材的联系人的唯一标识。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
}
String username = (String) object.get("username");
if (StringUtil.isEmpty(username)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("联系人姓名为空。"));
excel.add(object);
excptionList.add(new Object[] { matername, "联系人姓名为空", "用户没有填写姓名", "不导入该条数据" });
if (state[2] == 0) {
reason.append("找不到教材的联系人姓名。");
dealWith.append("放弃迁移。");
state[2] = 1;
}
continue;
}
String linkphone = (String) object.get("linkphone");
if (StringUtil.isEmpty(linkphone)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("联系人电话为空。"));
excel.add(object);
excptionList.add(new Object[] { matername, "联系人电话为空", "源数据没有填写电话", "不导入该条数据" });
if (state[3] == 0) {
reason.append("找不到联系人的电话。");
dealWith.append("放弃迁移。");
state[3] = 1;
}
continue;
}
String email = (String) object.get("email");
if (StringUtil.isEmpty(email)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("联系人邮箱为空。"));
excel.add(object);
excptionList.add(new Object[] { matername, "联系人邮箱为空", "源数据没有填写邮箱", "不导入该条数据" });
if (state[4] == 0) {
reason.append("找不到联系人的邮箱。");
dealWith.append("放弃迁移。");
state[4] = 1;
}
continue;
}
Integer orderno = null;
orderno = (Integer) object.get("orderno");
if (ObjectUtil.notNull(orderno) && orderno < 0) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("联系人排序不符合规范,默认999。"));
orderno = 999;
excel.add(object);
if (state[5] == 0) {
reason.append("联系人排序码为负数。");
dealWith.append("设为默认值迁入数据库。");
state[5] = 1;
}
}
MaterialContact materialContact = new MaterialContact();
materialContact.setMaterialId(materid);
materialContact.setContactUserId(userid);
materialContact.setContactUserName(username);
materialContact.setContactPhone(linkphone);
materialContact.setContactEmail(email);
materialContact.setSort(orderno);
materialContact = materialContactService.addMaterialContact(materialContact);
count++;
long pk = materialContact.getId();
if (ObjectUtil.notNull(pk)) {
// 更新旧表中new_pk字段
JdbcHelper.updateNewPrimaryKey(tableName, pk, "linkerid", linkId);
}
if (null == object.get("exception")) {
correctCount++;
}
}
// 没有错误数据
if (excptionList.size() == excptionListOldSize) {
excptionList.remove(excptionList.size() - 1);
excptionList.remove(excptionList.size() - 1);
} else {
// 插入一个空行
excptionList.add(new String[] { "" });
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "教材联系人表(一对多)", "material_contact");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != materialContactList.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "material_contact");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教材联系人表(一对多)");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, materialContactList.size());
result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, materialContactList.size() - count);
result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
SQLParameters.STATISTICS_RESULT.add(result);
}
logger.info("'{}'表迁移完成,异常条目数量:{}", tableName, excel.size());
logger.info("原数据库中共有{}条数据,迁移了{}条数据", materialContactList.size(), count);
// 记录信息
Map<String, Object> msg = new HashMap<String, Object>();
msg.put("result", "" + tableName + " 表迁移完成" + count + "/" + materialContactList.size());
SQLParameters.STATISTICS.add(msg);
}
use of com.bc.pmpheep.back.po.MaterialContact in project pmph by BCSquad.
the class MaterialContactServiceTest method testGetMaterialContactById.
@Test
@Rollback(Const.ISROLLBACK)
public void testGetMaterialContactById() {
materialContactService.addMaterialContact(materialContact);
MaterialContact materialContact = materialContactService.getMaterialContactById(this.materialContact.getId());
// 查询
Assert.assertNotNull("获取数据失败", materialContact);
materialContact = materialContactService.getMaterialContactById(222L);
}
use of com.bc.pmpheep.back.po.MaterialContact in project pmph by BCSquad.
the class MigrationStageFour method addMaterialCommunity.
protected void addMaterialCommunity() {
// 保存教材社区相关的信息
for (Material material : materials) {
MaterialExtra materialExtra = materialExtraService.getMaterialExtraByMaterialId(material.getId());
if (null == materialExtra) {
materialExtra = new MaterialExtra();
}
String detail = "<p>简介:驱蚊器</p>" + "<p><br/></p>" + "<p>邮寄地址:驱蚊器翁</p>" + "<p><br/></p>" + "<p>联 系 人:陈慧 (电话:18610032992,Emali:147258369@qq.com)</p>" + "<p><br/>/p>";
detail = detail + "<p>简介:" + null == materialExtra.getNotice() ? "" : materialExtra.getNotice() + "</p>";
detail = detail + "<p><br/></p><p>邮寄地址:" + material.getMailAddress() + "</p>";
List<MaterialContact> materialContacts = materialContactService.listMaterialContactByMaterialId(material.getId());
for (MaterialContact materialContact : materialContacts) {
detail = detail + "<p><br/></p><p>联 系 人:" + materialContact.getContactUserName() + " (电话:" + materialContact.getContactPhone() + ",Emali:" + materialContact.getContactEmail() + ")</p>";
}
Content content = new Content(detail);
content = contentService.add(content);
CmsContent cmsContent = new CmsContent();
cmsContent.setParentId(0L);
cmsContent.setPath("0");
cmsContent.setMid(content.getId());
cmsContent.setCategoryId(3L);
cmsContent.setTitle(material.getMaterialName());
cmsContent.setAuthorType(new Short("0"));
cmsContent.setAuthorId(material.getFounderId());
cmsContent.setIsPublished(material.getIsPublished());
cmsContent.setAuthStatus(material.getIsPublished() ? new Short("2") : new Short("0"));
cmsContent.setAuthDate(DateUtil.date2Str(material.getGmtUpdate() == null ? material.getGmtCreate() : material.getGmtUpdate()));
cmsContent.setAuthUserId(material.getFounderId());
cmsContent.setGmtCreate(material.getGmtCreate());
cmsContent.setGmtUpdate(material.getGmtUpdate() == null ? material.getGmtCreate() : material.getGmtUpdate());
cmsContent.setIsMaterialEntry(true);
cmsContent.setMaterialId(material.getId());
cmsContentService.addCmsContent(cmsContent);
}
}
use of com.bc.pmpheep.back.po.MaterialContact in project pmph by BCSquad.
the class MigrationStageTen method materialNotice.
public void materialNotice() {
List<Material> materials = materialService.getListMaterial("轮");
List<CmsCategory> categorys = cmsCategoryService.getCmsCategoryListByCategoryName("公告");
Long categoryId = categorys.get(0).getId();
final String html = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$f</span></strong>$d</p>";
final String htmlS1 = "<p><strong><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">$d</span></strong></p>";
final String htmlS2 = "<p style=\"box-sizing: border-box; margin-top: 0px; margin-bottom: 10px; padding: 0px;\">$d</p>";
for (Material material : materials) {
CmsContent cmsContent = new CmsContent();
cmsContent.setParentId(0L);
cmsContent.setCategoryId(categoryId);
cmsContent.setPath("0");
cmsContent.setTitle(material.getMaterialName());
cmsContent.setAuthorType((short) 0);
cmsContent.setMaterialId(material.getId());
/* 生成通知内容 */
StringBuilder sb = new StringBuilder();
String str = html.replace("$f", "截止日期:");
str = str.replace("$d", sdf.format(material.getDeadline()));
sb.append(str);
/* 获取教材联系人 */
List<MaterialContact> contacts = materialContactService.listMaterialContactByMaterialId(categoryId);
if (CollectionUtil.isNotEmpty(contacts)) {
str = htmlS1.replace("$f", "联系人:");
sb.append(str);
for (MaterialContact contact : contacts) {
/* 裴中惠 (电话:010-59787110 , Email:pzh@pmph.com) */
StringBuilder builder = new StringBuilder(contact.getContactUserName());
builder.append(" (电话:");
builder.append(contact.getContactPhone());
builder.append(" , Email:");
builder.append(contact.getContactEmail());
builder.append(")");
str = htmlS2.replace("$d", builder.toString());
sb.append(str);
}
}
str = html.replace("$f", "邮寄地址:");
str = str.replace("$d", material.getMailAddress());
sb.append(str);
/* 获取通知内容和备注 */
MaterialExtra extra = materialExtraService.getMaterialExtraByMaterialId(material.getId());
str = htmlS1.replace("$d", "简 介:");
sb.append(str);
if (null != extra) {
// str = htmlS2.replace("$d", extra.getNotice()) /* 存入MongoDB */
}
Content content = new Content(sb.toString());
content = contentService.add(content);
cmsContent.setMid(content.getId());
}
}
Aggregations