use of com.bc.pmpheep.back.po.Material in project pmph by BCSquad.
the class TextbookServiceImpl method addOrUpdateTextBookList.
@SuppressWarnings("unchecked")
@Override
public List<Textbook> addOrUpdateTextBookList(Long materialId, Boolean isPublic, String textbooks, String sessionId) throws CheckedServiceException {
if (ObjectUtil.isNull(materialId)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "教材id不能为空");
}
if (ObjectUtil.isNull(isPublic)) {
throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "可见性区别不能为空");
}
if (StringUtil.isEmpty(textbooks)) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "书籍信息不能为空");
}
/*
* 检测同一教材下书名和版次都相同的数据
*/
List<Map<String, Object>> list = new ArrayList<>();
Gson gson = new GsonBuilder().serializeNulls().create();
List<Textbook> bookList = gson.fromJson(textbooks, new TypeToken<ArrayList<Textbook>>() {
}.getType());
/*
* 对数据进行排序
*/
ComparatorChain comparatorChain = new ComparatorChain();
comparatorChain.addComparator(new BeanComparator<Textbook>("sort"));
Collections.sort(bookList, comparatorChain);
/*
* 查询此教材下现有的书籍
*/
List<Textbook> textbookList = textbookDao.getTextbookByMaterialId(materialId);
List<Long> ids = new ArrayList<>();
for (Textbook textbook : textbookList) {
ids.add(textbook.getId());
}
// 装数据库中本来已经有的书籍id
List<Long> delBook = new ArrayList<>();
// 判断书序号的连续性计数器
int count = 1;
for (Textbook book : bookList) {
if (ObjectUtil.isNull(book.getMaterialId())) {
book.setMaterialId(materialId);
}
if (StringUtil.isEmpty(book.getTextbookName())) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "书籍名称不能为空");
}
if (StringUtil.strLength(book.getTextbookName()) > 50) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.ILLEGAL_PARAM, "书籍名称字数不能超过25个,请修改后再提交");
}
if (ObjectUtil.isNull(book.getTextbookRound())) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "书籍轮次不能为空");
}
if (book.getTextbookRound().intValue() > 2147483647) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.ILLEGAL_PARAM, "图书轮次过大,请修改后再提交");
}
if (ObjectUtil.isNull(book.getSort())) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "图书序号不能为空");
}
if (book.getSort().intValue() > 2147483647) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.ILLEGAL_PARAM, "图书序号过大,请修改后再提交");
}
if (ObjectUtil.isNull(book.getFounderId())) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "创建人id不能为空");
}
if (count != book.getSort()) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.ILLEGAL_PARAM, "书籍序号必须从1开始且连续");
}
Map<String, Object> map = new HashMap<>();
map.put(book.getTextbookName(), book.getTextbookRound());
if (list.contains(map)) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.ILLEGAL_PARAM, "同一教材下书名和版次不能都相同");
}
/*
* 设置书目录时保存操作传回来的对象里可能有已经存在的书籍,已经存在的修改 相关信息,没有的进行新增操作
*/
if (ObjectUtil.notNull(textbookDao.getTextbookById(book.getId()))) {
textbookDao.updateTextbook(book);
delBook.add(book.getId());
} else {
textbookDao.addTextbook(book);
}
list.add(map);
count++;
}
/* 设置书目录时若删除了部分书籍,找出这些书籍的id并将表中的相关数据删除掉 */
ids.removeAll(delBook);
if (CollectionUtil.isNotEmpty(ids)) {
for (Long id : ids) {
if (CollectionUtil.isNotEmpty(decPositionService.listDecPositionsByTextbookId(id)) && decPositionService.listDecPositionsByTextbookId(id).size() > 0) {
throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "被申报的书籍不允许被删除");
} else {
textbookDao.deleteTextbookById(id);
}
}
}
/* 修改对应的教材的可见性区别 */
Material material = new Material();
material.setId(materialId);
material.setIsPublic(isPublic);
materialService.updateMaterial(material, sessionId);
return textbookDao.getTextbookByMaterialId(materialId);
}
use of com.bc.pmpheep.back.po.Material in project pmph by BCSquad.
the class WordHelperTest method test.
@Test
@Ignore
public void test() throws CheckedServiceException, IllegalArgumentException, IllegalAccessException {
List<DeclarationEtcBO> list = declarationService.declarationEtcBO(2L, null, null, null, null, null, null, null, null, null);
Material material = materialService.getMaterialById(2L);
StringBuilder str = new StringBuilder();
str.append(material.getIsEduExpUsed() ? "1" : "0");
str.append(material.getIsWorkExpUsed() ? "1" : "0");
str.append(material.getIsTeachExpUsed() ? "1" : "0");
str.append(material.getIsAchievementUsed() ? "1" : "0");
str.append(material.getIsAcadeUsed() ? "1" : "0");
str.append(material.getIsLastPositionUsed() ? "1" : "0");
str.append(material.getIsNationalPlanUsed() ? "1" : "0");
str.append(material.getIsPmphTextbookUsed() ? "1" : "0");
str.append(material.getIsTextbookUsed() ? "1" : "0");
str.append(material.getIsMoocDigitalUsed() ? "1" : "0");
str.append(material.getIsCourseUsed() ? "1" : "0");
str.append(material.getIsResearchUsed() ? "1" : "0");
str.append(material.getIsMonographUsed() ? "1" : "0");
str.append(material.getIsPublishRewardUsed() ? "1" : "0");
str.append(material.getIsSciUsed() ? "1" : "0");
str.append(material.getIsClinicalRewardUsed() ? "1" : "0");
str.append(material.getIsAcadeRewardUsed() ? "1" : "0");
str.append(material.getIsIntentionUsed() ? "1" : "0");
String src = this.getClass().getResource("/").getPath();
src = src.substring(1);
if (!src.endsWith(File.separator)) {
src += File.separator;
}
wordHelper.export("测试", src, list, str.toString(), materialExtensionService.getMaterialExtensionByMaterialId(2L));
}
Aggregations