shichongfu
2023-04-25 ce0b49552668d3331055e2b1a1447a743dc54939
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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<Object> 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());
        }
    }
 
}