123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- 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<ApplyPaymentSettle, ApplyPaymentSettleExample> {
- //文件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<ApplyPaymentSettle> list(Tablepar tablepar, ApplyPaymentSettle model, DateTrans dt) {
- PageHelper.startPage(tablepar.getPageNum(), tablepar.getPageSize());
- List<ApplyPaymentSettle> list = null;//modelMapper.selectByExample(getCondition(model,dt));
- PageInfo<ApplyPaymentSettle> pageInfo = new PageInfo<>(list);
- return pageInfo;
- }
- public Object listAll(ApplyPaymentSettle model, DateTrans dt) {
- List<ApplyPaymentSettle> list = null;//modelMapper.selectByExample(getCondition(model,dt));
- return list;
- }
- @Override
- public int deleteByPrimaryKey(String ids) {
- List<String> 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<ApplyPaymentSettle> 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<String, Object> getUserInfoByUserId(String userId) {
- Map<String, Object> 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<FlowMain> 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<FlowMainPush> 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<FramePermission> framePermissions = framePermissionService.selectByExample(framePermissionExample);
- if (CollectionUtils.isNotEmpty(framePermissions)) {
- String menuIndex = framePermissions.get(0).getId();
- FramePermissionExample permissionExample = new FramePermissionExample();
- permissionExample.createCriteria().andNameEqualTo("付款审批流程");
- List<FramePermission> 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<String, Object>();
- 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<FlowMainPush> 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<String, Object>();
- 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<FramePermission> framePermissions = framePermissionService.selectByExample(framePermissionExample);
- if (CollectionUtils.isNotEmpty(framePermissions)) {
- String menuIndex = framePermissions.get(0).getId();
- FramePermissionExample permissionExample = new FramePermissionExample();
- permissionExample.createCriteria().andNameEqualTo("付款审批流程");
- List<FramePermission> 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);
- }
- }
|