163 lines
5.9 KiB
Plaintext
163 lines
5.9 KiB
Plaintext
|
|
package com.sercurityControl.proteam.callInterface.controller;
|
||
|
|
|
||
|
|
import com.alibaba.fastjson2.JSONObject;
|
||
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
||
|
|
import com.github.pagehelper.PageHelper;
|
||
|
|
import com.github.pagehelper.PageInfo;
|
||
|
|
import com.securityControl.common.core.utils.AESCBCUtils;
|
||
|
|
import com.securityControl.common.core.utils.StringUtils;
|
||
|
|
import com.sercurityControl.proteam.callInterface.domain.TeamEvaDto;
|
||
|
|
import com.sercurityControl.proteam.callInterface.domain.TeamEvaVo;
|
||
|
|
import com.sercurityControl.proteam.callInterface.service.CallInterfaceService;
|
||
|
|
import com.sercurityControl.proteam.util.DateTimeHelper;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.slf4j.Logger;
|
||
|
|
import org.slf4j.LoggerFactory;
|
||
|
|
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.annotation.Resource;
|
||
|
|
import java.lang.reflect.Field;
|
||
|
|
import java.lang.reflect.Method;
|
||
|
|
import java.util.HashMap;
|
||
|
|
import java.util.List;
|
||
|
|
import java.util.Map;
|
||
|
|
import java.util.Objects;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 第三方调用接口web层
|
||
|
|
*/
|
||
|
|
@RestController
|
||
|
|
@RequestMapping("/pot/api")
|
||
|
|
@Slf4j
|
||
|
|
public class CallInterfaceController {
|
||
|
|
|
||
|
|
Logger logger = LoggerFactory.getLogger(CallInterfaceController.class);
|
||
|
|
|
||
|
|
|
||
|
|
@Resource(name = "CallInterfaceService")
|
||
|
|
private CallInterfaceService service;
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return com.securityControl.common.core.web.domain.AjaxResult
|
||
|
|
* @author cw chen
|
||
|
|
* @description 获取班组评价数据
|
||
|
|
* @Param bean
|
||
|
|
* @date 2023-06-06 10:29
|
||
|
|
*/
|
||
|
|
@PostMapping("getTeamEvaList")
|
||
|
|
public Map<String, Object> getTeamEvaList(@RequestBody TeamEvaDto dto) {
|
||
|
|
Map<String, Object> map = new HashMap<>(16);
|
||
|
|
try {
|
||
|
|
boolean flag = verifyParam(dto);
|
||
|
|
if(!flag){
|
||
|
|
map.put("code", 500);
|
||
|
|
map.put("msg", "参数未加密");
|
||
|
|
}else{
|
||
|
|
TeamEvaDto teamEvaDto = setValue(dto);
|
||
|
|
PageHelper.startPage(Integer.parseInt(teamEvaDto.getPage()), Integer.parseInt(teamEvaDto.getLimit()));
|
||
|
|
PageInfo<TeamEvaVo> pageInfo = service.getTeamEvaList(teamEvaDto);
|
||
|
|
List<TeamEvaVo> list = pageInfo.getList();
|
||
|
|
if(CollectionUtils.isNotEmpty(list)){
|
||
|
|
// JSONObject jsonObject = new JSONObject();
|
||
|
|
String jsonStrList = JSONObject.toJSONString(list);
|
||
|
|
map.put("data", AESCBCUtils.encrypt(jsonStrList, AESCBCUtils.sKey));
|
||
|
|
}else{
|
||
|
|
map.put("data",list);
|
||
|
|
}
|
||
|
|
map.put("code", 200);
|
||
|
|
map.put("msg", "获取数据成功");
|
||
|
|
map.put("total", pageInfo.getTotal());
|
||
|
|
}
|
||
|
|
} catch (Exception e) {
|
||
|
|
logger.error("服务异常,请稍后重试", e);
|
||
|
|
map.put("code", 500);
|
||
|
|
map.put("msg", "服务异常,请稍后重试");
|
||
|
|
}
|
||
|
|
return map;
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return java.lang.String
|
||
|
|
* @author cw chen
|
||
|
|
* @description 解析参数
|
||
|
|
* @Param value
|
||
|
|
* @date 2023-06-07 15:05
|
||
|
|
*/
|
||
|
|
public String decryptString(String value) {
|
||
|
|
if (StringUtils.isNotBlank(value)) {
|
||
|
|
try {
|
||
|
|
return AESCBCUtils.decrypt(value);
|
||
|
|
} catch (Exception e) {
|
||
|
|
logger.error("参数未加密", e);
|
||
|
|
return "error";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return boolean
|
||
|
|
* @author cw chen
|
||
|
|
* @description 校验班组评价参数是否加密
|
||
|
|
* @Param dto
|
||
|
|
* @date 2023-06-07 15:43
|
||
|
|
*/
|
||
|
|
public boolean verifyParam(TeamEvaDto dto) throws Exception {
|
||
|
|
boolean flag = true;
|
||
|
|
Field[] fields = dto.getClass().getDeclaredFields();
|
||
|
|
for (int i = 0; i < fields.length; i++) {
|
||
|
|
String name = fields[i].getName();
|
||
|
|
name = name.substring(0, 1).toUpperCase() + name.substring(1);
|
||
|
|
Method method = dto.getClass().getMethod("get" + name);
|
||
|
|
String value = (String) method.invoke(dto);
|
||
|
|
if (StringUtils.isNotBlank(value)) {
|
||
|
|
String ds = decryptString(value);
|
||
|
|
if (Objects.equals(ds, "error") || Objects.equals("",ds)) {
|
||
|
|
flag = false;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return flag;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return com.sercurityControl.proteam.callInterface.domain.TeamEvaDto
|
||
|
|
* @author cw chen
|
||
|
|
* @description 设置班组评价参数值
|
||
|
|
* @Param dto
|
||
|
|
* @date 2023-06-07 15:56
|
||
|
|
*/
|
||
|
|
public TeamEvaDto setValue(TeamEvaDto dto) throws Exception {
|
||
|
|
TeamEvaDto teamEvaDto = new TeamEvaDto();
|
||
|
|
if (StringUtils.isBlank(dto.getPage())) {
|
||
|
|
teamEvaDto.setPage("1");
|
||
|
|
} else {
|
||
|
|
teamEvaDto.setPage(decryptString(dto.getPage()));
|
||
|
|
}
|
||
|
|
if (StringUtils.isBlank(dto.getLimit())) {
|
||
|
|
teamEvaDto.setLimit("100000");
|
||
|
|
} else {
|
||
|
|
teamEvaDto.setLimit(decryptString(dto.getLimit()));
|
||
|
|
}
|
||
|
|
if (StringUtils.isBlank(dto.getStartTime()) && StringUtils.isBlank(dto.getEndTime())) {
|
||
|
|
teamEvaDto.setStartTime(DateTimeHelper.getNowDate());
|
||
|
|
teamEvaDto.setEndTime(DateTimeHelper.getNowDate());
|
||
|
|
} else if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
|
||
|
|
teamEvaDto.setStartTime(decryptString(dto.getStartTime()));
|
||
|
|
teamEvaDto.setEndTime(decryptString(dto.getEndTime()));
|
||
|
|
} else if (StringUtils.isNotBlank(dto.getStartTime()) && StringUtils.isBlank(dto.getEndTime())) {
|
||
|
|
teamEvaDto.setStartTime(decryptString(dto.getStartTime()));
|
||
|
|
} else if (StringUtils.isBlank(dto.getStartTime()) && StringUtils.isNotBlank(dto.getEndTime())) {
|
||
|
|
teamEvaDto.setEndTime(decryptString(dto.getEndTime()));
|
||
|
|
}
|
||
|
|
return teamEvaDto;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|