Commit 1008db2d authored by 付培阳's avatar 付培阳

消防专家接口

parent 80c0258a
......@@ -102,4 +102,7 @@ public class FireExpertsDto extends BaseDto {
@ApiModelProperty(value = "出生日期")
private Date birthdayTime;
@ApiModelProperty(value = "年龄")
private Integer age;
}
......@@ -13,10 +13,8 @@ import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import com.yeejoin.amos.boot.module.common.biz.service.impl.FireExpertsServiceImpl;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
......@@ -89,7 +87,9 @@ public class FireExpertsController extends BaseController {
@DeleteMapping(value = "/{sequenceNbr}")
@ApiOperation(httpMethod = "DELETE", value = "根据sequenceNbr删除", notes = "根据sequenceNbr删除")
public ResponseModel<Boolean> deleteBySequenceNbr(@PathVariable(value = "sequenceNbr") Long sequenceNbr) {
return ResponseHelper.buildResponse(fireExpertsServiceImpl.removeById(sequenceNbr));
FireExperts fireExperts = fireExpertsServiceImpl.getById(sequenceNbr);
fireExperts.setIsDelete(true);
return ResponseHelper.buildResponse(fireExpertsServiceImpl.updateById(fireExperts));
}
/**
......@@ -101,8 +101,12 @@ public class FireExpertsController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/{sequenceNbr}")
@ApiOperation(httpMethod = "GET", value = "根据sequenceNbr查询单个", notes = "根据sequenceNbr查询单个")
public ResponseModel<FireExpertsDto> selectOne(@PathVariable Long sequenceNbr) {
return ResponseHelper.buildResponse(fireExpertsServiceImpl.queryBySeq(sequenceNbr));
public ResponseModel<FireExpertsDto> selectOne(@PathVariable Long sequenceNbr) throws Exception {
FireExpertsDto fireExpertsDto = fireExpertsServiceImpl.queryBySeq(sequenceNbr);
Date birthdayTime = fireExpertsDto.getBirthdayTime();
int age = BeanDtoVoUtils.getAge(birthdayTime);
fireExpertsDto.setAge(age);
return ResponseHelper.buildResponse(fireExpertsDto);
}
/**
......@@ -155,7 +159,7 @@ public class FireExpertsController extends BaseController {
IPage<FireExperts> page;
pageBean = new Page<>(current, size);
page = fireExpertsServiceImpl.page(pageBean, fireExpertsQueryWrapper);
IPage<FireExpertsDto> fireExpertsDtoIPage = BeanDtoVoUtils.iPageDtoStream(page, FireExpertsDto.class);
IPage<FireExpertsDto> fireExpertsDtoIPage = BeanDtoVoUtils.iPageDtoStreamFireExperts(page);
return ResponseHelper.buildResponse(fireExpertsDtoIPage);
}
......@@ -168,7 +172,13 @@ public class FireExpertsController extends BaseController {
@ApiOperation(httpMethod = "GET", value = "列表全部数据查询", notes = "列表全部数据查询")
@GetMapping(value = "/list")
public ResponseModel<List<FireExpertsDto>> selectForList() {
return ResponseHelper.buildResponse(fireExpertsServiceImpl.queryForFireExpertsList());
List<FireExpertsDto> fireExpertsDtoList = fireExpertsServiceImpl.queryForFireExpertsList();
fireExpertsDtoList.stream().map(item -> {
item.setAge(BeanDtoVoUtils.getAge(item.getBirthdayTime()));
return item;
}).collect(Collectors.toList());
return ResponseHelper.buildResponse(fireExpertsDtoList);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
......@@ -189,4 +199,6 @@ public class FireExpertsController extends BaseController {
// 创建挂在主节点
return ResponseHelper.buildResponse(menuList);
}
}
package com.yeejoin.amos.boot.module.common.biz.utils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yeejoin.amos.boot.module.common.api.dto.FireExpertsDto;
import com.yeejoin.amos.boot.module.common.api.entity.FireExperts;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import java.util.Calendar;
import java.util.Date;
/**
* @title: 实体类 Dto,Vo,entity 转换工具类
* @Author fpy
......@@ -43,7 +49,34 @@ public class BeanDtoVoUtils {
}
/**
* IPage<Entity> 分页对象转 IPage<Dto>
* Dot ,Vo ,Entity 相互转换
*
* @param source 原数据
* @return 转换返回值
*/
public static FireExpertsDto convertFireExperts(FireExperts source) {
// 判断source是否为空
if (source == null) {
return null;
}
try {
// 创建新的对象实例
FireExpertsDto target = FireExpertsDto.class.newInstance();
// 把原对象数据拷贝到新对象
BeanUtils.copyProperties(source, target);
// 计算年龄
int age = getAge(source.getBirthdayTime());
target.setAge(age);
// 返回新对象
return target;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* IPage<Entity> 分页对象转 Page<Dto>
*
* @param page 原分页对象
* @param v 目标vo类
......@@ -51,7 +84,7 @@ public class BeanDtoVoUtils {
* @param <V> 泛型类
* @return 转换后的分页对象
*/
public static <E, V> IPage<V> iPageVoStream(IPage<E> page, Class<V> v) {
public static <E, V> IPage<V> iPageDtoStream(IPage<E> page, Class<V> v) {
return page.convert(item -> {
try {
return convert(item, v);
......@@ -65,19 +98,44 @@ public class BeanDtoVoUtils {
* IPage<Entity> 分页对象转 Page<Dto>
*
* @param page 原分页对象
* @param v 目标vo类
* @param <E> 泛型类
* @param <V> 泛型类
* @return 转换后的分页对象
*/
public static <E, V> IPage<V> iPageDtoStream(IPage<E> page, Class<V> v) {
public static IPage<FireExpertsDto> iPageDtoStreamFireExperts(IPage<FireExperts> page) {
return page.convert(item -> {
try {
return convert(item, v);
return convertFireExperts(item);
} catch (Exception e) {
return null;
}
});
}
//由出生日期获得年龄
public static int getAge(Date birthDay) {
Calendar cal = Calendar.getInstance();
if (cal.before(birthDay)) {
throw new IllegalArgumentException("出生日期小于当前时间,无效的日期!");
}
int yearNow = cal.get(Calendar.YEAR);
int monthNow = cal.get(Calendar.MONTH);
int dayOfMonthNow = cal.get(Calendar.DAY_OF_MONTH);
cal.setTime(birthDay);
int yearBirth = cal.get(Calendar.YEAR);
int monthBirth = cal.get(Calendar.MONTH);
int dayOfMonthBirth = cal.get(Calendar.DAY_OF_MONTH);
int age = yearNow - yearBirth;
if (monthNow <= monthBirth) {
if (monthNow == monthBirth) {
if (dayOfMonthNow < dayOfMonthBirth) age--;
} else {
age--;
}
}
return age;
}
}
\ No newline at end of file
......@@ -111,7 +111,9 @@ public class AlertSubmittedServiceImpl extends BaseService<AlertSubmittedDto, Al
public Boolean save(AlertSubmittedDto alertSubmittedDto, String userName) throws Exception {
Long alertSubmittedId = saveAlertSubmitted(alertSubmittedDto, userName);
// 组装规则入参
AlertCalled alertCalled = alertCalledService.getById(alertSubmittedDto.getAlertCalledId());
AlertCalledVo alertCalledVo = new AlertCalledVo();
alertCalledVo.setAlertCalled(alertCalled);
List<AlertFormValue> alertFormValue = new ArrayList<>();
AlertFormValue formValue = new AlertFormValue();
formValue.setFieldCode("alertSubmittedId");
......@@ -128,30 +130,38 @@ public class AlertSubmittedServiceImpl extends BaseService<AlertSubmittedDto, Al
*/
public void ruleCallbackAction(String smsCode, String sendIds, Object object) throws Exception {
// 获取报送对象列表
List<AlertSubmittedObject> alertSubmittedObjectList = new ArrayList<>();
List<AlertSubmittedObject> alertSubmittedObjectList = Lists.newArrayList();;
Set<String> mobiles = new HashSet<>();
HashMap<String, String> smsParams = new HashMap<>();
// 根据id列表查询所有人员信息
List<Long> ids = StringUtil.String2LongList(sendIds);
if (object instanceof AlertCalledRo) {
AlertCalledRo calledRo = (AlertCalledRo) object;
String sequenceNbr = calledRo.getSequenceNbr();
String alertSubmittedId = calledRo.getAlertSubmittedId();
// 组装人员信息
List<Map<String, Object>> orgUsers = orgUsrService.selectForShowByListId(ids);
for (Map<String, Object> orgUser : orgUsers) {
AlertSubmittedObject alertSubmittedObject = new AlertSubmittedObject();
alertSubmittedObject.setAlertSubmittedId(Long.parseLong(sequenceNbr));
alertSubmittedObject.setAlertSubmittedId(Long.parseLong(alertSubmittedId));
alertSubmittedObject.setType(false);
alertSubmittedObject.setCompanyId((Long) orgUser.get("parentId"));
alertSubmittedObject.setCompanyName((String) orgUser.get("parentName"));
alertSubmittedObject.setUserId((Long) orgUser.get("bizOrgCode"));
alertSubmittedObject.setCompanyId(Long.valueOf((String) orgUser.get("parentId")));
alertSubmittedObject.setCompanyName((String) orgUser.get("parenName"));
alertSubmittedObject.setUserId(10010L);
alertSubmittedObject.setUserName((String) orgUser.get("bizOrgName"));
alertSubmittedObject.setUserPhone((String) orgUser.get("telephone"));
alertSubmittedObject.setRecUserName("ZW");
mobiles.add((String) orgUser.get("telephone"));
alertSubmittedObjectList.add(alertSubmittedObject);
}
// 组装报送内容
smsParams.put("alertType", calledRo.getAlertType());
smsParams.put("trappedNum", calledRo.getTrappedNum());
smsParams.put("companyName", calledRo.getCompanyName());
}
// 执行短信报送对象
saveAlertSubmittedObject(alertSubmittedObjectList, smsCode, mobiles, object);
saveAlertSubmittedObject(alertSubmittedObjectList, smsCode, mobiles, smsParams);
}
/**
......@@ -164,7 +174,6 @@ public class AlertSubmittedServiceImpl extends BaseService<AlertSubmittedDto, Al
Long alertSubmittedId = alertSubmittedDto.getSequenceNbr();
String smsCode = "";
Set<String> mobiles = new HashSet<>();
HashMap<String, String> smsParams;
if (alertSubmittedId == null) {
// 1.保存警情记录主表
......@@ -237,7 +246,11 @@ public class AlertSubmittedServiceImpl extends BaseService<AlertSubmittedDto, Al
// 4.发送任务消息
// 4.1组织短信内容
smsParams = JSON.parseObject(JSON.toJSONString(alertSubmittedDto.getSubmitContent()), HashMap.class);
HashMap<String, String> smsParams = new HashMap<>();
JSONObject submitContent = alertSubmittedDto.getSubmitContent();
smsParams.put("alertType", submitContent.get("alertType").toString());
smsParams.put("trappedNum", submitContent.get("trappedNum").toString());
smsParams.put("companyName", submitContent.get("companyName").toString());
// 4.2调用短信发送接口
alertCalledAction.sendAlertCalleCmd(smsCode, mobiles, smsParams);
return finalAlertSubmittedId;
......@@ -249,16 +262,13 @@ public class AlertSubmittedServiceImpl extends BaseService<AlertSubmittedDto, Al
* @param alertSubmittedObjectList 报送对象列表
* @param smsCode 短信模板code
* @param mobiles 电话号码列表
* @param object 报送内容
* @param smsParams 报送内容
*/
public void saveAlertSubmittedObject(List<AlertSubmittedObject> alertSubmittedObjectList, String smsCode,
Set<String> mobiles, Object object) {
Set<String> mobiles, HashMap<String, String> smsParams) {
alertSubmittedObjectServiceImpl.saveBatch(alertSubmittedObjectList);
// 发送任务消息
// 组织短信内容
HashMap<String, String> smsParams = new HashMap<>();
Map<String, String> objectMap = JSON.parseObject(JSON.toJSONString(object), HashMap.class);
smsParams.putAll(objectMap);
// 调用短信发送接口
alertCalledAction.sendAlertCalleCmd(smsCode, mobiles, smsParams);
}
......
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