| | |
| | | package com.ycl.service.message.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.mail.javamail.JavaMailSenderImpl; |
| | | import org.springframework.mail.javamail.MimeMessageHelper; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | messageMapper.deleteById(savedMessage); |
| | | } |
| | | |
| | | ArrayList<Long> ids = new ArrayList<>(); |
| | | ArrayList<Message> ids = new ArrayList<>(); |
| | | message.setTargetFrom(umsAdminMapper.selectById(message.getCreateUser()).getUsername()); |
| | | if (message.getId() == null) { |
| | | for (String receive : message.getTargetTo().split(",")) { |
| | |
| | | sendMessage.setSendTime(new Date()); |
| | | sendMessage.setTargetTo(receive); |
| | | sendMessage.setSendTime(new Date()); |
| | | sendMessage.setPhoneNumber(umsAdminMapper.selectById(receive).getMobile()); |
| | | if (ChannelCode.INNER.equals(message.getChannelCode())){ |
| | | sendMessage.setPhoneNumber(message.getTargetTo()); |
| | | |
| | | if (ChannelCode.INNER.equals(message.getChannelCode())) { |
| | | sendMessage.setIsView(0); |
| | | } |
| | | this.save(sendMessage); |
| | | ids.add(sendMessage.getId()); |
| | | ids.add(sendMessage); |
| | | } |
| | | } |
| | | switch (message.getChannelCode()) { |
| | |
| | | |
| | | @SneakyThrows |
| | | @Transactional(rollbackFor = Exception.class) |
| | | void sendSMS(Message message, List<Long> mesIds) { |
| | | String[] ids = message.getTargetTo().split(","); |
| | | String[] mobiles = new String[ids.length]; |
| | | for (int i = 0; i < ids.length; i++) { |
| | | mobiles[i] = umsAdminMapper.selectById(ids[i]).getMobile(); |
| | | public void sendSMS(Message message, List<Message> messageList) { |
| | | List<String> mobiles = new ArrayList<>(); |
| | | List<Long> mesIds = new ArrayList<>(); |
| | | for (Message m : messageList) { |
| | | mobiles.add(m.getPhoneNumber()); |
| | | mesIds.add(m.getId()); |
| | | } |
| | | message.setPhoneNumber(StringUtils.join(mobiles, ",")); |
| | | Integer messageStatus = sendMessages(message); |
| | |
| | | ObjectMapper objectMapper = new ObjectMapper(); |
| | | |
| | | HttpEntity<String> stringHttpEntity = new HttpEntity<>(Base64Utils.encodeToString(objectMapper.writeValueAsBytes(mac)), httpHeaders); |
| | | |
| | | SendRes sendRes = objectMapper.readValue(restTemplate.postForEntity(url, stringHttpEntity, String.class).getBody(), SendRes.class); |
| | | ResponseEntity<String> response = restTemplate.postForEntity(url + "/sms/submit", sendReq, String.class); |
| | | SendRes sendRes = objectMapper.readValue(response.getBody(), SendRes.class); |
| | | if (sendRes.getRspcod().equals("success")) { |
| | | return 2; |
| | | } else { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Page<Message> queryMyMessage(Page<Message> page, Long userId) { |
| | | List<Message> list = list(); |
| | | ArrayList<Long> ids = new ArrayList<>(); |
| | | list.forEach(item -> { |
| | | String targetTo = item.getTargetTo(); |
| | | if (StringUtils.isNotBlank(targetTo)) { |
| | | String[] split = targetTo.split(","); |
| | | for (String s : split) { |
| | | if (userId.equals(Long.getLong(s))) { |
| | | ids.add(item.getId()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | if (CollUtil.isEmpty(ids)) { |
| | | return new Page<>(); |
| | | } |
| | | return baseMapper.selectPage(page, new QueryWrapper<Message>().lambda().in(Message::getId, ids)); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean deleteMessages(List<Long> ids) { |
| | | LambdaQueryWrapper<Message> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.in(Message::getId, ids).or().in(Message::getParentId, ids); |