| | |
| | | import me.zhengjie.modules.business.service.BusinessPlanService; |
| | | import me.zhengjie.modules.business.service.dto.BusinessPlanDto; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.quartz.service.OpaiDingTalkService; |
| | | import me.zhengjie.modules.quartz.service.impl.WeComServiceImpl; |
| | | import me.zhengjie.modules.system.domain.CustomerResources; |
| | | import me.zhengjie.modules.system.domain.CustomerResourcesUser; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.CustomerResourcesUserRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.modules.system.repository.CustomerResourcesRepository; |
| | | import me.zhengjie.modules.system.service.CustomerResourcesService; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | private final CustomerResourcesRepository customerResourcesRepository; |
| | | private final CustomerResourcesMapper customerResourcesMapper; |
| | | private final UserRepository userRepository; |
| | | private final OpaiDingTalkService opaiDingTalkService; |
| | | private final WeComServiceImpl weComService; |
| | | private final CustomerResourcesUserRepository customerResourcesUserRepository; |
| | | private final BusinessPlanService businessPlanService; |
| | | |
| | |
| | | public void create(CustomerResources resources) throws Exception { |
| | | // 提醒时间为空,状态为提醒说明是立即提醒,发送钉钉消息 |
| | | if(ObjectUtils.isEmpty(resources.getOpeningTime()) && resources.getRemind().equals(Constant.RESOURCES_TYPE_REMIND)){ |
| | | // 调用 |
| | | resources = setDingding(resources); |
| | | // 发送通知 |
| | | resources = sendNotice(resources); |
| | | } |
| | | // 保存 |
| | | customerResourcesRepository.save(resources); |
| | |
| | | customerResources.copy(resources); |
| | | // 提醒时间为空,状态为提醒说明是立即提醒,发送钉钉消息 |
| | | if(ObjectUtils.isEmpty(resources.getOpeningTime()) && resources.getRemind().equals(Constant.RESOURCES_TYPE_REMIND)){ |
| | | // 调用 |
| | | customerResources = setDingding(customerResources); |
| | | // 发送通知 |
| | | customerResources = sendNotice(customerResources); |
| | | }else if(resources.getRemind().equals(Constant.RESOURCES_TYPE_NOREMIND)){ |
| | | customerResources.setOpeningTime(null); |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 发送钉钉(公共) |
| | | * 向其他应用发送通知公共方法 |
| | | * |
| | | * @param resources |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public CustomerResources setDingding(CustomerResources resources) throws Exception { |
| | | public CustomerResources sendNotice(CustomerResources resources) { |
| | | // 获取当前时间 |
| | | SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String time = sf.format(new Date()); |
| | | resources.setOpeningTime(Timestamp.valueOf(time)); |
| | | // 获取存储用户钉钉号 |
| | | List<String> dingDingList = new ArrayList<>(); |
| | | // 获取存储用户企微ID |
| | | List<String> weComList = new ArrayList<>(); |
| | | if(resources.getRemindPeople().size() != 0){ |
| | | for(Long userId : resources.getRemindPeople()){ |
| | | // 查询用户 |
| | | User user = userRepository.findById(userId).orElseGet(User::new); |
| | | if(ObjectUtils.isNotEmpty(user.getDingding())){ |
| | | dingDingList.add(user.getDingding()); |
| | | if (StringUtils.isNotBlank(user.getWeComId())) { |
| | | weComList.add(user.getWeComId()); |
| | | } |
| | | } |
| | | } |
| | | // 发送内容至钉钉 |
| | | opaiDingTalkService.sendNotice(dingDingList, "客户资源管理提示", "### 客户资源管理提示 \n >" + |
| | | " \n 标题:" + resources.getTitle() + |
| | | " \n 分类: " + resources.getClassification() + |
| | | " \n 客户资源有变动,请登录PMS系统查看。", "card"); |
| | | // 发送内容至企微 |
| | | weComService.sendNotice(weComList, "客户资源管理提示", String.format("<div class=\"normal\">标题:%s</div>" + |
| | | "<div class=\"normal\">分类:%s</div>" + |
| | | "<div class=\"highlight\">客户资源有变动,请登录PMS系统查看。</div>", |
| | | resources.getTitle(), |
| | | resources.getClassification()), Constant.WECOM_MESSAGE_TYPE_TEXTCARD); |
| | | return resources; |
| | | } |
| | | |