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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.vci.web.controller;
 
 
import com.vci.corba.common.PLException;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.query.data.KV;
import com.vci.omd.utils.ObjectTool;
import com.vci.dto.AuditTaskDTO;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
 
/**
 * Description: 评审任务控制器
 *
 * @author: LiHang
 * @date: Created on 2022/2/22
 */
@RestController()
@RequestMapping("/auditTaskController")
public class AuditTaskController {
    /**
     * 平台的客户端调用工具类
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 按每个负责人分别创建评审任务
     *
     * @param auditTaskDTO 评审任务页面传输对象
     * @return 执行结果
     */
    @PostMapping("/create")
    public BaseResult createByPrincipal(@RequestBody AuditTaskDTO auditTaskDTO) {
        VciBaseUtil.alertNotNull(auditTaskDTO.getProcessreviewoid(), "工艺评审主键", auditTaskDTO.getPrincipal(), "负责人");
//        BusinessObjectOperation operation = new BusinessObjectOperation();
        List<BusinessObject> createList = new ArrayList<>();
        List<String> principalList = VciBaseUtil.str2List(auditTaskDTO.getPrincipal());
        List<List<String>> oracleIn = WebUtil.switchListForOracleIn(principalList);
        try {
            oracleIn.forEach(list -> {
                try {
                    String principalStr = Arrays.toString(list.toArray()).replaceAll(",", "','")
                            .replaceAll("\\[","")
                            .replaceAll("\\]","")
                            .replaceAll(" ","");
                    principalStr = "('" + principalStr + "')";
                    String sql = "select us.PLUSERNAME, dept.PLNAME\n" +
                            "from PLUSER us\n" +
                            "         left join PLUSERDEPT ud on us.PLUID = ud.PLUSERUID\n" +
                            "         left join PLDEPT dept on dept.PLUID = ud.PLDEPTUID\n" +
                            "where us.pluid in " + principalStr;
                    KV[][] kvs = platformClientUtil.getQueryService().queryBySql(sql);
                    for (int index = 0; index < kvs.length; index++) {
                        BusinessObject cbo = platformClientUtil.getBOFService().initBusinessObject("audittask");
                        copyAttribute(cbo, auditTaskDTO);
                        ObjectTool.setBOAttributeValue(cbo, "principal", "PLUSERNAME".equals(kvs[index][0].key.toUpperCase(Locale.ROOT)) ? kvs[index][0].value : kvs[index][1].value);
                        ObjectTool.setBOAttributeValue(cbo,"departmentname","PLNAME".equals(kvs[index][0].key.toUpperCase(Locale.ROOT)) ? kvs[index][0].value : kvs[index][1].value);
                        createList.add(cbo);
                    }
                } catch ( PLException vciError) {
                    vciError.printStackTrace();
                }
            });
 
            platformClientUtil.getBOFService().batchCreateBusinessObject(createList.toArray(new BusinessObject[0]),false,false);
        } catch ( PLException vciError) {
            vciError.printStackTrace();
            return BaseResult.fail("创建评审任务失败");
        }
        return BaseResult.success();
    }
 
    /**
     * 复制评审任务字段
     *
     * @param cbo          评审任务业务类型对象
     * @param auditTaskDTO 评审任务页面传输对象
     */
    private void copyAttribute(BusinessObject cbo, AuditTaskDTO auditTaskDTO) {
        setAttribute(cbo, "assigner", StringUtils.isBlank(auditTaskDTO.getAssigner())? WebUtil.getCurrentUserId(): auditTaskDTO.getAssigner());
        setAttribute(cbo, "principal", auditTaskDTO.getPrincipal());
        setAttribute(cbo, "departmentName", auditTaskDTO.getDepartmentname());
        setAttribute(cbo, "content", auditTaskDTO.getContent());
        setAttribute(cbo, "type", auditTaskDTO.getType());
        setAttribute(cbo, "processReviewOid", auditTaskDTO.getProcessreviewoid());
        setAttribute(cbo, "planedStartDate", VciDateUtil.date2Str(auditTaskDTO.getPlanedstartdate(), "yyyy-MM-dd HH:mm:ss"));
        setAttribute(cbo, "place", auditTaskDTO.getPlace());
    }
 
    /**
     * 业务类型设置字段值
     *
     * @param cbo            业务类型
     * @param attributeName  字段名
     * @param attributeValue 字段值
     */
    private void setAttribute(BusinessObject cbo, String attributeName, String attributeValue) {
        if (StringUtils.isNotBlank(attributeValue)) {
            ObjectTool.setBOAttributeValue(cbo, attributeName, attributeValue);
        }
    }
}