forked from gzzfw/backEnd/gz-dyh

wangwh
2024-08-28 b47d4a7accabce974e19d2a1ffb3c5c67507d74b
dyh-service/dyh-sync/src/main/java/cn/huge/module/sync/service/SyncService.java
@@ -2,7 +2,9 @@
import cn.huge.module.client.api.impl.CustClientImpl;
import cn.huge.module.sync.dao.mapper.SyncMapper;
import cn.huge.module.sync.domain.source.SourceCtAccount;
import cn.huge.module.sync.domain.source.SourceCtUnit;
import cn.huge.module.sync.domain.target.TargetCtAccount;
import cn.huge.module.sync.domain.target.TargetCtUnit;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.beanutils.ConvertUtils;
@@ -38,19 +40,14 @@
    @Autowired
    private CustClientImpl custClient;
    private static final String MYSQL_TABLE = "dyh_ct_unit";
    private static final String MYSQL_TABLE = "dyh_ct_account";
    public void syncData() {
        try {
            List<SourceCtUnit> sourceCtUnitList = new ArrayList<>();
            List<TargetCtUnit> targetCtUnitList = new ArrayList<>();
            List<SourceCtAccount> sourceTableList = new ArrayList<>();
            // 查询MySQL表结构
            Sort sort = Sort.by(Sort.Direction.ASC, "create_time");
            int page = 1;
            int size = 1000;
            PageRequest pageRequest = PageRequest.of(page-1, size, sort);
            sourceCtUnitList = syncMapper.pageInfo(MYSQL_TABLE, pageRequest);
            //查询mysql总量
            int total = syncMapper.countData(MYSQL_TABLE);
@@ -62,18 +59,28 @@
                maxPage += 1;
            }
            for (int i = 1; i >= maxPage; i++) {
                for(SourceCtUnit sourceCtUnit: sourceCtUnitList){
                    TargetCtUnit targetCtUnit = new TargetCtUnit();
            for (int i = 1; i <= maxPage; i++) {
                // 查询MySQL表结构
                Sort sort = Sort.by(Sort.Direction.ASC, "create_time");
                PageRequest pageRequest = PageRequest.of(page-1, size, sort);
                sourceTableList = syncMapper.pageInfo(MYSQL_TABLE, pageRequest);
                page++;
                List<TargetCtAccount> targetTableList = new ArrayList<>();
                for(SourceCtAccount sourceTable: sourceTableList){
                    TargetCtAccount tagetTable = new TargetCtAccount();
                    ConvertUtils.register(new DateConverter(null), java.util.Date.class);
                    BeanUtils.copyProperties(targetCtUnit, sourceCtUnit);
                    BeanUtils.copyProperties(tagetTable, sourceTable);
//                    for(Field field: sourceCtUnit.getClass().getDeclaredFields()){
//                        convertType(field.get(sourceCtUnit), field.getName(), targetCtUnit);
//                    }
                    targetCtUnitList.add(targetCtUnit);
                    //字段名不一致,手动set
                    tagetTable.setCipher(sourceTable.getCipher());
                    tagetTable.setAccType(1);
                    targetTableList.add(tagetTable);
                }
                if(CollectionUtils.isNotEmpty(targetCtUnitList)){
                    custClient.saveCtUnitList(targetCtUnitList);
                if(CollectionUtils.isNotEmpty(targetTableList)){
                    custClient.saveTableList1(targetTableList);
                }
            }
        } catch (Exception e) {