|
|
@@ -190,10 +190,12 @@ public class QwSopTempServiceImpl implements IQwSopTempService {
|
|
|
|
|
|
@Override
|
|
|
public int shareQwSopTemp(QwSopShareTempParam param) {
|
|
|
- QwSopTemp qwSopTemp = qwSopTempMapper.selectQwSopTempById(param.getTempleId());
|
|
|
+ QwSopTemp sourceTemp = qwSopTempMapper.selectQwSopTempById(param.getTempleId());
|
|
|
+ String sourceId = sourceTemp.getId();
|
|
|
Arrays.stream(param.getCompanyIds()).forEach(companyId -> {
|
|
|
-
|
|
|
Company company = companyService.selectCompanyById(companyId);
|
|
|
+ QwSopTemp qwSopTemp = BeanCopyUtils.copy(sourceTemp, QwSopTemp.class);
|
|
|
+ qwSopTemp.setId(sourceId);
|
|
|
qwSopTemp.setCreateBy(company.getUserId().toString());
|
|
|
qwSopTemp.setCompanyId(companyId);
|
|
|
copyTemplate(qwSopTemp);
|
|
|
@@ -365,6 +367,7 @@ public class QwSopTempServiceImpl implements IQwSopTempService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @DataSource(DataSourceType.SOP)
|
|
|
public void copyTemplate(QwSopTemp qwSopTemp) {
|
|
|
String oldId = qwSopTemp.getId();
|
|
|
String newId = UUID.randomUUID().toString();
|
|
|
@@ -381,31 +384,60 @@ public class QwSopTempServiceImpl implements IQwSopTempService {
|
|
|
qwSopTemp.setCreateTime(sdf.format(new Date()));
|
|
|
qwSopTemp.setCreateBy(qwSopTemp.getCreateBy());
|
|
|
qwSopTempMapper.insertQwSopTemp(qwSopTemp);
|
|
|
- List<QwSopTempDay> dayList = qwSopTempRulesService.listByTempIdAll(oldId);
|
|
|
- if (dayList.isEmpty()) return;
|
|
|
-// List<QwSopTempRules> rulesList = qwSopTempRulesService.listByTempId(oldId);
|
|
|
+ List<QwSopTempDay> sourceDayList = qwSopTempRulesService.listByTempIdAll(oldId);
|
|
|
+ if (sourceDayList.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 深拷贝,避免修改源模板数据;清空主键以便 insertBatch 执行 INSERT 而非 UPDATE
|
|
|
+ List<QwSopTempDay> dayList = JSON.parseArray(JSON.toJSONString(sourceDayList), QwSopTempDay.class);
|
|
|
dayList.forEach(day -> {
|
|
|
+ day.setId(null);
|
|
|
day.setTempId(newId);
|
|
|
- if (day.getList() != null && !day.getList().isEmpty()) {
|
|
|
- day.getList().forEach(e -> {
|
|
|
- e.setTempId(newId);
|
|
|
- if (e.getSettingList() != null && !e.getSettingList().isEmpty()) {
|
|
|
- e.getSettingList().forEach(item -> {
|
|
|
- item.setTempId(newId);
|
|
|
+ if (CollectionUtils.isNotEmpty(day.getList())) {
|
|
|
+ day.getList().forEach(rule -> {
|
|
|
+ rule.setId(null);
|
|
|
+ rule.setDayId(null);
|
|
|
+ rule.setTempId(newId);
|
|
|
+ if (CollectionUtils.isNotEmpty(rule.getSettingList())) {
|
|
|
+ rule.getSettingList().forEach(content -> {
|
|
|
+ content.setId(null);
|
|
|
+ content.setRulesId(null);
|
|
|
+ content.setDayId(null);
|
|
|
+ content.setTempId(newId);
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
qwSopTempDayService.insertBatch(dayList);
|
|
|
- dayList.forEach(e -> e.getList().forEach(item -> item.setDayId(e.getId())));
|
|
|
- List<QwSopTempRules> collect = dayList.stream().flatMap(e -> e.getList().stream()).collect(Collectors.toList());
|
|
|
+ dayList.forEach(day -> {
|
|
|
+ if (CollectionUtils.isNotEmpty(day.getList())) {
|
|
|
+ day.getList().forEach(rule -> rule.setDayId(day.getId()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<QwSopTempRules> collect = dayList.stream()
|
|
|
+ .filter(day -> CollectionUtils.isNotEmpty(day.getList()))
|
|
|
+ .flatMap(day -> day.getList().stream())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (collect.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
qwSopTempRulesService.insertBatch(collect);
|
|
|
- collect.forEach(e -> e.getSettingList().forEach(item -> {
|
|
|
- item.setRulesId(e.getId());
|
|
|
- item.setDayId(e.getDayId());
|
|
|
- }));
|
|
|
- qwSopTempContentService.insertBatch(collect.stream().flatMap(e -> e.getSettingList().stream()).collect(Collectors.toList()));
|
|
|
+ collect.forEach(rule -> {
|
|
|
+ if (CollectionUtils.isNotEmpty(rule.getSettingList())) {
|
|
|
+ rule.getSettingList().forEach(content -> {
|
|
|
+ content.setRulesId(rule.getId());
|
|
|
+ content.setDayId(rule.getDayId());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<QwSopTempContent> contentList = collect.stream()
|
|
|
+ .filter(rule -> CollectionUtils.isNotEmpty(rule.getSettingList()))
|
|
|
+ .flatMap(rule -> rule.getSettingList().stream())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!contentList.isEmpty()) {
|
|
|
+ qwSopTempContentService.insertBatch(contentList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|