逻辑完成
This commit is contained in:
@@ -6,9 +6,12 @@ import com.kkz.kpersonalre.service.AlarmService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
/**
|
||||
* @program: KPersonal
|
||||
* @description: 闹钟入口
|
||||
@@ -28,10 +31,10 @@ public class AlarmController {
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/uploadLocation")
|
||||
public R<String> uploadLocation(String location) {
|
||||
@GetMapping("/uploadLocation/{person}/{location}")
|
||||
public R<String> uploadLocation(@PathVariable String person,@PathVariable String location) {
|
||||
log.info("进入[上传位置信息接口],入参:{}", location);
|
||||
R<String> result = alarmService.uploadLocation(location);
|
||||
R<String> result = alarmService.uploadLocation(person, location);
|
||||
log.info("离开[上传位置信息接口],出参:{}", result);
|
||||
return result;
|
||||
}
|
||||
@@ -43,4 +46,12 @@ public class AlarmController {
|
||||
public void checkWorkDay() {
|
||||
alarmService.checkWorkDay();
|
||||
}
|
||||
|
||||
@GetMapping("/getAlarm/{personId}")
|
||||
public R<LocalTime> getAlarm(@PathVariable String personId) {
|
||||
log.info("进入[获取闹钟信息接口],入参:{}", personId);
|
||||
R<LocalTime> result = alarmService.getAlarm(personId);
|
||||
log.info("离开[获取闹钟信息接口],出参:{}", result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
@@ -42,7 +43,7 @@ public class BaseEntity {
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_time", fill = FieldFill.INSERT)
|
||||
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
@@ -55,6 +56,6 @@ public class BaseEntity {
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE,update = "now()")
|
||||
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -31,6 +32,7 @@ public class TbAlarmClockConfigEntity extends BaseEntity {
|
||||
/**
|
||||
* 闹钟时间
|
||||
*/
|
||||
@JsonFormat(pattern = "HH:mm", timezone = "GMT+8")
|
||||
private LocalTime alarmTime;
|
||||
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class TbAlarmPersonConfigEntity extends BaseEntity {
|
||||
/**
|
||||
* 配置描述
|
||||
*/
|
||||
private String describe;
|
||||
private String describes;
|
||||
|
||||
/**
|
||||
* json类型
|
||||
|
||||
@@ -30,4 +30,9 @@ public class TbLocationUploadEntity extends BaseEntity {
|
||||
*/
|
||||
private Integer locationConfigId;
|
||||
|
||||
/**
|
||||
* 人员配置表id
|
||||
*/
|
||||
private Integer personConfigId;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.kkz.kpersonalre.service;
|
||||
|
||||
import com.kkz.kpersonalre.api.R;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
public interface AlarmService {
|
||||
|
||||
/**
|
||||
@@ -10,10 +12,12 @@ public interface AlarmService {
|
||||
* @param location
|
||||
* @return
|
||||
*/
|
||||
R<String> uploadLocation(String location);
|
||||
R<String> uploadLocation(String person, String location);
|
||||
|
||||
/**
|
||||
* 查询工作日
|
||||
*/
|
||||
void checkWorkDay();
|
||||
|
||||
R<LocalTime> getAlarm(String username);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,15 @@ import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
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;
|
||||
@@ -22,8 +27,12 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @program: KPersonal
|
||||
@@ -64,15 +73,28 @@ public class AlarmServiceImpl implements AlarmService {
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public R<String> uploadLocation(String location) {
|
||||
public R<String> uploadLocation(String person, String location) {
|
||||
|
||||
TbLocationConfigEntity locationConfigEntity = locationConfigMapper.selectOne(new LambdaQueryWrapper<TbLocationConfigEntity>()
|
||||
.eq(TbLocationConfigEntity::getName, location));
|
||||
TbLocationConfigEntity locationConfigEntity = null;
|
||||
List<TbLocationConfigEntity> tbLocationConfigEntities = locationConfigMapper.selectList(new LambdaQueryWrapper<TbLocationConfigEntity>());
|
||||
for (TbLocationConfigEntity tbLocationConfigEntity : tbLocationConfigEntities) {
|
||||
if (location.contains(tbLocationConfigEntity.getName())) {
|
||||
locationConfigEntity = tbLocationConfigEntity;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (locationConfigEntity == null) {
|
||||
return R.failed("位置不存在");
|
||||
}
|
||||
TbPersonConfigEntity personConfigEntity = personConfigMapper.selectOne(new LambdaQueryWrapper<TbPersonConfigEntity>().eq(TbPersonConfigEntity::getPerson, person));
|
||||
if (BeanUtil.isEmpty(personConfigEntity)) {
|
||||
return R.failed("用户不存在");
|
||||
}
|
||||
locationUploadMapper.insert(new TbLocationUploadEntity()
|
||||
.setLocationConfigId(locationConfigEntity.getId().intValue()));
|
||||
.setLocationConfigId(locationConfigEntity.getId().intValue())
|
||||
.setPersonConfigId(personConfigEntity.getId().intValue()));
|
||||
//检查一下工作日信息
|
||||
checkWorkDay();
|
||||
return R.ok("上传成功");
|
||||
}
|
||||
|
||||
@@ -94,4 +116,91 @@ public class AlarmServiceImpl implements AlarmService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public R<LocalTime> getAlarm(String username) {
|
||||
|
||||
//判断今天是不是工作日
|
||||
TbDateWeekdayEntity dateWeekdayEntity = dateWeekdayMapper.selectOne(new LambdaQueryWrapper<TbDateWeekdayEntity>()
|
||||
.eq(TbDateWeekdayEntity::getDate, LocalDate.now()));
|
||||
if (BeanUtil.isEmpty(dateWeekdayEntity) || dateWeekdayEntity.getHolidayFlag()) {
|
||||
return R.failed("今天放假");
|
||||
}
|
||||
//找到人
|
||||
TbPersonConfigEntity personConfigEntity = personConfigMapper.selectOne(new LambdaQueryWrapper<TbPersonConfigEntity>()
|
||||
.eq(TbPersonConfigEntity::getPerson, username));
|
||||
//找到配置
|
||||
List<TbAlarmPersonConfigEntity> alarmPersonConfigEntities = alarmPersonConfigMapper.selectList(new LambdaQueryWrapper<>());
|
||||
List<String> configs = alarmPersonConfigEntities.stream().map(TbAlarmPersonConfigEntity::getConfig).toList();
|
||||
//先判断是不是自己的,不是自己的就没有配置
|
||||
//personId,localtionId,alarmClockId
|
||||
for (String configStr : configs) {
|
||||
Integer alarmClockId = findAlarmClockId(configStr, personConfigEntity.getId().intValue());
|
||||
if (alarmClockId != null) {
|
||||
TbAlarmClockConfigEntity entity = alarmClockConfigMapper.selectById(alarmClockId);
|
||||
if (BeanUtil.isEmpty(entity)){
|
||||
return R.failed("不响铃");
|
||||
}
|
||||
return R.ok(entity.getAlarmTime());
|
||||
}
|
||||
}
|
||||
return R.failed("自定义闹钟");
|
||||
}
|
||||
|
||||
public Integer findAlarmClockId(String json, Integer personId) {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Integer myClockId = null;
|
||||
try {
|
||||
List<List<Integer>> configs = objectMapper.readValue(json, new TypeReference<>() {
|
||||
});
|
||||
|
||||
// 优先处理组合模式
|
||||
if (configs.size() > 1) {
|
||||
for (List<Integer> config : configs) {
|
||||
if (matchCondition(config)) {
|
||||
//需要每个都查一遍
|
||||
if (Objects.equals(personId, config.get(0))) {
|
||||
myClockId = config.get(2);
|
||||
}
|
||||
} else {
|
||||
//走到这里说明另一个没有匹配上
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return myClockId;
|
||||
}
|
||||
|
||||
// 处理单条模式
|
||||
if (!configs.isEmpty() && matchCondition(configs.get(0))) {
|
||||
return configs.get(0).get(2);
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON解析失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchCondition(List<Integer> config) {
|
||||
Integer configPersonId = config.get(0);
|
||||
Integer locationId = config.get(1);
|
||||
|
||||
return locationExists(configPersonId, locationId); // 验证location存在性
|
||||
}
|
||||
|
||||
private boolean locationExists(Integer personId, Integer locationId) {
|
||||
// MyBatis Plus查询:检查location_config_id是否存在
|
||||
LambdaQueryWrapper<TbLocationUploadEntity> query = new LambdaQueryWrapper<>();
|
||||
query
|
||||
.eq(TbLocationUploadEntity::getLocationConfigId, locationId)
|
||||
.eq(TbLocationUploadEntity::getPersonConfigId, personId);
|
||||
List<TbLocationUploadEntity> locationUploadEntities = locationUploadMapper.selectList(query);
|
||||
if (locationUploadEntities.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
//要最新的一条
|
||||
TbLocationUploadEntity locationUploadEntity = locationUploadEntities.get(locationUploadEntities.size() - 1);
|
||||
//最新的一条必须符合条件
|
||||
return Objects.equals(locationUploadEntity.getLocationConfigId(), locationId) && Objects.equals(locationUploadEntity.getPersonConfigId(), personId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user