Commit 511ab673 authored by jichao's avatar jichao

推送记录

parent ed28b05c
package org.rcisoft.business.mainte.energyplan.controller;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.mainte.energyplan.service.BusPushRecordService;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* Created by JiChao on 2018/6/19.
*/
@RestController
@RequestMapping("buspushrecord")
public class BusPushRecordController {
@Autowired
private BusPushRecordService busPushRecordServiceImpl;
@ApiOperation(value="查询所有推送信息", notes="查询所有推送信息")
@RequestMapping(value = "/queryAll")
public Result queryAll(@RequestParam String proId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, busPushRecordServiceImpl.queryAll(proId));
}
// @ApiOperation(value="新增推送", notes="新增推送")
// @PostMapping(value = "/add")
// public Result add(BusPushRecord busPushRecord) {
// Integer result = busPushRecordServiceImpl.add(busPushRecord);
// return Result.builder(new PersistModel(result), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, result);
// }
}
package org.rcisoft.business.mainte.energyplan.dao;
import org.rcisoft.business.mainte.energyplan.entity.BusPushRecord;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;
/**
* Created by JiChao on 2018/6/19.
*/
@Repository
public interface BusPushRecordRepository extends Mapper<BusPushRecord> {
}
package org.rcisoft.business.mainte.energyplan.entity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;
/**
* Created by JiChao on 2018/6/19.
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "bus_push_record")
public class BusPushRecord {
@Id
private Integer id;
private String proId;
private Date tm;
private String content;
}
package org.rcisoft.business.mainte.energyplan.service;
import org.rcisoft.business.mainte.energyplan.entity.BusPushRecord;
import java.util.List;
/**
* Created by JiChao on 2018/6/19.
*/
public interface BusPushRecordService {
/**
* 查询所有
* @param proId
* @return
*/
List<BusPushRecord> queryAll(String proId);
/**
* 新增
* @param busPushRecord
* @return
*/
Integer add(BusPushRecord busPushRecord);
}
package org.rcisoft.business.mainte.energyplan.service.impl;
import org.rcisoft.business.mainte.energyplan.dao.BusPushRecordRepository;
import org.rcisoft.business.mainte.energyplan.entity.BusPushRecord;
import org.rcisoft.business.mainte.energyplan.service.BusPushRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
/**
* Created by JiChao on 2018/6/19.
*/
@Service
public class BusPushRecordServiceImpl implements BusPushRecordService {
@Autowired
private BusPushRecordRepository busPushRecordRepository;
@Override
public List<BusPushRecord> queryAll(String proId) {
Example example = new Example(BusPushRecord.class);
Example.Criteria criteria = example.createCriteria();
criteria.andEqualTo("proId", proId);
example.orderBy("TM DESC");
return busPushRecordRepository.selectByExample(example);
}
@Override
public Integer add(BusPushRecord busPushRecord) {
return busPushRecordRepository.insert(busPushRecord);
}
}
......@@ -85,5 +85,7 @@ public class BusProject{
private String online;
private Integer receiveData;
private String inspectIds;
}
......@@ -42,6 +42,13 @@ public interface BusProjectService {
*/
List<Map<String,Object>> findByParam(BusProject bus);
/**
* 根据项目id查询
* @param proId
* @return
*/
BusProject findByProId(String proId);
/**
* 分页查询
* @param busProject
......
......@@ -241,6 +241,13 @@ public class BusProjectServiceImpl implements BusProjectService {
return projectRepository.queryBusProjects(bus);
}
@Override
public BusProject findByProId(String proId) {
BusProject busProject = new BusProject();
busProject.setProId(proId);
return projectRepository.selectOne(busProject);
}
/**
* 分页查询 busProject
* @param busProject
......
......@@ -109,5 +109,10 @@ public interface UserService {
Map<String, Object> getUserByOpenId(@Param("openId") String openId);
/**
* 根据用户id查询用户
* @param ids
* @return
*/
List<SysUser> getUsersByIds(String ids);
}
......@@ -2,6 +2,7 @@ package org.rcisoft.business.system.user.service.impl;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.device.assets.entity.BusDevice;
import org.rcisoft.business.evaluate.team.dao.BusTeamRepository;
import org.rcisoft.business.manage.dao.SysUserProjectRepository;
......@@ -29,10 +30,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* @Author: GaoLiWei
......@@ -398,6 +396,20 @@ public class UserServiceImpl implements UserService {
return result;
}
@Override
public List<SysUser> getUsersByIds(String ids) {
if (StringUtils.isNotEmpty(ids)) {
String[] split = ids.split(",");
List<String> list = Arrays.asList(split);
Example example = new Example(SysUser.class);
Example.Criteria criteria = example.createCriteria();
criteria.andIn("userId", list);
return userRepository.selectByExample(example);
} else {
return null;
}
}
public List<Map<String, Object>> handleMenu(List<Map<String, Object>> menuList){
List<Map<String, Object>> result = new ArrayList<>();
for(Map<String, Object> tmap : menuList){
......
......@@ -7,6 +7,14 @@ import me.chanjar.weixin.mp.bean.result.WxMpUser;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
import org.apache.commons.lang3.StringUtils;
import org.rcisoft.business.mainte.energyplan.entity.BusPushRecord;
import org.rcisoft.business.mainte.energyplan.service.BusPushRecordService;
import org.rcisoft.business.manage.entity.BusProject;
import org.rcisoft.business.manage.service.BusProjectService;
import org.rcisoft.business.system.user.entity.SysUser;
import org.rcisoft.business.system.user.service.UserService;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
import org.rcisoft.core.result.ResultCode;
import org.rcisoft.wechat.service.WxPortalService;
......@@ -18,7 +26,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -36,6 +47,15 @@ public class WechatRedirectController {
@Autowired
private WxMpService wxService;
@Autowired
private BusProjectService busProjectServiceImpl;
@Autowired
private UserService userServiceImpl;
@Autowired
private BusPushRecordService busPushRecordServiceImpl;
@RequestMapping(value = {"/index"})
public String index(String code) {
......@@ -67,27 +87,62 @@ public class WechatRedirectController {
return null;
}
/**
* 推送消息接口
* @param proId 项目id
* @param message 推送的消息
* @return
*/
@PostMapping(value = {"/push"})
@ResponseBody
public Result push(String proId, String message) {
Date date = new Date();
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
BusPushRecord busPushRecord = new BusPushRecord(null, proId, date, message);
// 发送的结果
Integer result = 0;
// 查询项目名称和巡检人ids
BusProject busProject = busProjectServiceImpl.findByProId(proId);
// 名称
String proNm = busProject.getProNm();
// 巡检人ids
String inspectIds = busProject.getInspectIds();
// 根据ids查询巡检人的openId
List<SysUser> list = userServiceImpl.getUsersByIds(inspectIds);
if (list != null && list.size() > 0) {
for (SysUser sysUser : list) {
String openid = sysUser.getOpenid();
if (StringUtils.isNotEmpty(openid) && !StringUtils.equals("string", openid)) {
result += this.sendMessage(proNm, time, message, openid);
}
}
}
// 判断发送的信息数量,插入数据
if (result > 0)
busPushRecordServiceImpl.add(busPushRecord);
return Result.builder(new PersistModel(result), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, result);
}
/**
* 发送模版消息(此方法参数需要修改,需要替换几个参数在此处需要传入几个参数,但是openId是必须的)
* @param message
* @param openId
* @return
*/
@PostMapping(value = {"/sendMessage"})
@ResponseBody
public Result sendMessage(String message, String openId) {
Result result = new Result();
private Integer sendMessage(String proNm, String time, String message, String openId) {
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(openId)
.templateId("此处填写模版消息ID")
.url(" ")
.templateId("LwdzUKkiSezoITPvgV3bhW7ANnX7f965DBA4FdRkqIw")
// .url(" ")//详情连接
.build();
// 模版中有几个需要替换的参数templateMessage就添加几个WxMpTemplateData
templateMessage
.addData(new WxMpTemplateData("first", "替换对应first的内容", "#FF00FF"))
.addData(new WxMpTemplateData("remark", "替换对应remark的内容", "#FF00FF"));
.addData(new WxMpTemplateData("first", "工作内容", "#FF00FF"))
.addData(new WxMpTemplateData("keyword1", time, "#FF00FF"))
.addData(new WxMpTemplateData("keyword2", proNm, "#FF00FF"))
.addData(new WxMpTemplateData("keyword3", "调整设备参数", "#FF00FF"))
.addData(new WxMpTemplateData("remark", message, "#FF00FF"));
// 消息发送完之后返回的消息id,用于判断是否发送成功
String msgId;
try {
......@@ -100,11 +155,11 @@ public class WechatRedirectController {
}
// 判断msgId是否为空,来判断是否发送成功
if(StringUtils.isNotEmpty(msgId)) {
result.setCode(ResultCode.SUCCESS);
return 1;
} else {
result.setCode(ResultCode.FAIL);
return 0;
}
return result;
// return result;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.rcisoft.business.mainte.energyplan.dao.BusPushRecordRepository">
<resultMap id="BaseResultMap" type="org.rcisoft.business.mainte.energyplan.entity.BusPushRecord">
<id column="ID" jdbcType="INTEGER" property="id"/>
<result column="PRO_ID" jdbcType="VARCHAR" property="proId"/>
<result column="TM" jdbcType="TIMESTAMP" property="tm"/>
<result column="CONTENT" jdbcType="VARCHAR" property="content"/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
</mapper>
\ No newline at end of file
......@@ -23,6 +23,7 @@
<result column="TOPOLOGY" jdbcType="VARCHAR" property="topology"/>
<result column="SHUT_POWER" jdbcType="DECIMAL" property="shutPower"/>
<result column="RECEIVE_DATA" jdbcType="DECIMAL" property="receiveData"/>
<result column="INSPECT_IDS" jdbcType="VARCHAR" property="inspectIds"/>
</resultMap>
<!--<cache type="${corePackag!}.util.RedisCache"/>-->
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment