package com.idea.oa.apply.service; import cn.hutool.core.codec.Base64; import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.symmetric.AES; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.idea.oa.apply.mapper.ApplyPaymentSettleExtendMapper; import com.idea.oa.apply.mapper.ApplyPaymentSettleMapper; import com.idea.oa.apply.model.ApplyPaymentSettle; import com.idea.oa.apply.model.ApplyPaymentSettleExample; import com.idea.oa.apply.model.inout.ApplyPaymentSettleIn; import com.idea.oa.apply.util.constant.ConstantFlowType; import com.idea.oa.apply.util.constant.RedisToUse; import com.idea.oa.flow2.model.FlowMain; import com.idea.oa.flow2.model.FlowMainExample; import com.idea.oa.flow2.model.FlowMainPush; import com.idea.oa.flow2.model.FlowMainPushExample; import com.idea.oa.flow2.service.FlowMainPushService; import com.idea.oa.flow2.service.FlowMainService; import com.idea.util.DateUtils; import com.idea.util.OAUtil; import com.idea.workPanel.enume.HandleTypeEnum; import com.idea.workPanel.service.ParkWaitHandleService; import com.rockstar.common.base.BaseService; import com.rockstar.common.support.Convert; import com.rockstar.frame.model.FramePermission; import com.rockstar.frame.model.FramePermissionExample; import com.rockstar.frame.model.FrameUser; import com.rockstar.frame.model.extend.DateTrans; import com.rockstar.frame.model.extend.Tablepar; import com.rockstar.frame.service.FramePermissionService; import com.rockstar.frame.service.FrameUserService; import com.rockstar.shiro.util.ShiroUtils; import com.rockstar.util.UUIDUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Slf4j @Service public class ApplyPaymentSettleService implements BaseService { //文件mapper @Autowired private ApplyPaymentSettleMapper modelMapper; @Autowired private ApplyPaymentSettleExtendMapper ApplyPaymentSettleExtendMapper; @Autowired private FlowMainPushService flowMainPushService; @Autowired private FlowMainService flowMainService; @Autowired private ParkWaitHandleService parkWaitHandleService; @Autowired private FramePermissionService framePermissionService; @Autowired private FrameUserService frameUserService; @Value("${serverUrl}") private String serverUrl; @Value("${ssoKey}") private String ssoKey; /** * 分页查询 * * @return */ public PageInfo list(Tablepar tablepar, ApplyPaymentSettle model, DateTrans dt) { PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize()); List list = null;//modelMapper.selectByExample(getCondition(model,dt)); PageInfo pageInfo = new PageInfo<>(list); return pageInfo; } public Object listAll(ApplyPaymentSettle model, DateTrans dt) { List list = null;//modelMapper.selectByExample(getCondition(model,dt)); return list; } @Override public int deleteByPrimaryKey(String ids) { List lista = Convert.toListStrArray(ids); ApplyPaymentSettleExample example = new ApplyPaymentSettleExample(); example.createCriteria().andIdIn(lista); return modelMapper.deleteByExample(example); } @Override public ApplyPaymentSettle selectByPrimaryKey(String id) { return modelMapper.selectByPrimaryKey(id); } @Override public int updateByPrimaryKeySelective(ApplyPaymentSettle record) { return modelMapper.updateByPrimaryKeySelective(record); } @Override public int updateByExampleSelective(ApplyPaymentSettle record, ApplyPaymentSettleExample example) { return modelMapper.updateByExampleSelective(record, example); } @Override public int updateByExample(ApplyPaymentSettle record, ApplyPaymentSettleExample example) { return modelMapper.updateByExample(record, example); } @Override public List selectByExample(ApplyPaymentSettleExample example) { return modelMapper.selectByExample(example); } @Override public long countByExample(ApplyPaymentSettleExample example) { return modelMapper.countByExample(example); } @Override public int deleteByExample(ApplyPaymentSettleExample example) { return modelMapper.deleteByExample(example); } public int insert(ApplyPaymentSettle record) { record.setId(UUIDUtils.middleUUID()); return insertWithoutId(record); } public int insertWithoutId(ApplyPaymentSettle record) { record.setCreatedAt(new Date()); return modelMapper.insert(record); } @Override public int insertSelective(ApplyPaymentSettle record) { record.setId(UUIDUtils.middleUUID()); record.setCreatedAt(new Date()); return modelMapper.insertSelective(record); } public ApplyPaymentSettleIn getInfoByFlowMainId(String flowMainId) { return ApplyPaymentSettleExtendMapper.getInfoByFlowMainId(flowMainId); } public ApplyPaymentSettleIn getInfoByFlowMainPushId(String flowMainPushId) { return ApplyPaymentSettleExtendMapper.getInfoByFlowMainPushId(flowMainPushId); } public Map getUserInfoByUserId(String userId) { Map userInfoByUserId = ApplyPaymentSettleExtendMapper.getUserInfoByUserId(userId); return userInfoByUserId; } // public static void main(String[] args) { // System.out.println(new ApplyPaymentSettleService().getMaxNum()); // } /** * 付款记录编号 : 付款领用单20240401-002 * * @return */ public String getMaxNum() { String maxnum = null; try { int c = 0; while ("#".equals(RedisToUse.pmnumber)) { try { c++; Thread.sleep(100);//等待毫秒 } catch (InterruptedException e) { throw new RuntimeException(e); } if (c >= 1000) { break; } } maxnum = RedisToUse.pmnumber; RedisToUse.pmnumber = "#"; if (maxnum == null) { maxnum = ApplyPaymentSettleExtendMapper.selectMaxNum(); } SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String topName = "付款领用单" + sdf.format(new Date()) + "-"; // 20221111-04 if (StringUtils.isEmpty(maxnum)) { maxnum = topName + "001"; } else { String substring = maxnum.substring(0, topName.length()); if (topName.equals(substring)) { maxnum = RedisToUse.addNumber(topName, maxnum); } else { maxnum = topName + "001"; } } } finally { RedisToUse.pmnumber = maxnum; } return maxnum; } /** * 发起流程 推送泛微和工作台待办 * @param id * @param applyTheme */ public void startOaAndHandle(String id,String applyTheme) { try { String flowId = ""; String nodeName = ""; FlowMainExample flowMainExample = new FlowMainExample(); flowMainExample.createCriteria().andFormIdEqualTo(id).andFlowTypeEqualTo(ConstantFlowType.PAYMENT); List flowMains = flowMainService.selectByExample(flowMainExample); if (CollectionUtils.isNotEmpty(flowMains)) { FlowMain flowMain = flowMains.get(0); flowId = flowMain.getId(); FlowMainPushExample flowMainPushExample = new FlowMainPushExample(); flowMainPushExample.createCriteria().andFlowMainIdEqualTo(flowId).andStatusEqualTo(0); List flowMainPushes = flowMainPushService.selectByExample(flowMainPushExample); if (CollectionUtils.isNotEmpty(flowMainPushes)) { FlowMainPush flowMainPush = flowMainPushes.get(0); nodeName = flowMainPush.getNodeName(); // 给本系统下一个节点的人推送待办 /** * 添加待办 * @param title 显示标题 * @param typeEnum 处理类型枚举 * @param srcUserType 来源用户类型 0管理,1企业 * @param srcUserId 来源用户id * @param srcUserName 来源用户名称 * @param receiveUserId 接收用户id or 0=全部 or 角色id * @param routeParam 跳转携带参数,例: id=***&type=** */ String waitUrl = ""; // 查询待办页面的 菜单id FramePermissionExample framePermissionExample = new FramePermissionExample(); framePermissionExample.createCriteria().andNameEqualTo("流程审批"); List framePermissions = framePermissionService.selectByExample(framePermissionExample); if (CollectionUtils.isNotEmpty(framePermissions)) { String menuIndex = framePermissions.get(0).getId(); FramePermissionExample permissionExample = new FramePermissionExample(); permissionExample.createCriteria().andNameEqualTo("付款审批流程"); List permissions = framePermissionService.selectByExample(framePermissionExample); if (CollectionUtils.isNotEmpty(permissions)) { String subMenu = permissions.get(0).getId(); waitUrl = "/backstage?menuIndex=" + menuIndex + "&subMenu=" + subMenu; } } String title = applyTheme; HandleTypeEnum typeEnum = HandleTypeEnum.FK; Integer srcUserType = 0;//来源用户类型 0管理,1企业 String srcUserId = ShiroUtils.getUserId(); String srcUserName = ShiroUtils.getUser().getTruename(); String receiveUserId = flowMainPush.getPushUser(); String routeParam = "id=" + flowId + "&flowMainPushId=" + flowMainPush.getId() + "&applyUser=" + flowMain.getApplyUser(); HandleTypeEnum.FK.setUrl(waitUrl); parkWaitHandleService.addHandle(title, typeEnum, srcUserType, srcUserId, srcUserName, receiveUserId, routeParam); // TODO: 2024/11/21 和泛OA对接 推送待办 FrameUser receiveUser = frameUserService.selectByPrimaryKey(receiveUserId); String username = encryptUsername(receiveUser.getUsername()); String syscode = "AJ"; String requestname = applyTheme; String workflowname = ConstantFlowType.PAYMENT_NAME; String pcurl = serverUrl + "&loginid=" + username; String appurl = ""; String isremark = "0"; String viewtype = "0"; // TODO: 2024/11/15 创建者和接收者需求oa协商 String creator = "ceshi"; String receiver = "ceshi"; String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date()); String receivets = System.currentTimeMillis() + ""; Map map = new HashMap(); map.put("syscode", syscode); map.put("flowid", flowId); map.put("requestname", requestname); map.put("workflowname", workflowname); map.put("nodeName", nodeName); map.put("pcurl", pcurl); map.put("appurl", appurl); map.put("creator", creator); map.put("createdatetime", date); map.put("receiver", receiver); map.put("receivedatetime", date); map.put("isremark", isremark); map.put("viewtype", viewtype); map.put("receivets", receivets); log.info("泛微推送详情:{}", map); String result = OAUtil.receiveRequestInfoByJson(map); log.info("泛微推送结果:{}", result); } } } catch (Exception e) { log.error("推送异常", e); } } /** * 推送泛微和工作台待办 * * @param flowMainPush * @param flowMain * @param waitUrl */ public void pushOaAndHandle(FlowMainPush flowMainPush, FlowMain flowMain, String waitUrl) { try { String flowId = flowMain.getId(); FlowMainPushExample flowMainPushExample = new FlowMainPushExample(); flowMainPushExample.createCriteria().andFlowMainIdEqualTo(flowId).andStatusEqualTo(0); List flowMainPushes = flowMainPushService.selectByExample(flowMainPushExample); if (CollectionUtils.isNotEmpty(flowMainPushes)) { FlowMainPush push = flowMainPushes.get(0); // 给本系统下一个节点的人推送待办 /** * 添加待办 * @param title 显示标题 * @param typeEnum 处理类型枚举 * @param srcUserType 来源用户类型 0管理,1企业 * @param srcUserId 来源用户id * @param srcUserName 来源用户名称 * @param receiveUserId 接收用户id or 0=全部 or 角色id * @param routeParam 跳转携带参数,例: id=***&type=** */ String title = flowMain.getApplyTheme(); HandleTypeEnum typeEnum = HandleTypeEnum.FK; Integer srcUserType = 0;//来源用户类型 0管理,1企业 String srcUserId = ShiroUtils.getUserId(); String srcUserName = ShiroUtils.getUser().getTruename(); String receiveUserId = push.getPushUser(); String routeParam = "id=" + flowId + "&flowMainPushId=" + push.getId() + "&applyUser=" + flowMain.getApplyUser(); HandleTypeEnum.FK.setUrl(waitUrl); parkWaitHandleService.addHandle(title, typeEnum, srcUserType, srcUserId, srcUserName, receiveUserId, routeParam); // TODO: 2024/11/21 和泛微对接 推送信息 FrameUser receiveUser = frameUserService.selectByPrimaryKey(receiveUserId); String username = encryptUsername(receiveUser.getUsername()); String syscode = "AJ"; String requestname = flowMain.getApplyTheme(); String workflowname = ConstantFlowType.PAYMENT_NAME; String nodeName = flowMainPush.getNodeName(); String pcurl = serverUrl + "&loginid=" + username; String appurl = ""; String isremark = "0"; String viewtype = "0"; // TODO: 2024/11/15 创建者和接收者需求oa协商 String creator = "ceshi"; String receiver = "ceshi"; String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, new Date()); String receivets = System.currentTimeMillis() + ""; Map map = new HashMap(); map.put("syscode", syscode); map.put("flowid", flowId); map.put("requestname", requestname); map.put("workflowname", workflowname); map.put("nodeName", nodeName); map.put("pcurl", pcurl); map.put("appurl", appurl); map.put("creator", creator); map.put("createdatetime", date); map.put("receiver", receiver); map.put("receivedatetime", date); map.put("isremark", isremark); map.put("viewtype", viewtype); map.put("receivets", receivets); log.info("泛微推送详情:{}", map); String result = OAUtil.receiveRequestInfoByJson(map); log.info("泛微推送结果:{}", result); } } catch (Exception e) { log.error("推送异常", e); } } /** * 获取待办页面的url * * @return */ public String getWaitUrl() { String waitUrl = ""; // 查询待办页面的 菜单id FramePermissionExample framePermissionExample = new FramePermissionExample(); framePermissionExample.createCriteria().andNameEqualTo("流程审批"); List framePermissions = framePermissionService.selectByExample(framePermissionExample); if (CollectionUtils.isNotEmpty(framePermissions)) { String menuIndex = framePermissions.get(0).getId(); FramePermissionExample permissionExample = new FramePermissionExample(); permissionExample.createCriteria().andNameEqualTo("付款审批流程"); List permissions = framePermissionService.selectByExample(framePermissionExample); if (CollectionUtils.isNotEmpty(permissions)) { String subMenu = permissions.get(0).getId(); waitUrl = "/backstage?menuIndex=" + menuIndex + "&subMenu=" + subMenu; } } return waitUrl; } /** * 加密用户名 * * @param username * @return */ public String encryptUsername(String username) { byte[] key = Base64.decode(ssoKey); // 构建 AES aes = SecureUtil.aes(key); return aes.encryptHex(username); } }