package com.vci.plugins.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.plugins.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 createList = new ArrayList<>(); List principalList = VciBaseUtil.str2List(auditTaskDTO.getPrincipal()); List> 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); } } }