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

parent 8080d9ba
package cn.quantgroup.xyqb.controller.external.queryLog; package cn.quantgroup.xyqb.controller.external.queryLog;
import cn.quantgroup.xyqb.entity.Address;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserDetail; import cn.quantgroup.xyqb.entity.UserDetail;
import cn.quantgroup.xyqb.entity.UserQueryLog; import cn.quantgroup.xyqb.entity.UserQueryLog;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.model.UserQueryInfo; import cn.quantgroup.xyqb.model.UserQueryInfo;
import cn.quantgroup.xyqb.service.http.IHttpService; 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.IUserDetailService;
import cn.quantgroup.xyqb.service.user.IUserQueryLogService; import cn.quantgroup.xyqb.service.user.IUserQueryLogService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
...@@ -20,10 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -20,10 +22,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import java.util.ArrayList; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.*;
import java.util.HashMap;
import java.util.List;
/** /**
* Created by zenglibin on 17/06/13. * Created by zenglibin on 17/06/13.
...@@ -38,6 +38,8 @@ public class UserQueryLogController { ...@@ -38,6 +38,8 @@ public class UserQueryLogController {
private IUserQueryLogService userQueryLogService; private IUserQueryLogService userQueryLogService;
@Autowired @Autowired
private IUserDetailService userDetailService; private IUserDetailService userDetailService;
@Autowired
private IAddressService addressService;
@Value("${xyqb.paycenter.url}") @Value("${xyqb.paycenter.url}")
private String payCenterUrl; private String payCenterUrl;
...@@ -48,85 +50,116 @@ public class UserQueryLogController { ...@@ -48,85 +50,116 @@ public class UserQueryLogController {
private IHttpService httpService; private IHttpService httpService;
@RequestMapping("/queryLog") @RequestMapping("/queryLog")
public JsonResult queryLog(String date,Long pageId,Long PageSize) { public JsonResult queryLog(Date beginDate,Date endDate,Long pageId,Long pageSize) {
//List<UserQueryLog> userQueryLogs=userQueryLogService.findByDate(date);
return null; List<UserQueryLog> userQueryLogs=userQueryLogService.findByTimestamp(beginDate,endDate,pageId-1,pageSize);
return JsonResult.buildSuccessResult("查询成功",userQueryLogs);
} }
@RequestMapping("/queryUserInfo") @RequestMapping("/queryUserInfo")
public JsonResult queryForResult(String keys,String userName, String columns) { public JsonResult queryForResult(String key,String keyValues,String userName, String columns,Long pageId,Long pageSize) {
//手机号、身份证号、userId
//columns=> userId,phoneNo,idNo,bankCard,address
//key=>phoneNo、idNo、userId
//checkKeysType; //checkKeysType;
String[] values=keys.split(";");
String[] values=keyValues.split(";");
List<String> queryV= Arrays.asList(values); List<String> queryV= Arrays.asList(values);
List<UserQueryInfo> userQueryInfos=new ArrayList<UserQueryInfo>(); List<UserQueryInfo> userQueryInfos=new ArrayList<UserQueryInfo>();
List<UserDetail> userDetails=new ArrayList<UserDetail>(); List<UserDetail> userDetails=new ArrayList<UserDetail>();
//用户userIds List<Address> addresslist=new ArrayList<Address>();
// List<Long> userIds=new ArrayList<Long>(); if(key.equals("userId")){
// for(String s:queryV){ List<Long> userIds=new ArrayList<Long>();
// long uid=Long.valueOf(s); for(String s:queryV){
// userIds.add(uid); long uid=Long.valueOf(s);
// } userIds.add(uid);
}
userDetails=userDetailService.findByUserIdIn(userIds);
}else if(key.equals("phoneNo")){
//userDetails=userDetailService.findByUserIdIn(userIds); userDetails=userDetailService.findByPhoneNos(queryV);
}else if(key.equals("idNo")){
//userDetails=userDetailService.findByPhoneNos(queryV); userDetails=userDetailService.findByIdnos(queryV);
}
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(); //转换userDetail to userQueryInfo
// uql.setLoginUserName(userName); for(UserDetail ud:userDetails){
// uql.setQueryCondition("userId");//phoneNo,IdNo UserQueryInfo uqi=new UserQueryInfo();
// uql.setResultAmount(234l); if(columns.contains("idNo")){
// uql.setQueryItems(columns);//userId,手机号,身份证号,银行卡号,地址 uqi.setIdNo(ud.getIdNo());
// userQueryLogService.save(uql); }
// return null; 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(); return JsonResult.buildSuccessResult("成功",userQueryInfos);
uql.setLoginUserName(userName);
uql.setQueryCondition("userId");//phoneNo,IdNo
uql.setResultAmount(234l);
uql.setQueryItems(columns);//userId,手机号,身份证号,银行卡号,地址
userQueryLogService.save(uql);
return null;
} }
private String getBankCardsByPhoneNos(String phoneNo){ private String getBankCardsByPhoneNos(String phoneNo){
HashMap<String, String> parameters = new HashMap<>(); // HashMap<String, String> parameters = new HashMap<>();
parameters.put("phoneNo", phoneNo); // parameters.put("phoneNo", phoneNo);
parameters.put("merchantId", payCenterId); // parameters.put("merchantId", payCenterId);
//访问用户中心查询用户银行卡接口 // //访问用户中心查询用户银行卡接口
String resultStr = httpService.post(payCenterUrl + "ex/common_bank_card/list", parameters); // String resultStr = httpService.post(payCenterUrl + "ex/common_bank_card/list", parameters);
StringBuffer cardList=null; // StringBuffer cardList=null;
try{ // try{
JsonObject obj = new JsonParser().parse(resultStr).getAsJsonObject(); // JsonObject obj = new JsonParser().parse(resultStr).getAsJsonObject();
if(obj.get("data")!=null){ // if(obj.get("data")!=null){
JsonArray array = obj.get("data").getAsJsonArray(); // JsonArray array = obj.get("data").getAsJsonArray();
for(JsonElement jsonElement : array){ // for(JsonElement jsonElement : array){
JsonObject jo = jsonElement.getAsJsonObject(); // JsonObject jo = jsonElement.getAsJsonObject();
String cardNo=jo.get("cardNo").getAsString(); // String cardNo=jo.get("cardNo").getAsString();
cardList.append(cardNo+","); // cardList.append(cardNo+",");
} // }
} // }
//
}catch(Exception e){ // }catch(Exception e){
//
} // }
return cardList.toString(); // return cardList.toString();
return null;
} }
} }
...@@ -46,4 +46,8 @@ public class Address implements Serializable { ...@@ -46,4 +46,8 @@ public class Address implements Serializable {
public void preUpdate(){ public void preUpdate(){
this.updateAt = new Timestamp(System.currentTimeMillis()); this.updateAt = new Timestamp(System.currentTimeMillis());
} }
public String toString(){
return province+"(省)"+city+"(市)"+district+"(区/县)"+address;
}
} }
...@@ -29,6 +29,8 @@ public class UserQueryLog implements Serializable { ...@@ -29,6 +29,8 @@ public class UserQueryLog implements Serializable {
private String queryItems; private String queryItems;
@Column(name = "result_amount") @Column(name = "result_amount")
private Long resultAmount; private Long resultAmount;
@Column(name = "query_detail")
private String queryDetail;
@Column(name = "created_at") @Column(name = "created_at")
private Timestamp createdAt; private Timestamp createdAt;
......
package cn.quantgroup.xyqb.repository; package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.Address; 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.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/** /**
* Created by 11 on 2016/12/30. * 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); Address findByUserId(Long userId);
} }
...@@ -2,8 +2,12 @@ package cn.quantgroup.xyqb.repository; ...@@ -2,8 +2,12 @@ package cn.quantgroup.xyqb.repository;
import cn.quantgroup.xyqb.entity.UserQueryLog; import cn.quantgroup.xyqb.entity.UserQueryLog;
import org.springframework.data.jpa.repository.JpaRepository; 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.sql.Timestamp;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -11,4 +15,9 @@ import java.util.List; ...@@ -11,4 +15,9 @@ import java.util.List;
*/ */
public interface IUserQueryLogRepository extends JpaRepository<UserQueryLog, Long> { public interface IUserQueryLogRepository extends JpaRepository<UserQueryLog, Long> {
List<UserQueryLog> findByCreatedAt(Timestamp date); 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; ...@@ -2,6 +2,8 @@ package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.entity.Address; import cn.quantgroup.xyqb.entity.Address;
import java.util.List;
/** /**
* Created by Miraculous on 2017/1/3. * Created by Miraculous on 2017/1/3.
*/ */
...@@ -12,4 +14,6 @@ public interface IAddressService { ...@@ -12,4 +14,6 @@ public interface IAddressService {
Address save(Address addressObj); Address save(Address addressObj);
Address saveAddress(Address address); Address saveAddress(Address address);
List<Address> findByUserIds(List<Long> userIds);
} }
...@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.Address; ...@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.entity.Address;
import cn.quantgroup.xyqb.entity.UserQueryLog; import cn.quantgroup.xyqb.entity.UserQueryLog;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -11,7 +12,7 @@ import java.util.List; ...@@ -11,7 +12,7 @@ import java.util.List;
*/ */
public interface IUserQueryLogService { public interface IUserQueryLogService {
List<UserQueryLog> findByTimestamp(Timestamp date); List<UserQueryLog> findByTimestamp(Date beginDate, Date endDate,Long pageId,Long pageSize);
UserQueryLog save(UserQueryLog userQueryLog); UserQueryLog save(UserQueryLog userQueryLog);
......
...@@ -8,6 +8,8 @@ import org.springframework.cache.annotation.CacheEvict; ...@@ -8,6 +8,8 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
/** /**
* Created by Miraculous on 2017/1/3. * Created by Miraculous on 2017/1/3.
*/ */
...@@ -34,4 +36,12 @@ public class AddressServiceImpl implements IAddressService { ...@@ -34,4 +36,12 @@ public class AddressServiceImpl implements IAddressService {
public Address saveAddress(Address address) { public Address saveAddress(Address address) {
return addressRepository.save(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; ...@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date;
import java.util.List; import java.util.List;
/** /**
...@@ -19,8 +20,8 @@ public class UserQueryLogServiceImpl implements IUserQueryLogService { ...@@ -19,8 +20,8 @@ public class UserQueryLogServiceImpl implements IUserQueryLogService {
private IUserQueryLogRepository userQueryLogRepository; private IUserQueryLogRepository userQueryLogRepository;
@Override @Override
public List<UserQueryLog> findByTimestamp(Timestamp date) { public List<UserQueryLog> findByTimestamp(Date beginDate,Date endDate,Long pageId,Long pageSize) {
return userQueryLogRepository.findByCreatedAt(date); return userQueryLogRepository.findQueryLogCreatedAt(beginDate,endDate,pageId,pageSize);
} }
@Override @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