|
|
@@ -1,11 +1,41 @@
|
|
|
package com.xjrsoft.module.base.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
+import com.xjrsoft.common.utils.LocalDateTimeUtil;
|
|
|
+import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
+import com.xjrsoft.config.CommonPropertiesConfig;
|
|
|
+import com.xjrsoft.module.base.dto.AddBaseClassDynamicsDto;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
import com.xjrsoft.module.base.entity.BaseClassDynamics;
|
|
|
+import com.xjrsoft.module.base.entity.BaseClassDynamicsRelation;
|
|
|
import com.xjrsoft.module.base.mapper.BaseClassDynamicsMapper;
|
|
|
+import com.xjrsoft.module.base.mapper.BaseClassDynamicsRelationMapper;
|
|
|
import com.xjrsoft.module.base.service.IBaseClassDynamicsService;
|
|
|
+import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
+import com.xjrsoft.module.organization.dto.WeChatSendMessageDto;
|
|
|
+import com.xjrsoft.module.organization.entity.User;
|
|
|
+import com.xjrsoft.module.organization.entity.UserStudent;
|
|
|
+import com.xjrsoft.module.organization.service.IUserService;
|
|
|
+import com.xjrsoft.module.organization.service.IWeChatService;
|
|
|
+import com.xjrsoft.module.student.dto.BaseStudentUserPageDto;
|
|
|
+import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
+import com.xjrsoft.module.student.service.IBaseStudentService;
|
|
|
+import com.xjrsoft.module.student.vo.BaseStudentUserPageVo;
|
|
|
+import com.xjrsoft.module.workflow.entity.WorkflowFormRelation;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import me.zhyd.oauth.log.Log;
|
|
|
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @title: 班级动态表
|
|
|
@@ -16,4 +46,109 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class BaseClassDynamicsServiceImpl extends MPJBaseServiceImpl<BaseClassDynamicsMapper, BaseClassDynamics> implements IBaseClassDynamicsService {
|
|
|
+
|
|
|
+ private final IBaseStudentService studentService;
|
|
|
+ private final IUserService userService;
|
|
|
+ private final BaseClassDynamicsRelationMapper dynamicsRelationMapper;
|
|
|
+ private final CommonPropertiesConfig commonPropertiesConfig;
|
|
|
+ private final IWeChatService weChatService;
|
|
|
+ private final IBaseClassService classService;
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public Boolean add(AddBaseClassDynamicsDto dto) {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ BaseClassDynamics baseClassDynamics = BeanUtil.toBean(dto, BaseClassDynamics.class);
|
|
|
+ baseClassDynamics.setCreateDate(new Date());
|
|
|
+ this.save(baseClassDynamics);
|
|
|
+
|
|
|
+ BaseClass aClass = classService.getById(dto.getClassId());
|
|
|
+
|
|
|
+ List<Long> classIds = new ArrayList<>();
|
|
|
+ classIds.add(dto.getClassId());
|
|
|
+ List<BaseStudentUserPageVo> studentList = studentService.getStudentList(new BaseStudentUserPageDto() {{
|
|
|
+ setClassIds(classIds);
|
|
|
+ }});
|
|
|
+ for (BaseStudentUserPageVo studentUserPageVo : studentList) {
|
|
|
+ BaseClassDynamicsRelation dynamicsRelation = new BaseClassDynamicsRelation() {{
|
|
|
+ setBaseClassDynamicsId(baseClassDynamics.getId());
|
|
|
+ setUserId(Long.parseLong(studentUserPageVo.getId()));
|
|
|
+ setReadMark(0);
|
|
|
+ }};
|
|
|
+ dynamicsRelationMapper.insert(dynamicsRelation);
|
|
|
+
|
|
|
+ try {
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setUserId(studentUserPageVo.getOpenId());
|
|
|
+ weChatSendMessageDto.setTemplateId("qmpXORPM1Cocqn503Qa4On6BJhR92UZ00eod2-6IcGo");
|
|
|
+ weChatSendMessageDto.setUrl(StrUtil.format("{}pages/student/trends/detail?id={}", commonPropertiesConfig.getDomainApp(), baseClassDynamics.getId()));
|
|
|
+ weChatSendMessageDto.setMsgId(dynamicsRelation.getId().toString());
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject data1 = new JSONObject();
|
|
|
+ data1.put("value", baseClassDynamics.getTitle());
|
|
|
+ data.put("thing23", data1);
|
|
|
+
|
|
|
+ JSONObject data2 = new JSONObject();
|
|
|
+ data2.put("value", (aClass.getName() == null) ? "重庆铜梁职业教育中心" : aClass.getName());
|
|
|
+ data.put("thing29", data2);
|
|
|
+
|
|
|
+ JSONObject data3 = new JSONObject();
|
|
|
+ data3.put("value", LocalDateTimeUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ data.put("time17", data3);
|
|
|
+ weChatSendMessageDto.setContent(data);
|
|
|
+ weChatService.sendTemplateMessage(weChatSendMessageDto);
|
|
|
+ }catch (Exception e){
|
|
|
+ Log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<User> list = userService.list(
|
|
|
+ new MPJLambdaWrapper<User>()
|
|
|
+ .select(User::getId)
|
|
|
+ .select(User.class, x -> VoToColumnUtil.fieldsToColumns(User.class).contains(x.getProperty()))
|
|
|
+ .innerJoin(UserStudent.class, UserStudent::getUserId, User::getId)
|
|
|
+ .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getUserId, UserStudent::getStudentId)
|
|
|
+ .innerJoin(WorkflowFormRelation.class, WorkflowFormRelation::getFormKeyValue, UserStudent::getId)
|
|
|
+ .eq(BaseStudentSchoolRoll::getClassId, dto.getClassId())
|
|
|
+ .eq(WorkflowFormRelation::getCurrentState, HistoricProcessInstance.STATE_COMPLETED)
|
|
|
+ .isNotNull(User::getOpenId)
|
|
|
+ );
|
|
|
+
|
|
|
+ for (User user : list) {
|
|
|
+ BaseClassDynamicsRelation dynamicsRelation = new BaseClassDynamicsRelation() {{
|
|
|
+ setBaseClassDynamicsId(baseClassDynamics.getId());
|
|
|
+ setUserId(user.getId());
|
|
|
+ setReadMark(0);
|
|
|
+ }};
|
|
|
+ dynamicsRelationMapper.insert(dynamicsRelation);
|
|
|
+
|
|
|
+ try {
|
|
|
+ WeChatSendMessageDto weChatSendMessageDto = new WeChatSendMessageDto();
|
|
|
+ weChatSendMessageDto.setUserId(user.getOpenId());
|
|
|
+ weChatSendMessageDto.setTemplateId("qmpXORPM1Cocqn503Qa4On6BJhR92UZ00eod2-6IcGo");
|
|
|
+ weChatSendMessageDto.setUrl(StrUtil.format("{}pages/student/trends/detail?id={}", commonPropertiesConfig.getDomainApp(), baseClassDynamics.getId()));
|
|
|
+ weChatSendMessageDto.setMsgId(dynamicsRelation.getId().toString());
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+
|
|
|
+ JSONObject data1 = new JSONObject();
|
|
|
+ data1.put("value", baseClassDynamics.getTitle());
|
|
|
+ data.put("thing23", data1);
|
|
|
+
|
|
|
+ JSONObject data2 = new JSONObject();
|
|
|
+ data2.put("value", (aClass.getName() == null) ? "重庆铜梁职业教育中心" : aClass.getName());
|
|
|
+ data.put("thing29", data2);
|
|
|
+
|
|
|
+ JSONObject data3 = new JSONObject();
|
|
|
+ data3.put("value", LocalDateTimeUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
|
|
|
+ data.put("time17", data3);
|
|
|
+ weChatSendMessageDto.setContent(data);
|
|
|
+ weChatService.sendTemplateMessage(weChatSendMessageDto);
|
|
|
+ }catch (Exception e){
|
|
|
+ Log.error(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|