Commit c4bd1dac authored by 王向伟's avatar 王向伟

配置生成insert sql语句

parent 1023341a
...@@ -22,4 +22,7 @@ public interface ChannelConfService { ...@@ -22,4 +22,7 @@ public interface ChannelConfService {
Boolean editChannelConfInfo(ChannelConfVo confVo); Boolean editChannelConfInfo(ChannelConfVo confVo);
List<ChannelModel> getAll(); List<ChannelModel> getAll();
String exportChannelConf(Long channelId);
} }
...@@ -4,23 +4,24 @@ import cn.quantgroup.cashloanflowboss.api.channel.entity.ChannelConf; ...@@ -4,23 +4,24 @@ import cn.quantgroup.cashloanflowboss.api.channel.entity.ChannelConf;
import cn.quantgroup.cashloanflowboss.api.channel.model.*; import cn.quantgroup.cashloanflowboss.api.channel.model.*;
import cn.quantgroup.cashloanflowboss.api.channel.repository.ChannelConfRepository; import cn.quantgroup.cashloanflowboss.api.channel.repository.ChannelConfRepository;
import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil; import cn.quantgroup.cashloanflowboss.api.channel.util.ChannelConfUtil;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ChannelApplyInfoStrategy; import cn.quantgroup.cashloanflowboss.spi.clf.entity.*;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfCallbackConfiguration;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfChannelConfiguration;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.ClfOrderCallBack;
import cn.quantgroup.cashloanflowboss.spi.clf.model.KANoticeType; import cn.quantgroup.cashloanflowboss.spi.clf.model.KANoticeType;
import cn.quantgroup.cashloanflowboss.spi.clf.service.CLFCenterService; import cn.quantgroup.cashloanflowboss.spi.clf.service.CLFCenterService;
import cn.quantgroup.cashloanflowboss.utils.IgnorePropertiesUtil; import cn.quantgroup.cashloanflowboss.utils.IgnorePropertiesUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.*;
import java.util.Date;
import java.util.List;
/** /**
* function: * function:
...@@ -30,6 +31,7 @@ import java.util.List; ...@@ -30,6 +31,7 @@ import java.util.List;
*/ */
@Service @Service
@Slf4j
public class ChannelConfServiceImpl implements ChannelConfService { public class ChannelConfServiceImpl implements ChannelConfService {
@Autowired @Autowired
...@@ -39,6 +41,7 @@ public class ChannelConfServiceImpl implements ChannelConfService { ...@@ -39,6 +41,7 @@ public class ChannelConfServiceImpl implements ChannelConfService {
private ChannelConfRepository channelConfRepository; private ChannelConfRepository channelConfRepository;
@Override @Override
public Page<ChannelListModel> getChannelInfo(Integer pageNumber, Integer pageSize, Long channelId, String channelName) { public Page<ChannelListModel> getChannelInfo(Integer pageNumber, Integer pageSize, Long channelId, String channelName) {
...@@ -158,4 +161,125 @@ public class ChannelConfServiceImpl implements ChannelConfService { ...@@ -158,4 +161,125 @@ public class ChannelConfServiceImpl implements ChannelConfService {
return channelModelList; return channelModelList;
} }
@Override
public String exportChannelConf(Long channelId) {
ClfChannelConfiguration channelConfiguration= clfCenterService.findChannelConfigurationByChannelId(channelId);
List<CallbackConfiguration> callbackConfigurations = clfCenterService.findCallbackConfigurationByChannelId(channelId);
List<ChannelApplyInfoStrategy> channelApplyInfoStrategies = clfCenterService.findChannelApplyInfoStrategyByChannelId(channelId);
StringJoiner joiner = new StringJoiner("\n");
joiner.add(generateInsertSql(channelConfiguration));
if(CollectionUtils.isNotEmpty(callbackConfigurations)){
for (CallbackConfiguration callbackConfiguration : callbackConfigurations) {
joiner.add(generateInsertSql(callbackConfiguration));
}
}
if(CollectionUtils.isNotEmpty(channelApplyInfoStrategies)){
for (ChannelApplyInfoStrategy channelApplyInfoStrategy : channelApplyInfoStrategies) {
joiner.add(generateInsertSql(channelApplyInfoStrategy));
}
}
return joiner.toString();
}
//生成sql语句
private String generateInsertSql(Object obj){
if(Objects.isNull(obj)){
throw new RuntimeException("对象为空,无法解析");
}
Class<?> clazz = obj.getClass();
Annotation[] annotations = clazz.getAnnotations();
if(annotations.length <= 0){
throw new RuntimeException("类名上没有注解,不能获得表名");
}
StringJoiner joiner = new StringJoiner(" ");
joiner.add("insert into");
//获得表名
for (Annotation annotation : annotations) {
if(annotation instanceof Table){
//只获得@Table注解的,@Entity有了以后再加
Table table = (Table) annotation;
String tableName = table.name();
joiner.add(tableName);
break;
}
}
Field[] declaredFields = clazz.getDeclaredFields();
if(declaredFields.length <= 0){
throw new RuntimeException("没有字段,不能获得表的列名");
}
Map<String,Object> field2Value = new HashMap<>();
for (Field declaredField : declaredFields) {
declaredField.setAccessible(true);
Id idAnnotation = declaredField.getAnnotation(Id.class);
if(Objects.isNull(idAnnotation)){
continue;
}
Column annotation = declaredField.getAnnotation(Column.class);
if(Objects.isNull(annotation)){
log.warn("{}字段没有对应的列",declaredField.getName());
continue;
}
try {
field2Value.put(annotation.name(),declaredField.get(obj));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
StringJoiner fields = new StringJoiner(",");
StringJoiner values = new StringJoiner(",");
for (Map.Entry<String, Object> entry : field2Value.entrySet()) {
fields.add(entry.getKey());
//空值
if(Objects.isNull(entry.getValue())){
values.add(null);
continue;
}
//非空值
Object value = entry.getValue();
//数字不加引号
if(value instanceof Number || value instanceof Boolean){
values.add(value.toString());
continue;
}
//其他类型一律按照字符串处理,有问题加if判断
values.add("'"+value.toString()+"'");
}
joiner.add("(");
joiner.add(fields.toString());
joiner.add(")");
joiner.add("values");
joiner.add("(");
joiner.add(values.toString());
joiner.add(");");
return joiner.toString();
}
public static void main(String[] args) {
StringJoiner joiner = new StringJoiner(",");
joiner.add("seg");
joiner.add(null);
joiner.add("www");
System.out.println(joiner.toString());
}
} }
...@@ -3,6 +3,7 @@ package cn.quantgroup.cashloanflowboss.core.configuration.data; ...@@ -3,6 +3,7 @@ package cn.quantgroup.cashloanflowboss.core.configuration.data;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource; import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowBossPubConfDataSource;
import cn.quantgroup.cashloanflowboss.spi.apollo.service.ApolloSettingService; import cn.quantgroup.cashloanflowboss.spi.apollo.service.ApolloSettingService;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder; import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; ...@@ -20,6 +21,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.persistence.EntityManagerFactory; import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.sql.Connection;
import java.util.Map; import java.util.Map;
@Configuration @Configuration
......
package cn.quantgroup.cashloanflowboss.spi.clf.entity;
import cn.quantgroup.cashloanflowboss.spi.clf.model.CallbackRouter;
import lombok.*;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.*;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
/**
* Created by liqing on 2017/5/5 0005.
*/
@Setter
@Getter
@Entity
@Table(name = "callback_configuration", catalog = "cash_loan_flow")
public class CallbackConfiguration implements Serializable {
private static final long serialVersionUID = -1L;
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "channel_id")
private Long channelId;
@Column(name = "is_loan_makeup")
private Boolean isLoanMakeup;
@Column(name = "is_repay_makeup")
private Boolean isRepayMakeup;
@Column(name = "loan_makeup_strategy")
private String loanMakeupStrategy;
@Column(name = "repay_makeup_strategy")
private String repayMakeupStrategy;
@Column(name = "is_active")
private Boolean isActive;
@Column(name = "only_new_user")
private Boolean onlyNewUser;
@Column(name = "callback_service_name")
private String callbackServiceName;
@Column(name = "callback_no_push_progress")
private String callbackNoPushProgress;
@Column(name = "pre_progress")
private String preProgress;
@Column(name = "retry_max_times")
private Long retryMaxTimes;
@Enumerated(EnumType.ORDINAL)
@Column(name = "callback_router")
private CallbackRouter callbackRouter;
// @Transient
// private LoanMakeupStrategyModel loanMakeupStrategyModel;
// @Transient
// private RepayMakeupStrategyModel repayMakeupStrategyModel;
//
// public void generateMakeupStrategyModel() {
// if (StringUtils.isNotBlank(loanMakeupStrategy)) {
// loanMakeupStrategyModel = Constants.GSON.fromJson(loanMakeupStrategy, LoanMakeupStrategyModel.class);
// }
// if (StringUtils.isNotBlank(repayMakeupStrategy)) {
// repayMakeupStrategyModel = Constants.GSON.fromJson(repayMakeupStrategy, RepayMakeupStrategyModel.class);
// }
// }
//
// public LoanMakeupStrategyModel getLoanMakeupStrategyModel() {
// if (loanMakeupStrategyModel == null) {
// loanMakeupStrategyModel = Constants.GSON.fromJson(loanMakeupStrategy, LoanMakeupStrategyModel.class);
// }
// return loanMakeupStrategyModel;
// }
//
// public RepayMakeupStrategyModel getRepayMakeupStrategyModel() {
// if (repayMakeupStrategyModel == null) {
// repayMakeupStrategyModel = Constants.GSON.fromJson(repayMakeupStrategy, RepayMakeupStrategyModel.class);
// }
// return repayMakeupStrategyModel;
// }
//
// @Setter
// @Getter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public static class LoanMakeupStrategyModel implements Serializable {
// private static final long serialVersionUID = -1L;
//
// private Map<Integer, Integer> preProgressMap; // 前一个应推送的状态映射
// private Map<Integer, Integer> pushStatusMap; // 应推送的状态映射
// private Set<Integer> allStatus; // 所有需要关注的状态
// private Long hourAgo; // 关注hourAgo小时之内发生变更的状态
// private Integer maxCount; // 最多一次补偿数量
//
// public String toJson() {
// return Constants.GSON.toJson(this);
// }
// }
//
// @Setter
// @Getter
// @Builder
// @NoArgsConstructor
// @AllArgsConstructor
// public static class RepayMakeupStrategyModel implements Serializable {
// private static final long serialVersionUID = -1L;
//
// private Long hourAgo; // 关注hourAgo小时之内发生收到的还款
// private Integer maxCount; // 最多一次补偿数量
//
// public String toJson() {
// return Constants.GSON.toJson(this);
// }
// }
}
...@@ -19,4 +19,6 @@ public interface ClfOrderCallbackRepository extends JpaRepository<ClfOrderCallBa ...@@ -19,4 +19,6 @@ public interface ClfOrderCallbackRepository extends JpaRepository<ClfOrderCallBa
@Query(value = "select * from order_callback where callback_status = ?1 and registered_from = ?2", nativeQuery = true) @Query(value = "select * from order_callback where callback_status = ?1 and registered_from = ?2", nativeQuery = true)
ClfOrderCallBack findByCallbackStatusAndRegisteredFrom(String callbackState, Long channelId); ClfOrderCallBack findByCallbackStatusAndRegisteredFrom(String callbackState, Long channelId);
} }
package cn.quantgroup.cashloanflowboss.spi.clf.repository;
import cn.quantgroup.cashloanflowboss.core.persistence.CashLoanFlowDataSource;
import cn.quantgroup.cashloanflowboss.spi.clf.entity.CallbackConfiguration;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* Created by liqing on 2017/5/5 0005.
*/
@CashLoanFlowDataSource
@Repository
public interface ICallbackConfigurationRepository extends JpaRepository<CallbackConfiguration, Long> {
List<CallbackConfiguration> findByChannelId(Long channelId);
}
...@@ -42,6 +42,10 @@ public interface CLFCenterService { ...@@ -42,6 +42,10 @@ public interface CLFCenterService {
void saveChannelApplyInfoStrategy(ChannelApplyInfoStrategy channelApplyInfoStrategy); void saveChannelApplyInfoStrategy(ChannelApplyInfoStrategy channelApplyInfoStrategy);
List<CallbackConfiguration> findCallbackConfigurationByChannelId(Long channelId);
List<ClfChannelConfiguration> findAll(); List<ClfChannelConfiguration> findAll();
} }
...@@ -49,6 +49,10 @@ public class CLFCenterServiceImpl implements CLFCenterService { ...@@ -49,6 +49,10 @@ public class CLFCenterServiceImpl implements CLFCenterService {
private ChannelApplyInfoStrategyRepository channelApplyInfoStrategyRepository; private ChannelApplyInfoStrategyRepository channelApplyInfoStrategyRepository;
@Autowired
private ICallbackConfigurationRepository callbackConfigurationRepository;
@Override @Override
public List<CallbackFailRecord> findCallbackFailRecordByApplyNo(String applyNo) { public List<CallbackFailRecord> findCallbackFailRecordByApplyNo(String applyNo) {
return callbackFailRecordRepository.findByApplyNo(applyNo); return callbackFailRecordRepository.findByApplyNo(applyNo);
...@@ -167,4 +171,11 @@ public class CLFCenterServiceImpl implements CLFCenterService { ...@@ -167,4 +171,11 @@ public class CLFCenterServiceImpl implements CLFCenterService {
} }
return list; return list;
} }
@Override
public List<CallbackConfiguration> findCallbackConfigurationByChannelId(Long channelId) {
return callbackConfigurationRepository.findByChannelId(channelId);
}
} }
...@@ -52,13 +52,13 @@ public class ChannelApplyInfoStrategyTest extends CashLoanFlowBossApplicationTes ...@@ -52,13 +52,13 @@ public class ChannelApplyInfoStrategyTest extends CashLoanFlowBossApplicationTes
//ChannelApplyInfoStrategy channelApplyInfoStrategy = channelConf.getBasicInfo().getChannelApplyInfoStrategyList(); //ChannelApplyInfoStrategy channelApplyInfoStrategy = channelConf.getBasicInfo().getChannelApplyInfoStrategyList();
//channelApplyInfoStrategy.setChannelUserId(true); //channelApplyInfoStrategy.setChannelUserId(true);
channelConfService.editChannelConfInfo(channelConf); // channelConfService.editChannelConfInfo(channelConf);
//数据恢复 //数据恢复
//channelApplyInfoStrategy.setChannelUserId(false); //channelApplyInfoStrategy.setChannelUserId(false);
channelConfService.editChannelConfInfo(channelConf); // channelConfService.editChannelConfInfo(channelConf);
System.out.println(channelConfService.exportChannelConf(159891L));
} }
......
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