Selaa lähdekoodia

修复履职缺陷

jiawuxian 1 vuosi sitten
vanhempi
commit
b31f7aebd4

+ 14 - 1
project_data/sql/0.0.4/soc/soc.sql

@@ -286,6 +286,17 @@ END IF;
         ALTER TABLE `core_resumption_plan_to_point` 
 			DROP COLUMN `effective_date`;
     END IF;
+	
+	IF
+       NOT EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE () AND TABLE_NAME = 'core_resumption_plan' AND COLUMN_NAME = 'publish_time' ) THEN
+        	ALTER TABLE `core_resumption_plan` 
+				ADD COLUMN `publish_time` datetime NULL COMMENT '最后一次下发时间' AFTER `task_has_completed`,
+				ADD COLUMN `withdraw_time` datetime NULL COMMENT '最后一次撤回时间' AFTER `publish_time`,
+				ADD COLUMN `effective_time` datetime NULL COMMENT '计划生效时间' AFTER `withdraw_time`;
+				update core_resumption_plan set publish_time =update_time WHERE publish_time is null and plan_status=1;
+				update core_resumption_plan set withdraw_time =update_time WHERE withdraw_time is null and plan_status=2;
+				update core_resumption_plan set effective_time =update_time WHERE effective_time is null and plan_status=1;
+    END IF;
 END ??
 DELIMITER;
 CALL schema_change ();
@@ -335,4 +346,6 @@ UPDATE sys_menu set menu_name='新增履职手册' WHERE menu_name='履职内容
 UPDATE sys_menu set menu_name='编辑手册' WHERE menu_name='履职内容库定义编辑' and menu_type='F' and platform_type=1;
 UPDATE sys_menu set menu_name='删除' WHERE menu_name='履职内容库定义删除' and menu_type='F' and platform_type=1;
 UPDATE sys_menu set menu_name='管理履职内容' WHERE menu_name='履职内容库管理' and menu_type='F' and platform_type=1;
-UPDATE sys_menu set menu_name='管理检查内容' WHERE menu_name='内容库管理' and menu_type='F' and platform_type=1;
+UPDATE sys_menu set menu_name='管理检查内容' WHERE menu_name='内容库管理' and menu_type='F' and platform_type=1;
+
+

+ 2 - 1
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/listener/WorkTimeChangeEventListener.java

@@ -46,7 +46,8 @@ public class WorkTimeChangeEventListener implements ApplicationListener<WorkTime
     private void resumptionTask(WorkTimeChangeEvent event) {
         try {
             log.info("履职开始处理机构作息变更");
-            rebuildResumptionTaskBusiness.rebuildTask(event);
+            //todo:若再放开作息 变更触发生成任务, 则需要考虑当每日任务会按天删除任务,但补生成时,不会再生成过时的任务。如:营业中,修改作息 ,此时会删除营业前的任务,但却不会补生成
+//            rebuildResumptionTaskBusiness.rebuildTask(event);
             log.info("履职结束处理机构作息变更");
         } catch (Exception e) {
             log.error(e.getMessage(), e);

+ 9 - 0
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/domain/AppPlan.java

@@ -179,6 +179,15 @@ public class AppPlan extends Model<AppPlan> implements Serializable {
 
     @ApiModelProperty(value = "1:表示有已完成的任务")
     private Integer taskHasCompleted;
+
+    @ApiModelProperty("下发时间")
+    private Date publishTime;
+
+    @ApiModelProperty("撤回时间")
+    private Date withdrawTime;
+
+    @ApiModelProperty("计划生效时间")
+    private Date effectiveTime;
 //    public static ObjectDataClass planTo(AppPlan appPlan) {
 //        ObjectDataClass objectDataClass = new ObjectDataClass();
 //        objectDataClass.setId(appPlan.getId());

+ 96 - 11
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/resumption/service/impl/AppPlanServiceImpl.java

@@ -1,6 +1,7 @@
 package com.xunmei.core.resumption.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateField;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -12,6 +13,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.constant.ErrorMsgConstants;
 import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.domain.DateRange;
 import com.xunmei.common.core.domain.R;
 import com.xunmei.common.core.enums.OrgTypeEnum;
 import com.xunmei.common.core.enums.PlanStatus;
@@ -181,6 +183,11 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
         AppPlan oldPlan = baseMapper.selectById(dto.getId());
         Long parentId = IDHelper.id();
         List<Object> hsPlans = new ArrayList<>();
+        Date now = new Date();
+        Date effectiveTime = new Date();
+        if (!immediateEffect) {
+            effectiveTime = DateUtil.offset(DateUtil.beginOfDay(DateUtils.getStartAndEnd(now, oldPlan.getPlanCycle()).getEndTime()), DateField.DAY_OF_YEAR, 1);
+        }
         //如果计划所属机构类型为省联社,生成下发子计划
         if (ObjectUtil.equal(oldPlan.getPlanOfOrgType(), 1L)) {
             for (DistributeStatusDto d :
@@ -192,7 +199,16 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
                 //如果子计划已存在
                 if (tempplan != null) {
                     //从停用状态下发,才会有已存在的子计划;
-                    tempplan.setPlanStatus(d.getStatus() > 0 ? 1 : 2);
+                    if (d.getStatus() > 0) {
+                        tempplan.setPlanStatus(1);
+                        tempplan.setPublishTime(now);
+                        tempplan.setEffectiveTime(effectiveTime);
+                    } else {
+                        tempplan.setPlanStatus(2);
+                        tempplan.setPublishTime(null);
+                        tempplan.setEffectiveTime(null);
+                    }
+
                     tempplan.setDistributePlanStatus(d.getStatus().toString());
                     tempplan.setDistributeStatus("1");
                     if (!immediateEffect) {
@@ -223,6 +239,9 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
                     plan.setPlanOfOrgType(Long.valueOf(orgService.selectSysOrgById(d.getOrgId(), SecurityConstants.INNER).getType()));
                     plan.setPlanStatus(d.getStatus());
                     plan.setDistributePlanStatus(d.getStatus().toString());
+                    if (ObjectUtil.equal(d.getStatus(), 1)) {
+                        plan.setPublishTime(now);
+                    }
                     plan.setCreateTime(new Date());
                     plan.setId(null);
 //            plan.setPlanName(plan.getPlanName()+"下发"+orgService.selectOrgById(d.getOrgId(),SecurityConstants.INNER).getName());
@@ -263,6 +282,8 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
         plan.setDistribute("1");
         //设置计划状态为使用中
         plan.setPlanStatus(1);
+        plan.setPublishTime(now);
+        plan.setEffectiveTime(effectiveTime);
 //        plan.setBuildTaskNow(null);
 
         baseMapper.updateById(plan);
@@ -287,6 +308,13 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
         Integer planStatus = plan.getPlanStatus();
         //设置计划状态
         plan.setPlanStatus(1);
+        Date now = new Date();
+        Date effectiveTime = new Date();
+        if (!immediateEffect) {
+            effectiveTime = DateUtil.offset(DateUtil.beginOfDay(DateUtils.getStartAndEnd(now, plan.getPlanCycle()).getEndTime()), DateField.DAY_OF_YEAR, 1);
+        }
+        plan.setPublishTime(now);
+        plan.setEffectiveTime(effectiveTime);
         //如果是行社撤回需要修改下发状态
         //行社下发
         if (plan.getPlanOfOrgType() == 3 && "0".equals(plan.getDistribute())) {
@@ -389,6 +417,10 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
 //        deleteTaskByPlanId(deleteByPlanIds);
     }
 
+    /**
+     * 删除本轮次及之前的所有任务(无论状态)
+     * @param solidPlanIds
+     */
     @Async
     protected void deleteTaskByPlanId(List<Long> solidPlanIds) {
         if (CollectionUtils.isEmpty(solidPlanIds)) {
@@ -397,7 +429,6 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
         Date date = DateUtil.beginOfDay(new Date());
         resumptionMapper.delete(new LambdaQueryWrapper<Resumption>()
                 .in(Resumption::getSolidId, solidPlanIds)
-                .ne(Resumption::getStatus, ResumptionTaskStatus.Completed.getCode())
                 .and(w ->
                         w.ge(Resumption::getYmdDate, date)
                                 .or(w1 -> w1.ge(Resumption::getPlanEndTime, date))
@@ -532,10 +563,9 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
             LambdaQueryWrapper<AppPlanToPoint> pointWrapper = new LambdaQueryWrapper<>();
             pointWrapper.eq(AppPlanToPoint::getPlanId, app.getId());
 
-            //任务为使用中且有已完成或停用,则下个周期生效,需要副本;任务为使用中且无已完成,则删除所有任务,并重新生成任务
-            Boolean needCopy = (ObjectUtil.equal(app.getTaskHasCompleted(), 1)
-                    && ObjectUtil.equal(existPlan.getPlanStatus(), PlanStatus.USING.getCode()))
-                    || ObjectUtil.equal(existPlan.getPlanStatus(), PlanStatus.DELETED.getCode());
+
+            //任务为使用中且有已完成或当前周期内停用,则下个周期生效,需要副本;任务为使用中且无已完成,则删除所有任务,并重新生成任务
+            Boolean needCopy = needCopyOnEdit(existPlan);
             List<Object> needRebuildPlans = new ArrayList<>();
             //修改所有子计划
             List<AppPlan> appPlans = baseMapper.selectList(new LambdaQueryWrapper<AppPlan>().eq(AppPlan::getParentId, plan.getId()));
@@ -549,15 +579,17 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
                     baseMapper.copyChildren(ap.getId(), newChildPlanId, newPlanID);
                     baseMapper.copyPlanOrgs(ap.getId(), newChildPlanId);
                     baseMapper.copyPlanRoles(ap.getId(), newChildPlanId);
-                    Integer c= baseMapper.copyPlanPoints(ap.getId(), newChildPlanId);
+                    Integer c = baseMapper.copyPlanPoints(ap.getId(), newChildPlanId);
 
                     baseMapper.updateById(ap);
                     baseMapper.deleteById(ap.getId());
 
-                    child=baseMapper.selectById(newChildPlanId);
-                } else {
+                    child = baseMapper.selectById(newChildPlanId);
+                }
+                if (needRebuildOnEdit(child)) {
                     needRebuildPlans.add(child);
                 }
+
                 Map<Long, AppPlanToPoint> planPoints = appPlanToItemMapper.selectList(pointWrapper).stream()
                         .collect(Collectors.toMap(AppPlanToPoint::getPointId, p -> p));
 //                Date defaultEffectiveDate = calendar.getTime();
@@ -707,7 +739,7 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
             plan.setPlanCreateOrgName(null);
             baseMapper.updateById(plan);
 
-            if (!needCopy && ObjectUtil.equal(plan.getPlanOfOrgType(), OrgTypeEnum.HANG_SHE.getCode().longValue())) {
+            if (needRebuildOnEdit(plan)) {
                 needRebuildPlans.add(baseMapper.selectById(plan.getId()));
             }
             resumptionTaskBusiness.rebuildCurrentCycleTask(needRebuildPlans);
@@ -718,6 +750,59 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
         }
     }
 
+    /**
+     * 编辑时,该计划是否需要副本。
+     * 1.使用中且还没有到生效时间,不需要;
+     * 2.使用中且有已完成时,需要
+     * 3.使用中且无完成,不需要副本
+     * <p>
+     * 4.停用,本周期之前停用,不需要
+     * 5.停用,本周期停用,需要
+     * 6.草稿,不需要
+     *
+     * @param plan
+     * @return
+     */
+    private Boolean needCopyOnEdit(AppPlan plan) {
+        DateRange dateRange = DateUtils.getStartAndEnd(new Date(), plan.getPlanCycle());
+        if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.USING.getCode()) && new Date().before(plan.getEffectiveTime())) {
+            return false;
+        } else if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.USING.getCode())
+                && ObjectUtil.isNotNull(plan.getTaskHasCompleted())
+                && ObjectUtil.notEqual(plan.getTaskHasCompleted(), 0)) {
+            return true;
+        } else if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.USING.getCode()) && (ObjectUtil.isNull(plan.getTaskHasCompleted()) ||
+                ObjectUtil.equal(plan.getTaskHasCompleted(), 0))) {
+            return false;
+        } else if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.DELETED.getCode()) && dateRange.getStartTime().after(plan.getWithdrawTime())) {
+            return false;
+        } else if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.DELETED.getCode())
+                && dateRange.getStartTime().before(plan.getWithdrawTime())
+                && dateRange.getEndTime().after(plan.getWithdrawTime())) {
+            return true;
+        } else if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.DRAFT.getCode())) {
+            return false;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * 编辑时,是否需要重新生成任务
+     *
+     * @param plan
+     * @return
+     */
+    private Boolean needRebuildOnEdit(AppPlan plan) {
+        if (ObjectUtil.equal(plan.getPlanStatus(), PlanStatus.USING.getCode())
+                && (ObjectUtil.isNull(plan.getTaskHasCompleted()) || ObjectUtil.equal(plan.getPlanStatus(), 0))
+                && !new Date().before(plan.getEffectiveTime())) {
+            return true;
+        }
+
+        return false;
+    }
+
     @Override
     public AppPlanVo findById(Long id) {
         AppPlan appPlan = baseMapper.selectById(id);
@@ -797,7 +882,7 @@ public class AppPlanServiceImpl extends ServiceImpl<AppPlanMapper, AppPlan> impl
                 .select(AppPlan::getId, AppPlan::getSolidId));
 
         if (ObjectUtil.equal(plan.getTaskHasCompleted(), 1)) {
-            //有已完成时,计划逻辑删除,删除当前轮次及之后未完成的任务
+            //有已完成时,计划逻辑删除,删除当前轮次及之后任务
             LambdaQueryWrapper<AppPlan> wrapper = new LambdaQueryWrapper<>();
             wrapper.in(AppPlan::getId, plans.stream().map(AppPlan::getId).collect(Collectors.toList()));
 

+ 8 - 2
soc-modules/soc-modules-core/src/main/resources/mapper/resumption/AppPlanMapper.xml

@@ -465,7 +465,10 @@
                `build_task_now`,
                `plan_of_org_type`,
                `pdf_url`,
-               `task_has_completed`
+               `task_has_completed`,
+                `publish_time`,
+                  `withdraw_time`,
+                  `effective_time`
         FROM core_resumption_plan
         WHERE id = #{planId}
     </insert>
@@ -500,7 +503,10 @@
                `build_task_now`,
                `plan_of_org_type`,
                `pdf_url`,
-               `task_has_completed`
+               `task_has_completed`,
+                   `publish_time`,
+               `withdraw_time`,
+               `effective_time`
         FROM core_resumption_plan
         WHERE id = #{planId}
     </insert>

+ 15 - 5
soc-modules/soc-modules-core/src/main/resources/mapper/resumption/ResumptionMapper.xml

@@ -128,16 +128,27 @@
         inner join core_resumption_plan p on r.plan_id = p.id
         where r.org_id=#{res.orgId}
         <if test="res.roleId!=null and res.roleId.size>0">
-            and r.parent_plan_id in
+            and r.plan_id in
             (select distinct plan_id from core_resumption_plan_to_role pr
-            inner join core_resumption_plan p on pr.plan_id=p.id and p.parent_id =-1
+            inner join core_resumption_plan p on pr.plan_id=p.id
             where pr.role_id in
             <foreach collection="res.roleId" item="roleId" open="(" close=")" separator=",">
                 #{roleId}
             </foreach>)
         </if>
         <if test="res.dateTime != null ">
-            and r.plan_start_time &lt;= #{res.startTime} and r.plan_end_time>= #{res.endTime}
+            and ((
+            #{res.startTime}   <![CDATA[<=]]> r.plan_start_time
+            and #{res.endTime} >= r.plan_start_time
+            )
+            or (
+            #{res.startTime}    <![CDATA[<=]]> r.plan_end_time
+            and #{res.endTime} >= r.plan_end_time
+            )
+            or (
+            #{res.startTime} >= r.plan_start_time
+            and #{res.endTime}  <![CDATA[<=]]> r.plan_end_time
+            ))
         </if>
     </select>
     <select id="selectAllByPlanStartTime" resultType="com.xunmei.core.resumption.domain.Resumption">
@@ -242,11 +253,10 @@
         t.status
         from core_resumption t
         where t.org_id = #{request.orgId}
-
         and t.plan_id in (select pr.plan_id
         from core_resumption_plan_to_role pr
         inner join core_resumption_plan p
-        on pr.plan_id = p.id and p.deleted = 0 and p.plan_status = 1
+        on pr.plan_id = p.id
         <if test="request.roleIdList!=null and request.roleIdList.size()>0">
             and pr.role_id in
             <foreach collection="request.roleIdList" item="roleId" open="(" close=")" separator=",">