Browse Source

[feat]

1、修改预警查询接口
2、开发预警统计接口
pull/1/head
杨威 4 months ago
parent
commit
6757782115
  1. 35
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java
  2. 9
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java
  3. 5
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessDepartBoundaryController.java
  4. 9
      dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java
  5. 27
      dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java
  6. 31
      dk-modules/business/src/main/java/org/dromara/business/domain/enums/AlertTypeEnum.java
  7. 9
      dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertVo.java
  8. 51
      dk-modules/business/src/main/java/org/dromara/business/handler/AlertTypeHandler.java
  9. 5
      dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java
  10. 3
      dk-modules/business/src/main/java/org/dromara/business/service/BusinessAlertStatisticsService.java
  11. 3
      dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java
  12. 2
      dk-modules/business/src/main/java/org/dromara/business/service/IBusinessDepartBoundaryService.java
  13. 40
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java
  14. 44
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java
  15. 68
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessDepartBoundaryServiceImpl.java
  16. 126
      dk-modules/business/src/main/java/org/dromara/business/utils/JsonUtil.java
  17. 70
      dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml
  18. 4
      pom.xml

35
dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java

@ -12,6 +12,9 @@ import org.dromara.common.web.core.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* 预警服务
*
@ -29,33 +32,11 @@ public class BusinessAlertController extends BaseController {
private final IBusinessAlertService businessAlertService;
/**
* 查询全部预警
*/
@Operation(summary ="查询全部预警",description = "查询全部预警")
@GetMapping("/alert/page/all")
public TableDataInfo<BusinessAlert> pageBusinessAlert(BusinessAlertBo bo, PageQuery pageQuery) {
return businessAlertService.pageBusinessAlert(bo, pageQuery);
}
/**
* 查询审批的预警
* 查询全部预警/待办/已完成/忽略
*/
@Operation(summary ="查询待办的预警",description = "查询待办的预警")
@GetMapping("/alert/page/todo")
public TableDataInfo<BusinessAlert> pageBusinessAlertTodo(BusinessAlertBo bo, PageQuery pageQuery) {
return businessAlertService.pageBusinessAlertTodo(bo, pageQuery);
@Operation(summary ="查询全部预警/待办/已完成/忽略",description = "查询全部预警/待办/已完成/忽略")
@GetMapping("/alert/{alertCode}/page")
public TableDataInfo<BusinessAlert> pageBusinessAlert(BusinessAlertBo bo, PageQuery pageQuery,@PathVariable String alertCode) {
return businessAlertService.getInfo(bo,pageQuery,alertCode);
}
/**
* 查询审批完成的预警
* @param bo
* @param pageQuery
* @return
*/
@Operation(summary ="查询审批完成的预警",description = "查询审批完成的预警")
@GetMapping("/alert/page/finish")
public TableDataInfo<BusinessAlert> pageBusinessAlertFinish(BusinessAlertBo bo, PageQuery pageQuery) {
return businessAlertService.pageBusinessAlertFinish(bo, pageQuery);
}
}

9
dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertStatisticsController.java

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
* 预警统计相关服务
@ -57,7 +58,9 @@ public class BusinessAlertStatisticsController extends BaseController {
//预警对比统计
//1、处理状态柱状图,x轴为选中的部门
//2、预警类型柱状图,x轴为选中的部门
@Operation(summary="预警对比统计", description="预警对比统计")
@GetMapping(value = "/compare/count")
public R<List<Map<String, Object>>> countAlertCompare(BusinessAlertBo businessAlertBo) {
return R.ok(statisticsService.countAlertCompare(businessAlertBo));
}
}

5
dk-modules/business/src/main/java/org/dromara/business/controller/BusinessDepartBoundaryController.java

@ -57,9 +57,8 @@ public class BusinessDepartBoundaryController extends BaseController {
*/
@Operation(summary ="批量新增部门区域",description = "批量新增部门区域")
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public R<Void> uploadShpFile(@RequestParam("file") MultipartFile file,
@RequestParam(value = "deptId" ,required = false)String deptId) {
return toAjax(departBoundaryService.uploadShpFile(file,deptId));
public R<Void> uploadShpFile(@RequestParam("file") MultipartFile file) {
return toAjax(departBoundaryService.uploadShpFile(file));
}
/**

9
dk-modules/business/src/main/java/org/dromara/business/domain/BusinessAlert.java

@ -1,6 +1,7 @@
package org.dromara.business.domain;
import org.dromara.business.domain.enums.AlertTypeEnum;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import org.dromara.business.handler.AlertTypeHandler;
import org.dromara.common.core.enums.BusinessStatusEnum;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import com.baomidou.mybatisplus.annotation.*;
@ -12,6 +13,7 @@ import org.dromara.common.translation.constant.TransConstant;
import java.util.Date;
import java.io.Serial;
import java.util.List;
/**
* 预警任务对象 business_alert
@ -67,7 +69,8 @@ public class BusinessAlert extends BaseEntity {
/**
* 预警类型
*/
private AlertTypeEnum alertType;
@TableField(value = "alert_type",typeHandler = JacksonTypeHandler.class)
private List<String> alertType;
/**
* 纬度
@ -135,7 +138,7 @@ public class BusinessAlert extends BaseEntity {
/**
* 流程处置状态(verify:验证,cancel:已撤销,draft:草稿,waiting:待审核,finish:已完成,invalid:已作废,back:已退回,termination:已终止)
*/
private BusinessStatusEnum handleType;
private String handleType;
/**
* 是否违建 01

27
dk-modules/business/src/main/java/org/dromara/business/domain/bo/BusinessAlertBo.java

@ -50,7 +50,7 @@ public class BusinessAlertBo extends BaseEntity {
/**
* 预警类型
*/
private String alertType;
private List<String> alertType;
/**
* 纬度
@ -67,6 +67,11 @@ public class BusinessAlertBo extends BaseEntity {
*/
private String taskHandleType;
/**
* 流程处置状态(verify:验证,cancel:已撤销,draft:草稿,waiting:待审核,finish:已完成,invalid:已作废,back:已退回,termination:已终止)
*/
private String handleType;
/**
* 任务内容
@ -189,5 +194,25 @@ public class BusinessAlertBo extends BaseEntity {
List<Long> deptIdList;
/**
* 识别类型集合
*/
List<String> alertTypeList;
/**
*
*/
String year;
/**
* 月份集合
*/
List<String> monthList;
/**
* 年月集合
*/
List<String> dateList;
}

31
dk-modules/business/src/main/java/org/dromara/business/domain/enums/AlertTypeEnum.java

@ -1,31 +0,0 @@
package org.dromara.business.domain.enums;
import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import java.util.Arrays;
/**
* 预警类型枚举类
*/
@Getter
public enum AlertTypeEnum {
;
private String code;
private String description;
public static AlertTypeEnum getTypeByCode(String code){
if(StrUtil.isNotEmpty(code)){
return Arrays.stream(values()).filter(p -> StrUtil.equals(p.name(),code.toUpperCase())).findAny().orElse(null);
}
return null;
}
}

9
dk-modules/business/src/main/java/org/dromara/business/domain/vo/BusinessAlertVo.java

@ -5,15 +5,12 @@ import com.alibaba.excel.annotation.ExcelProperty;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.dromara.business.domain.BusinessAlert;
import org.dromara.business.domain.enums.AlertTypeEnum;
import org.dromara.common.core.enums.BusinessStatusEnum;
import org.dromara.common.translation.annotation.Translation;
import org.dromara.common.translation.constant.TransConstant;
import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
@ -64,7 +61,7 @@ public class BusinessAlertVo implements Serializable {
/**
* 预警类型
*/
private String alertType;
private List<String> alertType;
/**
* 纬度
@ -136,7 +133,7 @@ public class BusinessAlertVo implements Serializable {
/**
* 流程处置状态(verify:验证,cancel:已撤销,draft:草稿,waiting:待审核,finish:已完成,invalid:已作废,back:已退回,termination:已终止)
*/
private BusinessStatusEnum handleType;
private String handleType;
/**
* 是否违建 01

51
dk-modules/business/src/main/java/org/dromara/business/handler/AlertTypeHandler.java

@ -0,0 +1,51 @@
package org.dromara.business.handler;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import org.apache.ibatis.type.TypeHandler;
import org.dromara.business.utils.JsonUtil;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@MappedJdbcTypes(JdbcType.VARCHAR) // 数据库类型
@MappedTypes({List.class}) // java数据类型
public class AlertTypeHandler implements TypeHandler<List<String>> {
@Override
public void setParameter(PreparedStatement preparedStatement, int i, List<String> alertTypeList, JdbcType jdbcType) throws SQLException {
preparedStatement.setString(i, JsonUtil.toJson(alertTypeList));
}
@Override
public List<String> getResult(ResultSet resultSet, String s) throws SQLException {
if (StringUtils.isBlank(resultSet.getString(s))) {
return new ArrayList<>();
}
return JsonUtil.jsonToList(resultSet.getString(s), String.class);
}
@Override
public List<String> getResult(ResultSet resultSet, int i) throws SQLException {
if (StringUtils.isBlank(resultSet.getString(i))) {
return new ArrayList<>();
}
return JsonUtil.jsonToList(resultSet.getString(i), String.class);
}
@Override
public List<String> getResult(CallableStatement callableStatement, int i) throws SQLException {
String value = callableStatement.getString(i);
if (StringUtils.isBlank(value)) {
return new ArrayList<>();
}
return JsonUtil.jsonToList(value, String.class);
}
}

5
dk-modules/business/src/main/java/org/dromara/business/mapper/BusinessAlertMapper.java

@ -48,4 +48,9 @@ public interface BusinessAlertMapper extends BaseMapperPlus<BusinessAlert, Busin
@DataColumn(key = "deptName", value = "ba.dept_id")
)
List<Map<String, Object>> listDepartAlertStatus(@Param("param") BusinessAlertBo businessAlertBo);
@DataPermission(
@DataColumn(key = "deptName", value = "ba.dept_id")
)
List<Map<String, Object>> countAlertCompare(@Param("param")BusinessAlertBo businessAlertBo);
}

3
dk-modules/business/src/main/java/org/dromara/business/service/BusinessAlertStatisticsService.java

@ -5,6 +5,7 @@ import org.dromara.business.domain.bo.BusinessAlertBo;
import org.dromara.business.domain.model.StatObj;
import java.util.List;
import java.util.Map;
public interface BusinessAlertStatisticsService {
List<StatObj> countMonthAlert(BusinessAlertBo businessAlertBo);
@ -14,4 +15,6 @@ public interface BusinessAlertStatisticsService {
List<StatObj> countMonthAlertStatus(BusinessAlertBo businessAlertBo);
List<StatObj> countDepartAlertStatus(BusinessAlertBo businessAlertBo);
List<Map<String, Object>> countAlertCompare(BusinessAlertBo businessAlertBo);
}

3
dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java

@ -20,7 +20,7 @@ public interface IBusinessAlertService {
TableDataInfo<BusinessAlert> pageBusinessAlertFinish(BusinessAlertBo bo, PageQuery pageQuery);
TableDataInfo<BusinessAlert> pageBusinessAlert(BusinessAlertBo bo, PageQuery pageQuery);
TableDataInfo<BusinessAlert> pageBusinessAlertAll(BusinessAlertBo bo, PageQuery pageQuery);
/**
* 新增预警任务
@ -63,4 +63,5 @@ public interface IBusinessAlertService {
*/
void updateAlertStatus(String businessId, String flowStatus);
TableDataInfo<BusinessAlert> getInfo(BusinessAlertBo bo, PageQuery pageQuery, String alertCode);
}

2
dk-modules/business/src/main/java/org/dromara/business/service/IBusinessDepartBoundaryService.java

@ -18,7 +18,7 @@ public interface IBusinessDepartBoundaryService extends IService<BusinessDepartB
List<BusinessDepartBoundary> queryByDeptId(String deptId);
boolean uploadShpFile(MultipartFile file,String deptId);
boolean uploadShpFile(MultipartFile file);
boolean deleteDepartBoundary(String id);

40
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java

@ -22,7 +22,9 @@ import org.dromara.system.api.domain.vo.RemoteUserVo;
import org.dromara.workflow.api.RemoteWorkflowService;
import org.springframework.stereotype.Service;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -41,7 +43,6 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
@DubboReference
RemoteWorkflowService remoteWorkflowService;
/**
* 新增预警任务
*
@ -51,7 +52,6 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
@Override
public Boolean addBusinessAlert(BusinessAlertBo param) {
BusinessAlert alert = MapstructUtils.convert(param, BusinessAlert.class);
validEntityBeforeSave(alert,false);
return this.baseMapper.insert(alert) > 0;
}
@ -74,7 +74,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
@Override
public Boolean editBusinessAlert(BusinessAlertBo param) {
BusinessAlert businessAlert = MapstructUtils.convert(param, BusinessAlert.class);
validEntityBeforeSave(businessAlert,true);
validEntityBeforeSave(businessAlert);
return baseMapper.updateById(businessAlert) > 0;
}
@ -112,7 +112,6 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
}
/**
* 查询全部预警
* @param bo
@ -120,7 +119,7 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
* @return
*/
@Override
public TableDataInfo<BusinessAlert> pageBusinessAlert(BusinessAlertBo bo, PageQuery pageQuery) {
public TableDataInfo<BusinessAlert> pageBusinessAlertAll(BusinessAlertBo bo, PageQuery pageQuery) {
QueryWrapper<BusinessAlert> wrapper = buildQueryWrapper(bo);
Page<BusinessAlert> page = this.baseMapper.pageBusinessAlert(pageQuery.build(), wrapper);
@ -160,8 +159,8 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
wrapper.eq("uu.del_flag", 0);
wrapper.in("uu.type", 1,2,3);
wrapper.in("a.processed_by", remoteWorkflowService.getPermissions());
wrapper.in("a.flow_status", BusinessStatusEnum.WAITING.getStatus());
wrapper.in("uu.processed_by", remoteWorkflowService.getPermissions());
wrapper.in("b.flow_status", BusinessStatusEnum.WAITING.getStatus());
Page<BusinessAlert> page = this.baseMapper.pageAlertTodo(pageQuery.build(), wrapper);
List<BusinessAlert> records = page.getRecords();
@ -188,6 +187,14 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
private QueryWrapper<BusinessAlert> buildQueryWrapper(BusinessAlertBo bo) {
QueryWrapper<BusinessAlert> wrapper = new QueryWrapper<>();
if (ObjectUtil.isNotEmpty(bo.getAlertTypeList())){
wrapper.in("ba.alert_type", bo.getAlertTypeList());
}
if (ObjectUtil.isNotEmpty(bo.getHandleType())){
wrapper.eq("ba.handle_type", bo.getHandleType());
}
wrapper.orderByAsc("ba.create_time");
return wrapper;
}
@ -206,9 +213,26 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
/**
* 保存前的数据校验
*/
private void validEntityBeforeSave(BusinessAlert alert, Boolean validId){
private void validEntityBeforeSave(BusinessAlert alert){
if (ObjectUtil.isEmpty(alert.getId())){
throw new ServiceException("预警【Id】为空!");
}
}
@SuppressWarnings("unchecked")
@Override
public TableDataInfo<BusinessAlert> getInfo(BusinessAlertBo bo, PageQuery pageQuery, String alertCode) {
String methodName = "pageBusinessAlert" + alertCode; // 拼接方法名
try {
Method method = this.getClass().getDeclaredMethod(methodName, BusinessAlertBo.class, PageQuery.class);
Object result = method.invoke(this, bo, pageQuery);
if (result instanceof TableDataInfo<?>) {
return (TableDataInfo<BusinessAlert>) result;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}

44
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertStatisticsServiceImpl.java

@ -13,10 +13,9 @@ import org.dromara.system.api.domain.vo.RemoteDeptVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
@ -95,4 +94,41 @@ public class BusinessAlertStatisticsServiceImpl implements BusinessAlertStatisti
}
/**
* 预警对比统计
* @param businessAlertBo
* @return
*/
@Override
public List<Map<String, Object>> countAlertCompare(BusinessAlertBo businessAlertBo) {
businessAlertBo.setDateList(buildDateList(businessAlertBo));
List<Map<String, Object>> mapList = baseMapper.countAlertCompare(businessAlertBo);
return mapList;
}
private List<String> buildDateList(BusinessAlertBo businessAlertBo) {
List<String> resultList = new ArrayList<>();
String currentYear = String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
String regex = "^(\\d{4})-(\\d{1,2})$";
Pattern pattern = Pattern.compile(regex);
if (ObjectUtil.isNotEmpty(businessAlertBo.getMonthList())) {
businessAlertBo.getMonthList().forEach(month -> {
String date =ObjectUtil.isNotEmpty(businessAlertBo.getYear())?businessAlertBo.getYear() + "-" + month:currentYear + "-" + month;
Matcher matcher = pattern.matcher(date);
if (matcher.find()) {
// 匹配年-月格式(例如 "2025-1")
if (matcher.group(1) != null && matcher.group(2) != null) {
String year = matcher.group(1);
String currentMonth = String.format("%02d", Integer.parseInt(matcher.group(2)));
date = year + "-" + currentMonth;
}
}
resultList.add(date);
});
}
return resultList;
}
}

68
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessDepartBoundaryServiceImpl.java

@ -29,6 +29,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.sql.DataSource;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.sql.Connection;
@ -76,7 +77,33 @@ public class BusinessDepartBoundaryServiceImpl extends ServiceImpl<BusinessDepar
@Override
@Transactional(rollbackFor = Exception.class)
public boolean uploadShpFile(MultipartFile file,String deptId) {
public boolean uploadShpFile(MultipartFile file) {
try {
List<BusinessGeospatialVectors> geospatialVectorsList = buildGeospatialVector(file);
//6、生成新的对象集合存储数据表中
List<BusinessDepartBoundary> boundaryList = buildBusinessDepartBoundary(geospatialVectorsList);
// 分批处理
int startIndex = 0; // 从第 0 条开始
int batchSize = 2000; // 每批处理 2000 条
boolean flag = BatchProcessorUtil.processBatches(boundaryList, batchSize, startIndex, batch -> {
//批量新增部门区域数据
this.baseMapper.saveBatchBoundary(batch);
});
if (flag) {
System.out.println("所有数据处理完成!");
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
private List<BusinessGeospatialVectors> buildGeospatialVector(MultipartFile file){
List<BusinessGeospatialVectors> geospatialVectorsList = new ArrayList<>();
try {
//1、首先调用解析工具拿到解析的字段集合
@ -138,27 +165,11 @@ public class BusinessDepartBoundaryServiceImpl extends ServiceImpl<BusinessDepar
geoVector.setCreateTime(new Date());
geospatialVectorsList.add(geoVector);
}
//6、生成新的对象集合存储数据表中
List<BusinessDepartBoundary> boundaryList = buildBusinessDepartBoundary(geospatialVectorsList,deptId);
// 分批处理
int startIndex = 0; // 从第 0 条开始
int batchSize = 2000; // 每批处理 2000 条
boolean flag = BatchProcessorUtil.processBatches(boundaryList, batchSize, startIndex, batch -> {
//批量新增部门区域数据
// this.baseMapper.saveBatchBoundary(batch);
});
if (flag) {
System.out.println("所有数据处理完成!");
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
return geospatialVectorsList;
}
@Override
@ -201,23 +212,26 @@ public class BusinessDepartBoundaryServiceImpl extends ServiceImpl<BusinessDepar
* @param geospatialVectorsList
* @return
*/
private List<BusinessDepartBoundary> buildBusinessDepartBoundary(List<BusinessGeospatialVectors> geospatialVectorsList,String deptId) {
private List<BusinessDepartBoundary> buildBusinessDepartBoundary(List<BusinessGeospatialVectors> geospatialVectorsList) {
List<BusinessDepartBoundary> resultList = new ArrayList<>();
List<Map<String,Object>> namePathList = remoteDeptService.getNamePathList();
Map<String, List<Map<String, Object>>> namePathMap = namePathList.stream()
.filter(item -> item.containsKey("shpNo"))
.collect(Collectors.groupingBy(item -> item.get("shpNo").toString()));
.collect(Collectors.groupingBy(item -> item.get("deptName").toString()));
geospatialVectorsList.forEach(param->{
BusinessDepartBoundary businessDepartBoundary = new BusinessDepartBoundary();
//获取区划名称
String divisionName = param.getAdminDivisionName();
businessDepartBoundary.setBoundary(param.getLandCategories());
businessDepartBoundary.setShpNo(param.getLandUnitCode());
if (ObjectUtil.isNotEmpty(namePathMap.get(param.getLandUnitCode()))){
businessDepartBoundary.setDeptName(namePathMap.get(param.getLandUnitCode()).get(0).get("deptName") + "");
businessDepartBoundary.setDeptId(namePathMap.get(param.getLandUnitCode()).get(0).get("deptId") + "");
businessDepartBoundary.setCommunityName(namePathMap.get(param.getLandUnitCode()).get(0).get("namePath") + "");
if (ObjectUtil.isNotEmpty(namePathMap.get(divisionName))){
Map<String, Object> objectMap = namePathMap.get(divisionName).get(0);
businessDepartBoundary.setShpNo(ObjectUtil.isEmpty(objectMap.get("shpNo"))?null:(String)objectMap.get("shpNo"));
businessDepartBoundary.setDeptName(objectMap.get("deptName") + "");
businessDepartBoundary.setDeptId(objectMap.get("deptId") + "");
businessDepartBoundary.setCommunityName(objectMap.get("namePath") + "");
resultList.add(businessDepartBoundary);
}

126
dk-modules/business/src/main/java/org/dromara/business/utils/JsonUtil.java

@ -0,0 +1,126 @@
package org.dromara.business.utils;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* 定义响应结构
*/
public class JsonUtil {
private static ObjectMapper MAPPER;
static{
MAPPER=new ObjectMapper();
}
/**
* 将对象转换成json字符串
* @param data
* @return
*/
public static String toJson(Object data){
String string = null;
try {
string = MAPPER.writeValueAsString(data);
if(StringUtils.isEmpty(string)){
return null;
}
return string;
} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}
/**
* 将json结果集转化为对象
*
* @param jsonData json数据
* @return
*/
public static <T> T jsonToPojo(String jsonData, Class<T> beanType) {
try {
T t = MAPPER.readValue(jsonData, beanType);
return t;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 将json数据转换成pojo对象list
* <p>Title: jsonToList</p>
* <p>Description: </p>
* @param jsonData
* @param beanType
* @return
*/
public static <T>List<T> jsonToList(String jsonData, Class<T> beanType) {
JavaType javaType = MAPPER.getTypeFactory().constructParametricType(List.class, beanType);
try {
List<T> list = MAPPER.readValue(jsonData, javaType);
return list;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 将Object对象里面的属性和值转化成Map对象
*
* @param obj
* @return
* @throws IllegalAccessException
*/
public static Map<String, Object> objectToMap(Object obj){
try {
Map<String, Object> map = new HashMap<String,Object>();
Class<?> clazz = obj.getClass();
for (Field field : clazz.getDeclaredFields()) {
field.setAccessible(true);
String fieldName = field.getName();
if(ObjectUtil.isNotEmpty(field.get(obj))){
Object value = field.get(obj);
map.put(fieldName, value);
}else{
map.put(fieldName, "");
}
}
return map;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static Map<String, Object> jsonToMap(String json){
try {
return MAPPER.readValue(json, new TypeReference<Map<String, Object>>(){});
} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}
public static LinkedHashMap<String, String> jsonToStrMap(String json){
try {
return MAPPER.readValue(json, new TypeReference<LinkedHashMap<String, String>>(){});
} catch (JsonProcessingException e) {
e.printStackTrace();
return null;
}
}
}

70
dk-modules/business/src/main/resources/mapper/business/BusinessAlertMapper.xml

@ -8,7 +8,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select
ba.*,
b.flow_status flowStatus,
b.business_id businessId,
b.business_id businessId
from dk_business.business_alert ba
left join dk_workflow.flow_instance b on ba.id = b.business_id
${ew.getCustomSqlSegment}
@ -50,7 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -59,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -68,7 +68,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -77,7 +77,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -86,7 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -95,7 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -104,7 +104,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -113,7 +113,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -122,7 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -131,7 +131,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -140,7 +140,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
union all
@ -149,7 +149,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="param.deptIdList != null and param.deptIdList.size > 0">
and ba.dept_id in
<foreach collection="param.deptIdList" item="item" open="(" close=")" separator=",">
item
#{item}
</foreach>
</if>
@ -202,4 +202,48 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
ba.dept_name,ba.dept_id
</select>
<select id="countAlertCompare" resultType="java.util.Map">
WITH RECURSIVE months AS (
SELECT MAKEDATE(COALESCE(#{param.year}, YEAR(NOW())), 1) AS dateMonth
UNION ALL
SELECT DATE_ADD(dateMonth, INTERVAL 1 MONTH)
FROM months
WHERE <![CDATA[ dateMonth < MAKEDATE(COALESCE(#{param.year}, YEAR(NOW())), 1) + INTERVAL 11 MONTH ]]>
),
param_departments AS (
SELECT dept_id, dept_name,tenant_id
FROM business_alert
WHERE dept_id IN
<foreach collection="param.deptIdList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
),
month_department AS (
SELECT d.dept_id, m.dateMonth, d.dept_name,d.tenant_id
FROM param_departments d
CROSS JOIN months m
<where>
<if test="param.dateList != null and param.dateList.size > 0">
DATE_FORMAT(m.dateMonth, '%Y-%m') IN
<foreach collection="param.dateList" open="(" close=")" separator="," item="item">
#{item}
</foreach>
</if>
</where>
)
SELECT
md.dept_id deptId,
md.dept_name deptName,
DATE_FORMAT(md.dateMonth, '%Y-%m') AS date,
COUNT(DISTINCT ba.id) AS total,
IFNULL(SUM( ba.handle_type = 'waiting' ),0) AS todoCount,
IFNULL(SUM( ba.handle_type = 'finish' ),0) AS finishCount
FROM month_department md
LEFT JOIN business_alert ba
ON md.dept_id = ba.dept_id
AND DATE_FORMAT(ba.create_time, '%Y-%m') = DATE_FORMAT(md.dateMonth, '%Y-%m')
GROUP BY md.dept_id, md.dateMonth, md.dept_name
ORDER BY md.dept_id, md.dateMonth
</select>
</mapper>

4
pom.xml

@ -86,12 +86,12 @@
<properties>
<!-- 环境标识,需要与配置文件的名称相对应 -->
<profiles.active>dev</profiles.active>
<nacos.server>127.0.0.1:8848</nacos.server>
<nacos.server>114.235.183.147:8848</nacos.server>
<nacos.discovery.group>DEFAULT_GROUP</nacos.discovery.group>
<nacos.config.group>DEFAULT_GROUP</nacos.config.group>
<nacos.username>nacos</nacos.username>
<nacos.password>nacos</nacos.password>
<logstash.address>127.0.0.1:4560</logstash.address>
<logstash.address>114.235.183.147:4560</logstash.address>
</properties>
<activation>
<!-- 默认环境 -->

Loading…
Cancel
Save