|
|
@@ -6,10 +6,9 @@ import com.x.base.core.entity.annotation.CheckPersistType;
|
|
|
import com.x.base.core.project.config.Config;
|
|
|
import com.x.base.core.project.config.StorageMapping;
|
|
|
import com.x.base.core.project.exception.ExceptionAccessDenied;
|
|
|
-import com.x.base.core.project.exception.ExceptionEntityNotExist;
|
|
|
import com.x.base.core.project.http.ActionResult;
|
|
|
import com.x.base.core.project.http.EffectivePerson;
|
|
|
-import com.x.base.core.project.jaxrs.WoId;
|
|
|
+import com.x.base.core.project.jaxrs.WrapBoolean;
|
|
|
import com.x.base.core.project.logger.Logger;
|
|
|
import com.x.base.core.project.logger.LoggerFactory;
|
|
|
import com.x.base.core.project.tools.ExtractTextTools;
|
|
|
@@ -18,38 +17,29 @@ import com.x.processplatform.assemble.surface.ThisApplication;
|
|
|
import com.x.processplatform.assemble.surface.WorkControl;
|
|
|
import com.x.processplatform.core.entity.content.Attachment;
|
|
|
import com.x.processplatform.core.entity.content.Work;
|
|
|
-import com.x.processplatform.core.entity.element.Application;
|
|
|
-import com.x.processplatform.core.entity.element.Process;
|
|
|
+import com.x.processplatform.core.entity.content.WorkCompleted;
|
|
|
+import com.x.processplatform.core.entity.element.ActivityType;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.tika.Tika;
|
|
|
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
|
|
|
|
|
-class ActionManageUpload extends BaseAction {
|
|
|
+class ActionManageBatchUpload extends BaseAction {
|
|
|
|
|
|
- private static Logger logger = LoggerFactory.getLogger(ActionManageUpload.class);
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(ActionManageBatchUpload.class);
|
|
|
|
|
|
- ActionResult<Wo> execute(EffectivePerson effectivePerson, String workId, String site, String fileName, byte[] bytes,
|
|
|
+ ActionResult<Wo> execute(EffectivePerson effectivePerson, String workIds, String site, String fileName, byte[] bytes,
|
|
|
FormDataContentDisposition disposition, String extraParam, String person) throws Exception {
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
ActionResult<Wo> result = new ActionResult<>();
|
|
|
Business business = new Business(emc);
|
|
|
- /* 后面要重新保存 */
|
|
|
- Work work = emc.find(workId, Work.class);
|
|
|
- /* 判断work是否存在 */
|
|
|
- if (null == work) {
|
|
|
- throw new ExceptionEntityNotExist(workId, Work.class);
|
|
|
- }
|
|
|
- Process process = business.process().pick(work.getProcess());
|
|
|
- Application application = business.application().pick(work.getApplication());
|
|
|
// 需要对这个应用的管理权限
|
|
|
- if (!business.canManageApplicationOrProcess(effectivePerson, application, process)) {
|
|
|
+ if (!business.canManageApplication(effectivePerson, null)) {
|
|
|
throw new ExceptionAccessDenied(effectivePerson);
|
|
|
}
|
|
|
+
|
|
|
if (StringUtils.isEmpty(fileName)) {
|
|
|
fileName = this.fileName(disposition);
|
|
|
}
|
|
|
- /* 调整可能的附件名称 */
|
|
|
- fileName = this.adjustFileName(business, work.getJob(), fileName);
|
|
|
|
|
|
/* 天谷印章扩展 */
|
|
|
if (StringUtils.isNotEmpty(extraParam)) {
|
|
|
@@ -61,26 +51,41 @@ class ActionManageUpload extends BaseAction {
|
|
|
site = wiExtraParam.getSite();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
person = business.organization().person().get(person);
|
|
|
if(StringUtils.isEmpty(person)){
|
|
|
person = effectivePerson.getDistinguishedName();
|
|
|
}
|
|
|
- StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
|
|
|
- Attachment attachment = this.concreteAttachment(work, person, site);
|
|
|
- attachment.saveContent(mapping, bytes, fileName);
|
|
|
- attachment.setType((new Tika()).detect(bytes, fileName));
|
|
|
- logger.debug("filename:{}, file type:{}.", attachment.getName(), attachment.getType());
|
|
|
- if (Config.query().getExtractImage() && ExtractTextTools.supportImage(attachment.getName())
|
|
|
- && ExtractTextTools.available(bytes)) {
|
|
|
- attachment.setText(ExtractTextTools.image(bytes));
|
|
|
- logger.debug("filename:{}, file type:{}, text:{}.", attachment.getName(), attachment.getType(),
|
|
|
- attachment.getText());
|
|
|
+ if(StringUtils.isNotEmpty(workIds) && bytes!=null && bytes.length>0) {
|
|
|
+ String[] idArray = workIds.split(",");
|
|
|
+ for (String workId : idArray) {
|
|
|
+ Attachment attachment = null;
|
|
|
+ Work work = emc.find(workId.trim(), Work.class);
|
|
|
+ if(work!=null) {
|
|
|
+ attachment = this.concreteAttachment(work, person, site);
|
|
|
+ }else{
|
|
|
+ WorkCompleted workCompleted = emc.find(workId, WorkCompleted.class);
|
|
|
+ if (null != workCompleted) {
|
|
|
+ attachment = this.concreteAttachment(workCompleted, person, site);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(attachment!=null){
|
|
|
+ StorageMapping mapping = ThisApplication.context().storageMappings().random(Attachment.class);
|
|
|
+ attachment.saveContent(mapping, bytes, fileName);
|
|
|
+ attachment.setType((new Tika()).detect(bytes, fileName));
|
|
|
+ if (Config.query().getExtractImage() && ExtractTextTools.supportImage(attachment.getName())
|
|
|
+ && ExtractTextTools.available(bytes)) {
|
|
|
+ attachment.setText(ExtractTextTools.image(bytes));
|
|
|
+ }
|
|
|
+ emc.beginTransaction(Attachment.class);
|
|
|
+ emc.persist(attachment, CheckPersistType.all);
|
|
|
+ emc.commit();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- emc.beginTransaction(Attachment.class);
|
|
|
- emc.persist(attachment, CheckPersistType.all);
|
|
|
- emc.commit();
|
|
|
+
|
|
|
Wo wo = new Wo();
|
|
|
- wo.setId(attachment.getId());
|
|
|
+ wo.setValue(true);
|
|
|
result.setData(wo);
|
|
|
return result;
|
|
|
}
|
|
|
@@ -104,7 +109,25 @@ class ActionManageUpload extends BaseAction {
|
|
|
return attachment;
|
|
|
}
|
|
|
|
|
|
- public static class Wo extends WoId {
|
|
|
+ private Attachment concreteAttachment(WorkCompleted workCompleted, String person, String site) throws Exception {
|
|
|
+ Attachment attachment = new Attachment();
|
|
|
+ attachment.setCompleted(true);
|
|
|
+ attachment.setPerson(person);
|
|
|
+ attachment.setLastUpdatePerson(person);
|
|
|
+ attachment.setSite(site);
|
|
|
+ /** 用于判断目录的值 */
|
|
|
+ attachment.setWorkCreateTime(workCompleted.getStartTime());
|
|
|
+ attachment.setApplication(workCompleted.getApplication());
|
|
|
+ attachment.setProcess(workCompleted.getProcess());
|
|
|
+ attachment.setJob(workCompleted.getJob());
|
|
|
+ attachment.setActivity(workCompleted.getActivity());
|
|
|
+ attachment.setActivityName(workCompleted.getActivityName());
|
|
|
+ attachment.setActivityToken(workCompleted.getActivity());
|
|
|
+ attachment.setActivityType(ActivityType.end);
|
|
|
+ return attachment;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static class Wo extends WrapBoolean {
|
|
|
|
|
|
}
|
|
|
|