逻辑完成

This commit is contained in:
NeuroLogeKCW
2025-04-11 23:46:28 +08:00
parent 66463ea540
commit 2683dc539a
6 changed files with 45 additions and 172 deletions

View File

@@ -1,10 +1,7 @@
package com.kkz.kpersonalre.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.kkz.kpersonalre.entity.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
@@ -32,8 +29,8 @@ public class AlarmPersonConfigEntity extends BaseEntity{
/**
* 配置描述
*/
@TableField("describe")
private String describe;
@TableField("describes")
private String describes;
/**
* json类型 融合为数组[[personId,localtionId,alarmClockId],[personId,localtionId,alarmClockId]] 单独不为数组,但元素一样,如果融合规则匹配则不匹配单独类型

View File

@@ -1,15 +1,13 @@
package com.kkz.kpersonalre.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.kkz.kpersonalre.entity.BaseEntity;
import java.time.LocalDate;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.time.LocalDate;
/**
* <p>
* 排班配置表
@@ -37,6 +35,6 @@ public class ForceWeekdayConfigEntity extends BaseEntity{
* 是否节假日 0否 1是
*/
@TableField("holiday_flag")
private byte[] holidayFlag;
private Boolean holidayFlag;
}

View File

@@ -1,38 +0,0 @@
package com.kkz.kpersonalre.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.time.LocalTime;
/**
* <p>
* 闹钟时刻配置表
* </p>
*
* @author auto-generation-by-kcw
* @since 2025-03-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Builder
@TableName("tb_alarm_clock_config")
public class TbAlarmClockConfigEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 闹钟时间
*/
@JsonFormat(pattern = "HH:mm", timezone = "GMT+8")
private LocalTime alarmTime;
}

View File

@@ -1,46 +0,0 @@
package com.kkz.kpersonalre.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
/**
* <p>
* 闹钟规则配置表
* </p>
*
* @author auto-generation-by-kcw
* @since 2025-03-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Builder
@TableName("tb_alarm_person_config")
public class TbAlarmPersonConfigEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 类型 1融合 2单独 融合的优先级最高
*/
private String type;
/**
* 配置描述
*/
private String describes;
/**
* json类型
融合为数组[[personId,localtionId,alarmClockId],[personId,localtionId,alarmClockId]]
单独不为数组,但元素一样,如果融合规则匹配则不匹配单独类型
*/
private String config;
}

View File

@@ -1,38 +0,0 @@
package com.kkz.kpersonalre.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import lombok.Builder;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
/**
* <p>
* 闹钟时刻表
* </p>
*
* @author auto-generation-by-kcw
* @since 2025-03-27
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
@Builder
@TableName("tb_location_upload")
public class TbLocationUploadEntity extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 地址配置表id
*/
private Integer locationConfigId;
/**
* 人员配置表id
*/
private Integer personConfigId;
}

View File

@@ -9,19 +9,19 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kkz.kpersonalre.api.R;
import com.kkz.kpersonalre.entity.TbAlarmClockConfigEntity;
import com.kkz.kpersonalre.entity.TbAlarmPersonConfigEntity;
import com.kkz.kpersonalre.entity.TbDateWeekdayEntity;
import com.kkz.kpersonalre.entity.TbLocationConfigEntity;
import com.kkz.kpersonalre.entity.TbLocationUploadEntity;
import com.kkz.kpersonalre.entity.TbPersonConfigEntity;
import com.kkz.kpersonalre.mapper.TbAlarmClockConfigMapper;
import com.kkz.kpersonalre.mapper.TbAlarmPersonConfigMapper;
import com.kkz.kpersonalre.mapper.TbDateWeekdayMapper;
import com.kkz.kpersonalre.mapper.TbForceWeekdayConfigMapper;
import com.kkz.kpersonalre.mapper.TbLocationConfigMapper;
import com.kkz.kpersonalre.mapper.TbLocationUploadMapper;
import com.kkz.kpersonalre.mapper.TbPersonConfigMapper;
import com.kkz.kpersonalre.entity.AlarmClockConfigEntity;
import com.kkz.kpersonalre.entity.AlarmPersonConfigEntity;
import com.kkz.kpersonalre.entity.DateWeekdayEntity;
import com.kkz.kpersonalre.entity.LocationConfigEntity;
import com.kkz.kpersonalre.entity.LocationUploadEntity;
import com.kkz.kpersonalre.entity.PersonConfigEntity;
import com.kkz.kpersonalre.mapper.AlarmClockConfigMapper;
import com.kkz.kpersonalre.mapper.AlarmPersonConfigMapper;
import com.kkz.kpersonalre.mapper.DateWeekdayMapper;
import com.kkz.kpersonalre.mapper.ForceWeekdayConfigMapper;
import com.kkz.kpersonalre.mapper.LocationConfigMapper;
import com.kkz.kpersonalre.mapper.LocationUploadMapper;
import com.kkz.kpersonalre.mapper.PersonConfigMapper;
import com.kkz.kpersonalre.service.AlarmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -45,25 +45,25 @@ import java.util.Objects;
public class AlarmServiceImpl implements AlarmService {
@Autowired
private TbAlarmClockConfigMapper alarmClockConfigMapper;
private AlarmClockConfigMapper alarmClockConfigMapper;
@Autowired
private TbAlarmPersonConfigMapper alarmPersonConfigMapper;
private AlarmPersonConfigMapper alarmPersonConfigMapper;
@Autowired
private TbDateWeekdayMapper dateWeekdayMapper;
private DateWeekdayMapper dateWeekdayMapper;
@Autowired
private TbForceWeekdayConfigMapper forceWeekdayConfigMapper;
private ForceWeekdayConfigMapper forceWeekdayConfigMapper;
@Autowired
private TbLocationConfigMapper locationConfigMapper;
private LocationConfigMapper locationConfigMapper;
@Autowired
private TbLocationUploadMapper locationUploadMapper;
private LocationUploadMapper locationUploadMapper;
@Autowired
private TbPersonConfigMapper personConfigMapper;
private PersonConfigMapper personConfigMapper;
/**
@@ -75,9 +75,9 @@ public class AlarmServiceImpl implements AlarmService {
@Override
public R<String> uploadLocation(String person, String location) {
TbLocationConfigEntity locationConfigEntity = null;
List<TbLocationConfigEntity> tbLocationConfigEntities = locationConfigMapper.selectList(new LambdaQueryWrapper<TbLocationConfigEntity>());
for (TbLocationConfigEntity tbLocationConfigEntity : tbLocationConfigEntities) {
LocationConfigEntity locationConfigEntity = null;
List<LocationConfigEntity> tbLocationConfigEntities = locationConfigMapper.selectList(new LambdaQueryWrapper<LocationConfigEntity>());
for (LocationConfigEntity tbLocationConfigEntity : tbLocationConfigEntities) {
if (location.contains(tbLocationConfigEntity.getName())) {
locationConfigEntity = tbLocationConfigEntity;
break;
@@ -86,11 +86,11 @@ public class AlarmServiceImpl implements AlarmService {
if (locationConfigEntity == null) {
return R.failed("位置不存在");
}
TbPersonConfigEntity personConfigEntity = personConfigMapper.selectOne(new LambdaQueryWrapper<TbPersonConfigEntity>().eq(TbPersonConfigEntity::getPerson, person));
PersonConfigEntity personConfigEntity = personConfigMapper.selectOne(new LambdaQueryWrapper<PersonConfigEntity>().eq(PersonConfigEntity::getPerson, person));
if (BeanUtil.isEmpty(personConfigEntity)) {
return R.failed("用户不存在");
}
locationUploadMapper.insert(new TbLocationUploadEntity()
locationUploadMapper.insert(new LocationUploadEntity()
.setLocationConfigId(locationConfigEntity.getId().intValue())
.setPersonConfigId(personConfigEntity.getId().intValue()));
//检查一下工作日信息
@@ -107,10 +107,10 @@ public class AlarmServiceImpl implements AlarmService {
String s = HttpUtil.get("https://api.jiejiariapi.com/v1/workdays/" + DateUtil.year(DateUtil.nextWeek()));
Map<String, Object> map = JSONUtil.toBean(s, HashMap.class);
for (Map.Entry<String, Object> stringObjectEntry : map.entrySet()) {
TbDateWeekdayEntity dateWeekdayEntity = dateWeekdayMapper.selectOne(new LambdaQueryWrapper<TbDateWeekdayEntity>()
.eq(TbDateWeekdayEntity::getDate, stringObjectEntry.getKey()));
DateWeekdayEntity dateWeekdayEntity = dateWeekdayMapper.selectOne(new LambdaQueryWrapper<DateWeekdayEntity>()
.eq(DateWeekdayEntity::getDate, stringObjectEntry.getKey()));
if (BeanUtil.isEmpty(dateWeekdayEntity)) {
dateWeekdayMapper.insert(new TbDateWeekdayEntity()
dateWeekdayMapper.insert(new DateWeekdayEntity()
.setDate(LocalDateTimeUtil.parseDate(stringObjectEntry.getKey()))
.setHolidayFlag(false));
}
@@ -121,23 +121,23 @@ public class AlarmServiceImpl implements AlarmService {
public R<LocalTime> getAlarm(String username) {
//判断今天是不是工作日
TbDateWeekdayEntity dateWeekdayEntity = dateWeekdayMapper.selectOne(new LambdaQueryWrapper<TbDateWeekdayEntity>()
.eq(TbDateWeekdayEntity::getDate, LocalDate.now()));
DateWeekdayEntity dateWeekdayEntity = dateWeekdayMapper.selectOne(new LambdaQueryWrapper<DateWeekdayEntity>()
.eq(DateWeekdayEntity::getDate, LocalDate.now()));
if (BeanUtil.isEmpty(dateWeekdayEntity) || dateWeekdayEntity.getHolidayFlag()) {
return R.failed("今天放假");
}
//找到人
TbPersonConfigEntity personConfigEntity = personConfigMapper.selectOne(new LambdaQueryWrapper<TbPersonConfigEntity>()
.eq(TbPersonConfigEntity::getPerson, username));
PersonConfigEntity personConfigEntity = personConfigMapper.selectOne(new LambdaQueryWrapper<PersonConfigEntity>()
.eq(PersonConfigEntity::getPerson, username));
//找到配置
List<TbAlarmPersonConfigEntity> alarmPersonConfigEntities = alarmPersonConfigMapper.selectList(new LambdaQueryWrapper<>());
List<String> configs = alarmPersonConfigEntities.stream().map(TbAlarmPersonConfigEntity::getConfig).toList();
List<AlarmPersonConfigEntity> alarmPersonConfigEntities = alarmPersonConfigMapper.selectList(new LambdaQueryWrapper<>());
List<String> configs = alarmPersonConfigEntities.stream().map(AlarmPersonConfigEntity::getConfig).toList();
//先判断是不是自己的,不是自己的就没有配置
//personId,localtionId,alarmClockId
for (String configStr : configs) {
Integer alarmClockId = findAlarmClockId(configStr, personConfigEntity.getId().intValue());
if (alarmClockId != null) {
TbAlarmClockConfigEntity entity = alarmClockConfigMapper.selectById(alarmClockId);
AlarmClockConfigEntity entity = alarmClockConfigMapper.selectById(alarmClockId);
if (BeanUtil.isEmpty(entity)){
return R.failed("不响铃");
}
@@ -190,16 +190,16 @@ public class AlarmServiceImpl implements AlarmService {
private boolean locationExists(Integer personId, Integer locationId) {
// MyBatis Plus查询检查location_config_id是否存在
LambdaQueryWrapper<TbLocationUploadEntity> query = new LambdaQueryWrapper<>();
LambdaQueryWrapper<LocationUploadEntity> query = new LambdaQueryWrapper<>();
query
.eq(TbLocationUploadEntity::getLocationConfigId, locationId)
.eq(TbLocationUploadEntity::getPersonConfigId, personId);
List<TbLocationUploadEntity> locationUploadEntities = locationUploadMapper.selectList(query);
.eq(LocationUploadEntity::getLocationConfigId, locationId)
.eq(LocationUploadEntity::getPersonConfigId, personId);
List<LocationUploadEntity> locationUploadEntities = locationUploadMapper.selectList(query);
if (locationUploadEntities.isEmpty()) {
return false;
}
//要最新的一条
TbLocationUploadEntity locationUploadEntity = locationUploadEntities.get(locationUploadEntities.size() - 1);
LocationUploadEntity locationUploadEntity = locationUploadEntities.get(locationUploadEntities.size() - 1);
//最新的一条必须符合条件
return Objects.equals(locationUploadEntity.getLocationConfigId(), locationId) && Objects.equals(locationUploadEntity.getPersonConfigId(), personId);
}