|
@@ -0,0 +1,250 @@
|
|
|
+package com.xxh.cloud.healthy.behavior.framework.modules.biz.service.impl;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.xxh.cloud.framework.common.exception.BusinessException;
|
|
|
+import com.xxh.cloud.framework.common.user.LoginUser;
|
|
|
+import com.xxh.cloud.framework.common.validator.ValidatorUtils;
|
|
|
+import com.xxh.cloud.healthy.behavior.client.api.constant.BehaviorSourceTypeConstant;
|
|
|
+import com.xxh.cloud.healthy.behavior.client.api.constant.PatientOperatedTypeEnum;
|
|
|
+import com.xxh.cloud.healthy.behavior.client.api.util.BehaviorSecureUtil;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.bean.entity.PatientBehaviorInfo;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.bean.service.PatientBehaviorInfoService;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.biz.bean.dto.PatientBehaviorAddDTO;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.biz.bean.dto.PatientBehaviorUploadDTO;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.biz.bean.vo.PatientBehaviorBaseVO;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.biz.bean.vo.PatientBehaviorVO;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.biz.helper.PatientBehaviorHelper;
|
|
|
+import com.xxh.cloud.healthy.behavior.framework.modules.biz.service.PatientBehaviorBizService;
|
|
|
+import com.xxh.cloud.healthy.serve.pushServe.client.api.PatientPushServeClientService;
|
|
|
+import com.xxh.cloud.healthy.serve.pushServe.client.api.bean.bo.PatientRemindBO;
|
|
|
+import com.xxh.cloud.healthy.serve.pushServe.client.api.bean.bo.PatientScheduleBO;
|
|
|
+import com.xxh.cloud.healthy.serve.pushServe.client.api.constant.PatientPushServeConstant;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PatientBehaviorBizServiceImpl implements PatientBehaviorBizService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatientBehaviorInfoService patientBehaviorInfoService;
|
|
|
+ @Autowired
|
|
|
+ private PatientPushServeClientService patientPushServeClientService;
|
|
|
+
|
|
|
+ // 感兴趣的浏览时长
|
|
|
+ @Value("${behavior.interestedTime:30}")
|
|
|
+ private String interestedTime;
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public PatientBehaviorBaseVO upload(PatientBehaviorUploadDTO params, LoginUser user) {
|
|
|
+ log.info("用户行为上报>>>>>>PatientBehaviorUploadDTO={}; LoginUser={}", JSON.toJSONString(params), JSON.toJSONString(user));
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+
|
|
|
+ // 根据媒体ID查询各种数据来源id及类型
|
|
|
+ String[] sourceData = BehaviorSecureUtil.decomposeSourceData(params.getSourceData());
|
|
|
+
|
|
|
+ PatientBehaviorBaseVO vo = new PatientBehaviorBaseVO();
|
|
|
+
|
|
|
+ PatientBehaviorAddDTO patientBehaviorAddDTO = new PatientBehaviorAddDTO();
|
|
|
+ patientBehaviorAddDTO.setId(params.getId());
|
|
|
+ patientBehaviorAddDTO.setOperatedType(params.getOperatedType());
|
|
|
+ patientBehaviorAddDTO.setOperatedDuration(params.getOperatedDuration());
|
|
|
+ patientBehaviorAddDTO.setContentType(params.getMediaType());
|
|
|
+ patientBehaviorAddDTO.setContentId(params.getMediaId());
|
|
|
+ patientBehaviorAddDTO.setCreator(user.getUserName());
|
|
|
+ patientBehaviorAddDTO.setIp(params.getIp());
|
|
|
+ patientBehaviorAddDTO.setUa(params.getUa());
|
|
|
+ patientBehaviorAddDTO.setOperatedContent(params.getOperatedContent());
|
|
|
+
|
|
|
+ patientBehaviorAddDTO.setSourceOneType(sourceData[0]);
|
|
|
+ patientBehaviorAddDTO.setSourceOneId(sourceData[1]);
|
|
|
+
|
|
|
+ if (BehaviorSourceTypeConstant.SourceOneTypeEnum.Schedule.getCode().equals(sourceData[0])) {
|
|
|
+ PatientScheduleBO patientScheduleBO = patientPushServeClientService.updatePatientScheduleStatus(sourceData[1], PatientPushServeConstant.ScheduleStatus.DONE.getCode()); // 查询并更新日程状态
|
|
|
+ if (null != patientScheduleBO) {
|
|
|
+ if (!patientScheduleBO.getUserId().equals(user.getId())) {
|
|
|
+ throw new BusinessException("没有权限");
|
|
|
+ }
|
|
|
+ patientBehaviorAddDTO.setPatientId(patientScheduleBO.getPatientId());
|
|
|
+ patientBehaviorAddDTO.setUserId(patientScheduleBO.getUserId());
|
|
|
+ patientBehaviorAddDTO.setSourceTwoType(BehaviorSourceTypeConstant.SourceTwoTypeEnum.PatientPushServe.getCode());
|
|
|
+ patientBehaviorAddDTO.setSourceTwoId(patientScheduleBO.getBizId());
|
|
|
+ patientBehaviorAddDTO.setSourceThreeType(BehaviorSourceTypeConstant.SourceThreeTypeEnum.PushServeConfig.getCode());
|
|
|
+ patientBehaviorAddDTO.setSourceThreeId(patientScheduleBO.getPatientPushServeBO().getPushServeId());
|
|
|
+ }
|
|
|
+ } else if (BehaviorSourceTypeConstant.SourceOneTypeEnum.Remind.getCode().equals(sourceData[0])) {
|
|
|
+ PatientRemindBO patientRemindBO = patientPushServeClientService.getPatientRemindBO(sourceData[1]);
|
|
|
+ if (null != patientRemindBO) {
|
|
|
+ if (!patientRemindBO.getUserId().equals(user.getId())) {
|
|
|
+ throw new BusinessException("没有权限");
|
|
|
+ }
|
|
|
+ patientBehaviorAddDTO.setPatientId(patientRemindBO.getPatientId());
|
|
|
+ patientBehaviorAddDTO.setUserId(patientRemindBO.getUserId());
|
|
|
+ patientBehaviorAddDTO.setSourceTwoType(BehaviorSourceTypeConstant.SourceTwoTypeEnum.PatientPushServe.getCode());
|
|
|
+ patientBehaviorAddDTO.setSourceTwoId(patientRemindBO.getBizId());
|
|
|
+ patientBehaviorAddDTO.setSourceThreeType(BehaviorSourceTypeConstant.SourceThreeTypeEnum.PushServeConfig.getCode());
|
|
|
+ patientBehaviorAddDTO.setSourceThreeId(patientRemindBO.getPatientPushServeBO().getPushServeId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BusinessException("不支持的上报");
|
|
|
+ }
|
|
|
+
|
|
|
+ PatientBehaviorVO patientBehaviorVO = this.add(patientBehaviorAddDTO);
|
|
|
+ if (null != patientBehaviorAddDTO) {
|
|
|
+ vo.setId(patientBehaviorVO.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public PatientBehaviorVO add(PatientBehaviorAddDTO params) {
|
|
|
+ ValidatorUtils.validateEntity(params);
|
|
|
+
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ // zs20231026 根据浏览时长判断是否感兴趣
|
|
|
+ if (PatientOperatedTypeEnum.Browse_Duration.getCode().equals(params.getOperatedType()) && params.getOperatedDuration() >= Integer.valueOf(interestedTime)) {
|
|
|
+ PatientBehaviorInfo entity = patientBehaviorInfoService.getOne(new QueryWrapper<PatientBehaviorInfo>()
|
|
|
+ .eq(StrUtil.isNotBlank(params.getPatientId()), "patient_id", params.getPatientId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getUserId()), "user_id", params.getUserId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getContentType()), "content_type", params.getContentType())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getContentId()), "content_id", params.getContentId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceOneType()), "source_one_type", params.getSourceOneType())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceOneId()), "source_one_id", params.getSourceOneId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceTwoType()), "source_two_type", params.getSourceTwoType())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceTwoId()), "source_two_id", params.getSourceTwoId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceThreeType()), "source_three_type", params.getSourceThreeType())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceThreeId()), "source_three_id", params.getSourceThreeId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceFourType()), "source_four_type", params.getSourceFourType())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceFourId()), "source_four_id", params.getSourceFourId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceFiveType()), "source_five_type", params.getSourceFiveType())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getSourceFiveId()), "source_five_id", params.getSourceFiveId())
|
|
|
+ .eq(StrUtil.isNotBlank(params.getOperatedType()), "operated_type", PatientOperatedTypeEnum.Interested.getCode())
|
|
|
+ );
|
|
|
+ if (null == entity) {
|
|
|
+ PatientBehaviorAddDTO patientBehaviorAddDTO = new PatientBehaviorAddDTO();
|
|
|
+ patientBehaviorAddDTO.setPatientId(params.getPatientId());
|
|
|
+ patientBehaviorAddDTO.setUserId(params.getUserId());
|
|
|
+ patientBehaviorAddDTO.setContentType(params.getContentType());
|
|
|
+ patientBehaviorAddDTO.setContentId(params.getContentId());
|
|
|
+ patientBehaviorAddDTO.setSourceOneType(params.getSourceOneType());
|
|
|
+ patientBehaviorAddDTO.setSourceOneId(params.getSourceOneId());
|
|
|
+ patientBehaviorAddDTO.setSourceTwoType(params.getSourceTwoType());
|
|
|
+ patientBehaviorAddDTO.setSourceTwoId(params.getSourceTwoId());
|
|
|
+ patientBehaviorAddDTO.setSourceThreeType(params.getSourceThreeType());
|
|
|
+ patientBehaviorAddDTO.setSourceThreeId(params.getSourceThreeId());
|
|
|
+ patientBehaviorAddDTO.setSourceFourType(params.getSourceFourType());
|
|
|
+ patientBehaviorAddDTO.setSourceFourId(params.getSourceFourId());
|
|
|
+ patientBehaviorAddDTO.setSourceFiveType(params.getSourceFiveType());
|
|
|
+ patientBehaviorAddDTO.setSourceFiveId(params.getSourceFiveId());
|
|
|
+ patientBehaviorAddDTO.setOperatedType(PatientOperatedTypeEnum.Interested.getCode());
|
|
|
+ patientBehaviorAddDTO.setCreator(params.getCreator());
|
|
|
+ patientBehaviorAddDTO.setIp(params.getIp());
|
|
|
+ patientBehaviorAddDTO.setUa(params.getUa());
|
|
|
+ this.add(patientBehaviorAddDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // zs20231026 在上报时间时,每次浏览都会上报多次浏览时长,所以第一次上报返回id,之后上报用id更新浏览时长,上报的浏览时长直接更新不做增量更新
|
|
|
+ // TODO 可以通过nginx配置,一直让某个请求在padding状态(一直保持http连接),之后如果离开页面则连接断开,这样可以用nginx判断连接了多长时间,从而间接得出浏览时长
|
|
|
+ if (StrUtil.isNotBlank(params.getId()) && PatientOperatedTypeEnum.Browse_Duration.getCode().equals(params.getOperatedType())) {
|
|
|
+ PatientBehaviorInfo entity = patientBehaviorInfoService.getById(params.getId());
|
|
|
+ if (null != entity && PatientOperatedTypeEnum.Browse_Duration.getCode().equals(entity.getOperatedType())) {
|
|
|
+ if (params.getOperatedDuration() > entity.getOperatedDuration()) {
|
|
|
+ entity.setOperatedDuration(params.getOperatedDuration());
|
|
|
+ entity.setOperatedEndDate(now);
|
|
|
+ patientBehaviorInfoService.updateById(entity);
|
|
|
+ }
|
|
|
+ return PatientBehaviorHelper.getPatientBehaviorVO(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PatientBehaviorInfo entity = new PatientBehaviorInfo();
|
|
|
+ entity.setId(PatientBehaviorHelper.getPatientBehaviorInfoId());
|
|
|
+ entity.setPatientId(params.getPatientId());
|
|
|
+ entity.setUserId(params.getUserId());
|
|
|
+ entity.setContentType(params.getContentType());
|
|
|
+ entity.setContentId(params.getContentId());
|
|
|
+ entity.setSourceOneType(params.getSourceOneType());
|
|
|
+ entity.setSourceOneId(params.getSourceOneId());
|
|
|
+ entity.setSourceTwoType(params.getSourceTwoType());
|
|
|
+ entity.setSourceTwoId(params.getSourceTwoId());
|
|
|
+ entity.setSourceThreeType(params.getSourceThreeType());
|
|
|
+ entity.setSourceThreeId(params.getSourceThreeId());
|
|
|
+ entity.setSourceFourType(params.getSourceFourType());
|
|
|
+ entity.setSourceFourId(params.getSourceFourId());
|
|
|
+ entity.setSourceFiveType(params.getSourceFiveType());
|
|
|
+ entity.setSourceFiveId(params.getSourceFiveId());
|
|
|
+ entity.setOperatedType(params.getOperatedType());
|
|
|
+ entity.setOperatedStartDate(now);
|
|
|
+ entity.setOperatedDuration(params.getOperatedDuration());
|
|
|
+
|
|
|
+ entity.setCreateDate(now);
|
|
|
+ entity.setCreator(params.getCreator());
|
|
|
+ entity.setIp(params.getIp());
|
|
|
+ entity.setUa(params.getUa());
|
|
|
+
|
|
|
+ entity.setOperatedContent(params.getOperatedContent());
|
|
|
+
|
|
|
+ patientBehaviorInfoService.save(entity);
|
|
|
+
|
|
|
+ return PatientBehaviorHelper.getPatientBehaviorVO(entity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void addBatch(List<PatientBehaviorAddDTO> params) {
|
|
|
+ List<PatientBehaviorInfo> list = new ArrayList<>();
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ params.forEach(i -> {
|
|
|
+ PatientBehaviorInfo entity = new PatientBehaviorInfo();
|
|
|
+ entity.setId(PatientBehaviorHelper.getPatientBehaviorInfoId());
|
|
|
+ entity.setPatientId(i.getPatientId());
|
|
|
+ entity.setUserId(i.getUserId());
|
|
|
+ entity.setContentType(i.getContentType());
|
|
|
+ entity.setContentId(i.getContentId());
|
|
|
+ entity.setSourceOneType(i.getSourceOneType());
|
|
|
+ entity.setSourceOneId(i.getSourceOneId());
|
|
|
+ entity.setSourceTwoType(i.getSourceTwoType());
|
|
|
+ entity.setSourceTwoId(i.getSourceTwoId());
|
|
|
+ entity.setSourceThreeType(i.getSourceThreeType());
|
|
|
+ entity.setSourceThreeId(i.getSourceThreeId());
|
|
|
+ entity.setSourceFourType(i.getSourceFourType());
|
|
|
+ entity.setSourceFourId(i.getSourceFourId());
|
|
|
+ entity.setSourceFiveType(i.getSourceFiveType());
|
|
|
+ entity.setSourceFiveId(i.getSourceFiveId());
|
|
|
+ entity.setOperatedType(i.getOperatedType());
|
|
|
+ entity.setOperatedDuration(i.getOperatedDuration());
|
|
|
+
|
|
|
+ entity.setOperatedStartDate(now);
|
|
|
+ entity.setCreateDate(now);
|
|
|
+
|
|
|
+ if (null != i.getCreateDate()) {
|
|
|
+ entity.setOperatedStartDate(i.getCreateDate());
|
|
|
+ entity.setCreateDate(i.getCreateDate());
|
|
|
+ }
|
|
|
+
|
|
|
+ entity.setCreator(i.getCreator());
|
|
|
+ entity.setIp(i.getIp());
|
|
|
+ entity.setUa(i.getUa());
|
|
|
+
|
|
|
+ entity.setOperatedContent(i.getOperatedContent());
|
|
|
+
|
|
|
+ list.add(entity);
|
|
|
+ });
|
|
|
+ patientBehaviorInfoService.saveBatch(list);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|