服务指令计划定时批量生成指令数据池

This commit is contained in:
曹磊 2025-11-12 10:45:55 +08:00
parent c0c3f18406
commit d87ba36dd1
10 changed files with 389 additions and 28 deletions

View File

@ -63,5 +63,11 @@
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.nursingunit.boot</groupId>
<artifactId>nu-system-api</artifactId>
<version>2.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -3,6 +3,7 @@ package com.nu.modules.directive.datapool.controller;
import com.nu.modules.directive.datapool.entity.DataPool;
import com.nu.modules.directive.datapool.service.IDataPoolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
@ -40,6 +41,7 @@ public class DataPoolController extends JeecgController<DataPool, IDataPoolServi
* 新增即时指令
* @return
*/
@ApiOperation(value="即时服务指令添加", notes="即时服务指令添加")
@PostMapping(value = "/addInstant")
public Result<?> addInstant(DataPool dataPool) {
return service.addInstant(dataPool);

View File

@ -110,4 +110,6 @@ public class DataPool implements Serializable {
@TableField(exist = false)
private String serviceDuration;
/**是否删除 0未删除 1删除*/
private String delFlag;
}

View File

@ -0,0 +1,103 @@
package com.nu.modules.directive.datapool.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.util.Date;
/**
* @Description: 服务指令数据池子表
* @Author: caolei
* @Date: 2025-11-11
* @Version: V1.0
*/
@Data
@TableName("nu_biz_nu_directive_data_pool_sub")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value="nu_biz_nu_directive_data_pool对象", description="服务指令数据池子表")
public class DataPoolSub implements Serializable {
private static final long serialVersionUID = 1L;
/**id*/
@TableId(type = IdType.ASSIGN_ID)
private String id;
/**主表id*/
private String mainId;
/**护理单元id*/
private String nuId;
/**护理单元名称*/
private String nuName;
/**客户id*/
private String customerId;
/**客户姓名*/
private String customerName;
/**分类标签id*/
private String instructionTagId;
/**分类标签*/
private String instructionTagName;
/**服务类别id*/
private String categoryId;
/**服务类别名称*/
private String categoryName;
/**服务类型id*/
private String typeId;
/**服务类型名称*/
private String typeName;
/**服务指令id*/
private String directiveId;
/**服务指令名称*/
private String directiveName;
/**周期类型ID*/
private String cycleTypeId;
/**周期类型*/
private String cycleType;
/**周期值*/
private String cycleValue;
/**服务指令图片大图*/
private String previewFile;
/**服务指令图片小图*/
private String previewFileSmall;
/**指令音频文件*/
private String mp3File;
/**指令视频文件*/
private String mp4File;
/**服务时长(分钟)*/
private String serviceDuration;
/**服务描述*/
private String serviceContent;
/**指令包id*/
private String packageId;
/**指令包名称*/
private String packageName;
/**是否是服务指令包 0否 1是*/
private String izPackage;
/**开始时间*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date startTime;
/**结束时间*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date endTime;
/**创建人*/
private String createBy;
/**创建日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date createTime;
/**更新人*/
private String updateBy;
/**更新日期*/
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
private Date updateTime;
/**是否删除 0未删除 1删除*/
private String delFlag;
}

View File

@ -2,6 +2,7 @@ package com.nu.modules.directive.datapool.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nu.modules.directive.datapool.entity.DataPool;
import com.nu.modules.directive.datapool.entity.DataPoolSub;
import java.util.List;

View File

@ -0,0 +1,17 @@
package com.nu.modules.directive.datapool.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.nu.modules.directive.datapool.entity.DataPoolSub;
import java.util.List;
/**
* @Description: 服务指令数据池管理子表
* @Author: caolei
* @Date: 2025-11-11
* @Version: V1.0
*/
public interface DataPoolSubMapper extends BaseMapper<DataPoolSub> {
DataPoolSub queryDirectiveOne(DataPoolSub dataPoolSub);
List<DataPoolSub> queryDirectiveList(DataPoolSub dataPoolSub);
}

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nu.modules.directive.datapool.mapper.DataPoolSubMapper">
<select id="queryDirectiveOne" resultType="com.nu.modules.directive.datapool.entity.DataPoolSub">
select
a.instruction_tag_id as instructionTagId,
b.instruction_name as instructionTagName,
a.category_id as categoryId,
c.category_name AS categoryName,
a.type_id as typeId,
d.type_name as typeName,
a.id as directiveId,
a.directive_name as directiveName,
a.cycle_type as cycleTypeId,
f.item_text AS cycleType,
a.preview_file as previewFile,
a.preview_file_small as previewFileSmall,
a.mp3_file as mp3File,
a.mp4_file as mp4File,
a.service_duration as serviceDuration,
a.service_content as serviceContent
from nu_config_service_directive a
left join nu_config_service_instruction_tag b on a.instruction_tag_id = b.id
left join nu_config_service_category c on a.category_id = c.id
left join nu_config_service_type d on a.type_id = d.id
left join sys_dict_item f on f.dict_id = '1900374791386140674' and f.item_value = a.cycle_type
where a.id = #{directiveId}
</select>
<select id="queryDirectiveList" resultType="com.nu.modules.directive.datapool.entity.DataPoolSub">
select
b.instruction_tag_id as instructionTagId,
e.instruction_name as instructionTagName,
b.category_id as categoryId,
c.category_name AS categoryName,
b.type_id as typeId,
d.type_name as typeName,
b.id as directiveId,
b.directive_name as directiveName,
b.cycle_type as cycleTypeId,
f.item_text AS cycleType,
a.cycle_value AS cycleValue,
b.preview_file as previewFile,
b.preview_file_small as previewFileSmall,
b.mp3_file as mp3File,
b.mp4_file as mp4File,
b.service_duration as serviceDuration,
b.service_content as serviceContent
from nu_config_package_directive a
left join nu_config_service_directive b on a.directive_id = b.id
left join nu_config_service_category c on b.category_id = c.id
left join nu_config_service_type d on b.type_id = d.id
left join nu_config_service_instruction_tag e on b.instruction_tag_id = e.id
left join sys_dict_item f on f.dict_id = '1900374791386140674' and f.item_value = b.cycle_type
where a.package_id = #{packageId}
</select>
</mapper>

View File

@ -0,0 +1,17 @@
package com.nu.modules.directive.datapool.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.nu.modules.directive.datapool.entity.DataPoolSub;
import java.util.List;
/**
* @Description: 服务指令数据池管理子表
* @Author: caolei
* @Date: 2025-11-11
* @Version: V1.0
*/
public interface IDataPoolSubService extends IService<DataPoolSub> {
DataPoolSub queryDirectiveOne(DataPoolSub dataPoolSub);
List<DataPoolSub> queryDirectiveList(DataPoolSub dataPoolSub);
}

View File

@ -1,12 +1,20 @@
package com.nu.modules.directive.datapool.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nu.modules.directive.datapool.entity.DataPool;
import com.nu.modules.directive.datapool.entity.DataPoolSub;
import com.nu.modules.directive.datapool.mapper.DataPoolMapper;
import com.nu.modules.directive.datapool.mapper.DataPoolSubMapper;
import com.nu.modules.directive.datapool.service.IDataPoolService;
import com.nu.modules.directive.datapool.service.IDataPoolSubService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Calendar;
@ -22,6 +30,11 @@ import java.util.List;
@Slf4j
public class DataPoolServiceImpl extends ServiceImpl<DataPoolMapper, DataPool> implements IDataPoolService {
@Autowired
private ISysBaseAPI sysBaseAPI;
@Autowired
IDataPoolSubService dataPoolSubService;
/**
* 批量生成
*/
@ -51,52 +64,158 @@ public class DataPoolServiceImpl extends ServiceImpl<DataPoolMapper, DataPool> i
}
private void addDataPool(DataPool dataPool){
dataPool.setIzSend("0");
dataPool.setDelFlag("0");
String izPackage = dataPool.getIzPackage();
if(izPackage!=null&&izPackage.equals("1")){
//指令包入指令池
dataPool.setIzSend("0");
this.save(dataPool);
addPackage(dataPool);
}else{
String typeId = dataPool.getCycleTypeId();
if(typeId!=null){
if(typeId.equals("1")){
//常规入指令池
dataPool.setIzSend("0");
this.save(dataPool);
addDaily(dataPool);
}
if(typeId.equals("2")){
//周期先判断是星期还是月份再判断当前时间是否命中周期
Calendar calendar = Calendar.getInstance();
String cycleValue = dataPool.getCycleValue();
if(cycleValue.length()>1){
//月周期
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
Integer cv = Integer.valueOf(cycleValue);
if(dayOfMonth == cv){
//计划执行月中的几号是当天则入指令池
this.save(dataPool);
}
addMonthDay(dataPool);
}else{
//星期周期
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); //1周日 2周一 3周二 4周三 5周四 6周五 7周六
// cycleValue 存js的星期 0周一 1周二 2周三 3周四 4周五 5周六 6周日 js +2 2 3 4 5 6 7 8 /7 %
Integer cv = Integer.valueOf(cycleValue);
//处理js星期使其能和java的星期进行比较
cv = cv + 2;
if(cv-7>0){
cv = cv -7;
}
if(dayOfWeek == cv){
//计划执行星期几是当天则入指令池
this.save(dataPool);
}
addWeekDay(dataPool);
}
}
}
}
}
//生成日常
private void addDaily(DataPool dataPool){
//入指令池主表
this.save(dataPool);
//入指令池子表
addSub(dataPool);
}
//生成星期周期
private void addWeekDay(DataPool dataPool){
String cycleValue = dataPool.getCycleValue();
Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); //1周日 2周一 3周二 4周三 5周四 6周五 7周六
// cycleValue 存js的星期 0周一 1周二 2周三 3周四 4周五 5周六 6周日 js +2 2 3 4 5 6 7 8 /7 %
Integer cv = Integer.valueOf(cycleValue);
//处理js星期使其能和java的星期进行比较
cv = cv + 2;
if(cv-7>0){
cv = cv -7;
}
//计划执行星期几是当天则入指令池
if(dayOfWeek == cv){
//入指令池主表
this.save(dataPool);
//入指令池子表
addSub(dataPool);
}
}
//生成月周期
private void addMonthDay(DataPool dataPool){
String cycleValue = dataPool.getCycleValue();
Calendar calendar = Calendar.getInstance();
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
Integer cv = Integer.valueOf(cycleValue);
//计划执行月中的几号是当天则入指令池
if(dayOfMonth == cv){
//入指令池主表
this.save(dataPool);
//入指令池子表
addSub(dataPool);
}
}
//生成指令包
private void addPackage(DataPool dataPool){
//入指令池主表
this.save(dataPool);
//入指令池子表
addPackageSubs(dataPool);
}
//生成数据池子表
private void addSub(DataPool dataPool){
DataPoolSub entity = new DataPoolSub();
entity.setDirectiveId(dataPool.getDirectiveId());
DataPoolSub dataPoolSub = dataPoolSubService.queryDirectiveOne(entity);
dataPoolSub.setCycleValue(dataPool.getCycleValue());
dataPoolSub.setNuId(dataPool.getNuId());
dataPoolSub.setNuName(dataPool.getNuName());
dataPoolSub.setCustomerId(dataPool.getCustomerId());
dataPoolSub.setCustomerName(dataPool.getCustomerName());
dataPoolSub.setStartTime(dataPool.getStartTime());
dataPoolSub.setEndTime(dataPool.getEndTime());
dataPoolSub.setIzPackage("0");
dataPoolSub.setDelFlag(dataPool.getDelFlag());
dataPoolSub.setMainId(dataPool.getId());
dataPoolSubService.save(dataPoolSub);
}
//生成数据池子表
private void addPackageSubs(DataPool dataPool){
DataPoolSub entity = new DataPoolSub();
entity.setPackageId(dataPool.getPackageId());
List<DataPoolSub> subList = dataPoolSubService.queryDirectiveList(entity);
for(int i=0;i<subList.size();i++){
DataPoolSub dataPoolSub = subList.get(i);
String cycleValue = dataPoolSub.getCycleValue();
if(cycleValue==null || cycleValue.equals("")){
//日常
addPackageSub(dataPool,dataPoolSub);
}else{
if(cycleValue.length()>1){
//月周期
Calendar calendar = Calendar.getInstance();
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
Integer cv = Integer.valueOf(cycleValue);
//计划执行月中的几号是当天则入指令池
if(dayOfMonth == cv){
addPackageSub(dataPool,dataPoolSub);
}
}else{
//星期周期
Calendar calendar = Calendar.getInstance();
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); //1周日 2周一 3周二 4周三 5周四 6周五 7周六
//cycleValue 存js的星期 0周一 1周二 2周三 3周四 4周五 5周六 6周日 js +2 2 3 4 5 6 7 8 /7 %
Integer cv = Integer.valueOf(cycleValue);
//处理js星期使其能和java的星期进行比较
cv = cv + 2;
if(cv-7>0){
cv = cv -7;
}
//计划执行星期几是当天则入指令池
if(dayOfWeek == cv){
addPackageSub(dataPool,dataPoolSub);
}
}
}
}
}
private void addPackageSub(DataPool dataPool,DataPoolSub dataPoolSub){
dataPoolSub.setNuId(dataPool.getNuId());
dataPoolSub.setNuName(dataPool.getNuName());
dataPoolSub.setCustomerId(dataPool.getCustomerId());
dataPoolSub.setCustomerName(dataPool.getCustomerName());
dataPoolSub.setStartTime(dataPool.getStartTime());
dataPoolSub.setEndTime(dataPool.getEndTime());
dataPoolSub.setIzPackage("1");
dataPoolSub.setPackageId(dataPool.getPackageId());
dataPoolSub.setPackageName(dataPool.getPackageName());
dataPoolSub.setDelFlag(dataPool.getDelFlag());
dataPoolSub.setMainId(dataPool.getId());
dataPoolSubService.save(dataPoolSub);
}
/**
* 单一生成
* @param directiveDataPool
@ -132,8 +251,12 @@ public class DataPoolServiceImpl extends ServiceImpl<DataPoolMapper, DataPool> i
// c.add(Calendar.MINUTE,10);
// entity.setStartTime(c.getTime());
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
JSONObject sysUser = sysBaseAPI.queryUserById(user.getId());
String employessId = sysUser.getString("employessId");
dataPool.setCreateBy(employessId);
dataPool.setCycleTypeId("3");
this.save(dataPool);
return Result.OK();
}

View File

@ -0,0 +1,31 @@
package com.nu.modules.directive.datapool.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nu.modules.directive.datapool.entity.DataPoolSub;
import com.nu.modules.directive.datapool.mapper.DataPoolSubMapper;
import com.nu.modules.directive.datapool.service.IDataPoolSubService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Description: 服务指令数据池管理
* @Author: caolei
* @Date: 2025-11-07
* @Version: V1.0
*/
@Service
@Slf4j
public class DataPoolSubServiceImpl extends ServiceImpl<DataPoolSubMapper, DataPoolSub> implements IDataPoolSubService {
@Override
public DataPoolSub queryDirectiveOne(DataPoolSub dataPoolSub){
return baseMapper.queryDirectiveOne(dataPoolSub);
}
@Override
public List<DataPoolSub> queryDirectiveList(DataPoolSub dataPoolSub){
return baseMapper.queryDirectiveList(dataPoolSub);
}
}