添加内部系统脱敏查询接口

parent 8080d9ba
package cn.quantgroup.xyqb.controller.external.queryLog;
import cn.quantgroup.xyqb.entity.Address;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.entity.UserQueryLog;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.model.UserQueryInfo;
import cn.quantgroup.xyqb.service.http.IHttpService;
import cn.quantgroup.xyqb.service.user.IAddressService;
import cn.quantgroup.xyqb.service.user.IUserDetailService;
import cn.quantgroup.xyqb.service.user.IUserQueryLogService;
import cn.quantgroup.xyqb.service.user.IUserService;
......@@ -20,10 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Created by zenglibin on 17/06/13.
......@@ -38,6 +38,8 @@ public class UserQueryLogController {
private IUserQueryLogService userQueryLogService;
@Autowired
private IUserDetailService userDetailService;
@Autowired
private IAddressService addressService;
@Value("${xyqb.paycenter.url}")
private String payCenterUrl;
......@@ -48,85 +50,116 @@ public class UserQueryLogController {
private IHttpService httpService;
@RequestMapping("/queryLog")
public JsonResult queryLog(String date,Long pageId,Long PageSize) {
//List<UserQueryLog> userQueryLogs=userQueryLogService.findByDate(date);
public JsonResult queryLog(Date beginDate,Date endDate,Long pageId,Long pageSize) {
return null;
List<UserQueryLog> userQueryLogs=userQueryLogService.findByTimestamp(beginDate,endDate,pageId-1,pageSize);
return JsonResult.buildSuccessResult("查询成功",userQueryLogs);
}
@RequestMapping("/queryUserInfo")
public JsonResult queryForResult(String keys,String userName, String columns) {
//手机号、身份证号、userId
public JsonResult queryForResult(String key,String keyValues,String userName, String columns,Long pageId,Long pageSize) {
//columns=> userId,phoneNo,idNo,bankCard,address
//key=>phoneNo、idNo、userId
//checkKeysType;
String[] values=keys.split(";");
String[] values=keyValues.split(";");
List<String> queryV= Arrays.asList(values);
List<UserQueryInfo> userQueryInfos=new ArrayList<UserQueryInfo>();
List<UserDetail> userDetails=new ArrayList<UserDetail>();
//用户userIds
// List<Long> userIds=new ArrayList<Long>();
// for(String s:queryV){
// long uid=Long.valueOf(s);
// userIds.add(uid);
// }
//userDetails=userDetailService.findByUserIdIn(userIds);
//userDetails=userDetailService.findByPhoneNos(queryV);
userDetails=userDetailService.findByIdnos(queryV);
List<Address> addresslist=new ArrayList<Address>();
if(key.equals("userId")){
List<Long> userIds=new ArrayList<Long>();
for(String s:queryV){
long uid=Long.valueOf(s);
userIds.add(uid);
}
userDetails=userDetailService.findByUserIdIn(userIds);
}else if(key.equals("phoneNo")){
userDetails=userDetailService.findByPhoneNos(queryV);
}else if(key.equals("idNo")){
userDetails=userDetailService.findByIdnos(queryV);
}
if(columns.contains("bankCard")){
//需加银行卡信息
}
return JsonResult.buildSuccessResult("查询成功",userDetails.size());
if(columns.contains("address")){
List<Long> uidss=new ArrayList<Long>();
//加地址信息
for(UserDetail ud:userDetails){
uidss.add(ud.getUserId());
}
if(uidss!=null&&uidss.size()>0){
addresslist=addressService.findByUserIds(uidss);
}
}
// UserQueryLog uql=new UserQueryLog();
// uql.setLoginUserName(userName);
// uql.setQueryCondition("userId");//phoneNo,IdNo
// uql.setResultAmount(234l);
// uql.setQueryItems(columns);//userId,手机号,身份证号,银行卡号,地址
// userQueryLogService.save(uql);
// return null;
}
//转换userDetail to userQueryInfo
for(UserDetail ud:userDetails){
UserQueryInfo uqi=new UserQueryInfo();
if(columns.contains("idNo")){
uqi.setIdNo(ud.getIdNo());
}
if(columns.contains("phoneNo")){
uqi.setPhoneNo(ud.getPhoneNo());
}
if(columns.contains("userId")){
uqi.setUserId(ud.getUserId());
}
if(columns.contains("address")){
Optional<Address> oad=addresslist.stream().filter(addr->addr.getUserId()==ud.getUserId()).findFirst();
if(oad.isPresent()){
uqi.setAddress(oad.get().toString());
}
}
userQueryInfos.add(uqi);
@RequestMapping("/query")
public JsonResult outputToExcel(String keys,String userName, String columns) {
}
//保存记录
UserQueryLog log=new UserQueryLog();
log.setQueryItems(columns);
log.setResultAmount(Long.valueOf(userQueryInfos.size()));
log.setQueryCondition(key);
log.setQueryDetail(keyValues);
log.setLoginUserName(userName);
if(keyValues!=null&&keyValues.length()<=2048){
log.setQueryDetail(keyValues);
}else{
log.setQueryDetail(keyValues.substring(0,2048));
}
userQueryLogService.save(log);
UserQueryLog uql=new UserQueryLog();
uql.setLoginUserName(userName);
uql.setQueryCondition("userId");//phoneNo,IdNo
uql.setResultAmount(234l);
uql.setQueryItems(columns);//userId,手机号,身份证号,银行卡号,地址
userQueryLogService.save(uql);
return null;
return JsonResult.buildSuccessResult("成功",userQueryInfos);
}
private String getBankCardsByPhoneNos(String phoneNo){
HashMap<String, String> parameters = new HashMap<>();
parameters.put("phoneNo", phoneNo);
parameters.put("merchantId", payCenterId);
//访问用户中心查询用户银行卡接口
String resultStr = httpService.post(payCenterUrl + "ex/common_bank_card/list", parameters);
StringBuffer cardList=null;
try{
JsonObject obj = new JsonParser().parse(resultStr).getAsJsonObject();
if(obj.get("data")!=null){
JsonArray array = obj.get("data").getAsJsonArray();
for(JsonElement jsonElement : array){
JsonObject jo = jsonElement.getAsJsonObject();
String cardNo=jo.get("cardNo").getAsString();
cardList.append(cardNo+",");
}
}
}catch(Exception e){
}
return cardList.toString();
// HashMap<String, String> parameters = new HashMap<>();
// parameters.put("phoneNo", phoneNo);
// parameters.put("merchantId", payCenterId);
// //访问用户中心查询用户银行卡接口
// String resultStr = httpService.post(payCenterUrl + "ex/common_bank_card/list", parameters);
// StringBuffer cardList=null;
// try{
// JsonObject obj = new JsonParser().parse(resultStr).getAsJsonObject();
// if(obj.get("data")!=null){
// JsonArray array = obj.get("data").getAsJsonArray();
// for(JsonElement jsonElement : array){
// JsonObject jo = jsonElement.getAsJsonObject();
// String cardNo=jo.get("cardNo").getAsString();
// cardList.append(cardNo+",");
// }
// }
//
// }catch(Exception e){
//
// }
// return cardList.toString();
return null;
}
}
......@@ -46,4 +46,8 @@ public class Address implements Serializable {
public void preUpdate(){
this.updateAt = new Timestamp(System.currentTimeMillis());
}
public String toString(){
return province+"(省)"+city+"(市)"+district+"(区/县)"+address;
}
}
......@@ -29,6 +29,8 @@ public class UserQueryLog implements Serializable {
private String queryItems;
@Column(name = "result_amount")
private Long resultAmount;
@Column(name = "query_detail")
private String queryDetail;
@Column(name = "created_at")
private Timestamp createdAt;
......
package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.Address;
import cn.quantgroup.xyqb.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* Created by 11 on 2016/12/30.
*/
public interface IAddressRepository extends JpaRepository<Address, Long> {
public interface IAddressRepository extends JpaRepository<Address, Long> ,JpaSpecificationExecutor<Address> {
Address findByUserId(Long userId);
}
......@@ -2,8 +2,12 @@ package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.UserQueryLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
/**
......@@ -11,4 +15,9 @@ import java.util.List;
*/
public interface IUserQueryLogRepository extends JpaRepository<UserQueryLog, Long> {
List<UserQueryLog> findByCreatedAt(Timestamp date);
@Transactional
@Modifying
@Query(nativeQuery=true,value = "select * from user_query_log ul where created_At between ?1 and ?2 limit ?3 ,?4 ")
List<UserQueryLog> findQueryLogCreatedAt(Date beginDate, Date endDate,Long pageId,Long pageSize);
}
......@@ -2,6 +2,8 @@ package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.Address;
import java.util.List;
/**
* Created by Miraculous on 2017/1/3.
*/
......@@ -12,4 +14,6 @@ public interface IAddressService {
Address save(Address addressObj);
Address saveAddress(Address address);
List<Address> findByUserIds(List<Long> userIds);
}
......@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.Address;
import cn.quantgroup.xyqb.entity.UserQueryLog;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
/**
......@@ -11,7 +12,7 @@ import java.util.List;
*/
public interface IUserQueryLogService {
List<UserQueryLog> findByTimestamp(Timestamp date);
List<UserQueryLog> findByTimestamp(Date beginDate, Date endDate,Long pageId,Long pageSize);
UserQueryLog save(UserQueryLog userQueryLog);
......
......@@ -8,6 +8,8 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Created by Miraculous on 2017/1/3.
*/
......@@ -34,4 +36,12 @@ public class AddressServiceImpl implements IAddressService {
public Address saveAddress(Address address) {
return addressRepository.save(address);
}
@Override
public List<Address> findByUserIds(List<Long> userIds) {
return addressRepository.findAll((root, query, cb) -> {
query.where(root.get("userId").in(userIds));
return query.getRestriction();
});
}
}
......@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
/**
......@@ -19,8 +20,8 @@ public class UserQueryLogServiceImpl implements IUserQueryLogService {
private IUserQueryLogRepository userQueryLogRepository;
@Override
public List<UserQueryLog> findByTimestamp(Timestamp date) {
return userQueryLogRepository.findByCreatedAt(date);
public List<UserQueryLog> findByTimestamp(Date beginDate,Date endDate,Long pageId,Long pageSize) {
return userQueryLogRepository.findQueryLogCreatedAt(beginDate,endDate,pageId,pageSize);
}
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment