/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.desk.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.secure.utils.SecureUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.desk.entity.WorkOvertime;
import org.springblade.desk.entity.WorkOvertimePeople;
import org.springblade.desk.entity.WorkOvertimePeopleApprove;
import org.springblade.desk.entity.WorkOvertimeTotalHours;
import org.springblade.desk.mapper.WorkOvertimeMapper;
import org.springblade.desk.service.IWorkOvertimeService;
import org.springblade.desk.utils.DeptUserUtil;
import org.springblade.flow.core.constant.ProcessConstant;
import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.feign.IFlowClient;
import org.springblade.flow.core.utils.FlowUtil;
import org.springblade.flow.core.utils.TaskUtil;
import org.springblade.system.entity.Dept;
import org.springblade.system.user.entity.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 服务实现类 加班申请单
*
* @author*/
@Slf4j
@Service
@AllArgsConstructor
public class WorkOvertimeServiceImpl extends BaseServiceImpl<WorkOvertimeMapper, WorkOvertime> implements IWorkOvertimeService {
private IFlowClient flowClient;
private DeptUserUtil deptUserUtil;
private OaSerialServiceImpl oaSerialService;
private WorkOvertimePeopleServiceImpl workOvertimePeopleServiceImpl;
private WorkOvertimeMapper workOvertimeMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public boolean startProcess(WorkOvertime bean) {
//是否启动流程
boolean isStartProcess = false;
//是否新增数据
boolean isAdd = false;
if(bean!=null){
if(Func.isEmpty(bean.getProcessInstanceId())){
isStartProcess = true;
}
if(Func.isEmpty(bean.getId())){
isAdd = true;
}
//更新业务数据
if(isAdd){
Date now = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
String dateStr = format.format(now);
if(Func.isNull(bean.getWorkOvertimeNumber())){
bean.setWorkOvertimeNumber(oaSerialService.getSerial(bean.getTenantId(),"WorkOvertime",dateStr,dateStr,5));
}
}
saveOrUpdate(bean);
//加班人员
if(isAdd){
//新增
savePeople(bean.getWorkOvertimePeopleList(),bean);
}else{
//修改从新发起 修改先删除旧的,插入新的
workOvertimePeopleServiceImpl.removeById(bean.getId());
//插入新的
savePeople(bean.getWorkOvertimePeopleList(),bean);
}
}
//获取经理职位
Long managerUser=null;
String roleId=deptUserUtil.getRoleId(AuthUtil.getTenantId(), "经理");
List<User>users=deptUserUtil.getUserListByRoleIdAndDeptId(roleId,String.valueOf(bean.getProposerDepartmentCode()),false);
if(!Func.isEmpty(users)){
managerUser=users.get(0).getId();
}
log.info("获取经理职位roleId====="+roleId+"------users========================"+users);
//获取部门总监
String majorRoleId=deptUserUtil.getRoleId(AuthUtil.getTenantId(), "总监");
List<User>majordomoUsers=deptUserUtil.getUserListByRoleIdAndDeptId(majorRoleId,String.valueOf(bean.getProposerDepartmentCode()),true);
Long generalManager=null;
if(null!=majordomoUsers && majordomoUsers.size()>0){
generalManager =majordomoUsers.get(0).getId();
}
log.info("获取总监majorRoleId===="+majorRoleId+"-----majordomoUsers========================"+majordomoUsers);
//获取副总
String deputyPostId = deptUserUtil.getPostId("副总经理",bean.getTenantId());
List<User> deputyUsers = deptUserUtil.getUserListByPostIdAndDeptId(deputyPostId,String.valueOf(bean.getProposerDepartmentCode()));
Long presidentUser =null;
if(null!=deputyUsers && deputyUsers.size()>0){
presidentUser =deputyUsers.get(0).getId();
}
log.info("获取副总deputyPostId====="+deputyPostId+"-------deputyUsers========================"+deputyUsers);
//获取总经理
String companyBossPostId=deptUserUtil.getPostId("总经理",bean.getTenantId());
List<User>companyBossUsers=deptUserUtil.getUserListByPostId(companyBossPostId);//总经理不属于某个部门,不用根据部门id查询
Long companyBoss=null;
if(null!=companyBossUsers && companyBossUsers.size()>0){
companyBoss=companyBossUsers.get(0).getId();
}
log.info("获取总经理companyBossPostId====="+companyBossPostId+"-------companyBossUsers========================"+companyBossUsers);
/**
* 判断条件
*/
//如果发起人是总监或者经理不是部门最高领导 没有的职位跳过经理职位
if(null!=managerUser){
if(bean.getProposerCode().longValue()==managerUser.longValue()){
managerUser=null;//经理
}
}
//跳过总监
if(null!=generalManager){
//跳过总监
if(bean.getProposerCode().longValue()==generalManager.longValue()){
//跳过经理
managerUser=null;//经理
//跳过总监职位
generalManager=null;
}
} //根据部门获取部门信息
Dept deptInfo= deptUserUtil.getDeptById(bean.getProposerDepartmentCode());
String isDepartmentHead="0";//0不是最高主管,1是最高主管
String isSell="其他";
String isManager="2";//2上级主管不是最大领导,3是部门最大领导
log.info("根据部门获取部门信息deptInfo================="+deptInfo);
if(!Func.isEmpty(deptInfo)){
if(deptInfo.getManagerUser().longValue()==bean.getProposerCode().longValue()){
isDepartmentHead="1";
}
//判断是不是销售部人员
if(deptInfo.getDeptName().equals("销售部")){
isSell="销售";
}
//判断是不是部门最大领导 申请人编号和部门领导号相同 是部门最大领导
if(deptInfo.getManagerUser().longValue()==bean.getProposerCode()){
isManager="3";
}
}
// 启动流程
Kv variables = Kv.create()
.set(ProcessConstant.TASK_VARIABLE_CREATE_USER, SecureUtil.getUserName())
.set("subject",bean.getProposerName()+","+bean.getProposerName())//主题
.set("orderCode",bean.getWorkOvertimeNumber())//流程编号
.set("taskUser", TaskUtil.getTaskUser(AuthUtil.getUser().getUserId().toString()))
.set("isDepartmentHead",isDepartmentHead)//是不是部门最高领导
.set("isSell",isSell)//是不是销售部人员
.set("isManager",isManager)//2上级主管不是部门最大领导,3是最大领导
.set("overtimeType",bean.getOvertimeType())//申请类型 调休,付薪
.set("managerSkip", Func.isEmpty(managerUser))
.set("managerUser",TaskUtil.getTaskUser(String.valueOf(managerUser==null ? "" : managerUser)))
.set("generalManagerSkip", Func.isEmpty(generalManager))
.set("generalManager", TaskUtil.getTaskUser(String.valueOf(generalManager==null ? "" : generalManager)))
.set("presidentSkip",Func.isEmpty(presidentUser))
.set("presidentUser", TaskUtil.getTaskUser(String.valueOf(presidentUser==null ? "" : presidentUser)))
.set("companyBossSkip",Func.isEmpty(companyBoss))
.set("companyBossUser", TaskUtil.getTaskUser(String.valueOf(companyBoss==null ? "" : companyBoss)))//总经理
.set("pass",true)
.set("_FLOWABLE_SKIP_EXPRESSION_ENABLED",true); //启动流程
if (isStartProcess) {
String businessTable = FlowUtil.getBusinessTable(ProcessConstant.WORK_OVERTIME);
R<BladeFlow> result = flowClient.startProcessInstanceById(bean.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(bean.getId())), variables);
if (result.isSuccess()) {
log.debug("流程已启动,流程ID:" + result.getData().getProcessInstanceId());
// 返回流程id写入业务表中
bean.setProcessInstanceId(result.getData().getProcessInstanceId());
updateById(bean);
} else {
throw new ServiceException("开启流程失败");
}
}
else{
if(!Func.isEmpty(bean.getFlow())&&!Func.isEmpty(bean.getFlow().getTaskId())&&!Func.isEmpty(bean.getProcessInstanceId())){
variables.put(ProcessConstant.PASS_KEY, true);
flowClient.completeTask(bean.getFlow().getTaskId(),bean.getProcessInstanceId(),bean.getFlow().getComment(),variables);
}
}
return true;
}
/**
* 获取明细
* @param businessId
* @return
*/
@Override
public WorkOvertime getDtail(Long businessId) {
//获取主表信息
WorkOvertime workOvertime=getById(businessId);
Map<String,Object>map=new HashMap<String,Object>();
map.put("id",businessId);
List<WorkOvertimePeople>list=workOvertimePeopleServiceImpl.listByMap(map);
workOvertime.setWorkOvertimePeopleList(list);
return workOvertime;
} /**
* 审批通过后根据流程实例id查询加班申请单信息
* @param processInstanceId
* @return
*/
@Transactional(rollbackFor = Exception.class)
@Override
public boolean getWorkOvertimeServiceInfo(String processInstanceId) {
WorkOvertime workOvertime=workOvertimeMapper.getWorkOvertimeServiceInfo(processInstanceId);
//根据id获取加班人员信息
Map<String,Object>mapId=new HashMap<String,Object>();
mapId.put("id",workOvertime.getId());
List<WorkOvertimePeople>listPerson=workOvertimePeopleServiceImpl.listByMap(mapId);
workOvertime.setWorkOvertimePeopleList(listPerson);
log.info("审批通过后根据流程实例id查询加班申请单信息processInstanceId=================="+processInstanceId+"-----workOvertime========="+workOvertime);
System.out.println(!Func.isEmpty(workOvertime));
if(!Func.isEmpty(workOvertime)){
if(!Func.isEmpty(workOvertime.getWorkOvertimePeopleList())){
String dateTime=new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss:SSS").format(new Date()).toString();
log.info("dateTime=============="+dateTime);
for (WorkOvertimePeople workOvertimePeople : workOvertime.getWorkOvertimePeopleList()){
//人员加班总时长表如果存在 则根据加班类型修改相应的时长,如果不存在则插入 根据用户号
//根据用户号查询人员加班总时长是否已经存在
WorkOvertimeTotalHours workOvertimeTotalHours=workOvertimeMapper.getWorkOvertimeTotalHoursInfo(workOvertimePeople.getUserCode());
//根据用户号查询人员加班总时长不存在
if(Func.isEmpty(workOvertimeTotalHours)){
WorkOvertimeTotalHours totalHoursDetail =new WorkOvertimeTotalHours();
if(workOvertimePeople.getOvertimeType().equals("调休")){
//调休加班总时长
totalHoursDetail.setTotalHours(workOvertimePeople.getDuration());
}
//付薪加班总时长
if(workOvertimePeople.getOvertimeType().equals("付薪")){
totalHoursDetail.setPayTotalHours(workOvertimePeople.getDuration());
}
//人员名称
totalHoursDetail.setUserName(workOvertimePeople.getUserName());
// 人员编号
totalHoursDetail.setUserCode(workOvertimePeople.getUserCode());
//人员部门名称
totalHoursDetail.setDepartmentName(workOvertimePeople.getDepartmentName());
//人员部门编号
totalHoursDetail.setDepartmentCode(workOvertimePeople.getDepartmentCode());
//租户id
totalHoursDetail.setTenantId(workOvertimePeople.getTenantId());
//更新时间到时分秒
totalHoursDetail.setUpdateTime(dateTime);
//信息写入加班总时长表
log.info("totalHoursDetail=============="+totalHoursDetail);
workOvertimeMapper.saveWorkOvertimeTotalHoursInfo(totalHoursDetail); }else{
log.info("用户加班时长已经存在workOvertimeTotalHours============"+workOvertimeTotalHours);
WorkOvertimeTotalHours totalHoursInfo =new WorkOvertimeTotalHours();
//用户加班总时长信息已经存在
if(workOvertimePeople.getOvertimeType().equals("调休")){
//如果调休加班时长为空
if(Func.isEmpty(workOvertimeTotalHours.getTotalHours())){
Double hours=workOvertimePeople.getDuration();
totalHoursInfo.setTotalHours(hours);
}else{
//如果调休加班时长为不为空
Double hours=add(workOvertimeTotalHours.getTotalHours(),workOvertimePeople.getDuration());
totalHoursInfo.setTotalHours(hours);
} }
if(workOvertimePeople.getOvertimeType().equals("付薪")){
//如果付薪时长为空
if(Func.isEmpty(workOvertimeTotalHours.getPayTotalHours())){
Double hours1=workOvertimePeople.getDuration();
totalHoursInfo.setPayTotalHours(hours1);
}else {
//付薪时长不为空
Double hours1=add(workOvertimeTotalHours.getPayTotalHours(),workOvertimePeople.getDuration());
totalHoursInfo.setPayTotalHours(hours1);
} }
totalHoursInfo.setUserCode(workOvertimePeople.getUserCode());
log.info("totalHoursInfo======================"+totalHoursInfo);
workOvertimeMapper.updateWorkOvertimeTotalHoursInfo(totalHoursInfo);
}
//将信息插入员加班明细表
// 将 实体类 转换为 Map
Map<String,Object> maps= JSONObject.parseObject(JSONObject.toJSONString(workOvertimePeople), Map.class);
maps.remove("id");
maps.remove("createTime");
maps.put("updateTime",dateTime);
log.info("将信息插入员加班明细表maps==================="+maps);
//将人员加班信息插入人员加班详情表
workOvertimeMapper.saveWorkOvertimePeopleApprove(maps);
}
}
}
return true;
}
/**
* 根据用户号查询加班总时长详情
* @param userCode
* @return
*/
@Override
public WorkOvertimeTotalHours getWorkOvertimeTotalHoursDetail(Long userCode) {
return workOvertimeMapper.getWorkOvertimeTotalHoursDetail(userCode);
} @Override
public IPage<WorkOvertimePeopleApprove> getWorkOvertimePeopleApprovePage(IPage<WorkOvertimePeopleApprove> page,WorkOvertimePeopleApprove workOvertimePeopleApprove) {
log.info("workOvertimePeopleApprove================"+workOvertimePeopleApprove);
String startTime=workOvertimePeopleApprove.getStartTime();
String endTime=workOvertimePeopleApprove.getEndTime();
String departmentName=workOvertimePeopleApprove.getDepartmentName();
String overtimeType=workOvertimePeopleApprove.getOvertimeType();
String tenantId=workOvertimePeopleApprove.getTenantId();
Long user_code=workOvertimePeopleApprove.getUserCode();
List<WorkOvertimePeopleApprove>list=workOvertimeMapper.getWorkOvertimePeopleApprovePage(page,startTime,endTime,departmentName,overtimeType,tenantId,user_code);
return page.setRecords(list);
} /**
* @Description 两个Double数相加
*
* @param d1
* @param d2
* @return Double
*/
public static Double add(Double d1,Double d2){
BigDecimal b1 = new BigDecimal(d1.toString());
BigDecimal b2 = new BigDecimal(d2.toString());
return b1.add(b2).doubleValue();
} /**
* 保存加班人员
*/
public void savePeople(List<WorkOvertimePeople>list,WorkOvertime bean){
log.info("保存加班人员bean=============="+bean+"-----list======"+list);
if(null!=list && list.size()>0){
for (WorkOvertimePeople workOvertimePeople : list){
//加班时长
workOvertimePeople.setDuration(bean.getDuration());
workOvertimePeople.setStartTime(bean.getStartTime());
workOvertimePeople.setEndTime(bean.getEndTime());
workOvertimePeople.setId(bean.getId());
workOvertimePeople.setWorkOvertimeNumber(bean.getWorkOvertimeNumber());
workOvertimePeople.setOvertimeReason(bean.getOvertimeReason());
workOvertimePeople.setCreateTime(bean.getCreateTime());
workOvertimePeople.setOvertimeType(bean.getOvertimeType());
workOvertimePeopleServiceImpl.save(workOvertimePeople);
}
}
} }

加班申请单flowable中的更多相关文章

  1. Flowable中的Service

    前言 在学习博客[(https://blog.csdn.net/puhaiyang/article/details/79845248)]时,注意到Flowable中的各种Service(如下),进而在 ...

  2. flowable中传入审批人是list

    package org.springblade.flow.engine.listener; import org.flowable.engine.delegate.DelegateExecution; ...

  3. flowable 中task的相关操作

    1 获取任务列表 1)获取候选人的任务列表 TaskService taskService = processEngine.getTaskService(); List<Task> tas ...

  4. flowable中使用到的一些方法。获取人员部门信息

    package org.springblade.desk.utils; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf ...

  5. Winform开发框架中工作流模块之申请单草稿处理

    在我们开发工作流模块的时候,有时候填写申请单过程中,暂时不想提交审批,那么可以暂存为草稿,以供下次继续填写或者提交处理,那么这个草稿的功能是比较实用的,否则对于一些填写内容比较多的申请单,每次要重填写 ...

  6. WPF开发查询加班小工具

    先说一下,我们公司是六点下班,超过7点开始算加班,但是加班的时间是从六点开始计算,以0.5个小时为计数,就是你到了六点半,不算加班半小时,但是加班到七点半,就是加班了一个半小时. 一.打卡记录 首先, ...

  7. 关于IT行业加班的问题

    众所周知,所有行业中,IT行业加班最为严重,国内比较大的IT公司都有加班文化. 为什么要加班?有的时候加班是为了项目上线,因为正在运行的项目,在晚上的时候访问量是最小的,这个时候做系统更新是损失最小的 ...

  8. Android RxJava 2 的用法 just 、from、map、subscribe、flatmap、Flowable、Function、Consumer ...【转】

    先简单说说RxJava的用途与价值 原文出处:Android RxJava 2 的用法 用途: 异步 (也就是开线程跳转) 价值: 面对复杂的逻辑,它依然 简洁 ,代码 易读 RxJava2 与 Rx ...

  9. flowable学习笔记-简单流程概念介绍

    1 Flowable process engine允许我们创建ProcessEngine 对象和使用 Flowable 的API ProcessEngine是线程安全的,他是通过 ProcessEng ...

随机推荐

  1. 用Python爬取英雄联盟(lol)全部皮肤

    小三:"怎么了小二?一副无精打采的样子!" 小二:"唉!别提了,还不是最近又接触了一个叫英雄联盟的游戏,游戏中很多皮肤都需要花钱买,但是我钱不够呀..." 小三 ...

  2. kafka监听出现的问题,解决和剖析

    问题如下: kafka为什么监听不到数据 kafka为什么会有重复数据发送 kafka数据重复如何解决 为什么kafka会出现俩个消费端都可以消费问题 kafka监听配置文件 一. 解决问题一(kaf ...

  3. Django----初始化项目结构

    1.初始化项目结构图 │ .gitignore # 提交git仓库时,不提交的文件必须要在这里进行标注 │ README.en.md # 英文(项目介绍) │ README.md # 中文项目简介 │ ...

  4. Verilog单周期CPU(未完待续)

    单周期CPU:指令周期=CPU周期 Top模块作为数据通路 运算器中有ALU,通路寄存器(R1.R2.R3.R4),数据缓冲寄存器(鉴于书上的运算器只有R0)........... 此为ALU和通用寄 ...

  5. 解决:com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server

    com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known serve ...

  6. moviepy音视频剪辑VideoClip类fl_image方法image_func报错ValueError: assignment destination is read-only解决办法

    ☞ ░ 前往老猿Python博文目录 ░ moviepy音视频剪辑模块的视频剪辑基类VideoClip的fl_image方法用于进行对剪辑帧数据进行变换. 调用语法:fl_image(self, im ...

  7. PyQt+moviepy音视频剪辑实战文章目录

    ☞ ░ 前往老猿Python博文目录 ░ 本专栏为moviepy音视频剪辑合成相关内容介绍的免费专栏,对应的收费专栏为<moviepy音视频开发专栏>. 一.moviepy基础能力系统介绍 ...

  8. 【.Net Core】 使用 Nginx 发布 .Net Core 3.1 项目至LInux(Centos7)。

    前置博客(博客中使用的项目来自于此): [Docker] .Net Core 3.1 webapi 集成EF Code First,使用MySql进行业务操作 .配置swagger (三) 环境:.N ...

  9. CTF SHOW WEB_AK赛

    CTF SHOW平台的WEB AK赛: 签到_观己 <?php ​ if(isset($_GET['file'])){ $file = $_GET['file']; if(preg_match( ...

  10. jarvisoj babyphp

    jarvisoj babyphp 涉及知识点: (1)GitHack处理.git源码泄露 (2)php代码注入 解析: 进入题目界面. 看到题目中的用了git那么第一反应肯定是可能存在.git源码泄露 ...