Browse Source

Merge remote-tracking branch 'origin/dev_jmreport' into dev_jmreport

master
yinzuomei 3 years ago
parent
commit
127c10d6cb
  1. 13
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/annotation/ReportRequest.java
  2. 83
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/ReportRequestAspect.java
  3. 33
      epmet-module/oper-customize/oper-customize-client/src/main/java/com/epmet/dto/form/ReportEditFormDTO.java
  4. 29
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/IcCustomerReportController.java
  5. 11
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/IcCustomerReportService.java
  6. 14
      epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/IcCustomerReportServiceImpl.java

13
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/annotation/ReportRequest.java

@ -0,0 +1,13 @@
package com.epmet.commons.tools.annotation;
import java.lang.annotation.*;
/**
* 标记一个接口它会被报表服务所调用
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ReportRequest {
}

83
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aspect/ReportRequestAspect.java

@ -0,0 +1,83 @@
package com.epmet.commons.tools.aspect;
import cn.hutool.core.bean.BeanUtil;
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];
Class<?> argClazz = arg.getClass();
RequestBody requestBodyAnno = parameters[i].getAnnotation(RequestBody.class);
if (arg != null && requestBodyAnno != null) {
Object argBean = BeanUtil.mapToBean(storedParams, arg.getClass(), true);
BeanUtil.copyProperties(argBean, arg);
return;
}
}
}
}

33
epmet-module/oper-customize/oper-customize-client/src/main/java/com/epmet/dto/form/ReportEditFormDTO.java

@ -0,0 +1,33 @@
package com.epmet.dto.form;
import lombok.Data;
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;
private List<String> customerIds;
private List<String> categoryKeys;
}

29
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/controller/IcCustomerReportController.java

@ -1,25 +1,21 @@
package com.epmet.controller;
import com.epmet.commons.tools.annotation.LoginUser;
import com.epmet.commons.tools.aop.NoRepeatSubmit;
import com.epmet.commons.tools.page.PageData;
import com.epmet.commons.tools.security.dto.TokenDto;
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.IcCustomerReportDTO;
import com.epmet.dto.result.ReportResultDTO;
import com.epmet.dto.form.PreviewReportFormDTO;
import com.epmet.dto.form.ReportEditFormDTO;
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.*;
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 java.util.List;
import java.util.Map;
/**
@ -61,4 +57,17 @@ public class IcCustomerReportController {
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();
}
}

11
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/IcCustomerReportService.java

@ -3,6 +3,9 @@ package com.epmet.service;
import com.epmet.commons.mybatis.service.BaseService;
import com.epmet.dto.form.PreviewReportFormDTO;
import com.epmet.dto.result.PreviewReportResDTO;
import com.epmet.commons.tools.page.PageData;
import com.epmet.dto.IcCustomerReportDTO;
import com.epmet.dto.form.ReportEditFormDTO;
import com.epmet.dto.result.ReportResultDTO;
import com.epmet.entity.IcCustomerReportEntity;
@ -30,4 +33,12 @@ public interface IcCustomerReportService extends BaseService<IcCustomerReportEnt
* @return
*/
PreviewReportResDTO previewReport(PreviewReportFormDTO formDTO);
/**
* Desc: 报表编辑
* @param formDTO
* @author zxc
* @date 2022/8/8 14:09
*/
void reportEdit(ReportEditFormDTO formDTO);
}

14
epmet-module/oper-customize/oper-customize-server/src/main/java/com/epmet/service/impl/IcCustomerReportServiceImpl.java

@ -16,6 +16,8 @@ import com.epmet.dao.IcCustomerReportDao;
import com.epmet.dto.CustomerDTO;
import com.epmet.dto.form.PreviewReportFormDTO;
import com.epmet.dto.result.PreviewReportResDTO;
import com.epmet.dto.IcCustomerReportDTO;
import com.epmet.dto.form.ReportEditFormDTO;
import com.epmet.dto.result.ReportResultDTO;
import com.epmet.entity.IcCustomerReportEntity;
import com.epmet.feign.EpmetAdminOpenFeignClient;
@ -113,4 +115,16 @@ public class IcCustomerReportServiceImpl extends BaseServiceImpl<IcCustomerRepor
return reportResDTO;
}
/**
* Desc: 报表编辑
* @param formDTO
* @author zxc
* @date 2022/8/8 14:09
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void reportEdit(ReportEditFormDTO formDTO) {
}
}
Loading…
Cancel
Save