Browse Source
# Conflicts: # epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/ServiceConstant.java # epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/HouseService.java # epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/HouseServiceImpl.javamaster
62 changed files with 2317 additions and 80 deletions
@ -0,0 +1,5 @@ |
|||
INSERT INTO `epmet_admin`.`sys_dict_type` (`id`, `dict_type`, `dict_name`, `remark`, `sort`, `DEL_FLAG`, `REVISION`, `CREATED_BY`, `CREATED_TIME`, `UPDATED_BY`, `UPDATED_TIME`) VALUES ('1556509011061993473', 'jmreport_category', '报表应用类别', '居民信息、房屋信息', 32, 0, 0, '1', '2022-08-08 13:14:01', '1', '2022-08-08 13:14:01'); |
|||
|
|||
|
|||
INSERT INTO `epmet_admin`.`sys_dict_data` (`id`, `dict_type_id`, `dict_label`, `dict_value`, `dict_p_value`, `remark`, `sort`, `DEL_FLAG`, `REVISION`, `CREATED_BY`, `CREATED_TIME`, `UPDATED_BY`, `UPDATED_TIME`) VALUES ('1556509175185108994', 1556509011061993473, '房屋信息', 'house_info', '0', '', 2, 0, 0, '1', '2022-08-08 13:14:41', '1', '2022-08-08 13:14:41'); |
|||
INSERT INTO `epmet_admin`.`sys_dict_data` (`id`, `dict_type_id`, `dict_label`, `dict_value`, `dict_p_value`, `remark`, `sort`, `DEL_FLAG`, `REVISION`, `CREATED_BY`, `CREATED_TIME`, `UPDATED_BY`, `UPDATED_TIME`) VALUES ('1556509102015475714', 1556509011061993473, '居民信息', 'resi_info', '0', '', 1, 0, 0, '1', '2022-08-08 13:14:23', '1', '2022-08-08 13:14:23'); |
@ -0,0 +1,24 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" |
|||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|||
<parent> |
|||
<artifactId>epmet-commons</artifactId> |
|||
<groupId>com.epmet</groupId> |
|||
<version>2.0.0</version> |
|||
<!--<relativePath>../../pom.xml</relativePath>--> |
|||
</parent> |
|||
<modelVersion>4.0.0</modelVersion> |
|||
<packaging>jar</packaging> |
|||
|
|||
<artifactId>epmet-commons-feignclient</artifactId> |
|||
|
|||
<dependencies> |
|||
<dependency> |
|||
<groupId>com.epmet</groupId> |
|||
<artifactId>epmet-commons-tools</artifactId> |
|||
<version>2.0.0</version> |
|||
</dependency> |
|||
</dependencies> |
|||
|
|||
</project> |
@ -0,0 +1,22 @@ |
|||
package com.epmet.commons.feignclient.dtos; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 积木报表的返回值Page对象 |
|||
* @param <T> |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class JiMuPage<T> { |
|||
private int pageNo; |
|||
private int pageSize; |
|||
private int total; |
|||
private int pages; |
|||
private List<?> records; |
|||
} |
@ -0,0 +1,20 @@ |
|||
package com.epmet.commons.feignclient.dtos; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
/** |
|||
* 积木报表的返回值Result对象 |
|||
* @param <T> |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class JiMuResult<T> { |
|||
private boolean success = true; |
|||
private String message = ""; |
|||
private Integer code = 0; |
|||
private T result; |
|||
private T data; |
|||
} |
@ -0,0 +1,33 @@ |
|||
package com.epmet.commons.feignclient.dtos.form; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/8 15:08 |
|||
* @DESC |
|||
*/ |
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class JiMuReportFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 3590609549416867701L; |
|||
|
|||
/** |
|||
* 报表IDs |
|||
*/ |
|||
private List<String> reportIds; |
|||
|
|||
/** |
|||
* 类别 |
|||
*/ |
|||
private List<String> categoryKeys; |
|||
|
|||
private String id; |
|||
} |
@ -0,0 +1,27 @@ |
|||
package com.epmet.commons.feignclient.dtos.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* 批量导出用的requst dto |
|||
*/ |
|||
@Data |
|||
public class JimuReportExportRequestDTO { |
|||
private String excelConfigId; |
|||
private ExportRequestQueryParam queryParam = new ExportRequestQueryParam(); |
|||
|
|||
/** |
|||
* 批量导出用的请求参数 |
|||
*/ |
|||
@Data |
|||
public static class ExportRequestQueryParam { |
|||
private String id; |
|||
private String token; |
|||
private String paramKey; |
|||
private String pageNo; |
|||
private Integer pageSize; |
|||
private String currentPageNo; |
|||
private Integer currentPageSize; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package com.epmet.commons.feignclient.dtos.result; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
import java.util.Date; |
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
public class JiMuReportDetailResultDTO { |
|||
private String id; |
|||
private String code; |
|||
private String name; |
|||
private String note; |
|||
private String status; |
|||
private String type; |
|||
private String jsonStr; |
|||
private String apiUrl; |
|||
private String apiMethod; |
|||
private String apiCode; |
|||
private String thumb; |
|||
private Integer template; |
|||
private String createBy; |
|||
private Date createTime; |
|||
private String updateBy; |
|||
private Date updateTime; |
|||
private Map<String, Object> dataList; |
|||
} |
@ -0,0 +1,26 @@ |
|||
package com.epmet.commons.feignclient.dtos.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/8 15:10 |
|||
* @DESC |
|||
*/ |
|||
@Data |
|||
public class JiMuReportResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -4048477731892329569L; |
|||
|
|||
private String code; |
|||
|
|||
private String name; |
|||
|
|||
private String id; |
|||
private String reportId; |
|||
private String reportName; |
|||
|
|||
private Boolean isList = false; |
|||
} |
@ -0,0 +1,18 @@ |
|||
package com.epmet.commons.feignclient.dtos.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class JimuReportDbDataResultDTO { |
|||
|
|||
private ReportDB reportDb; |
|||
|
|||
@Data |
|||
public static class ReportDB { |
|||
private String apiUrl; |
|||
private String apiMethod; |
|||
private String isList; |
|||
private String dbChName; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,26 @@ |
|||
package com.epmet.commons.feignclient.dtos.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 积木报表,报表字段列表 |
|||
*/ |
|||
@Data |
|||
public class JimuReportFieldTreeResultDTO { |
|||
|
|||
private Boolean expand; |
|||
private String code; |
|||
private List<Child> children; |
|||
private String dbId; |
|||
private String type; |
|||
private String isList; |
|||
|
|||
@Data |
|||
public static class Child { |
|||
private Boolean expand; |
|||
private String title; |
|||
private String fieldText; |
|||
} |
|||
} |
@ -0,0 +1,47 @@ |
|||
package com.epmet.commons.feignclient.feigns; |
|||
|
|||
import com.epmet.commons.feignclient.dtos.JiMuPage; |
|||
import com.epmet.commons.feignclient.dtos.JiMuResult; |
|||
import com.epmet.commons.feignclient.dtos.form.JimuReportExportRequestDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JiMuReportDetailResultDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JimuReportDbDataResultDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JimuReportFieldTreeResultDTO; |
|||
import com.epmet.commons.feignclient.feigns.fallback.JiMuReportOpenFeignClientFallbackFactory; |
|||
import com.epmet.commons.tools.constant.ServiceConstant; |
|||
import feign.Response; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/8 13:52 |
|||
* @DESC |
|||
*/ |
|||
@FeignClient(name = ServiceConstant.EPMET_JM_REPORT, fallbackFactory = JiMuReportOpenFeignClientFallbackFactory.class) |
|||
//@FeignClient(name = ServiceConstant.EPMET_JM_REPORT, fallbackFactory = JiMuReportOpenFeignClientFallbackFactory.class, url = "localhost:8118")
|
|||
public interface JiMuReportOpenFeignClient { |
|||
|
|||
@GetMapping(value = "jmreport/excelQuery") |
|||
JiMuResult<JiMuPage<JiMuReportDetailResultDTO>> getList(@RequestParam("pageNo") Integer pageNo, |
|||
@RequestParam("pageSize") Integer pageSize, |
|||
@RequestParam("name") String name, |
|||
@RequestParam("reportType") String reportType, |
|||
@RequestParam("token") String token, |
|||
@RequestHeader MultiValueMap<String, String> headers); |
|||
|
|||
@GetMapping("jmreport/show") |
|||
JiMuResult<Map<String,Object>> getReport(@RequestParam("id") String id,@RequestParam("apiUrl") String apiUrl,@RequestParam("params") String params,@RequestHeader MultiValueMap<String, String> headers); |
|||
|
|||
@GetMapping("/jmreport/field/tree/{report-id}") |
|||
JiMuResult<List<List<JimuReportFieldTreeResultDTO>>> fieldTree(@PathVariable("report-id") String reportId); |
|||
|
|||
@GetMapping("jmreport/loadDbData/{report-id}") |
|||
JiMuResult<JimuReportDbDataResultDTO> loadDbData(@PathVariable("report-id") String reportId); |
|||
|
|||
@PostMapping("jmreport/exportAllExcelStream") |
|||
Response exportAllExcelStream(JimuReportExportRequestDTO param); |
|||
} |
@ -0,0 +1,51 @@ |
|||
package com.epmet.commons.feignclient.feigns.fallback; |
|||
|
|||
import com.epmet.commons.feignclient.dtos.JiMuPage; |
|||
import com.epmet.commons.feignclient.dtos.JiMuResult; |
|||
import com.epmet.commons.feignclient.dtos.form.JimuReportExportRequestDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JiMuReportDetailResultDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JimuReportDbDataResultDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JimuReportFieldTreeResultDTO; |
|||
import com.epmet.commons.feignclient.feigns.JiMuReportOpenFeignClient; |
|||
import feign.Response; |
|||
import org.springframework.util.MultiValueMap; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/8 13:53 |
|||
* @DESC |
|||
*/ |
|||
public class JiMuReportOpenFeignClientFallback implements JiMuReportOpenFeignClient { |
|||
|
|||
@Override |
|||
public JiMuResult<JiMuPage<JiMuReportDetailResultDTO>> getList(Integer pageNo, Integer pageSize, String name, String reportType, String token, MultiValueMap<String, String> headers) { |
|||
JiMuResult<JiMuPage<JiMuReportDetailResultDTO>> rst = new JiMuResult<>(false, "请求失败", 200, null,null); |
|||
return rst; |
|||
} |
|||
|
|||
@Override |
|||
public JiMuResult<Map<String,Object>> getReport(String id,String apiUrl,String params,MultiValueMap<String, String> headers) { |
|||
JiMuResult<Map<String,Object>> rst = new JiMuResult<>(false, "请求失败", 200, null,null); |
|||
return rst; |
|||
} |
|||
|
|||
@Override |
|||
public JiMuResult<JimuReportDbDataResultDTO> loadDbData(String reportId) { |
|||
JiMuResult<JimuReportDbDataResultDTO> rst = new JiMuResult<>(false, "请求失败", 200, null,null); |
|||
return rst; |
|||
} |
|||
|
|||
@Override |
|||
public Response exportAllExcelStream(JimuReportExportRequestDTO param) { |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public JiMuResult<List<List<JimuReportFieldTreeResultDTO>>> fieldTree(String reportId) { |
|||
JiMuResult rst = new JiMuResult<>(false, "请求失败", 200, null,null); |
|||
return rst; |
|||
} |
|||
} |
@ -0,0 +1,24 @@ |
|||
package com.epmet.commons.feignclient.feigns.fallback; |
|||
|
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import feign.hystrix.FallbackFactory; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/9 13:27 |
|||
* @DESC |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
public class JiMuReportOpenFeignClientFallbackFactory implements FallbackFactory<JiMuReportOpenFeignClientFallback> { |
|||
|
|||
private JiMuReportOpenFeignClientFallback fallback = new JiMuReportOpenFeignClientFallback(); |
|||
|
|||
@Override |
|||
public JiMuReportOpenFeignClientFallback create(Throwable cause) { |
|||
log.error(String.format("FeignClient调用发生异常,异常信息:%s", ExceptionUtils.getThrowableErrorStackTrace(cause))); |
|||
return fallback; |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
package com.epmet.commons.tools.annotation; |
|||
|
|||
import java.lang.annotation.*; |
|||
|
|||
/** |
|||
* 标记一个接口,它会被报表服务所调用 |
|||
*/ |
|||
@Target(ElementType.METHOD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
@Documented |
|||
public @interface ReportRequest { |
|||
|
|||
} |
@ -0,0 +1,86 @@ |
|||
package com.epmet.commons.tools.aspect; |
|||
|
|||
import cn.hutool.core.bean.BeanUtil; |
|||
import cn.hutool.core.bean.copier.CopyOptions; |
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.EpmetException; |
|||
import com.epmet.commons.tools.redis.RedisUtils; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.aspectj.lang.JoinPoint; |
|||
import org.aspectj.lang.annotation.Aspect; |
|||
import org.aspectj.lang.annotation.Before; |
|||
import org.aspectj.lang.reflect.MethodSignature; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.core.annotation.Order; |
|||
import org.springframework.stereotype.Component; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.context.request.RequestAttributes; |
|||
import org.springframework.web.context.request.RequestContextHolder; |
|||
import org.springframework.web.context.request.ServletRequestAttributes; |
|||
|
|||
import java.lang.reflect.Parameter; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 需要被报表服务请求的api,需要加上这个注解 |
|||
* 1.该注解会取url中固定的key,去redis获取参数,给入参dto复制 |
|||
*/ |
|||
@Aspect |
|||
@Component |
|||
@Order(20) |
|||
@Slf4j |
|||
public class ReportRequestAspect { |
|||
|
|||
/** |
|||
* 从redis中取参数用 |
|||
*/ |
|||
public static final String REPORT_REDIS_KEY = "paramKey"; |
|||
|
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
@Before("@annotation(com.epmet.commons.tools.annotation.ReportRequest)") |
|||
public void before(JoinPoint point) { |
|||
RequestAttributes ra = RequestContextHolder.getRequestAttributes(); |
|||
ServletRequestAttributes sra = (ServletRequestAttributes) ra; |
|||
String paramKey = sra.getRequest().getParameter(REPORT_REDIS_KEY); |
|||
if (StringUtils.isBlank(paramKey)) { |
|||
// 没有携带key参数,直接跳过
|
|||
return; |
|||
} |
|||
|
|||
Map<String, Object> cachedParams = redisUtils.hGetAll(paramKey); |
|||
if (cachedParams == null || cachedParams.size() == 0) { |
|||
log.warn("【报表服务】根据paramKey:{}未获取到有效的参数缓存。", paramKey); |
|||
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "参数失效", "参数失效"); |
|||
// redis中没有此参数
|
|||
} |
|||
|
|||
// 使用方法签名获取出参数class列表
|
|||
Object[] args = point.getArgs(); |
|||
MethodSignature signature = (MethodSignature) point.getSignature(); |
|||
Parameter[] parameters = signature.getMethod().getParameters(); |
|||
fillArgsToRequestBody(args, cachedParams, parameters); |
|||
} |
|||
|
|||
/** |
|||
* 将redis中取出的参数,赋值到指定的入参dto上 |
|||
* @param args |
|||
* @param storedParams |
|||
*/ |
|||
private void fillArgsToRequestBody(Object[] args, Map<String, Object> storedParams, Parameter[] parameters) { |
|||
for (int i = 0; i < args.length; i++) { |
|||
Object arg = args[i]; |
|||
RequestBody requestBodyAnno = parameters[i].getAnnotation(RequestBody.class); |
|||
if (arg != null && requestBodyAnno != null) { |
|||
Object argBean = BeanUtil.mapToBean(storedParams, arg.getClass(), true); |
|||
|
|||
// "pageSize", "pageNo", "isPage"三个属性不从redis拷贝,而是取传递雇来的
|
|||
// redis里面的字段如果是null,则不会赋值给arg
|
|||
BeanUtil.copyProperties(argBean, arg, new CopyOptions(null, true, "pageSize", "pageNo", "isPage")); |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,13 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class ReportHouseTestFormDTO { |
|||
|
|||
private Integer pageNo = 1; |
|||
private Integer pageSize = 20; |
|||
private String id; |
|||
private String test; |
|||
|
|||
} |
@ -0,0 +1,14 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Data; |
|||
import lombok.NoArgsConstructor; |
|||
|
|||
@Data |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class ReportHouseTestResultDTO { |
|||
private String houseId; |
|||
private String doorName; |
|||
private String fullName; |
|||
} |
@ -0,0 +1,45 @@ |
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.tools.annotation.ReportRequest; |
|||
import com.epmet.commons.tools.page.PageData; |
|||
import com.epmet.commons.tools.redis.RedisUtils; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.dto.form.ReportHouseTestFormDTO; |
|||
import com.epmet.dto.result.ReportHouseTestResultDTO; |
|||
import com.epmet.service.HouseService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.HashMap; |
|||
|
|||
@RestController |
|||
@RequestMapping("report") |
|||
public class ReportController { |
|||
|
|||
@Autowired |
|||
private HouseService houseService; |
|||
|
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
/** |
|||
* todo 测试用的 |
|||
* @return |
|||
*/ |
|||
@PostMapping("houses/test") |
|||
@ReportRequest |
|||
public Result<PageData<ReportHouseTestResultDTO>> listHouses(@RequestBody ReportHouseTestFormDTO input) { |
|||
System.out.println("id:"+input.getId()); |
|||
PageData<ReportHouseTestResultDTO> pageData = houseService.listHouses4ReportTest(input.getId(), input.getPageNo(), input.getPageSize()); |
|||
return new Result<PageData<ReportHouseTestResultDTO>>().ok(pageData); |
|||
} |
|||
|
|||
@PostMapping("put") |
|||
public void put() { |
|||
final HashMap<String, Object> m = new HashMap<>(); |
|||
m.put("test", "aaa"); |
|||
|
|||
redisUtils.hMSet("ttt", m); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,65 @@ |
|||
package com.epmet.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
|
|||
/** |
|||
* 客户报表关系表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Data |
|||
public class IcCustomerReportDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 主键 |
|||
*/ |
|||
private String id; |
|||
|
|||
/** |
|||
* 报表id |
|||
*/ |
|||
private String reportId; |
|||
|
|||
/** |
|||
* 客户id |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 删除标识:0.未删除 1.已删除; |
|||
*/ |
|||
private Integer delFlag; |
|||
|
|||
/** |
|||
* 乐观锁 |
|||
*/ |
|||
private Integer revision; |
|||
|
|||
/** |
|||
* 创建人 |
|||
*/ |
|||
private String createdBy; |
|||
|
|||
/** |
|||
* 创建时间=绑定时间 |
|||
*/ |
|||
private Date createdTime; |
|||
|
|||
/** |
|||
* 更新人 |
|||
*/ |
|||
private String updatedBy; |
|||
|
|||
/** |
|||
* 更新时间 |
|||
*/ |
|||
private Date updatedTime; |
|||
|
|||
} |
@ -0,0 +1,64 @@ |
|||
package com.epmet.dto; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
import lombok.Data; |
|||
|
|||
|
|||
/** |
|||
* 报表所属功能表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Data |
|||
public class IcReportFunDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* |
|||
*/ |
|||
private String id; |
|||
|
|||
/** |
|||
* ic_customer_report.id |
|||
*/ |
|||
private String customerReportId; |
|||
|
|||
/** |
|||
* 功能类别来源于字典表key;eg:resi_info,house_info |
|||
*/ |
|||
private String funCategoryKey; |
|||
|
|||
/** |
|||
* 删除标识:0.未删除 1.已删除; |
|||
*/ |
|||
private Integer delFlag; |
|||
|
|||
/** |
|||
* 乐观锁 |
|||
*/ |
|||
private Integer revision; |
|||
|
|||
/** |
|||
* 创建人 |
|||
*/ |
|||
private String createdBy; |
|||
|
|||
/** |
|||
* 创建时间=绑定时间 |
|||
*/ |
|||
private Date createdTime; |
|||
|
|||
/** |
|||
* 更新人 |
|||
*/ |
|||
private String updatedBy; |
|||
|
|||
/** |
|||
* 更新时间 |
|||
*/ |
|||
private Date updatedTime; |
|||
|
|||
} |
@ -0,0 +1,29 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Description |
|||
* @Author yzm |
|||
* @Date 2022/8/8 13:31 |
|||
*/ |
|||
@Data |
|||
public class PreviewReportFormDTO { |
|||
public interface AddUserInternalGroup { |
|||
} |
|||
|
|||
@NotBlank(message = "reportId不能为空", groups = AddUserInternalGroup.class) |
|||
private String reportId; |
|||
@NotBlank(message = "categoryKey不能为空", groups = AddUserInternalGroup.class) |
|||
private String categoryKey; |
|||
private Map<String, Object> paramMap; |
|||
|
|||
@NotBlank(message = "customerId不能为空", groups = AddUserInternalGroup.class) |
|||
private String customerId; |
|||
@NotBlank(message = "staffId不能为空", groups = AddUserInternalGroup.class) |
|||
private String staffId; |
|||
} |
|||
|
@ -0,0 +1,22 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
|
|||
/** |
|||
* 报表批量导出form dto |
|||
*/ |
|||
@Data |
|||
public class ReportBatchExportFormDTO { |
|||
|
|||
//private String token;
|
|||
|
|||
private String paramKey; |
|||
|
|||
@NotBlank(message = "reportId必填") |
|||
private String reportId; |
|||
|
|||
private String id; |
|||
|
|||
} |
@ -0,0 +1,45 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.Valid; |
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/8 14:04 |
|||
* @DESC |
|||
*/ |
|||
@Data |
|||
public class ReportEditFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -2157859106926125470L; |
|||
|
|||
public interface ReportEditForm{} |
|||
|
|||
/** |
|||
* 操作类型,批量操作:add;单个编辑:edit |
|||
*/ |
|||
@NotBlank(message = "type不能为空", groups = ReportEditForm.class) |
|||
private String type; |
|||
|
|||
@NotBlank(message = "reportId不能为空", groups = ReportEditForm.class) |
|||
private String reportId; |
|||
|
|||
@Valid |
|||
private List<CustomerReportEditForm> customerList; |
|||
|
|||
|
|||
@Data |
|||
public static class CustomerReportEditForm implements Serializable{ |
|||
|
|||
private static final long serialVersionUID = 8154093835160706134L; |
|||
|
|||
private List<String> categoryKeys; |
|||
|
|||
@NotBlank(message = "customerId不能为空", groups = ReportEditForm.class) |
|||
private String customerId; |
|||
} |
|||
} |
@ -0,0 +1,21 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/8 15:16 |
|||
* @DESC |
|||
*/ |
|||
@Data |
|||
public class ReportListFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -4459838228433571457L; |
|||
|
|||
private List<String> categoryKeys; |
|||
|
|||
private String customerId; |
|||
} |
@ -0,0 +1,18 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @Description |
|||
* @Author yzm |
|||
* @Date 2022/8/8 13:37 |
|||
*/ |
|||
@Data |
|||
public class PreviewReportResDTO { |
|||
private String reportId; |
|||
/** |
|||
* rediskey格式:customerId:reportId:resiinfo:staffId |
|||
*/ |
|||
private String paramKey; |
|||
} |
|||
|
@ -0,0 +1,94 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* @Author zxc |
|||
* @DateTime 2022/8/8 10:29 |
|||
* @DESC |
|||
*/ |
|||
@Data |
|||
public class ReportResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -5798816843431200300L; |
|||
|
|||
/** |
|||
* 报表名字 |
|||
*/ |
|||
private String reportName; |
|||
|
|||
/** |
|||
* 报表ID |
|||
*/ |
|||
private String reportId; |
|||
|
|||
private Boolean isList; |
|||
|
|||
/** |
|||
* 客户ID |
|||
*/ |
|||
@JsonIgnore |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 客户名字 |
|||
*/ |
|||
@JsonIgnore |
|||
private String customerName; |
|||
|
|||
/** |
|||
* 分类名字 |
|||
*/ |
|||
@JsonIgnore |
|||
private String categoryName; |
|||
|
|||
/** |
|||
* 分类key |
|||
*/ |
|||
@JsonIgnore |
|||
private String categoryKey; |
|||
|
|||
/** |
|||
* 客户信息集合 |
|||
*/ |
|||
private List<CustomerList> customerList; |
|||
|
|||
|
|||
@Data |
|||
public static class CustomerList implements Serializable{ |
|||
|
|||
private static final long serialVersionUID = 7146198312265513418L; |
|||
|
|||
/** |
|||
* 客户ID |
|||
*/ |
|||
private String customerId; |
|||
|
|||
/** |
|||
* 客户名字 |
|||
*/ |
|||
private String customerName; |
|||
|
|||
/** |
|||
* 分类名字 |
|||
*/ |
|||
private String categoryName; |
|||
|
|||
/** |
|||
* 分类key |
|||
*/ |
|||
private String categoryKey; |
|||
} |
|||
|
|||
public ReportResultDTO() { |
|||
this.reportName = ""; |
|||
this.reportId = ""; |
|||
this.isList = false; |
|||
this.customerList = new ArrayList<>(); |
|||
} |
|||
} |
@ -0,0 +1,108 @@ |
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.feignclient.dtos.result.JiMuReportResultDTO; |
|||
import com.epmet.commons.tools.annotation.LoginUser; |
|||
import com.epmet.commons.tools.annotation.ReportRequest; |
|||
import com.epmet.commons.tools.security.dto.TokenDto; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.dto.form.*; |
|||
import com.epmet.dto.result.PreviewReportResDTO; |
|||
import com.epmet.dto.result.ReportResultDTO; |
|||
import com.epmet.service.IcCustomerReportService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.util.HashMap; |
|||
import java.util.List; |
|||
|
|||
|
|||
/** |
|||
* 客户报表关系表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("icCustomerReport") |
|||
public class IcCustomerReportController { |
|||
|
|||
@Autowired |
|||
private IcCustomerReportService icCustomerReportService; |
|||
|
|||
|
|||
/** |
|||
* Desc: 报表集合 |
|||
* @param |
|||
* @author zxc |
|||
* @date 2022/8/8 10:38 |
|||
*/ |
|||
@PostMapping("list") |
|||
public Result<List<ReportResultDTO>> reportList(){ |
|||
return new Result<List<ReportResultDTO>>().ok(icCustomerReportService.reportList()); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 在居民信息或者房屋信息等页面点击填表,存储入参到redis,返给前端key |
|||
* @param tokenDto |
|||
* @param formDTO |
|||
* @return |
|||
*/ |
|||
@PostMapping("preview") |
|||
public Result<PreviewReportResDTO> previewReport(@LoginUser TokenDto tokenDto, @RequestBody PreviewReportFormDTO formDTO) { |
|||
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|||
formDTO.setStaffId(tokenDto.getUserId()); |
|||
ValidatorUtils.validateEntity(formDTO, PreviewReportFormDTO.AddUserInternalGroup.class); |
|||
return new Result<PreviewReportResDTO>().ok(icCustomerReportService.previewReport(formDTO)); |
|||
} |
|||
/** |
|||
* Desc: 报表编辑 |
|||
* @param formDTO |
|||
* @author zxc |
|||
* @date 2022/8/8 14:09 |
|||
*/ |
|||
@PostMapping("edit") |
|||
public Result reportEdit(@RequestBody ReportEditFormDTO formDTO){ |
|||
ValidatorUtils.validateEntity(formDTO, ReportEditFormDTO.ReportEditForm.class); |
|||
icCustomerReportService.reportEdit(formDTO); |
|||
return new Result(); |
|||
} |
|||
|
|||
/** |
|||
* Desc: 居民信息/房屋信息-查询报表 |
|||
* @param formDTO |
|||
* @author zxc |
|||
* @date 2022/8/8 15:20 |
|||
*/ |
|||
@PostMapping("report-list") |
|||
public Result<List<JiMuReportResultDTO>> reportIdAndName(@RequestBody ReportListFormDTO formDTO,@LoginUser TokenDto tokenDto){ |
|||
formDTO.setCustomerId(tokenDto.getCustomerId()); |
|||
return new Result<List<JiMuReportResultDTO>>().ok(icCustomerReportService.reportIdAndName(formDTO)); |
|||
} |
|||
|
|||
/** |
|||
* 批量导出 |
|||
*/ |
|||
@PostMapping("batch-export") |
|||
public void batchExport(@RequestBody ReportBatchExportFormDTO input, HttpServletResponse response) { |
|||
ValidatorUtils.validateEntity(input); |
|||
String reportId = input.getReportId(); |
|||
String paramKey = input.getParamKey(); |
|||
final String id = input.getId(); |
|||
|
|||
icCustomerReportService.batchExport(id, reportId, paramKey, response); |
|||
} |
|||
|
|||
@ReportRequest |
|||
@PostMapping("test") |
|||
public void test(@RequestBody ExportResiUserFormDTO input) { |
|||
|
|||
System.out.println(input); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,70 @@ |
|||
package com.epmet.controller; |
|||
|
|||
import com.epmet.commons.tools.aop.NoRepeatSubmit; |
|||
import com.epmet.commons.tools.page.PageData; |
|||
import com.epmet.commons.tools.utils.Result; |
|||
import com.epmet.commons.tools.validator.AssertUtils; |
|||
import com.epmet.commons.tools.validator.ValidatorUtils; |
|||
import com.epmet.commons.tools.validator.group.AddGroup; |
|||
import com.epmet.commons.tools.validator.group.DefaultGroup; |
|||
import com.epmet.commons.tools.validator.group.UpdateGroup; |
|||
import com.epmet.dto.IcReportFunDTO; |
|||
import com.epmet.service.IcReportFunService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.Map; |
|||
|
|||
|
|||
/** |
|||
* 报表所属功能表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("icReportFun") |
|||
public class IcReportFunController { |
|||
|
|||
@Autowired |
|||
private IcReportFunService icReportFunService; |
|||
|
|||
@RequestMapping("page") |
|||
public Result<PageData<IcReportFunDTO>> page(@RequestParam Map<String, Object> params){ |
|||
PageData<IcReportFunDTO> page = icReportFunService.page(params); |
|||
return new Result<PageData<IcReportFunDTO>>().ok(page); |
|||
} |
|||
|
|||
@RequestMapping(value = "{id}",method = {RequestMethod.POST,RequestMethod.GET}) |
|||
public Result<IcReportFunDTO> get(@PathVariable("id") String id){ |
|||
IcReportFunDTO data = icReportFunService.get(id); |
|||
return new Result<IcReportFunDTO>().ok(data); |
|||
} |
|||
|
|||
@NoRepeatSubmit |
|||
@PostMapping("save") |
|||
public Result save(@RequestBody IcReportFunDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); |
|||
icReportFunService.save(dto); |
|||
return new Result(); |
|||
} |
|||
|
|||
@NoRepeatSubmit |
|||
@PostMapping("update") |
|||
public Result update(@RequestBody IcReportFunDTO dto){ |
|||
//效验数据
|
|||
ValidatorUtils.validateEntity(dto, UpdateGroup.class, DefaultGroup.class); |
|||
icReportFunService.update(dto); |
|||
return new Result(); |
|||
} |
|||
|
|||
@PostMapping("delete") |
|||
public Result delete(@RequestBody String[] ids){ |
|||
//效验数据
|
|||
AssertUtils.isArrayEmpty(ids, "id"); |
|||
icReportFunService.delete(ids); |
|||
return new Result(); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,40 @@ |
|||
package com.epmet.dao; |
|||
|
|||
import com.epmet.commons.mybatis.dao.BaseDao; |
|||
import com.epmet.dto.result.ReportResultDTO; |
|||
import com.epmet.entity.IcCustomerReportEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
import org.apache.ibatis.annotations.Param; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 客户报表关系表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Mapper |
|||
public interface IcCustomerReportDao extends BaseDao<IcCustomerReportEntity> { |
|||
|
|||
/** |
|||
* Desc: 报表集合 |
|||
* @param |
|||
* @author zxc |
|||
* @date 2022/8/8 10:38 |
|||
*/ |
|||
List<ReportResultDTO> reportList(@Param("categoryKeys")List<String> categoryKeys,@Param("customerId")String customerId); |
|||
|
|||
/** |
|||
* Desc: 根据客户IDs获取ids |
|||
* @param customerIds |
|||
* @author zxc |
|||
* @date 2022/8/8 15:39 |
|||
*/ |
|||
List<String> getIdsByCustomer(@Param("customerIds") List<String> customerIds,@Param("reportId") String reportId); |
|||
|
|||
void delCustomerReport(@Param("customerIds") List<String> customerIds,@Param("reportId")String reportId); |
|||
|
|||
void delCustomerReportFun(@Param("reportIds") List<String> reportIds); |
|||
|
|||
} |
@ -0,0 +1,16 @@ |
|||
package com.epmet.dao; |
|||
|
|||
import com.epmet.commons.mybatis.dao.BaseDao; |
|||
import com.epmet.entity.IcReportFunEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 报表所属功能表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Mapper |
|||
public interface IcReportFunDao extends BaseDao<IcReportFunEntity> { |
|||
|
|||
} |
@ -0,0 +1,31 @@ |
|||
package com.epmet.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
/** |
|||
* 客户报表关系表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("ic_customer_report") |
|||
public class IcCustomerReportEntity extends BaseEpmetEntity { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 报表id |
|||
*/ |
|||
private String reportId; |
|||
|
|||
/** |
|||
* 客户id |
|||
*/ |
|||
private String customerId; |
|||
|
|||
} |
@ -0,0 +1,34 @@ |
|||
package com.epmet.entity; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
|
|||
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 报表所属功能表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Data |
|||
@EqualsAndHashCode(callSuper=false) |
|||
@TableName("ic_report_fun") |
|||
public class IcReportFunEntity extends BaseEpmetEntity { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* ic_customer_report.id |
|||
*/ |
|||
private String customerReportId; |
|||
|
|||
/** |
|||
* 功能类别来源于字典表key;eg:resi_info,house_info |
|||
*/ |
|||
private String funCategoryKey; |
|||
|
|||
} |
@ -0,0 +1,55 @@ |
|||
package com.epmet.service; |
|||
|
|||
import com.epmet.commons.feignclient.dtos.result.JiMuReportResultDTO; |
|||
import com.epmet.commons.mybatis.service.BaseService; |
|||
import com.epmet.dto.form.PreviewReportFormDTO; |
|||
import com.epmet.dto.form.ReportEditFormDTO; |
|||
import com.epmet.dto.form.ReportListFormDTO; |
|||
import com.epmet.dto.result.PreviewReportResDTO; |
|||
import com.epmet.dto.result.ReportResultDTO; |
|||
import com.epmet.entity.IcCustomerReportEntity; |
|||
|
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 客户报表关系表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
public interface IcCustomerReportService extends BaseService<IcCustomerReportEntity> { |
|||
|
|||
/** |
|||
* Desc: 报表集合 |
|||
* @param |
|||
* @author zxc |
|||
* @date 2022/8/8 10:38 |
|||
*/ |
|||
List<ReportResultDTO> reportList(); |
|||
|
|||
/** |
|||
* 在居民信息或者房屋信息等页面点击填表,存储入参到redis,返给前端key |
|||
* @param formDTO |
|||
* @return |
|||
*/ |
|||
PreviewReportResDTO previewReport(PreviewReportFormDTO formDTO); |
|||
|
|||
/** |
|||
* Desc: 报表编辑 |
|||
* @param formDTO |
|||
* @author zxc |
|||
* @date 2022/8/8 14:09 |
|||
*/ |
|||
void reportEdit(ReportEditFormDTO formDTO); |
|||
|
|||
/** |
|||
* Desc: 居民信息/房屋信息-查询报表 |
|||
* @param formDTO |
|||
* @author zxc |
|||
* @date 2022/8/8 15:20 |
|||
*/ |
|||
List<JiMuReportResultDTO> reportIdAndName(ReportListFormDTO formDTO); |
|||
|
|||
void batchExport(String bizId, String reportId, String paramKey, HttpServletResponse response); |
|||
} |
@ -0,0 +1,78 @@ |
|||
package com.epmet.service; |
|||
|
|||
import com.epmet.commons.mybatis.service.BaseService; |
|||
import com.epmet.commons.tools.page.PageData; |
|||
import com.epmet.dto.IcReportFunDTO; |
|||
import com.epmet.entity.IcReportFunEntity; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 报表所属功能表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
public interface IcReportFunService extends BaseService<IcReportFunEntity> { |
|||
|
|||
/** |
|||
* 默认分页 |
|||
* |
|||
* @param params |
|||
* @return PageData<IcReportFunDTO> |
|||
* @author generator |
|||
* @date 2022-08-08 |
|||
*/ |
|||
PageData<IcReportFunDTO> page(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 默认查询 |
|||
* |
|||
* @param params |
|||
* @return java.util.List<IcReportFunDTO> |
|||
* @author generator |
|||
* @date 2022-08-08 |
|||
*/ |
|||
List<IcReportFunDTO> list(Map<String, Object> params); |
|||
|
|||
/** |
|||
* 单条查询 |
|||
* |
|||
* @param id |
|||
* @return IcReportFunDTO |
|||
* @author generator |
|||
* @date 2022-08-08 |
|||
*/ |
|||
IcReportFunDTO get(String id); |
|||
|
|||
/** |
|||
* 默认保存 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2022-08-08 |
|||
*/ |
|||
void save(IcReportFunDTO dto); |
|||
|
|||
/** |
|||
* 默认更新 |
|||
* |
|||
* @param dto |
|||
* @return void |
|||
* @author generator |
|||
* @date 2022-08-08 |
|||
*/ |
|||
void update(IcReportFunDTO dto); |
|||
|
|||
/** |
|||
* 批量删除 |
|||
* |
|||
* @param ids |
|||
* @return void |
|||
* @author generator |
|||
* @date 2022-08-08 |
|||
*/ |
|||
void delete(String[] ids); |
|||
} |
@ -0,0 +1,542 @@ |
|||
package com.epmet.service.impl; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.toolkit.IdWorker; |
|||
import com.epmet.commons.feignclient.dtos.JiMuPage; |
|||
import com.epmet.commons.feignclient.dtos.JiMuResult; |
|||
import com.epmet.commons.feignclient.dtos.form.JiMuReportFormDTO; |
|||
import com.epmet.commons.feignclient.dtos.form.JimuReportExportRequestDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JiMuReportDetailResultDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JiMuReportResultDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JimuReportDbDataResultDTO; |
|||
import com.epmet.commons.feignclient.dtos.result.JimuReportFieldTreeResultDTO; |
|||
import com.epmet.commons.feignclient.feigns.JiMuReportOpenFeignClient; |
|||
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.epmet.commons.tools.constant.*; |
|||
import com.epmet.commons.tools.dto.form.DictListFormDTO; |
|||
import com.epmet.commons.tools.dto.result.DictListResultDTO; |
|||
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|||
import com.epmet.commons.tools.exception.EpmetException; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.redis.RedisUtils; |
|||
import com.epmet.commons.tools.utils.*; |
|||
import com.epmet.constant.CustomerFunctionConstant; |
|||
import com.epmet.dao.IcCustomerReportDao; |
|||
import com.epmet.dto.CustomerDTO; |
|||
import com.epmet.dto.form.PreviewReportFormDTO; |
|||
import com.epmet.dto.form.ReportEditFormDTO; |
|||
import com.epmet.dto.form.ReportListFormDTO; |
|||
import com.epmet.dto.result.PreviewReportResDTO; |
|||
import com.epmet.dto.result.ReportResultDTO; |
|||
import com.epmet.entity.IcCustomerReportEntity; |
|||
import com.epmet.entity.IcReportFunEntity; |
|||
import com.epmet.feign.EpmetAdminOpenFeignClient; |
|||
import com.epmet.feign.OperCrmOpenFeignClient; |
|||
import com.epmet.service.IcCustomerReportService; |
|||
import com.epmet.service.IcReportFunService; |
|||
import feign.Response; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.collections4.CollectionUtils; |
|||
import org.apache.commons.collections4.ListUtils; |
|||
import org.apache.commons.io.IOUtils; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.http.HttpHeaders; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
import org.springframework.util.MultiValueMap; |
|||
|
|||
import javax.servlet.ServletOutputStream; |
|||
import javax.servlet.http.HttpServletResponse; |
|||
import java.io.*; |
|||
import java.net.URLEncoder; |
|||
import java.nio.file.Files; |
|||
import java.nio.file.Path; |
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
import java.util.*; |
|||
import java.util.concurrent.CompletableFuture; |
|||
import java.util.concurrent.CountDownLatch; |
|||
import java.util.concurrent.ExecutorService; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
import java.util.stream.Collectors; |
|||
import java.util.zip.ZipEntry; |
|||
import java.util.zip.ZipOutputStream; |
|||
|
|||
/** |
|||
* 客户报表关系表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Service |
|||
@Slf4j |
|||
public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerReportDao, IcCustomerReportEntity> implements IcCustomerReportService { |
|||
@Autowired |
|||
private RedisUtils redisUtils; |
|||
|
|||
@Autowired |
|||
private EpmetAdminOpenFeignClient adminOpenFeignClient; |
|||
@Autowired |
|||
private OperCrmOpenFeignClient operCrmOpenFeignClient; |
|||
@Autowired |
|||
private IcReportFunService reportFunService; |
|||
@Autowired |
|||
private JiMuReportOpenFeignClient jiMuReportOpenFeignClient; |
|||
@Autowired |
|||
private ExecutorService executorService; |
|||
|
|||
|
|||
private QueryWrapper<IcCustomerReportEntity> getWrapper(Map<String, Object> params) { |
|||
String id = (String) params.get(FieldConstant.ID_HUMP); |
|||
|
|||
QueryWrapper<IcCustomerReportEntity> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|||
|
|||
return wrapper; |
|||
} |
|||
|
|||
/** |
|||
* Desc: 报表集合 |
|||
* |
|||
* @param |
|||
* @author zxc |
|||
* @date 2022/8/8 10:38 |
|||
*/ |
|||
@Override |
|||
public List<ReportResultDTO> reportList() { |
|||
String authorization = EpmetRequestHolder.getHeader("Authorization"); |
|||
// 自定义header传递
|
|||
MultiValueMap<String, String> headers = new HttpHeaders(); |
|||
headers.add("token", authorization); |
|||
JiMuResult<JiMuPage<JiMuReportDetailResultDTO>> result = jiMuReportOpenFeignClient.getList(1, 10000, "", "datainfo", authorization, headers); |
|||
if (!result.isSuccess()) { |
|||
throw new EpmetException("获取所有jm报表失败"); |
|||
} |
|||
List<Map<String, Object>> records = (List<Map<String, Object>>) result.getResult().getRecords(); |
|||
List<JiMuReportResultDTO> allReports = new ArrayList<>(); |
|||
for (Map<String, Object> record : records) { |
|||
allReports.add(ConvertUtils.mapToEntity(record, JiMuReportResultDTO.class)); |
|||
} |
|||
if (CollectionUtils.isEmpty(allReports)) { |
|||
return new ArrayList<>(); |
|||
} |
|||
List<ReportResultDTO> allReportList = new ArrayList<>(); |
|||
allReports.forEach(r -> { |
|||
ReportResultDTO dto = new ReportResultDTO(); |
|||
dto.setReportId(r.getId()); |
|||
dto.setReportName(r.getName()); |
|||
allReportList.add(dto); |
|||
}); |
|||
List<ReportResultDTO> reportList = baseDao.reportList(null, null); |
|||
if (CollectionUtils.isEmpty(reportList)) { |
|||
return allReportList; |
|||
} |
|||
Result<List<DictListResultDTO>> dictList = adminOpenFeignClient.dictList(new DictListFormDTO(CustomerFunctionConstant.REPORT_CATEGORY)); |
|||
if (!dictList.success()) { |
|||
throw new EpmetException("查询字典信息失败:" + CustomerFunctionConstant.REPORT_CATEGORY); |
|||
} |
|||
if (CollectionUtils.isNotEmpty(dictList.getData())) { |
|||
dictList.getData().forEach(d -> reportList.stream().filter(r -> d.getValue().equals(r.getCategoryKey())).forEach(r -> r.setCategoryName(d.getLabel()))); |
|||
} |
|||
Result<List<CustomerDTO>> allCustomerList = operCrmOpenFeignClient.getAllCustomerList(); |
|||
if (!allCustomerList.success()) { |
|||
throw new EpmetException("获取客户信息失败..."); |
|||
} |
|||
if (CollectionUtils.isNotEmpty(allCustomerList.getData())) { |
|||
allCustomerList.getData().forEach(c -> reportList.stream().filter(r -> c.getId().equals(r.getCustomerId())).forEach(r -> r.setCustomerName(c.getCustomerName()))); |
|||
} |
|||
Map<String, List<ReportResultDTO>> groupByReport = reportList.stream().collect(Collectors.groupingBy(ReportResultDTO::getReportId)); |
|||
groupByReport.forEach((reportId, l) -> allReportList.stream().filter(a -> a.getReportId().equals(reportId)).forEach(a -> a.setCustomerList(ConvertUtils.sourceToTarget(l, ReportResultDTO.CustomerList.class)))); |
|||
return allReportList; |
|||
} |
|||
|
|||
/** |
|||
* 在居民信息或者房屋信息等页面点击填表,存储入参到redis,返给前端key |
|||
* |
|||
* @param formDTO |
|||
* @return |
|||
*/ |
|||
@Override |
|||
public PreviewReportResDTO previewReport(PreviewReportFormDTO formDTO) { |
|||
// rediskey格式:customerId:reportId:resiinfo:staffId
|
|||
PreviewReportResDTO reportResDTO = new PreviewReportResDTO(); |
|||
reportResDTO.setReportId(formDTO.getReportId()); |
|||
String key = "epmet:jmreport:paramkey:".concat(formDTO.getCustomerId()).concat(StrConstant.COLON).concat(formDTO.getReportId()).concat(StrConstant.COLON).concat(formDTO.getCategoryKey()).concat(StrConstant.COLON).concat(formDTO.getStaffId()); |
|||
redisUtils.hMSet(key, formDTO.getParamMap(), RedisUtils.DEFAULT_EXPIRE); |
|||
reportResDTO.setParamKey(key); |
|||
return reportResDTO; |
|||
} |
|||
|
|||
/** |
|||
* Desc: 报表编辑 |
|||
* |
|||
* @param formDTO |
|||
* @author zxc |
|||
* @date 2022/8/8 14:09 |
|||
*/ |
|||
@Transactional(rollbackFor = Exception.class) |
|||
@Override |
|||
public void reportEdit(ReportEditFormDTO formDTO) { |
|||
List<String> reportIds = new ArrayList<>(); |
|||
if (CollectionUtils.isNotEmpty(formDTO.getCustomerList())) { |
|||
reportIds = baseDao.getIdsByCustomer(formDTO.getCustomerList().stream().map(m -> m.getCustomerId()).collect(Collectors.toList()), formDTO.getReportId()); |
|||
} |
|||
if (formDTO.getType().equals(CustomerFunctionConstant.REPORT_EDIT)) { |
|||
// 单个编辑
|
|||
baseDao.delCustomerReport(Arrays.asList(formDTO.getCustomerList().get(NumConstant.ZERO).getCustomerId()), formDTO.getReportId()); |
|||
} else if (formDTO.getType().equals(CustomerFunctionConstant.REPORT_ADD)) { |
|||
baseDao.delCustomerReport(null, formDTO.getReportId()); |
|||
} |
|||
if (CollectionUtils.isNotEmpty(reportIds)) { |
|||
baseDao.delCustomerReportFun(reportIds); |
|||
} |
|||
if (CollectionUtils.isNotEmpty(formDTO.getCustomerList())) { |
|||
List<IcCustomerReportEntity> entities = new ArrayList<>(); |
|||
List<IcReportFunEntity> funEntities = new ArrayList<>(); |
|||
formDTO.getCustomerList().forEach(c -> { |
|||
IcCustomerReportEntity reportEntity = new IcCustomerReportEntity(); |
|||
reportEntity.setReportId(formDTO.getReportId()); |
|||
reportEntity.setCustomerId(c.getCustomerId()); |
|||
reportEntity.setId(IdWorker.getIdStr()); |
|||
if (CollectionUtils.isNotEmpty(c.getCategoryKeys())) { |
|||
c.getCategoryKeys().forEach(key -> { |
|||
IcReportFunEntity funEntity = new IcReportFunEntity(); |
|||
funEntity.setCustomerReportId(reportEntity.getId()); |
|||
funEntity.setFunCategoryKey(key); |
|||
funEntities.add(funEntity); |
|||
}); |
|||
} |
|||
entities.add(reportEntity); |
|||
}); |
|||
insetCustomerReportAndFun(entities, funEntities); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* Desc: 居民信息/房屋信息-查询报表 |
|||
* |
|||
* @param formDTO |
|||
* @author zxc |
|||
* @date 2022/8/8 15:20 |
|||
*/ |
|||
@Override |
|||
public List<JiMuReportResultDTO> reportIdAndName(ReportListFormDTO formDTO) { |
|||
List<ReportResultDTO> reportList = baseDao.reportList(formDTO.getCategoryKeys(), formDTO.getCustomerId()); |
|||
if (CollectionUtils.isEmpty(reportList)) { |
|||
return new ArrayList<>(); |
|||
} |
|||
List<String> recordIds = reportList.stream().map(m -> m.getReportId()).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList()); |
|||
List<JiMuReportResultDTO> result = new ArrayList<>(); |
|||
recordIds.forEach(r -> { |
|||
JiMuReportFormDTO form = new JiMuReportFormDTO(); |
|||
form.setId(r); |
|||
String authorization = EpmetRequestHolder.getHeader("Authorization"); |
|||
// 自定义header传递
|
|||
MultiValueMap<String, String> headers = new HttpHeaders(); |
|||
headers.add("token", authorization); |
|||
headers.add("Authorization", authorization); |
|||
JiMuResult<Map<String, Object>> report = jiMuReportOpenFeignClient.getReport(r, "", "", headers); |
|||
if (!report.isSuccess()) { |
|||
throw new EpmetException("获取jm报表详情失败:" + r); |
|||
} |
|||
JiMuReportResultDTO data = ConvertUtils.mapToEntity(report.getResult(), JiMuReportResultDTO.class); |
|||
JiMuResult<JimuReportDbDataResultDTO> reportDbDataResultDTOJiMuResult = jiMuReportOpenFeignClient.loadDbData(r); |
|||
if (!reportDbDataResultDTOJiMuResult.isSuccess()){ |
|||
throw new EpmetException("获取报表dbData失败:"+r); |
|||
} |
|||
log.info(JSON.toJSONString(reportDbDataResultDTOJiMuResult)); |
|||
JimuReportDbDataResultDTO.ReportDB reportDb = reportDbDataResultDTOJiMuResult.getResult().getReportDb(); |
|||
if (null != reportDb){ |
|||
data.setIsList(reportDb.getIsList().equals(NumConstant.ONE_STR)); |
|||
} |
|||
data.setReportId(data.getId()); |
|||
data.setReportName(data.getName()); |
|||
result.add(data); |
|||
}); |
|||
return result; |
|||
} |
|||
|
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void insetCustomerReportAndFun(List<IcCustomerReportEntity> reportEntities, List<IcReportFunEntity> funEntities) { |
|||
if (CollectionUtils.isNotEmpty(reportEntities)) { |
|||
insertBatch(reportEntities); |
|||
} |
|||
if (CollectionUtils.isNotEmpty(funEntities)) { |
|||
reportFunService.insertBatch(funEntities); |
|||
} |
|||
} |
|||
|
|||
@Override |
|||
public void batchExport(String bizId, String reportId, String paramKey, HttpServletResponse response) { |
|||
|
|||
// 1. 首先去积木服务,查询出报表数据源的详细信息,包括报表url,isList;获取到哪一列是id(idFieldName)
|
|||
|
|||
// 根据报表id查询数据源列表,取出第一个
|
|||
JiMuResult<List<List<JimuReportFieldTreeResultDTO>>> fResult = jiMuReportOpenFeignClient.fieldTree(reportId); |
|||
String datasourceId = fResult.getResult().get(0).get(0).getDbId(); |
|||
|
|||
// 根据数据源ID查询数据源信息
|
|||
JiMuResult<JimuReportDbDataResultDTO> dbData = jiMuReportOpenFeignClient.loadDbData(datasourceId); |
|||
JimuReportDbDataResultDTO.ReportDB reportDb = dbData.getResult().getReportDb(); |
|||
|
|||
// api的url
|
|||
String apiUrl = reportDb.getApiUrl(); |
|||
// api方法
|
|||
//String apiMethod = reportDb.getApiMethod();
|
|||
// 是否是集合
|
|||
//String isList = reportDb.getIsList();
|
|||
// 返回的列表中,哪个字段是ID
|
|||
String idFieldName = null; |
|||
boolean isHttps = false; |
|||
|
|||
Matcher matcher = Pattern.compile("(http://|https://).+idFieldName=(\\w+).*").matcher(apiUrl); |
|||
if (matcher.matches()) { |
|||
String proto = matcher.group(1); |
|||
if ("https://".equals(proto)) { |
|||
isHttps = true; |
|||
} |
|||
idFieldName = matcher.group(2); |
|||
} |
|||
|
|||
if (StringUtils.isBlank(idFieldName)) { |
|||
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), "配置的业务api url缺少idFieldName列"); |
|||
} |
|||
|
|||
// 2. 调用该url的接口,获取到一个列表,根据idFieldName取出ID列
|
|||
List<String> ids = listIds(bizId, paramKey, apiUrl, isHttps, idFieldName); |
|||
|
|||
// 3. 然后以这一列作为查询条件,循环,继续调用该接口,得到单条数据,每一条数据都下载一个excel,最后将其打包为一个压缩包下载
|
|||
Path storePath = makeTemporaryDownloadDir(reportId); |
|||
|
|||
// 4.生成压缩文件
|
|||
Path zipFile = downloadAndComppress(storePath, reportId, reportDb.getDbChName(), paramKey, ids); |
|||
|
|||
// 5.下载
|
|||
try (FileInputStream fis = new FileInputStream(zipFile.toFile())) { |
|||
ServletOutputStream os = response.getOutputStream(); |
|||
response.setCharacterEncoding("UTF-8"); |
|||
response.setHeader("content-Type", "application/zip"); |
|||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(zipFile.getFileName().toString(), "UTF-8")); |
|||
|
|||
IOUtils.copy(fis, os); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} finally { |
|||
try { |
|||
Files.delete(zipFile); |
|||
} catch (IOException e) { |
|||
log.error("【报表批量导出】删除临时zip文件失败"); |
|||
} |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 批量下载 |
|||
* @param storePath 本次导出文件的存储路径,子目录包括:zip文件,时间戳命名的子目录用于存放临时excel(导出完成会删掉) |
|||
* @param ids |
|||
* @return 压缩文件路径 |
|||
*/ |
|||
private Path downloadAndComppress(Path storePath, String reportId, String reportName, String paramKey, List<String> ids) { |
|||
// 请求头
|
|||
Map<String, Object> headers = new HashMap<>(); |
|||
headers.put(Constant.AUTHORIZATION_HEADER, EpmetRequestHolder.getHeader(Constant.AUTHORIZATION_HEADER)); |
|||
|
|||
// 请求体
|
|||
JimuReportExportRequestDTO param = new JimuReportExportRequestDTO(); |
|||
param.setExcelConfigId(reportId); |
|||
param.getQueryParam().setCurrentPageNo("1"); |
|||
param.getQueryParam().setCurrentPageSize(20); |
|||
param.getQueryParam().setPageNo("1"); |
|||
param.getQueryParam().setPageSize(20); |
|||
param.getQueryParam().setParamKey(paramKey); |
|||
param.getQueryParam().setToken(EpmetRequestHolder.getLoginUserAuthorizationToken()); |
|||
|
|||
ArrayList<File> files = new ArrayList<>(); |
|||
|
|||
String currentTimeStr = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss")); |
|||
|
|||
// 创建存放xlsx的临时目录
|
|||
Path xlsxStorePath = storePath.resolve(currentTimeStr); |
|||
try { |
|||
Files.createDirectories(xlsxStorePath); |
|||
} catch (IOException e) { |
|||
throw new EpmetException("【报表批量导出】生成临时目录失败:" + xlsxStorePath.toString()); |
|||
} |
|||
|
|||
// 将所有id分片,交给多个线程并行处理
|
|||
List<List<String>> idParts = ListUtils.partition(ids, 100); |
|||
|
|||
// 1. 循环下载所有id对应的excel
|
|||
CountDownLatch cdl = new CountDownLatch(idParts.size()); |
|||
for (List<String> idPart : idParts) { |
|||
CompletableFuture.runAsync(() -> { |
|||
downloadXlsByBatchByBizId(reportId, idPart, param, xlsxStorePath, files, cdl); |
|||
}, executorService); |
|||
} |
|||
|
|||
// 等待多线程执行完成,再执行打包
|
|||
try { |
|||
cdl.await(); |
|||
} catch (InterruptedException e) { |
|||
log.error(ExceptionUtils.getErrorStackTrace(e)); |
|||
throw new EpmetException("【报表批量导出】CountDownLatch等待被中断"); |
|||
} |
|||
|
|||
// 2,打包
|
|||
Path zipFile = storePath.resolve(reportName + "_" + currentTimeStr + ".zip"); |
|||
try (final FileOutputStream fos = new FileOutputStream(zipFile.toFile()); |
|||
final ZipOutputStream zos = new ZipOutputStream(fos)) { |
|||
|
|||
// 循环每一个文件
|
|||
for (File file : files) { |
|||
try (final FileInputStream fis = new FileInputStream(file.getAbsolutePath())) { |
|||
zos.putNextEntry(new ZipEntry(reportName + "_" + currentTimeStr + "/" + file.getName())); |
|||
final byte[] buffer = new byte[10240]; |
|||
for (int len; (len = fis.read(buffer)) > 0; ) { |
|||
zos.write(buffer, 0, len); |
|||
} |
|||
} finally { |
|||
zos.closeEntry(); |
|||
} |
|||
} |
|||
|
|||
zos.flush(); |
|||
} catch (Exception e) { |
|||
log.error("【报表批量导出】压缩文件失败,错误信息:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "压缩失败", "压缩失败"); |
|||
} finally { |
|||
// 删除临时文件
|
|||
cleanTemporaryFiles(storePath.resolve(currentTimeStr)); |
|||
} |
|||
|
|||
return zipFile; |
|||
} |
|||
|
|||
/** |
|||
* 批量下载xlsx |
|||
* @param reportId |
|||
* @param bizIds |
|||
* @param param |
|||
* @param xlsxStorePath |
|||
* @param files |
|||
*/ |
|||
public void downloadXlsByBatchByBizId(String reportId, List<String> bizIds, JimuReportExportRequestDTO param, Path xlsxStorePath, ArrayList<File> files, |
|||
CountDownLatch cdl) { |
|||
for (String id : bizIds) { |
|||
|
|||
try { |
|||
Thread.sleep(200l); |
|||
} catch (InterruptedException e) { |
|||
final String errorMsg = ExceptionUtils.getErrorStackTrace(e); |
|||
log.error("【报表批量导出】循环导出-请求jmreport,等待过程中睡眠发生意外:{}", errorMsg); |
|||
} |
|||
|
|||
//if (!Arrays.asList("1501821697823608834","1501821694665297922","1501821695114088450","1501821695177003009","1501821695269277697","1501821695344775169","1501821695579656193","1501821695676125186","1501821695755816962","1501821695843897346","1501821695978115074","1501821696108138497","1501821696179441665","1501821696229773313","1501821696284299266","1501821696334630913","1501821696393351170","1501821696452071426","1501821696502403073","1501821696582094849","1501821696645009409","1501821696758255617","1501821696871501826","1501821696917639169","1501821696955387906","1501821696993136641","1501821697135742977","1501821697181880321","1501821697232211969","1501821697274155009").contains(id)) {
|
|||
// continue;
|
|||
//}
|
|||
|
|||
param.getQueryParam().setId(id); |
|||
final Response response = jiMuReportOpenFeignClient.exportAllExcelStream(param); |
|||
// 取出文件后缀
|
|||
final LinkedList<String> header = (LinkedList) response.headers().get("content-disposition"); |
|||
final Matcher matcher = Pattern.compile("attachment;filename=(.+)(.xls|.xlsx)").matcher(header.get(0)); |
|||
if (!matcher.matches()) { |
|||
log.error("【报表批量导出】批量导出失败,后缀不匹配。文件名:{}, 报表ID:{}, 业务数据ID:{}", header.get(0), reportId, id); |
|||
continue; |
|||
} |
|||
|
|||
final File excelFile = xlsxStorePath.resolve("file_" + id + matcher.group(2)).toFile(); |
|||
|
|||
files.add(excelFile); |
|||
try (FileOutputStream fos = new FileOutputStream(excelFile)) { |
|||
IOUtils.copy(response.body().asInputStream(), fos); |
|||
} catch (Exception e) { |
|||
log.error("【报表批量导出】生成临时表格文件失败,文件名:{},报表ID:{}, 业务数据ID:{},错误信息:{}", header.get(0), reportId, id, ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
} |
|||
|
|||
cdl.countDown(); |
|||
} |
|||
|
|||
/** |
|||
* 清理临时保存文件 |
|||
*/ |
|||
private void cleanTemporaryFiles(Path tempStorePath) { |
|||
// 删除内部文件
|
|||
for (File file : tempStorePath.toFile().listFiles()) { |
|||
try { |
|||
Files.delete(file.toPath()); |
|||
} catch (IOException e) { |
|||
log.error("【报表批量导出】删除临时文件失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), null, null); |
|||
} |
|||
} |
|||
|
|||
// 删除文件夹
|
|||
try { |
|||
Files.delete(tempStorePath); |
|||
} catch (IOException e) { |
|||
log.error("【报表批量导出】删除临时目录失败:{}", ExceptionUtils.getErrorStackTrace(e)); |
|||
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), null, null); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 创建临时目录 |
|||
* |
|||
* @param reportId |
|||
* @return |
|||
*/ |
|||
private Path makeTemporaryDownloadDir(String reportId) { |
|||
|
|||
String userId = EpmetRequestHolder.getLoginUserId(); |
|||
try { |
|||
return FileUtils.getAndCreateDirUnderEpmetFilesDir("report/batch_export/", reportId, userId); |
|||
} catch (IOException e) { |
|||
throw new EpmetException("报表】批量导出-创建临时目录失败,错误信息:" + ExceptionUtils.getErrorStackTrace(e)); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* 列出id列表,批量下载用 |
|||
* |
|||
* @param apiUrl |
|||
* @param isHttps |
|||
* @param idFieldName |
|||
* @return |
|||
*/ |
|||
public List<String> listIds(String id, String paramKey, String apiUrl, boolean isHttps, String idFieldName) { |
|||
apiUrl = apiUrl.replace("'${id}'", id == null ? "" : id); |
|||
apiUrl = apiUrl.replace("'${paramKey}'", paramKey); |
|||
|
|||
Map<String, Object> headers = new HashMap<>(); |
|||
headers.put(Constant.AUTHORIZATION_HEADER, EpmetRequestHolder.getHeader(Constant.AUTHORIZATION_HEADER)); |
|||
Result<String> stringResult = HttpClientManager.getInstance().sendPost(apiUrl, isHttps, "{\"id\":" + id + "}", headers); |
|||
|
|||
JSONObject dataJsonObject = JSON.parseObject(stringResult.getData()); |
|||
Object data = dataJsonObject.get("data"); |
|||
|
|||
JSONArray array = new JSONArray(); |
|||
ArrayList<String> ids = new ArrayList<>(); |
|||
|
|||
if (data instanceof JSONObject) { |
|||
// 这种可能是pageData的
|
|||
JSONObject jo = (JSONObject) data; |
|||
array = jo.getJSONArray("list"); |
|||
} else { |
|||
// 可能是不分页的列表
|
|||
array = (JSONArray) data; |
|||
} |
|||
|
|||
for (ListIterator<Object> it = array.listIterator(); it.hasNext(); ) { |
|||
JSONObject e = (JSONObject) it.next(); |
|||
ids.add(e.getString(idFieldName)); |
|||
} |
|||
return ids; |
|||
} |
|||
} |
@ -0,0 +1,82 @@ |
|||
package com.epmet.service.impl; |
|||
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|||
import com.baomidou.mybatisplus.core.metadata.IPage; |
|||
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.epmet.commons.tools.constant.FieldConstant; |
|||
import com.epmet.commons.tools.page.PageData; |
|||
import com.epmet.commons.tools.utils.ConvertUtils; |
|||
import com.epmet.dao.IcReportFunDao; |
|||
import com.epmet.dto.IcReportFunDTO; |
|||
import com.epmet.entity.IcReportFunEntity; |
|||
import com.epmet.service.IcReportFunService; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.transaction.annotation.Transactional; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 报表所属功能表 |
|||
* |
|||
* @author generator generator@elink-cn.com |
|||
* @since v1.0.0 2022-08-08 |
|||
*/ |
|||
@Service |
|||
public class IcReportFunServiceImpl extends BaseServiceImpl<IcReportFunDao, IcReportFunEntity> implements IcReportFunService { |
|||
|
|||
@Override |
|||
public PageData<IcReportFunDTO> page(Map<String, Object> params) { |
|||
IPage<IcReportFunEntity> page = baseDao.selectPage( |
|||
getPage(params, FieldConstant.CREATED_TIME, false), |
|||
getWrapper(params) |
|||
); |
|||
return getPageData(page, IcReportFunDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
public List<IcReportFunDTO> list(Map<String, Object> params) { |
|||
List<IcReportFunEntity> entityList = baseDao.selectList(getWrapper(params)); |
|||
|
|||
return ConvertUtils.sourceToTarget(entityList, IcReportFunDTO.class); |
|||
} |
|||
|
|||
private QueryWrapper<IcReportFunEntity> getWrapper(Map<String, Object> params){ |
|||
String id = (String)params.get(FieldConstant.ID_HUMP); |
|||
|
|||
QueryWrapper<IcReportFunEntity> wrapper = new QueryWrapper<>(); |
|||
wrapper.eq(StringUtils.isNotBlank(id), FieldConstant.ID, id); |
|||
|
|||
return wrapper; |
|||
} |
|||
|
|||
@Override |
|||
public IcReportFunDTO get(String id) { |
|||
IcReportFunEntity entity = baseDao.selectById(id); |
|||
return ConvertUtils.sourceToTarget(entity, IcReportFunDTO.class); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void save(IcReportFunDTO dto) { |
|||
IcReportFunEntity entity = ConvertUtils.sourceToTarget(dto, IcReportFunEntity.class); |
|||
insert(entity); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void update(IcReportFunDTO dto) { |
|||
IcReportFunEntity entity = ConvertUtils.sourceToTarget(dto, IcReportFunEntity.class); |
|||
updateById(entity); |
|||
} |
|||
|
|||
@Override |
|||
@Transactional(rollbackFor = Exception.class) |
|||
public void delete(String[] ids) { |
|||
// 逻辑删除(@TableLogic 注解)
|
|||
baseDao.deleteBatchIds(Arrays.asList(ids)); |
|||
} |
|||
|
|||
} |
@ -0,0 +1,12 @@ |
|||
CREATE TABLE `ic_customer_report` ( |
|||
`ID` varchar(64) NOT NULL COMMENT '主键', |
|||
`REPORT_ID` varchar(64) NOT NULL COMMENT '报表id', |
|||
`CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户id', |
|||
`DEL_FLAG` int(11) NOT NULL COMMENT '删除标识:0.未删除 1.已删除;', |
|||
`REVISION` int(11) NOT NULL COMMENT '乐观锁', |
|||
`CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', |
|||
`CREATED_TIME` datetime NOT NULL COMMENT '创建时间=绑定时间', |
|||
`UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', |
|||
`UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', |
|||
PRIMARY KEY (`ID`) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='客户报表关系表'; |
@ -0,0 +1,12 @@ |
|||
CREATE TABLE `ic_report_fun` ( |
|||
`ID` varchar(64) NOT NULL, |
|||
`CUSTOMER_REPORT_ID` varchar(64) NOT NULL COMMENT 'ic_customer_report.id', |
|||
`FUN_CATEGORY_KEY` varchar(255) NOT NULL COMMENT '功能类别来源于字典表key;eg:resi_info,house_info', |
|||
`DEL_FLAG` int(11) NOT NULL COMMENT '删除标识:0.未删除 1.已删除;', |
|||
`REVISION` int(11) NOT NULL COMMENT '乐观锁', |
|||
`CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', |
|||
`CREATED_TIME` datetime NOT NULL COMMENT '创建时间=绑定时间', |
|||
`UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', |
|||
`UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', |
|||
PRIMARY KEY (`ID`) |
|||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='报表所属功能表'; |
@ -0,0 +1,61 @@ |
|||
<?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="com.epmet.dao.IcCustomerReportDao"> |
|||
|
|||
<delete id="delCustomerReport"> |
|||
DELETE FROM ic_customer_report |
|||
WHERE REPORT_ID = #{reportId} |
|||
<if test="null != customerIds and customerIds.size() > 0"> |
|||
AND CUSTOMER_ID IN ( |
|||
<foreach collection="customerIds" item="c" separator=","> |
|||
#{c} |
|||
</foreach> |
|||
) |
|||
</if> |
|||
</delete> |
|||
<delete id="delCustomerReportFun"> |
|||
DELETE FROM ic_report_fun |
|||
<if test="null != reportIds and reportIds.size() > 0"> |
|||
WHERE CUSTOMER_REPORT_ID IN ( |
|||
<foreach collection="reportIds" item="r" separator=","> |
|||
#{r} |
|||
</foreach> |
|||
) |
|||
</if> |
|||
</delete> |
|||
|
|||
<!-- 报表集合 --> |
|||
<select id="reportList" resultType="com.epmet.dto.result.ReportResultDTO"> |
|||
SELECT |
|||
cr.REPORT_ID, |
|||
cr.CUSTOMER_ID, |
|||
rf.FUN_CATEGORY_KEY AS categoryKey |
|||
FROM ic_customer_report cr |
|||
INNER JOIN ic_report_fun rf ON rf.CUSTOMER_REPORT_ID = cr.ID AND rf.DEL_FLAG = 0 |
|||
WHERE cr.DEL_FLAG = 0 |
|||
<if test="null != categoryKeys and categoryKeys.size() > 0"> |
|||
AND rf.FUN_CATEGORY_KEY in ( |
|||
<foreach collection="categoryKeys" item="r" separator=","> |
|||
#{r} |
|||
</foreach> |
|||
) |
|||
</if> |
|||
<if test='customerId != null and customerId != ""'> |
|||
AND cr.CUSTOMER_ID = #{customerId} |
|||
</if> |
|||
ORDER BY cr.CREATED_TIME DESC |
|||
</select> |
|||
|
|||
<!-- 根据客户IDs获取ids --> |
|||
<select id="getIdsByCustomer" resultType="java.lang.String"> |
|||
SELECT ID FROM ic_customer_report |
|||
WHERE DEL_FLAG = 0 |
|||
AND REPORT_ID = #{reportId} |
|||
AND CUSTOMER_ID IN ( |
|||
<foreach collection="customerIds" item="c" separator=","> |
|||
#{c} |
|||
</foreach> |
|||
) |
|||
</select> |
|||
</mapper> |
@ -0,0 +1,6 @@ |
|||
<?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="com.epmet.dao.IcReportFunDao"> |
|||
|
|||
</mapper> |
@ -0,0 +1,23 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
/** |
|||
* @Description |
|||
* @Author yzm |
|||
* @Date 2022/8/17 11:13 |
|||
*/ |
|||
@Data |
|||
public class ReportDataFormDTO { |
|||
/** |
|||
* 客户Id |
|||
*/ |
|||
private String customerId; |
|||
/** |
|||
* pageNo 报表用的 |
|||
*/ |
|||
private Integer pageNo = 1; |
|||
private Integer pageSize = 1000; |
|||
private String id; |
|||
} |
|||
|
Loading…
Reference in new issue