|
|
@@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
-import com.xjrsoft.common.enums.TextbookTypeEnum;
|
|
|
import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.module.base.entity.BaseClass;
|
|
|
@@ -35,6 +34,8 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -192,8 +193,8 @@ public class WfTextbookSubscriptionServiceImpl extends MPJBaseServiceImpl<WfText
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public WfTextbookSubscriptionVo getInfo(Long id) {
|
|
|
- WfTextbookSubscription wfTextbookSubscription = this.getById(id);
|
|
|
+ public WfTextbookSubscriptionVo getInfo(WfTextbookSubscriptionDto dto) {
|
|
|
+ WfTextbookSubscription wfTextbookSubscription = this.getById(dto.getId());
|
|
|
if (wfTextbookSubscription == null) {
|
|
|
return null;
|
|
|
}
|
|
|
@@ -210,6 +211,10 @@ public class WfTextbookSubscriptionServiceImpl extends MPJBaseServiceImpl<WfText
|
|
|
ext -> ext.selectAs(DictionaryDetail::getName, WfTextbookSubscriptionItemVo::getTextbookTypeCn))
|
|
|
.leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, Textbook::getCourseSubjectId)
|
|
|
.eq(WfTextbookSubscriptionItem::getWfTextbookSubscriptionId, wfTextbookSubscription.getId())
|
|
|
+ .eq(dto.getWfTextbookSubscriptionItemId() != null && dto.getWfTextbookSubscriptionItemId() > 0, WfTextbookSubscriptionItem::getId, dto.getWfTextbookSubscriptionItemId())
|
|
|
+ .eq(dto.getTextbookType() != null && !dto.getTextbookType().isEmpty(), Textbook::getTextbookType, dto.getTextbookType())
|
|
|
+ .like(dto.getBookName() != null && !dto.getBookName().isEmpty(), Textbook::getBookName, dto.getBookName())
|
|
|
+ .like(dto.getCourseSubjectIdCn() != null && !dto.getCourseSubjectIdCn().isEmpty(), BaseCourseSubject::getName, dto.getCourseSubjectIdCn())
|
|
|
;
|
|
|
List<WfTextbookSubscriptionItemVo> itemList = wfTextbookSubscriptionWfTextbookSubscriptionItemMapper.selectJoinList(WfTextbookSubscriptionItemVo.class, mpjLambdaWrapper);
|
|
|
|
|
|
@@ -339,30 +344,83 @@ public class WfTextbookSubscriptionServiceImpl extends MPJBaseServiceImpl<WfText
|
|
|
if (dtos.isEmpty()) {
|
|
|
return false;
|
|
|
}
|
|
|
+ Map<String, Object> result = saveData(dtos);
|
|
|
+ return result != null && (int) result.get("successNum") > 0;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public String excelImport(InputStream inputStream, Long wfTextbookSubscriptionId) {
|
|
|
+ AtomicReference<Map<String, Object>> atomicMap = new AtomicReference<>(new HashMap<>());
|
|
|
+ EasyExcel.read(inputStream, TextbookInstockroomImportDto.class, new PageReadListener<TextbookInstockroomImportDto>(dataList -> {
|
|
|
+ if (dataList.isEmpty()) {
|
|
|
+ throw new MyException("导入数据为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<TextbookInstockroomDto> textbookInstockroomDtoList = new ArrayList<>();
|
|
|
+ for (TextbookInstockroomImportDto item : dataList){
|
|
|
+ textbookInstockroomDtoList.add(new TextbookInstockroomDto(){{
|
|
|
+ setWfTextbookSubscriptionId(wfTextbookSubscriptionId);
|
|
|
+ setIssn(item.getIssn());
|
|
|
+ setInNum(item.getInNum());
|
|
|
+ }});
|
|
|
+ }
|
|
|
+ atomicMap.set(saveData(textbookInstockroomDtoList));
|
|
|
+ })).sheet().doRead();
|
|
|
+
|
|
|
+ if(atomicMap.get() != null){
|
|
|
+ return "计划入库教材" + atomicMap.get().get("allNum") + "样,成功入库" + atomicMap.get().get("successNum") + "样,成功入库" + atomicMap.get().get("instockroomNum") + "本";
|
|
|
+ }
|
|
|
+ return "计划入库教材0样,成功入库0样,成功入库0本";
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Object> saveData(List<TextbookInstockroomDto> dtos) {
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ int successNum = 0;
|
|
|
+ int instockroomNum = 0;
|
|
|
//获取需要修改的list
|
|
|
- LambdaQueryWrapper<WfTextbookSubscriptionItem> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ MPJLambdaWrapper<WfTextbookSubscriptionItem> queryWrapper = new MPJLambdaWrapper<>();
|
|
|
queryWrapper
|
|
|
+ .select(WfTextbookSubscriptionItem::getId)
|
|
|
+ .selectAs(Textbook::getIssn, WfTextbookSubscriptionItem::getIssn)
|
|
|
+ .select(WfTextbookSubscriptionItem.class, x -> VoToColumnUtil.fieldsToColumns(WfTextbookSubscriptionItem.class).contains(x.getProperty()))
|
|
|
+ .leftJoin(Textbook.class, Textbook::getId, WfTextbookSubscriptionItem::getTextbookId)
|
|
|
.eq(WfTextbookSubscriptionItem::getWfTextbookSubscriptionId, dtos.get(0).getWfTextbookSubscriptionId())
|
|
|
.eq(WfTextbookSubscriptionItem::getDeleteMark, DeleteMark.NODELETE.getCode())
|
|
|
;
|
|
|
List<WfTextbookSubscriptionItem> wfTextbookSubscriptionItemList = wfTextbookSubscriptionWfTextbookSubscriptionItemMapper.selectList(queryWrapper);
|
|
|
|
|
|
if (wfTextbookSubscriptionItemList.isEmpty()) {
|
|
|
- return false;
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- Map<Long, WfTextbookSubscriptionItem> itemMap = wfTextbookSubscriptionItemList
|
|
|
+ Map<Long, WfTextbookSubscriptionItem> itemByIdMap = wfTextbookSubscriptionItemList
|
|
|
.stream()
|
|
|
.collect(Collectors.toMap(
|
|
|
WfTextbookSubscriptionItem::getId,
|
|
|
item -> item
|
|
|
));
|
|
|
|
|
|
+ Map<String, WfTextbookSubscriptionItem> itemByIssnMap = wfTextbookSubscriptionItemList
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ WfTextbookSubscriptionItem::getIssn,
|
|
|
+ item -> item
|
|
|
+ ));
|
|
|
+
|
|
|
Date now = new Date();
|
|
|
Long loginId = StpUtil.getLoginIdAsLong();
|
|
|
for (TextbookInstockroomDto dto : dtos) {
|
|
|
- WfTextbookSubscriptionItem old = itemMap.get(dto.getId());
|
|
|
+ WfTextbookSubscriptionItem old;
|
|
|
+ if(dto.getId() != null && dto.getId() > 0){
|
|
|
+ old = itemByIdMap.get(dto.getId());
|
|
|
+ } else {
|
|
|
+ old = itemByIssnMap.get(dto.getIssn());
|
|
|
+ }
|
|
|
+
|
|
|
+ if(old == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
WfTextbookSubscriptionItem updateItem = new WfTextbookSubscriptionItem();
|
|
|
updateItem.setId(old.getId());
|
|
|
updateItem.setInStockroomNum(old.getInStockroomNum() + dto.getInNum());
|
|
|
@@ -376,89 +434,13 @@ public class WfTextbookSubscriptionServiceImpl extends MPJBaseServiceImpl<WfText
|
|
|
setWarehouseNumber(dto.getInNum());
|
|
|
setSource("wm_manual");
|
|
|
}});
|
|
|
+ successNum++;
|
|
|
+ instockroomNum += dto.getInNum();
|
|
|
}
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Boolean excelImport(InputStream inputStream) {
|
|
|
- EasyExcel.read(inputStream, TextbookImportDto.class, new PageReadListener<TextbookImportDto>(dataList -> {
|
|
|
- if (dataList.isEmpty()) {
|
|
|
- throw new MyException("导入数据为空");
|
|
|
- }
|
|
|
- saveData(dataList);
|
|
|
- })).sheet().headRowNumber(3).doRead();
|
|
|
-
|
|
|
- return true;
|
|
|
- }
|
|
|
+ result.put("allNum", dtos.size());
|
|
|
+ result.put("successNum", successNum);
|
|
|
+ result.put("instockroomNum", instockroomNum);
|
|
|
|
|
|
- private void saveData(List<TextbookImportDto> dataList) {
|
|
|
- /*//查询所有需要的数据
|
|
|
- //学科组
|
|
|
- List<SubjectGroup> subjectGroupList = subjectGroupMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
- Map<String, Long> subjectGroupNameAndIdMap = subjectGroupList.stream().collect(Collectors.toMap(SubjectGroup::getGroupName, SubjectGroup::getId, (k1, k2) -> k1));
|
|
|
-
|
|
|
- //使用课程
|
|
|
- List<BaseCourseSubject> baseCourseSubjectList = baseCourseSubjectMapper.selectList(new LambdaQueryWrapper<>());
|
|
|
- Map<String, Long> baseCourseSubjectNameAndIdMap = baseCourseSubjectList.stream().collect(Collectors.toMap(BaseCourseSubject::getName, BaseCourseSubject::getId, (k1, k2) -> k1));
|
|
|
-
|
|
|
- //批量插入或更新数据
|
|
|
- for (TextbookImportDto textbookImportDto : dataList) {
|
|
|
- TextbookCoreAttribute textbookCoreAttribute = new TextbookCoreAttribute();
|
|
|
- BeanUtils.copyProperties(textbookImportDto, textbookCoreAttribute);
|
|
|
-
|
|
|
- Textbook textbook = new Textbook();
|
|
|
- BeanUtils.copyProperties(textbookImportDto, textbook);
|
|
|
-
|
|
|
- // 处理学科组映射
|
|
|
- String groupName = textbookImportDto.getGroupName();
|
|
|
- Long subjectGroupId = Optional.ofNullable(groupName)
|
|
|
- .map(subjectGroupNameAndIdMap::get)
|
|
|
- .orElse(null);
|
|
|
- textbook.setSubjectGroupId(subjectGroupId);
|
|
|
-
|
|
|
- // 处理课程映射
|
|
|
- String courseName = textbookImportDto.getCourseName();
|
|
|
- Long courseSubjectId = Optional.ofNullable(courseName)
|
|
|
- .map(baseCourseSubjectNameAndIdMap::get)
|
|
|
- .orElse(null);
|
|
|
- textbook.setCourseSubjectId(courseSubjectId);
|
|
|
-
|
|
|
- // 处理是否教材计划字段
|
|
|
- String isTextbookPlanCn = textbookImportDto.getIsTextbookPlanCn();
|
|
|
- String isTextbookPlan = Optional.ofNullable(isTextbookPlanCn)
|
|
|
- .filter("是"::equals)
|
|
|
- .map(s -> "yes")
|
|
|
- .orElse("no");
|
|
|
- textbook.setIsTextbookPlan(isTextbookPlan);
|
|
|
-
|
|
|
- // 处理教材类型映射
|
|
|
- String textbookTypeCn = textbookImportDto.getTextbookTypeCn();
|
|
|
- String textbookTypeCode = Optional.ofNullable(textbookTypeCn)
|
|
|
- .map(TextbookTypeEnum::getCode)
|
|
|
- .orElse(null);
|
|
|
- textbook.setTextbookType(textbookTypeCode);
|
|
|
-
|
|
|
- // 判断导入的教材是否已经存在,根据教材的 ISBN 码和使用的学期判断
|
|
|
- LambdaQueryWrapper<Textbook> textbookLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- textbookLambdaQueryWrapper
|
|
|
- .eq(Textbook::getIssn, textbook.getIssn())
|
|
|
- ;
|
|
|
-
|
|
|
- Textbook oldTextbook = this.getOne(textbookLambdaQueryWrapper);
|
|
|
-
|
|
|
- // 已经存在,更新数据
|
|
|
- if (oldTextbook != null) {
|
|
|
- // 更新教材数据
|
|
|
- textbook.setId(oldTextbook.getId());
|
|
|
- textbookTextbookMapper.updateById(textbook);
|
|
|
- } else {
|
|
|
- textbookCoreAttributeService.save(textbookCoreAttribute);
|
|
|
-
|
|
|
- textbook.setTextbookCoreAttributeId(textbookCoreAttribute.getId());
|
|
|
- // 插入教材数据
|
|
|
- textbookTextbookMapper.insert(textbook);
|
|
|
- }
|
|
|
- }*/
|
|
|
+ return result;
|
|
|
}
|
|
|
}
|