use of com.bc.pmpheep.back.po.MaterialProjectEditor in project pmph by BCSquad.
the class MigrationStageFour method materialPprojectEeditor.
protected void materialPprojectEeditor() {
String sql = "select DISTINCT * from( " + "select " + "b.new_pk materid, " + "c.new_pk userid " + "from teach_material_linker a " + "LEFT JOIN teach_material b on b.materid = a.materid " + "LEFT JOIN sys_user c on c.userid = a.userid " + "where true " + "UNION select DISTINCT e.new_pk materid ,a.new_pk userid from sys_user a " + "LEFT JOIN sys_userorganize b on b.userid=a.userid " + "LEFT JOIN sys_userrole c on c.userid =a.userid " + "lEFT JOIN sys_role d on d.roleid =c.roleid " + "LEFT JOIN teach_material e on e.createorgid = b.orgid " + "where d.rolename like '%主任%' and e.materid is not null GROUP BY e.materid " + ")temp ";
List<Map<String, Object>> materialProjectEditorList = JdbcHelper.getJdbcTemplate().queryForList(sql);
List<Map<String, Object>> excel = new LinkedList<>();
Map<String, Object> result = new LinkedHashMap<>();
int count = 0;
int correctCount = 0;
int[] state = { 0, 0 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
for (Map<String, Object> object : materialProjectEditorList) {
StringBuilder exception = new StringBuilder();
Long materid = (Long) object.get("materid");
if (ObjectUtil.isNull(materid)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("教材id为空。"));
excel.add(object);
if (state[0] == 0) {
reason.append("找不到对应的教材。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
Long userid = (Long) object.get("userid");
if (ObjectUtil.isNull(userid)) {
object.put(SQLParameters.EXCEL_EX_HEADER, exception.append("用户id为空。"));
excel.add(object);
if (state[1] == 0) {
reason.append("找不到教材对应的项目编辑。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
}
MaterialProjectEditor materialProjectEditor = new MaterialProjectEditor();
materialProjectEditor.setMaterialId(materid);
materialProjectEditor.setEditorId(userid);
materialProjectEditor = materialProjectEditorService.addMaterialProjectEditor(materialProjectEditor);
count++;
if (null == object.get("exception")) {
correctCount++;
}
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "教材-项目编辑关联表(多对多)", "material_project_editor");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != materialProjectEditorList.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "material_project_editor");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教材-项目编辑关联表(多对多)");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, materialProjectEditorList.size());
result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, materialProjectEditorList.size() - count);
result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
SQLParameters.STATISTICS_RESULT.add(result);
}
logger.info("'{}'表迁移完成,异常条目数量:{}", "MaterialProjectEditor", excel.size());
logger.info("原数据库中共有{}条数据,迁移了{}条数据", materialProjectEditorList.size(), count);
// 记录信息
Map<String, Object> msg = new HashMap<String, Object>();
msg.put("result", "MaterialProjectEditor 表迁移完成" + count + "/" + materialProjectEditorList.size());
SQLParameters.STATISTICS.add(msg);
}
use of com.bc.pmpheep.back.po.MaterialProjectEditor in project pmph by BCSquad.
the class MaterialProjectEditorServiceTest method testListMaterialProjectEditors.
@Test
@Rollback(Const.ISROLLBACK)
public void testListMaterialProjectEditors() {
MaterialProjectEditor materialProjectEditor1 = new MaterialProjectEditor(1L, 1L);
materialProjectEditorService.addMaterialProjectEditor(materialProjectEditor1);
materialProjectEditorService.addMaterialProjectEditor(materialProjectEditor1);
// 根据教材id批量查找项目编辑
List<MaterialProjectEditorVO> materialProjectEditor = materialProjectEditorService.listMaterialProjectEditors(128L);
Assert.assertTrue("listMaterialProjectEditors查询失败", materialProjectEditor.size() > 0);
List<MaterialProjectEditorVO> materialProjectEditor2 = materialProjectEditorService.listMaterialProjectEditors(12345678987654L);
Assert.assertTrue("listMaterialProjectEditors查询失败", materialProjectEditor2 != null);
}
Aggregations