|
@@ -0,0 +1,68 @@
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.sd.SdApplication;
|
|
|
+import com.sd.business.entity.department.dto.DepartmentDto;
|
|
|
+import com.sd.business.entity.department.po.Department;
|
|
|
+import com.sd.business.service.department.DepartmentService;
|
|
|
+import org.junit.Test;
|
|
|
+import org.junit.runner.RunWith;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.test.context.junit4.SpringRunner;
|
|
|
+
|
|
|
+import javax.sql.DataSource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RunWith(SpringRunner.class)
|
|
|
+@SpringBootTest(classes = SdApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
|
|
+public class A3_SyncDetpTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DepartmentService departmentService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DataSource dataSource;
|
|
|
+
|
|
|
+ @DSTransactional
|
|
|
+ @Test
|
|
|
+ public void test() {
|
|
|
+
|
|
|
+ departmentService.remove(q -> q.isNotNull(Department::getOldId));
|
|
|
+
|
|
|
+ DynamicRoutingDataSource dynamicRoutingDataSource = (DynamicRoutingDataSource) dataSource;
|
|
|
+ DataSource sdDataSource = dynamicRoutingDataSource.getDataSource("business");
|
|
|
+
|
|
|
+ String sql = "SELECT\n" +
|
|
|
+ "\tid oldId,\n" +
|
|
|
+ "\taccount_number adminUsername,\n" +
|
|
|
+ "\t'123456' `adminPassword`,\n" +
|
|
|
+ "\tNAME `name`,\n" +
|
|
|
+ "\tphone telephone,\n" +
|
|
|
+ "\taddress address,\n" +
|
|
|
+ "\tcontacts contactPerson,\n" +
|
|
|
+ "\tcontact_phone contactNumber,\n" +
|
|
|
+ "\torder_mode orderMode,\n" +
|
|
|
+ "\tSTATUS `status`,\n" +
|
|
|
+ "\tcredit_limit lineCredit,\n" +
|
|
|
+ "\tused_credit_limit usedCredit,\n" +
|
|
|
+ "\twarehouse_code wlnWarehouseCode,\n" +
|
|
|
+ "\tbrand_name wlnBrand\n" +
|
|
|
+ "\t\n" +
|
|
|
+ "FROM\n" +
|
|
|
+ "\tt_sd_subsidiary";
|
|
|
+
|
|
|
+ List<Map<String, Object>> list = new JdbcTemplate(sdDataSource).queryForList(sql);
|
|
|
+
|
|
|
+ List<DepartmentDto> departmentList = BeanUtil.copyToList(list, DepartmentDto.class);
|
|
|
+
|
|
|
+ for (DepartmentDto departmentDto : departmentList) {
|
|
|
+ departmentService.add(departmentDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|