|
@@ -0,0 +1,156 @@
|
|
|
+package com.dragoninfo.dcuc.auth.auth.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.dto.*;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.entity.WorkFlow;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.enumresources.WorkFlowPermissionTypeEnum;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.repo.WorkFlowRepository;
|
|
|
+import com.dragoninfo.dcuc.auth.auth.service.IWorkFlowService;
|
|
|
+import com.dragoninfo.dcuc.auth.config.DcucAuthApprovalConfig;
|
|
|
+import com.dragoninfo.dcuc.common.Constants;
|
|
|
+import com.dragoninfo.dcuc.common.http.HttpUtil;
|
|
|
+import com.dragonsoft.duceap.base.entity.http.ResponseStatus;
|
|
|
+import com.dragonsoft.duceap.base.enums.BooleanEnum;
|
|
|
+import com.dragonsoft.duceap.base.utils.UserContextUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.http.Header;
|
|
|
+import org.apache.http.message.BasicHeader;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Example;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.web.context.request.RequestAttributes;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author mazq
|
|
|
+ * @date 2021/7/8
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class WorkFlowServiceImpl implements IWorkFlowService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ WorkFlowRepository workFlowRepository;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ DcucAuthApprovalConfig approvalConfig;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public WorkFlow saveWorkFlow(WorkFlowDTO dto) {
|
|
|
+ WorkFlow workFlow = new WorkFlow();
|
|
|
+ BeanUtils.copyProperties(dto, workFlow);
|
|
|
+ workFlow.setDeleted(BooleanEnum.FALSE.value);
|
|
|
+ return workFlowRepository.save(workFlow);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseStatus pushToApproval(AppFunAuthApplyDTO authApplyDTO) {
|
|
|
+ WorkFlowDTO workFlowDTO = authApplyDTO.getWorkFlow();
|
|
|
+ ApprovalWorkFlowDTO approvalWorkFlowDTO = new ApprovalWorkFlowDTO();
|
|
|
+ BeanUtils.copyProperties(workFlowDTO, approvalWorkFlowDTO, "resourceInfoDTO", "startTime", "endTime");
|
|
|
+ List<AppFunAuthResourceDTO> authResourceInfos = authApplyDTO.getResourceInfos();
|
|
|
+ String applicantIdcard = authApplyDTO.getWorkFlow().getApplicantIdcard();
|
|
|
+ String applicantName = authApplyDTO.getWorkFlow().getApplicantName();
|
|
|
+ ResourceInfoDTO resourceInfoDTO = new ResourceInfoDTO();
|
|
|
+ resourceInfoDTO.setVisitorName(applicantName);
|
|
|
+ resourceInfoDTO.setVisitorCode(applicantIdcard);
|
|
|
+
|
|
|
+ String funCodes = authResourceInfos.stream()
|
|
|
+ .map(AppFunAuthResourceDTO::getFunCodes)
|
|
|
+ .collect(Collectors.joining(StrUtil.COLON));
|
|
|
+ String funNames = authResourceInfos.stream()
|
|
|
+ .map(AppFunAuthResourceDTO::getFunNames)
|
|
|
+ .collect(Collectors.joining(StrUtil.COLON));
|
|
|
+ funCodes = funCodes.replaceAll(StrUtil.COMMA, StrUtil.SLASH).replaceAll(StrUtil.COLON, StrUtil.COMMA);
|
|
|
+ funNames = funNames.replaceAll(StrUtil.COMMA, StrUtil.SLASH).replaceAll(StrUtil.COLON, StrUtil.COMMA);
|
|
|
+ resourceInfoDTO.setVisitResourceCode(funCodes);
|
|
|
+ resourceInfoDTO.setVisitResourceName(funNames);
|
|
|
+ approvalWorkFlowDTO.setResourceInfoDTO(resourceInfoDTO);
|
|
|
+
|
|
|
+ if (WorkFlowPermissionTypeEnum.TEMP.getValue().equals(approvalWorkFlowDTO.getPermissionValidType())) {
|
|
|
+ Date startTime = workFlowDTO.getStartTime();
|
|
|
+ Date endTime = workFlowDTO.getEndTime();
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ if (null != startTime) {
|
|
|
+ String startTimeStr = format.format(startTime);
|
|
|
+ approvalWorkFlowDTO.setStartTime(startTimeStr);
|
|
|
+ }
|
|
|
+ if (null != endTime) {
|
|
|
+ String endTimeStr = format.format(endTime);
|
|
|
+ approvalWorkFlowDTO.setStartTime(endTimeStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Header> headers = new ArrayList<>();
|
|
|
+ RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
|
|
+ String userToken = "";
|
|
|
+ String appToken = "";
|
|
|
+ if (requestAttributes != null) {
|
|
|
+ ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) requestAttributes;
|
|
|
+ HttpServletRequest request = servletRequestAttributes.getRequest();
|
|
|
+ userToken = request.getHeader(Constants.USER_TOKEN);
|
|
|
+ appToken = request.getHeader(Constants.APP_TOKEN);
|
|
|
+ BasicHeader appTokenHeader = new BasicHeader(Constants.BUS_SRA_TOKEN, appToken);
|
|
|
+ BasicHeader userTokenHeader = new BasicHeader(Constants.BUS_SRE_TOKEN, userToken);
|
|
|
+ headers.add(appTokenHeader);
|
|
|
+ headers.add(userTokenHeader);
|
|
|
+ }
|
|
|
+
|
|
|
+ String idcard = UserContextUtils.getCurrentUser().getIdcard();
|
|
|
+ BasicHeader busSreIdcardHeader = new BasicHeader(Constants.BUS_SRE_IDCARD , idcard);
|
|
|
+ BasicHeader busSraIdHeader = new BasicHeader("bus_sra_id", approvalConfig.getBusSraId());
|
|
|
+ BasicHeader busServiceIdHeader = new BasicHeader("bus_service_id", approvalConfig.getBusServiceId());
|
|
|
+ BasicHeader busServiceFuncHeader = new BasicHeader("bus_service_func", approvalConfig.getBusServiceFunc());
|
|
|
+ headers.add(busSraIdHeader);
|
|
|
+ headers.add(busSreIdcardHeader);
|
|
|
+ headers.add(busServiceIdHeader);
|
|
|
+ headers.add(busServiceFuncHeader);
|
|
|
+ log.info("work flow push url:{}, busSraId:{}, busSreIdcard:{}, busServiceId:{}, busServiceFunc:{},userToken:{},appToken:{},flowType:{}",
|
|
|
+ approvalConfig.getWorkflowUrl(),
|
|
|
+ approvalConfig.getBusSraId(),
|
|
|
+ idcard,
|
|
|
+ approvalConfig.getBusServiceId(),
|
|
|
+ approvalConfig.getBusServiceFunc(),
|
|
|
+ userToken,
|
|
|
+ appToken,
|
|
|
+ workFlowDTO.getFlowType());
|
|
|
+ String postBody = JSON.toJSONString(approvalWorkFlowDTO);
|
|
|
+ log.info("work flow request body:{}", postBody);
|
|
|
+
|
|
|
+ String response = HttpUtil.postJSON(approvalConfig.getWorkflowUrl(), postBody, headers, null);
|
|
|
+ if(StringUtils.isBlank(response)) {
|
|
|
+ return new ResponseStatus(ResponseStatus.FAIL_CODE,"push to approve service failed");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("work flow push result:{}", response);
|
|
|
+ return JSON.parseObject(response, ResponseStatus.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public WorkFlow getByMessageId(String messageId) {
|
|
|
+ if(StringUtils.isBlank(messageId)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ WorkFlow query = new WorkFlow();
|
|
|
+ query.setMessageId(messageId);
|
|
|
+ Example<WorkFlow> example = Example.of(query);
|
|
|
+ return workFlowRepository.findOne(example).orElse(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void update(WorkFlow flow) {
|
|
|
+ workFlowRepository.update(flow);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|