Commit 8c78ce46 authored by kongfm's avatar kongfm

微信公众号相关功能提交

parent 65eb87bd
...@@ -30,7 +30,6 @@ import org.typroject.tyboot.core.foundation.utils.Bean; ...@@ -30,7 +30,6 @@ import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -107,10 +106,10 @@ public class ControllerAop { ...@@ -107,10 +106,10 @@ public class ControllerAop {
CompanyBo company = new CompanyBo(); CompanyBo company = new CompanyBo();
DepartmentBo department = new DepartmentBo(); DepartmentBo department = new DepartmentBo();
RoleBo role = new RoleBo(); RoleBo role = new RoleBo();
CompanyModel companyM = user.getCompanys().get(0); CompanyModel companyM = user.getCompanys() != null ? user.getCompanys().get(0) : null ;
Bean.copyExistPropertis(companyM, company); Bean.copyExistPropertis(companyM, company);
Map<Long, List<DepartmentModel>> mapDepartments = user.getCompanyDepartments(); Map<Long, List<DepartmentModel>> mapDepartments = user.getCompanyDepartments();
DepartmentModel departmentM = mapDepartments.get(companyM.getSequenceNbr()).get(0); DepartmentModel departmentM = companyM != null ? mapDepartments.get(companyM.getSequenceNbr()).get(0) : null ;
Bean.copyExistPropertis(departmentM, department); Bean.copyExistPropertis(departmentM, department);
Map<Long, List<RoleModel>> roles = user.getOrgRoles(); Map<Long, List<RoleModel>> roles = user.getOrgRoles();
Long sequenceNbr; Long sequenceNbr;
...@@ -121,7 +120,7 @@ public class ControllerAop { ...@@ -121,7 +120,7 @@ public class ControllerAop {
} }
RoleModel roleM = null; RoleModel roleM = null;
if (sequenceNbr == null) { if (sequenceNbr == null) {
roleM = roles.get(companyM.getSequenceNbr()).get(0); roleM = companyM != null ?roles.get(companyM.getSequenceNbr()).get(0) : null;
} else { } else {
roleM = roles.get(sequenceNbr).get(0); roleM = roles.get(sequenceNbr).get(0);
} }
......
package com.yeejoin.amos.boot.module.tzs.api.dto; package com.yeejoin.amos.boot.module.tzs.api.dto;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto; import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
...@@ -75,4 +76,8 @@ public class DispatchTaskDto extends BaseDto { ...@@ -75,4 +76,8 @@ public class DispatchTaskDto extends BaseDto {
@ApiModelProperty(value = "警情类型code") @ApiModelProperty(value = "警情类型code")
private String alertCode; private String alertCode;
@ApiModelProperty(value = "救援完成时间")
private Date saveTime;
} }
package com.yeejoin.amos.boot.module.tzs.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Map;
/**
* 微信公众号模板dto
*/
@Data
@ApiModel(value="WechatMessageDto", description="微信公众号模板消息dto类")
public class WechatMessageDto {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "模板id")
private String templateId;
@ApiModelProperty(value = "跳转地址")
private String url;
@ApiModelProperty(value = "数据")
private Map<String, String> data;
}
package com.yeejoin.amos.boot.module.tzs.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* 微信公众号任务id 和经纬度接受dto类
*
* @author system_generator
* @date 2021-09-22
*/
@Data
@ApiModel(value="WechatTaskLatLonDto", description="微信公众号任务id 和经纬度接受dto类")
public class WechatTaskLatLonDto {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "任务id")
private Long taskId;
@ApiModelProperty(value = "经度")
private String longitude;
@ApiModelProperty(value = "纬度")
private String latitude;
}
...@@ -124,4 +124,11 @@ public class DispatchTask extends BaseEntity { ...@@ -124,4 +124,11 @@ public class DispatchTask extends BaseEntity {
@TableField("task_status") @TableField("task_status")
private String taskStatus; private String taskStatus;
/**
* 救援完成时间
*/
@TableField("save_time")
private Date saveTime;
} }
...@@ -51,3 +51,4 @@ public enum AlertStatusEnum { ...@@ -51,3 +51,4 @@ public enum AlertStatusEnum {
return null; return null;
} }
} }
...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.tzs.api.service; ...@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.tzs.api.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMessageDto;
/** /**
* 微信公众号服务类 * 微信公众号服务类
...@@ -26,4 +27,11 @@ public interface IWechatService { ...@@ -26,4 +27,11 @@ public interface IWechatService {
* @return * @return
*/ */
JSONObject getUserInfo(String openId); JSONObject getUserInfo(String openId);
/**
* 发送微信模板消息
* @param openId
* @return
*/
JSONObject sendWechatModelMessage(String openId, WechatMessageDto wechatMessageDto);
} }
...@@ -6,15 +6,21 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController; ...@@ -6,15 +6,21 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils; import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.AlertCalledFormDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatAccessDto; import com.yeejoin.amos.boot.module.tzs.api.dto.WechatAccessDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMessageDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMyTaskDto; import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMyTaskDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMyTaskListDto; import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMyTaskListDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatRelationDto; import com.yeejoin.amos.boot.module.tzs.api.dto.WechatRelationDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatTaskLatLonDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.AlertFormValue; import com.yeejoin.amos.boot.module.tzs.api.entity.AlertFormValue;
import com.yeejoin.amos.boot.module.tzs.api.entity.DispatchTask;
import com.yeejoin.amos.boot.module.tzs.api.entity.WechatRelation; import com.yeejoin.amos.boot.module.tzs.api.entity.WechatRelation;
import com.yeejoin.amos.boot.module.tzs.api.service.IDispatchTaskService; import com.yeejoin.amos.boot.module.tzs.api.service.IDispatchTaskService;
import com.yeejoin.amos.boot.module.tzs.api.service.IWechatService; import com.yeejoin.amos.boot.module.tzs.api.service.IWechatService;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.AlertCalledServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.AlertFormValueServiceImpl; import com.yeejoin.amos.boot.module.tzs.biz.service.impl.AlertFormValueServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.DispatchTaskServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.WechatRelationServiceImpl; import com.yeejoin.amos.boot.module.tzs.biz.service.impl.WechatRelationServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils; import com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils;
import com.yeejoin.amos.component.feign.model.FeignClientResult; import com.yeejoin.amos.component.feign.model.FeignClientResult;
...@@ -88,9 +94,13 @@ public class WechatController extends BaseController { ...@@ -88,9 +94,13 @@ public class WechatController extends BaseController {
IDispatchTaskService dispatchTaskService; IDispatchTaskService dispatchTaskService;
@Autowired @Autowired
private AlertFormValueServiceImpl iAlertFormValueService; AlertFormValueServiceImpl iAlertFormValueService;
@Autowired
DispatchTaskServiceImpl dispatchTaskServiceImpl;
@Autowired
AlertCalledServiceImpl iAlertCalledService;
/** /**
* 获取微信回调信息返回验证是否通过 * 获取微信回调信息返回验证是否通过
...@@ -334,15 +344,14 @@ public class WechatController extends BaseController { ...@@ -334,15 +344,14 @@ public class WechatController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/returnDistance") @PostMapping(value = "/returnDistance")
@ApiOperation(httpMethod = "POST", value = "根据任务id 经纬度 返回现在距离任务距离", notes = "根据任务id 经纬度 返回现在距离任务距离") @ApiOperation(httpMethod = "POST", value = "根据任务id 经纬度 返回现在距离任务距离", notes = "根据任务id 经纬度 返回现在距离任务距离")
public ResponseModel<String> returnDistance(@ApiParam(value = "任务id", required = true) @RequestParam(name = "taskId") Long taskId, public ResponseModel<String> returnDistance(@RequestBody WechatTaskLatLonDto dto ) {
@ApiParam(value = "经度", required = true) @RequestParam(name = "longitude") String longitude, if (ValidationUtil.isEmpty(dto)
@ApiParam(value = "纬度", required = true) @RequestParam(name = "latitude") String latitude) { || ValidationUtil.isEmpty(dto.getTaskId())
if (ValidationUtil.isEmpty(taskId) || ValidationUtil.isEmpty(dto.getLatitude())
|| ValidationUtil.isEmpty(longitude) || ValidationUtil.isEmpty(dto.getLongitude())){
|| ValidationUtil.isEmpty(latitude)){
throw new BadRequest("参数校验失败."); throw new BadRequest("参数校验失败.");
} }
String distance = dispatchTaskService.returnDistanceByTaskId(taskId,longitude,latitude); String distance = dispatchTaskService.returnDistanceByTaskId(dto.getTaskId(),dto.getLongitude(),dto.getLatitude());
return ResponseHelper.buildResponse(distance); return ResponseHelper.buildResponse(distance);
} }
...@@ -464,9 +473,9 @@ public class WechatController extends BaseController { ...@@ -464,9 +473,9 @@ public class WechatController extends BaseController {
* @return * @return
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/taskArrive") @GetMapping(value = "/taskArrive/{taskId}")
@ApiOperation(httpMethod = "POST", value = "点击到达触发事件", notes = "点击到达触发事件") @ApiOperation(httpMethod = "GET", value = "点击到达触发事件", notes = "点击到达触发事件")
public ResponseModel<WechatMyTaskDto> taskArrive(@RequestParam Long taskId) { public ResponseModel<WechatMyTaskDto> taskArrive(@PathVariable Long taskId) {
if (ValidationUtil.isEmpty(taskId)){ if (ValidationUtil.isEmpty(taskId)){
throw new BadRequest("参数校验失败."); throw new BadRequest("参数校验失败.");
} }
...@@ -580,9 +589,9 @@ public class WechatController extends BaseController { ...@@ -580,9 +589,9 @@ public class WechatController extends BaseController {
* @return * @return
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@PostMapping(value = "/saveFinish") @GetMapping(value = "/saveFinish/{taskId}")
@ApiOperation(httpMethod = "POST", value = "点击救援完成触发事件", notes = "点击救援完成触发事件") @ApiOperation(httpMethod = "GET", value = "点击救援完成触发事件", notes = "点击救援完成触发事件")
public ResponseModel<WechatMyTaskDto> saveFinish(@RequestParam Long taskId) { public ResponseModel<WechatMyTaskDto> saveFinish(@PathVariable Long taskId) {
if (ValidationUtil.isEmpty(taskId)){ if (ValidationUtil.isEmpty(taskId)){
throw new BadRequest("参数校验失败."); throw new BadRequest("参数校验失败.");
} }
...@@ -749,4 +758,35 @@ public class WechatController extends BaseController { ...@@ -749,4 +758,35 @@ public class WechatController extends BaseController {
} }
return ResponseHelper.buildResponse(urlString); return ResponseHelper.buildResponse(urlString);
} }
/**
* 测试模板消息
*
* @return
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/testDispatch/{taskId}")
@ApiOperation(httpMethod = "GET", value = "测试模板消息", notes = "测试模板消息")
public ResponseModel<JSONObject> testDispatch(@PathVariable Long taskId) {
DispatchTask task = dispatchTaskServiceImpl.getById(taskId);
String tel = task.getResponseUserTel();
tel = "15353367807";
// 获取openId
WechatRelation relation = wechatRelationServiceImpl.getOne(new LambdaQueryWrapper<WechatRelation>().eq(WechatRelation::getPhone,tel));
if(relation == null ) {
throw new BadRequest("该用户未在系统中注册,无法发送模板消息"); // 接口迁移到服务中时改成日志形式;
}
WechatMessageDto test = new WechatMessageDto();
Map<String, String> data = new HashMap<>();
data.put("dispatchTime", DateUtils.date2LongStr(task.getDispatchTime()));
AlertCalledFormDto dto = iAlertCalledService.selectAlertCalledByIdNoCache(task.getAlertId());
data.put("address",dto.getAlertCalledDto().getAddress());
test.setUrl("www.baidu.com");
test.setTemplateId("SLjmNJoCNLC3FBcYzWzR-u3el0kqXf8WMTmzw8dAQm4");
test.setData(data);
JSONObject result = wechatService.sendWechatModelMessage(relation.getOpenId(),test);
return ResponseHelper.buildResponse(result);
}
} }
...@@ -209,7 +209,7 @@ public class DispatchTaskServiceImpl extends BaseService<DispatchTaskDto,Dispatc ...@@ -209,7 +209,7 @@ public class DispatchTaskServiceImpl extends BaseService<DispatchTaskDto,Dispatc
set(DispatchPaper::getSaveOrgName,task.getResponseOrgName()). set(DispatchPaper::getSaveOrgName,task.getResponseOrgName()).
eq(DispatchPaper::getSequenceNbr,task.getPaperId())); eq(DispatchPaper::getSequenceNbr,task.getPaperId()));
// 如果存在救援过程表更新救援过程表中信息 // 如果存在救援过程表更新救援过程表中信息
if(task.getIsSaveTask()) { if(task.getIsSaveTask() != null && task.getIsSaveTask()) {
rescueProcessServiceImpl.update(new LambdaUpdateWrapper<RescueProcess>(). rescueProcessServiceImpl.update(new LambdaUpdateWrapper<RescueProcess>().
set(RescueProcess::getArriveTime,now). set(RescueProcess::getArriveTime,now).
set(RescueProcess::getArriveStatus,true). set(RescueProcess::getArriveStatus,true).
...@@ -243,6 +243,8 @@ public class DispatchTaskServiceImpl extends BaseService<DispatchTaskDto,Dispatc ...@@ -243,6 +243,8 @@ public class DispatchTaskServiceImpl extends BaseService<DispatchTaskDto,Dispatc
set(RescueProcess::getRescueFeedbackType,"主动反馈"). set(RescueProcess::getRescueFeedbackType,"主动反馈").
set(RescueProcess::getRescueFeedbackCode,"856"). set(RescueProcess::getRescueFeedbackCode,"856").
eq(RescueProcess::getAlertId,task.getAlertId())); eq(RescueProcess::getAlertId,task.getAlertId()));
task.setSaveTime(now);
this.updateById(task);
} }
// 更新到达日志 // 更新到达日志
repairConsultServiceImpl.saveRepairConsultByAlertIdType( task.getAlertId(),"JC",taskId,null); repairConsultServiceImpl.saveRepairConsultByAlertIdType( task.getAlertId(),"JC",taskId,null);
...@@ -263,12 +265,13 @@ public class DispatchTaskServiceImpl extends BaseService<DispatchTaskDto,Dispatc ...@@ -263,12 +265,13 @@ public class DispatchTaskServiceImpl extends BaseService<DispatchTaskDto,Dispatc
// 更新反馈信息 // 更新反馈信息
DispatchTask task = this.getById(wechatDispatchFeedbackDto.getTaskId()); DispatchTask task = this.getById(wechatDispatchFeedbackDto.getTaskId());
DispatchPaper dispatchPaper = dispatchPaperServiceImpl.getById(task.getPaperId()); DispatchPaper dispatchPaper = dispatchPaperServiceImpl.getById(task.getPaperId());
Date now = new Date();
// 反馈方式 // 反馈方式
dispatchPaper.setFeedbackCode("856"); dispatchPaper.setFeedbackCode("856");
dispatchPaper.setFeedbackType("主动反馈"); dispatchPaper.setFeedbackType("主动反馈");
// 反馈时间 // 反馈时间
dispatchPaper.setFeedbackFinishTime(new Date()); dispatchPaper.setFeedbackFinishTime(now);
dispatchPaper.setFeedbackTime(new Date()); dispatchPaper.setFeedbackTime(now);
// 反馈人信息 // 反馈人信息
dispatchPaper.setFeedbackUid(task.getResponseUserId() + ""); dispatchPaper.setFeedbackUid(task.getResponseUserId() + "");
dispatchPaper.setFeedbackUname(task.getResponseUserName()); dispatchPaper.setFeedbackUname(task.getResponseUserName());
......
package com.yeejoin.amos.boot.module.tzs.biz.service.impl; package com.yeejoin.amos.boot.module.tzs.biz.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey; import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.tzs.api.dto.WechatMessageDto;
import com.yeejoin.amos.boot.module.tzs.api.service.IWechatService; import com.yeejoin.amos.boot.module.tzs.api.service.IWechatService;
import com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils; import com.yeejoin.amos.boot.module.tzs.biz.utils.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -113,4 +115,35 @@ public class WechatServiceImpl implements IWechatService { ...@@ -113,4 +115,35 @@ public class WechatServiceImpl implements IWechatService {
} }
} }
@Override
public JSONObject sendWechatModelMessage(String openId, WechatMessageDto wechatMessageDto) {
String accessToken = this.getAccessToken();
String modelMessageUrl = wechatUrl + "/cgi-bin/message/template/send?access_token=" + accessToken;
JSONObject messageBody = new JSONObject();
messageBody.put("touser",openId);
messageBody.put("template_id",wechatMessageDto.getTemplateId());
if(wechatMessageDto.getUrl() != null) {
messageBody.put("url",wechatMessageDto.getUrl());
}
JSONObject data = new JSONObject();
Map<String, String> datas = wechatMessageDto.getData();
for(Map.Entry<String, String> temp : datas.entrySet()) {
JSONObject tempObj = new JSONObject();
tempObj.put("value",temp.getValue());
data.put(temp.getKey(),tempObj);
}
messageBody.put("data",data);
System.out.println(messageBody.toJSONString());
String responseStr = HttpUtils.doPost(modelMessageUrl, messageBody.toJSONString());
JSONObject response = null;
try {
response = JSONObject.parseObject(responseStr);
} catch (Exception e) {
throw new BadRequest("发送模板消息出错:" + e.getMessage());
}
return response;
}
} }
\ No newline at end of file
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