use of com.bc.pmpheep.back.po.Textbook in project pmph by BCSquad.
the class ExcelHelper method fromTextbookTopic.
/**
* Description:用于设置选题号页面的导入功能
*
* @author:lyc
* @date:2018年1月23日下午6:03:03
* @param
* @return Workbook
*/
public Workbook fromTextbookTopic(List<Textbook> dataSource, String sheetName) throws CheckedServiceException, IllegalArgumentException, IllegalAccessException {
if (ObjectUtil.isNull(dataSource) || dataSource.isEmpty()) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "用于导出的数据源为空");
}
Workbook workbook = new HSSFWorkbook();
Sheet sheet = workbook.createSheet(sheetName);
Row header = sheet.createRow(0);
header.createCell(0).setCellValue("书序");
header.createCell(1).setCellValue("书籍名称");
header.createCell(2).setCellValue("版次");
header.createCell(3).setCellValue("选题号");
headerStyleSetup(workbook, 1);
int rowCount = 1;
for (Textbook textbook : dataSource) {
Row row = sheet.createRow(rowCount);
row.createCell(0).setCellValue(textbook.getSort());
row.createCell(1).setCellValue(textbook.getTextbookName());
row.createCell(2).setCellValue(textbook.getTextbookRound());
row.createCell(3).setCellValue(textbook.getTopicNumber());
rowCount++;
}
int[] maxLength = { 2, 12, 2, 12 };
return dataStyleSetup(workbook, 1, rowCount, new ColumnProperties(4, maxLength));
}
use of com.bc.pmpheep.back.po.Textbook in project pmph by BCSquad.
the class MigrationStageFive method textbook.
/**
* 教材书籍表
*/
private void textbook() {
String sql = "select DISTINCT a.*,b.new_pk newmaterid,c.new_pk bookcreateuserid,b.createdate newcreatedate," + " e.new_pk editroid,d.new_pk newcreateuserid,b.createuserid oldcreateuserid" + " from teach_bookinfo a " + " left join teach_material b on b.materid=a.materid " + " left join sys_user c on c.userid=a.createuserid " + " left join sys_user d on d.userid=b.createuserid " + " left join sys_user e on e.userid=a.userid " + " where a.bookname not like '%测%' and b.matername not like '%测%'" + " and b.matername not like '%sd%' " + " and b.matername not like '%7%' and b.matername not like '%1%'";
// 要迁移的旧表名称
String tableName = "teach_bookinfo";
// 增加new_pk字段
JdbcHelper.addColumn(tableName);
List<Map<String, Object>> maps = 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, 0, 0, 0 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
// 默认值
Long constant = 0L;
/* 开始遍历查询结果 */
for (Map<String, Object> map : maps) {
StringBuilder exception = new StringBuilder();
/* 根据MySQL字段类型进行类型转换 */
// 旧表主键
String id = (String) map.get("bookid");
Integer revision = (Integer) map.get("revision");
if (ObjectUtil.isNull(revision)) {
// 没有值,则书籍轮次默认为1
revision = 1;
}
Long c = (Long) map.get("newmaterid");
if (ObjectUtil.isNull(c)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("该教材id为空。"));
// 因教材id不能为空,默认为0
c = constant;
excel.add(map);
logger.error("该教材id为空,此结果将将被记录在Excel中");
if (state[0] == 0) {
reason.append("找不到教材的唯一标识。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
Long createuserid = (Long) map.get("bookcreateuserid");
Long newcreateuseid = (Long) map.get("newcreateuserid");
if (ObjectUtil.isNull(createuserid) && ObjectUtil.isNull(newcreateuseid)) {
/*记录教材书籍表没有的创建者id为空*/
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("该教材的创建者id为空。"));
newcreateuseid = constant;
excel.add(map);
logger.error("该教材的创建者id为空,此结果将将被记录在Excel中");
if (state[1] == 0) {
reason.append("找不到教材的创建者。");
dealWith.append("设为默认值迁入数据库。");
state[1] = 1;
}
// continue;
}
String bookname = (String) map.get("bookname");
if (StringUtil.isEmpty(bookname)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("该书籍名称为空。"));
excel.add(map);
logger.error("该书籍名称为空,此结果将将被记录在Excel中");
if (state[2] == 0) {
reason.append("找不到书籍的名称。");
dealWith.append("放弃迁移。");
state[2] = 1;
}
continue;
}
java.util.Date ceDate = (java.util.Date) map.get("createdate");
/*教材表对应书籍创建时间*/
java.util.Date createdate = (java.util.Date) map.get("newcreatedate");
if (ObjectUtil.isNull(ceDate) && ObjectUtil.isNull(createdate)) {
// 如果没有创建时间 就查找关联教材创建时间
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("创建时间为空。"));
excel.add(map);
logger.error("创建时间为空,因新库不能插入null,去教材表找对应创建时间,此结果将将被记录在Excel中");
if (state[3] == 0) {
reason.append("找不到书籍的创建时间。");
dealWith.append("放弃迁移。");
state[3] = 1;
}
continue;
}
Integer xnumber = (Integer) map.get("xnumber");
if (ObjectUtil.isNull(xnumber)) {
map.put(SQLParameters.EXCEL_EX_HEADER, exception.append("图书序号为空。"));
xnumber = (int) constant.longValue();
excel.add(map);
logger.error("图书序号为空,此结果将将被记录在Excel中");
if (state[4] == 0) {
reason.append("找不到书籍的序号。");
dealWith.append("设为默认值迁入数据库。");
state[4] = 1;
}
// continue;
}
Textbook textbook = new Textbook();
// 书籍轮次
textbook.setTextbookRound(revision);
// 教材id
textbook.setMaterialId(c);
if (createuserid == newcreateuseid) {
// 如果没有创建者id 就找教材创建者id
// 创建者id
textbook.setFounderId(createuserid);
} else {
// 创建者id
textbook.setFounderId(newcreateuseid);
}
if (ceDate == createdate) {
// 创建时间
textbook.setGmtCreate((Timestamp) ceDate);
} else {
textbook.setGmtCreate((Timestamp) createdate);
}
// 图书序号
textbook.setSort(xnumber);
// 策划编辑id
textbook.setPlanningEditor((Long) map.get("editroid"));
// 书籍名称
textbook.setTextbookName(bookname);
// 公布时间
textbook.setGmtPublished((Timestamp) map.get("resultpublishdate"));
// ISBN号
textbook.setIsbn((String) map.get("isbn"));
// 是否锁定(通过)旧平台无该状态 默认0
textbook.setIsLocked(false);
// 公布后再次修改次数 旧平台无该状态 默认0
textbook.setRevisionTimes(0);
// 公布后再次公布次数 旧平台无该状态 默认0
textbook.setRepublishTimes(0);
// 修改时间 旧平台无 默认为公布时间
textbook.setGmtUpdate((Timestamp) map.get("resultpublishdate"));
/**
* 旧表处理状态 10:待选主编/副主编;11:已分配主编/副主编;12:已确定主编/副主编 20:已分配策划编辑;30:策划编辑已预选编委;
* 40:第一主编已选编委;50:策划编辑审核通过编委;60:项目编辑审核通过编委;70:主任审核通过;80:已发布
*/
Integer dealtype = Integer.parseInt((String) map.get("dealtype"));
if (dealtype >= 11) {
// 是否已选定第一主编
textbook.setIsChiefChosen(true);
}
if (dealtype >= 12) {
// 是否已预选编委
textbook.setIsChiefPublished(true);
}
if (dealtype >= 40) {
// 主编是否选定编委
textbook.setIsListSelected(true);
}
if (dealtype >= 50) {
// 策划编辑是否确定名单
textbook.setIsPlanningEditorConfirm(true);
}
if (dealtype >= 60) {
// 项目编辑是否确定名单
textbook.setIsProjectEditorConfirm(true);
}
if (dealtype >= 80) {
// 是否已公布
textbook.setIsPublished(true);
}
/* 开始新增新表对象,并设置属性值 */
textbook = textbookService.addTextbook(textbook);
long pk = textbook.getId();
// 更新旧表中new_pk字段
JdbcHelper.updateNewPrimaryKey(tableName, pk, "bookid", id);
count++;
if (null == map.get("exception")) {
correctCount++;
}
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "教材书籍表", "textbook");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != maps.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "textbook");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "教材书籍表");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.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, maps.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("'{}'表迁移完成,异常条目数量:{}", tableName, excel.size());
logger.info("原数据库中共有{}条数据,迁移了{}条数据", maps.size(), count);
// 记录信息
Map<String, Object> msg = new HashMap<String, Object>();
msg.put("result", "" + tableName + " 表迁移完成" + count + "/" + maps.size());
SQLParameters.STATISTICS.add(msg);
}
use of com.bc.pmpheep.back.po.Textbook in project pmph by BCSquad.
the class TextbookServiceTest method testGetTextbook.
@Test
@Rollback(Const.ISROLLBACK)
public void testGetTextbook() {
long id = add().getId();
Textbook textbook = textbookService.getTextbookById(id);
Assert.assertNotNull("获取教材书籍信息失败", textbook);
}
use of com.bc.pmpheep.back.po.Textbook in project pmph by BCSquad.
the class TextbookServiceTest method testUpdateTextbook.
@Test
@Rollback(Const.ISROLLBACK)
public void testUpdateTextbook() {
Textbook textbook = add();
textbook.setMaterialId(17L);
textbook.setSort(6);
Integer count = textbookService.updateTextbook(textbook);
Assert.assertTrue("数据更新失败", count > 0);
}
use of com.bc.pmpheep.back.po.Textbook in project pmph by BCSquad.
the class TextbookServiceTest method add.
private Textbook add() {
Textbook textbook = new Textbook();
textbook.setMaterialId(1L);
textbook.setTextbookName("心理诊断学");
textbook.setTextbookRound(5);
textbook.setSort(2);
textbook.setFounderId(2L);
textbookService.addTextbook(textbook);
Textbook textbook2 = new Textbook(2L, "心理统计学", 3, 1, 9L);
textbookService.addTextbook(textbook2);
Textbook textbook3 = new Textbook(1L, "变态心理学", 8, 3, 10L);
textbookService.addTextbook(textbook3);
return textbook3;
}
Aggregations