package com.product.org.admin.controller; import com.product.common.lang.StringUtils; import com.product.core.config.CoreConst; import com.product.core.config.Global; import com.product.core.controller.support.AbstractBaseController; import com.product.core.dao.BaseDao; import com.product.core.entity.FieldSetEntity; import com.product.core.entity.RequestParameterEntity; import com.product.core.exception.BaseException; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.module.sys.version.ApiVersion; import com.product.org.admin.config.CmnConst; import com.product.org.admin.config.SystemCode; import com.product.util.BaseUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * @Author cheng * @Description 附件 * @Date 2021/4/23 16:31 * @Version 1.0 */ @RestController @RequestMapping("/api/attachment") public class AttachmentController extends AbstractBaseController { @Autowired BaseDao baseDao; @PostMapping("/find-attachment/{version}") @ApiVersion(1) public String findAttachment(HttpServletRequest request) { try { FieldSetEntity fse = null; Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA); RequestParameterEntity rpe = (RequestParameterEntity) bean; if (null != rpe && null != rpe.getFormData()) { fse = rpe.getFormData(); } if (fse == null) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); return this.error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText()); } // 验证表名 附件表关联的表名 字段名是否正确 if (!CmnConst.PRODUCT_SYS_ATTACHMENTS.equals(fse.getTableName()) || StringUtils.isEmpty(fse.getUUID()) || StringUtils.isEmpty(fse.getString(CmnConst.TABLE_NAME)) || StringUtils.isEmpty(fse.getString(CmnConst.FIELD_NAME))) { SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); return this.error(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText()); } List params = new ArrayList<>(); //luoxin 去掉限制后子流程表也可以引用主流程附件 // params.add(fse.getString(CmnConst.TABLE_NAME)); // params.add(fse.getString(CmnConst.FIELD_NAME)); params.addAll(Arrays.asList(fse.getUUID().split(","))); StringBuilder sb = new StringBuilder(); sb.append("select a.uuid,a.file_name name,a.view_online_sign,ifnull(b.dict_value,a.attachment_type_uuid) file_type,"); sb.append("ifnull((select 1 from dual where "); sb.append(BaseUtil.buildQuestionMarkFilter("LOWER(ifnull(b.dict_value,a.attachment_type_uuid))", Global.getSystemConfig("can.web.online.edit", "doc,docx,xls,xlsx.ppt,pptx,wps,cvs").split(","), true)); sb.append(") ,0)edit_online "); sb.append(" from "); sb.append(fse.getTableName()); sb.append(" a left join product_sys_dict b on b.dict_name='upload_file_format' and b.uuid=a.attachment_type_uuid where "); //luoxin 去掉限制后子流程表也可以引用主流程附件 // sb.append(" where attachment_data_table=? and attachment_data_field=? and "); sb.append(BaseUtil.buildQuestionMarkFilter("a.uuid", params.size(), true)); return OK_List(baseDao.listTable(sb.toString(), params.toArray())); } catch (BaseException e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); return error(e.getCode(), e.getMessage()); } catch (Exception e) { e.printStackTrace(); SpringMVCContextHolder.getSystemLogger().error(e); SpringMVCContextHolder.getSystemLogger().error(SystemCode.ATTACHMENT_FIND_FIAL.getValue(), SystemCode.ATTACHMENT_FIND_FIAL.getText()); return error(SystemCode.ATTACHMENT_FIND_FIAL.getValue(), SystemCode.ATTACHMENT_FIND_FIAL.getText()); } } }