首页 > 其他分享 >024.开发待审批表单Model层

024.开发待审批表单Model层

时间:2023-01-06 19:22:18浏览次数:53  
标签:ProcessFlow 审批表 form flow2 024 new employee import Model

1.leave_form.xml

<select id="selectByParams" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
        select f.*,e.name , d.*
        from
            adm_leave_form f,adm_process_flow pf , adm_employee e , adm_department d
        where
            f.form_id = pf.form_id
            and f.employee_id = e.employee_id
            and e.department_id = d.department_id
            <if test="pf_state != null">
                and pf.state = #{pf_state}
            </if>
            <if test="pf_operator_id != null">
                and pf.operator_id = #{pf_operator_id}
            </if>
    </select>

2.LeaveFormMapper.java

package com.imooc.oa.mapper;

import com.imooc.oa.entity.LeaveForm;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

public interface LeaveFormMapper {
    public void insert(LeaveForm form);
    /*
        map.put("pf_operator_id" , xxxx)
        map.put("pf_state" , xxxx)
     */
    public List<Map> selectByParams(@Param("pf_state") String pfState
            , @Param("pf_operator_id") Long pfOperatorId);
}

3.LeaveFormService.java

package com.imooc.oa.service;

import com.imooc.oa.entity.Employee;
import com.imooc.oa.entity.LeaveForm;
import com.imooc.oa.entity.ProcessFlow;
import com.imooc.oa.mapper.EmployeeMapper;
import com.imooc.oa.mapper.LeaveFormMapper;
import com.imooc.oa.mapper.ProcessFlowMapper;
import com.imooc.oa.utils.MybatisUtils;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class LeaveFormService {
    private EmployeeService employeeService = new EmployeeService();
    /**
     * 创建请假单
     * @param form 前端输入的请假单数据
     * @return 持久化后的请假单对象
     */
    public LeaveForm createLeaveForm(LeaveForm form){
        LeaveForm f = (LeaveForm) MybatisUtils.executeUpdate(sqlSession -> {
            //1.持久化form表单数据,8级以下员工表单状态为processing,8级(总经理)状态为approved
            EmployeeMapper employeeMapper = sqlSession.getMapper(EmployeeMapper.class);
            Employee employee = employeeMapper.selectById(form.getEmployeeId());
            if(employee.getLevel() == 8){
                form.setState("approved");
            }else{
                form.setState("processing");
            }
            LeaveFormMapper leaveFormMapper = sqlSession.getMapper(LeaveFormMapper.class);
            leaveFormMapper.insert(form);
            //2.增加第一条流程数据,说明表单已提交,状态为complete
            ProcessFlowMapper processFlowMapper = sqlSession.getMapper(ProcessFlowMapper.class);
            ProcessFlow flow1 = new ProcessFlow();
            flow1.setFormId(form.getFormId());
            flow1.setOperatorId(employee.getEmployeeId());
            flow1.setAction("apply");
            flow1.setCreateTime(new Date());
            flow1.setOrderNo(1);
            flow1.setState("complete");
            flow1.setIsLast(0);
            processFlowMapper.insert(flow1);
            //3.分情况创建其余流程数据
            //3.1 7级以下员工,生成部门经理审批任务,请假时间大于等于72小时,还需生成总经理审批任务
            if(employee.getLevel() < 7){
                Employee dmanager = employeeService.selectLeader(employee.getEmployeeId());
                ProcessFlow flow2 = new ProcessFlow();
                flow2.setFormId(form.getFormId());
                flow2.setOperatorId(dmanager.getEmployeeId());
                flow2.setAction("audit");
                flow2.setCreateTime(new Date());
                flow2.setOrderNo(2);
                flow2.setState("process");
                long diff = form.getEndTime().getTime() - form.getStartTime().getTime();
                float hours = diff/(1000*60*60) * 1f;
                if(hours >= 72){
                    flow2.setIsLast(0);
                    processFlowMapper.insert(flow2);
                    Employee manager = employeeService.selectLeader(dmanager.getEmployeeId());
                    ProcessFlow flow3 = new ProcessFlow();
                    flow3.setFormId(form.getFormId());
                    flow3.setOperatorId(manager.getEmployeeId());
                    flow3.setAction("audit");
                    flow3.setCreateTime(new Date());
                    flow3.setState("ready");
                    flow3.setOrderNo(3);
                    flow3.setIsLast(1);
                    processFlowMapper.insert(flow3);
                }else {
                    flow2.setIsLast(1);
                    processFlowMapper.insert(flow2);
                }
            }else if(employee.getLevel() == 7){
                //3.2 7级员工,仅生成总经理审批任务
                Employee manager = employeeService.selectLeader(employee.getEmployeeId());
                ProcessFlow flow2 = new ProcessFlow();
                flow2.setFormId(form.getFormId());
                flow2.setOperatorId(manager.getEmployeeId());
                flow2.setAction("audit");
                flow2.setCreateTime(new Date());
                flow2.setState("process");
                flow2.setOrderNo(2);
                flow2.setIsLast(1);
                processFlowMapper.insert(flow2);
            }else if(employee.getLevel() == 8){
                //3.3 8级员工,生成总经理审批任务,系统自动通过
                ProcessFlow flow2 = new ProcessFlow();
                flow2.setFormId(form.getFormId());
                flow2.setOperatorId(employee.getEmployeeId());
                flow2.setAction("audit");
                flow2.setResult("approved");
                flow2.setReason("自动通过");
                flow2.setCreateTime(new Date());
                flow2.setAuditTime(new Date());
                flow2.setState("complete");
                flow2.setOrderNo(2);
                flow2.setIsLast(1);
                processFlowMapper.insert(flow2);
            }


            return form;
        });
        return f;
    }
    /**
     * 获取指定任务状态及指定经办人对应的请假单列表
     * @param pfState ProcessFlow任务状态
     * @param operatorId 经办人编号
     * @return 请假单及相关数据列表
     */
    public List<Map> getLeaveFormList(String pfState, Long operatorId){
        return (List<Map>) MybatisUtils.executeQuery(sqlSession -> {
            LeaveFormMapper mapper = sqlSession.getMapper(LeaveFormMapper.class);
            List<Map> maps = mapper.selectByParams(pfState, operatorId);
            return maps;
        });
    }
}

 

标签:ProcessFlow,审批表,form,flow2,024,new,employee,import,Model
From: https://www.cnblogs.com/LLL0617/p/17031425.html

相关文章

  • CP1024 单词切分
    又是一道小题,(但是也不是空格作为分割符,范围更广)本质上还是连续字符串,又考了判断嵌套啊俺的做法:#include<stdio.h>#include<ctype.h>#include<string.h>intmain()......
  • 继承ModelViewSet 获取url上参数的写法
    url('^task/reqs/(?P<pk>\d+)/$',patroltaskviews.PatrolTaskViews.as_view({"get":"getTaskReqs"})),views视图classPatrolTaskViews(ModelViewSet):defget......
  • EGG配合利用EGG-SEQUELIZE-AUTO反生MODEL
    1.全局安装EGG-SEQUELIZE-AUTO模块cnpminstall-gegg-sequelize-auto 2.全局安装MYSQL2模块cnpminstall-gmysql213.创建MODELegg-sequelize-auto-o"./mod......
  • Linux Network IO Model、Socket IO Model - select、poll、epoll
    LinuxNetworkIOModel、SocketIOModel-select、poll、epoll目录0.引言1.IO机制简介2.阻塞式IO模型(blockingIOmodel)3.非阻塞式IO模型(......
  • jango框架:forms组件渲染标签、forms组件展示信息、forms组件校验补充、forms组件参数
    目录forms组件渲染标签forms组件展示信息forms组件校验补充钩子函数forms组件参数补充forms组件源码剖析modelform组件基本使用classMeta下常用参数save()方法forms组件......
  • 【阅读】Diffusion Models - Introduction
    参考:苏剑林.生成扩散模型漫谈WhatareDiffusionModels?DiffusionprocessTheytaketheinputimage\(\mathbf{x}_0\)andgraduallyaddGaussiannoisetoitt......
  • [AGC024B] Backfront
    \(\mathcalLink\)可以发现,一个值只需要移动一次即可。考虑让一些值固定不动,并让其他值移动一次。可以证明,这是最优方案。考虑任意可行方案,若没有数操作次数为\(0\),显......
  • form组件补充、modelform组件、django中间件
    form组件补充、modelform组件、django中间件目录form组件补充、modelform组件、django中间件form组件渲染标签form组件展示信息form组件校验补充form组件参数补充form组件......
  • Django中models的字段
    常见的field类型:1.AutoField自增字段,它是一个根据ID自增长的IntegerField字段,通常不用自己设置,如果没有设置主键,django会自动添加它为主键字段2.CharField(max_length=n......
  • 1024·致敬 | 迟到的小温暖,感谢不平凡的你们
    1024是2的10次方是电脑运行、存储,甚至分辨率的进制更是技术同学们最特别的节日今年的XTransfer1024线下活动由于疫情影响延后至今天举办在短暂的居家办公后大家重新相聚在办......