38 changed files with 769 additions and 69 deletions
@ -0,0 +1,113 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.controller.admin; |
||||
|
|
||||
|
import cn.iocoder.yudao.module.hand.dal.PersonnelDO; |
||||
|
import cn.iocoder.yudao.module.hand.service.PersonnelService; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelPageReqVO; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelRespVO; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelSaveReqVO; |
||||
|
import org.springframework.web.bind.annotation.*; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.security.access.prepost.PreAuthorize; |
||||
|
import io.swagger.v3.oas.annotations.tags.Tag; |
||||
|
import io.swagger.v3.oas.annotations.Parameter; |
||||
|
import io.swagger.v3.oas.annotations.Operation; |
||||
|
|
||||
|
import jakarta.validation.constraints.*; |
||||
|
import jakarta.validation.*; |
||||
|
import jakarta.servlet.http.*; |
||||
|
import java.util.*; |
||||
|
import java.io.IOException; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; |
||||
|
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; |
||||
|
|
||||
|
|
||||
|
@Tag(name = "管理后台 - 人员信息") |
||||
|
@RestController |
||||
|
@RequestMapping("/gas/personnel") |
||||
|
@Validated |
||||
|
public class PersonnelController { |
||||
|
|
||||
|
@Resource |
||||
|
private PersonnelService personnelService; |
||||
|
|
||||
|
@PostMapping("/create") |
||||
|
@Operation(summary = "创建人员信息") |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:create')") |
||||
|
public CommonResult<Long> createPersonnel(@Valid @RequestBody PersonnelSaveReqVO createReqVO) { |
||||
|
return success(personnelService.createPersonnel(createReqVO)); |
||||
|
} |
||||
|
|
||||
|
@PutMapping("/update") |
||||
|
@Operation(summary = "更新人员信息") |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:update')") |
||||
|
public CommonResult<Boolean> updatePersonnel(@Valid @RequestBody PersonnelSaveReqVO updateReqVO) { |
||||
|
personnelService.updatePersonnel(updateReqVO); |
||||
|
return success(true); |
||||
|
} |
||||
|
|
||||
|
@DeleteMapping("/delete") |
||||
|
@Operation(summary = "删除人员信息") |
||||
|
@Parameter(name = "id", description = "编号", required = true) |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:delete')") |
||||
|
public CommonResult<Boolean> deletePersonnel(@RequestParam("id") Long id) { |
||||
|
personnelService.deletePersonnel(id); |
||||
|
return success(true); |
||||
|
} |
||||
|
|
||||
|
@DeleteMapping("/delete-list") |
||||
|
@Parameter(name = "ids", description = "编号", required = true) |
||||
|
@Operation(summary = "批量删除人员信息") |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:delete')") |
||||
|
public CommonResult<Boolean> deletePersonnelList(@RequestParam("ids") List<Long> ids) { |
||||
|
personnelService.deletePersonnelListByIds(ids); |
||||
|
return success(true); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("/get") |
||||
|
@Operation(summary = "获得人员信息") |
||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024") |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:query')") |
||||
|
public CommonResult<PersonnelRespVO> getPersonnel(@RequestParam("id") Long id) { |
||||
|
PersonnelDO personnel = personnelService.getPersonnel(id); |
||||
|
return success(BeanUtils.toBean(personnel, PersonnelRespVO.class)); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("/page") |
||||
|
@Operation(summary = "获得人员信息分页") |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:query')") |
||||
|
public CommonResult<PageResult<PersonnelRespVO>> getPersonnelPage(@Valid PersonnelPageReqVO pageReqVO) { |
||||
|
PageResult<PersonnelDO> pageResult = personnelService.getPersonnelPage(pageReqVO); |
||||
|
return success(BeanUtils.toBean(pageResult, PersonnelRespVO.class)); |
||||
|
} |
||||
|
|
||||
|
@GetMapping("/getListAll") |
||||
|
@Operation(summary = "获得全部人员信息") |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:query')") |
||||
|
public CommonResult<List<PersonnelDO>> getListAll() { |
||||
|
List<PersonnelDO> listAll = personnelService.getListAll(); |
||||
|
return success(listAll); |
||||
|
} |
||||
|
@GetMapping("/export-excel") |
||||
|
@Operation(summary = "导出人员信息 Excel") |
||||
|
@PreAuthorize("@ss.hasPermission('gas:personnel:export')") |
||||
|
@ApiAccessLog(operateType = EXPORT) |
||||
|
public void exportPersonnelExcel(@Valid PersonnelPageReqVO pageReqVO, |
||||
|
HttpServletResponse response) throws IOException { |
||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); |
||||
|
List<PersonnelDO> list = personnelService.getPersonnelPage(pageReqVO).getList(); |
||||
|
// 导出 Excel
|
||||
|
ExcelUtils.write(response, "人员信息.xls", "数据", PersonnelRespVO.class, |
||||
|
BeanUtils.toBean(list, PersonnelRespVO.class)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.dal; |
||||
|
|
||||
|
import lombok.*; |
||||
|
import java.util.*; |
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.LocalDateTime; |
||||
|
import com.baomidou.mybatisplus.annotation.*; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
||||
|
|
||||
|
/** |
||||
|
* 人员信息 DO |
||||
|
* |
||||
|
* @author 超级管理员 |
||||
|
*/ |
||||
|
@TableName("gas_personnel") |
||||
|
@KeySequence("gas_personnel_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper = true) |
||||
|
@ToString(callSuper = true) |
||||
|
@Builder |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
public class PersonnelDO extends BaseDO { |
||||
|
|
||||
|
/** |
||||
|
* 主键ID |
||||
|
*/ |
||||
|
@TableId |
||||
|
private Long id; |
||||
|
/** |
||||
|
* 姓名 |
||||
|
*/ |
||||
|
private String name; |
||||
|
/** |
||||
|
* 工号 |
||||
|
*/ |
||||
|
private String employeeId; |
||||
|
/** |
||||
|
* 关联的系统用户ID (关联系统用户表, 可为空) |
||||
|
*/ |
||||
|
private Long userId; |
||||
|
/** |
||||
|
* 联系电话 |
||||
|
*/ |
||||
|
private String phone; |
||||
|
/** |
||||
|
* 电子邮箱 |
||||
|
*/ |
||||
|
private String email; |
||||
|
/** |
||||
|
* 状态 (1-在职, 0-离职) |
||||
|
*/ |
||||
|
private Integer status; |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,147 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.job; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
||||
|
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; |
||||
|
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; |
||||
|
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; |
||||
|
import cn.iocoder.yudao.module.hand.dal.HandAlarmDO; |
||||
|
import cn.iocoder.yudao.module.hand.enums.*; |
||||
|
import cn.iocoder.yudao.module.hand.service.HandAlarmService; |
||||
|
import cn.iocoder.yudao.module.hand.util.RedisKeyUtil; |
||||
|
import cn.iocoder.yudao.module.hand.util.RedisUtil; |
||||
|
import cn.iocoder.yudao.module.hand.vo.HandAlarmSaveReqVO; |
||||
|
import cn.iocoder.yudao.module.hand.vo.HandDataVo; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.time.LocalDateTime; |
||||
|
import java.time.ZoneId; |
||||
|
import java.util.ArrayList; |
||||
|
import java.util.Date; |
||||
|
import java.util.List; |
||||
|
import java.util.Map; |
||||
|
import java.util.concurrent.TimeUnit; |
||||
|
|
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class OfflineAlarmJob implements JobHandler { |
||||
|
|
||||
|
/** |
||||
|
* 定义设备离线阈值:10分钟 |
||||
|
*/ |
||||
|
private static final long OFFLINE_THRESHOLD_MINUTES = 10; |
||||
|
private static final long OFFLINE_THRESHOLD_MS = TimeUnit.MINUTES.toMillis(OFFLINE_THRESHOLD_MINUTES); |
||||
|
@Resource |
||||
|
private RedisUtil redisUtil; |
||||
|
// 1. 注入报警记录相关的Service
|
||||
|
@Resource |
||||
|
private HandAlarmService handAlarmService; |
||||
|
|
||||
|
@Override |
||||
|
@TenantJob |
||||
|
public String execute(String param) throws Exception { |
||||
|
Long tenantId = TenantContextHolder.getTenantId(); |
||||
|
if (tenantId == null) { |
||||
|
log.warn("无法获取到租户ID,任务终止"); |
||||
|
return "无法获取租户ID"; |
||||
|
} |
||||
|
|
||||
|
String tenantDeviceKey = RedisKeyUtil.getTenantDeviceHashKey(tenantId); |
||||
|
Map<Object, Object> deviceDataMap = redisUtil.hmget(tenantDeviceKey); |
||||
|
|
||||
|
if (deviceDataMap == null || deviceDataMap.isEmpty()) { |
||||
|
log.info("租户ID {} 下无设备数据,任务结束", tenantId); |
||||
|
return "无设备数据"; |
||||
|
} |
||||
|
|
||||
|
long currentTimeMillis = System.currentTimeMillis(); |
||||
|
// 用于存储需要批量插入数据库的新报警记录
|
||||
|
List<HandAlarmDO> newAlarmsToCreate = new ArrayList<>(); |
||||
|
|
||||
|
for (Map.Entry<Object, Object> entry : deviceDataMap.entrySet()) { |
||||
|
try { |
||||
|
HandDataVo handData = BeanUtils.toBean(entry.getValue(), HandDataVo.class); |
||||
|
|
||||
|
if (handData == null || handData.getTime() == null) { |
||||
|
continue; // 跳过无效数据
|
||||
|
} |
||||
|
|
||||
|
long lastReportTimeMillis = handData.getTime().getTime(); |
||||
|
long timeDifference = currentTimeMillis - lastReportTimeMillis; |
||||
|
|
||||
|
// 判断条件 1:设备是否离线? (时间差超过阈值)
|
||||
|
if (timeDifference > OFFLINE_THRESHOLD_MS) { |
||||
|
|
||||
|
// 判断条件 2:这是否是一次新的离线事件? (检查Redis中当前的状态是否还不是报警状态)
|
||||
|
// 如果已经是报警状态,则本次不再重复处理
|
||||
|
if (!OnlineStatusType.OFFLINE.getType().equals(handData.getOnlineStatus())) { |
||||
|
|
||||
|
// --- 这是新发现的离线设备,执行报警逻辑 ---
|
||||
|
log.info("【新设备离线报警】租户ID: {}, 设备SN: {} 已离线超过{}分钟", |
||||
|
tenantId, handData.getSn(), OFFLINE_THRESHOLD_MINUTES); |
||||
|
|
||||
|
// a. 更新设备状态
|
||||
|
handData.setOnlineStatus(OnlineStatusType.OFFLINE.getType()); |
||||
|
handData.setAlarmLevel(AlarmLevelEnum.OFFLINE.value()); |
||||
|
|
||||
|
// b. 将更新后的状态写回 Redis
|
||||
|
redisUtil.hset(tenantDeviceKey, entry.getKey().toString(), handData); |
||||
|
|
||||
|
// c. 准备要插入数据库的报警记录
|
||||
|
HandAlarmDO handAlarmDO = buildAlarmRecord(tenantId, handData); |
||||
|
newAlarmsToCreate.add(handAlarmDO); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
log.error("处理设备数据时发生异常,设备Key: {}. 错误: {}", entry.getKey(), e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// 批量将新产生的报警记录插入数据库
|
||||
|
if (!newAlarmsToCreate.isEmpty()) { |
||||
|
log.info("租户 {} 发现 {} 条新的设备离线报警,准备批量写入数据库...", tenantId, newAlarmsToCreate.size()); |
||||
|
try { |
||||
|
handAlarmService.insertBatch(newAlarmsToCreate); |
||||
|
log.info("批量写入 {} 条设备离线报警记录成功", newAlarmsToCreate.size()); |
||||
|
} catch (Exception e) { |
||||
|
log.error("批量写入设备离线报警记录失败", e); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
log.info("租户 {} 的设备离线检查任务执行完毕", tenantId); |
||||
|
return "任务执行成功"; |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 辅助方法:构建报警记录对象 |
||||
|
*/ |
||||
|
private HandAlarmDO buildAlarmRecord(Long tenantId, HandDataVo handData) { |
||||
|
HandAlarmDO alarm = new HandAlarmDO(); |
||||
|
alarm.setTenantId(tenantId); |
||||
|
alarm.setDetectorId(handData.getId()); |
||||
|
alarm.setPicX(handData.getLatitude()); |
||||
|
alarm.setPicY(handData.getLongitude()); |
||||
|
alarm.setName(handData.getName()); |
||||
|
alarm.setSn(handData.getSn()); |
||||
|
alarm.setAlarmType(AlarmType.OFFLINE.getType()); // 明确指定为离线报警类型
|
||||
|
alarm.setAlarmLevel(AlarmLevelEnum.OFFLINE.value()); |
||||
|
if (handData.getTime() != null) { |
||||
|
LocalDateTime lastReportTime = handData.getTime() |
||||
|
.toInstant() |
||||
|
.atZone(ZoneId.systemDefault()) |
||||
|
.toLocalDateTime(); |
||||
|
alarm.setTAlarmStart(lastReportTime); |
||||
|
} |
||||
|
|
||||
|
alarm.setStatus(EnableStatus.DISABLED.value()); |
||||
|
alarm.setGasType(handData.getUnit()); |
||||
|
alarm.setUnit(handData.getUnit()); |
||||
|
alarm.setCreator("admin"); |
||||
|
alarm.setCreateTime(LocalDateTime.now()); |
||||
|
|
||||
|
return alarm; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.mapper; |
||||
|
|
||||
|
import java.util.*; |
||||
|
|
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; |
||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
||||
|
import cn.iocoder.yudao.module.hand.dal.PersonnelDO; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelPageReqVO; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
|
||||
|
/** |
||||
|
* 人员信息 Mapper |
||||
|
* |
||||
|
* @author 超级管理员 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface PersonnelMapper extends BaseMapperX<PersonnelDO> { |
||||
|
|
||||
|
default PageResult<PersonnelDO> selectPage(PersonnelPageReqVO reqVO) { |
||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<PersonnelDO>() |
||||
|
.likeIfPresent(PersonnelDO::getName, reqVO.getName()) |
||||
|
.eqIfPresent(PersonnelDO::getEmployeeId, reqVO.getEmployeeId()) |
||||
|
.eqIfPresent(PersonnelDO::getUserId, reqVO.getUserId()) |
||||
|
.eqIfPresent(PersonnelDO::getPhone, reqVO.getPhone()) |
||||
|
.eqIfPresent(PersonnelDO::getEmail, reqVO.getEmail()) |
||||
|
.eqIfPresent(PersonnelDO::getStatus, reqVO.getStatus()) |
||||
|
.betweenIfPresent(PersonnelDO::getCreateTime, reqVO.getCreateTime()) |
||||
|
.orderByDesc(PersonnelDO::getId)); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,65 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.service; |
||||
|
|
||||
|
import java.util.*; |
||||
|
|
||||
|
import cn.iocoder.yudao.module.hand.dal.PersonnelDO; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelPageReqVO; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelSaveReqVO; |
||||
|
import jakarta.validation.*; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
|
|
||||
|
/** |
||||
|
* 人员信息 Service 接口 |
||||
|
* |
||||
|
* @author 超级管理员 |
||||
|
*/ |
||||
|
public interface PersonnelService { |
||||
|
|
||||
|
/** |
||||
|
* 创建人员信息 |
||||
|
* |
||||
|
* @param createReqVO 创建信息 |
||||
|
* @return 编号 |
||||
|
*/ |
||||
|
Long createPersonnel(@Valid PersonnelSaveReqVO createReqVO); |
||||
|
|
||||
|
/** |
||||
|
* 更新人员信息 |
||||
|
* |
||||
|
* @param updateReqVO 更新信息 |
||||
|
*/ |
||||
|
void updatePersonnel(@Valid PersonnelSaveReqVO updateReqVO); |
||||
|
|
||||
|
/** |
||||
|
* 删除人员信息 |
||||
|
* |
||||
|
* @param id 编号 |
||||
|
*/ |
||||
|
void deletePersonnel(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 批量删除人员信息 |
||||
|
* |
||||
|
* @param ids 编号 |
||||
|
*/ |
||||
|
void deletePersonnelListByIds(List<Long> ids); |
||||
|
|
||||
|
/** |
||||
|
* 获得人员信息 |
||||
|
* |
||||
|
* @param id 编号 |
||||
|
* @return 人员信息 |
||||
|
*/ |
||||
|
PersonnelDO getPersonnel(Long id); |
||||
|
|
||||
|
/** |
||||
|
* 获得人员信息分页 |
||||
|
* |
||||
|
* @param pageReqVO 分页查询 |
||||
|
* @return 人员信息分页 |
||||
|
*/ |
||||
|
PageResult<PersonnelDO> getPersonnelPage(PersonnelPageReqVO pageReqVO); |
||||
|
|
||||
|
List<PersonnelDO> getListAll(); |
||||
|
} |
||||
@ -0,0 +1,92 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.service.impl; |
||||
|
|
||||
|
import cn.hutool.core.collection.CollUtil; |
||||
|
import cn.iocoder.yudao.module.hand.dal.PersonnelDO; |
||||
|
import cn.iocoder.yudao.module.hand.mapper.PersonnelMapper; |
||||
|
import cn.iocoder.yudao.module.hand.service.PersonnelService; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelPageReqVO; |
||||
|
import cn.iocoder.yudao.module.hand.vo.PersonnelSaveReqVO; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import jakarta.annotation.Resource; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import java.util.*; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
||||
|
|
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
||||
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList; |
||||
|
import static cn.iocoder.yudao.module.hand.enums.ErrorCodeConstants.PERSONNEL_NOT_EXISTS; |
||||
|
|
||||
|
/** |
||||
|
* 人员信息 Service 实现类 |
||||
|
* |
||||
|
* @author 超级管理员 |
||||
|
*/ |
||||
|
@Service |
||||
|
@Validated |
||||
|
public class PersonnelServiceImpl implements PersonnelService { |
||||
|
|
||||
|
@Resource |
||||
|
private PersonnelMapper personnelMapper; |
||||
|
|
||||
|
@Override |
||||
|
public Long createPersonnel(PersonnelSaveReqVO createReqVO) { |
||||
|
// 插入
|
||||
|
PersonnelDO personnel = BeanUtils.toBean(createReqVO, PersonnelDO.class); |
||||
|
personnelMapper.insert(personnel); |
||||
|
|
||||
|
// 返回
|
||||
|
return personnel.getId(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void updatePersonnel(PersonnelSaveReqVO updateReqVO) { |
||||
|
// 校验存在
|
||||
|
validatePersonnelExists(updateReqVO.getId()); |
||||
|
// 更新
|
||||
|
PersonnelDO updateObj = BeanUtils.toBean(updateReqVO, PersonnelDO.class); |
||||
|
personnelMapper.updateById(updateObj); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deletePersonnel(Long id) { |
||||
|
// 校验存在
|
||||
|
validatePersonnelExists(id); |
||||
|
// 删除
|
||||
|
personnelMapper.deleteById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void deletePersonnelListByIds(List<Long> ids) { |
||||
|
// 删除
|
||||
|
personnelMapper.deleteByIds(ids); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private void validatePersonnelExists(Long id) { |
||||
|
if (personnelMapper.selectById(id) == null) { |
||||
|
throw exception(PERSONNEL_NOT_EXISTS); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public PersonnelDO getPersonnel(Long id) { |
||||
|
return personnelMapper.selectById(id); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public PageResult<PersonnelDO> getPersonnelPage(PersonnelPageReqVO pageReqVO) { |
||||
|
return personnelMapper.selectPage(pageReqVO); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public List<PersonnelDO> getListAll() { |
||||
|
return personnelMapper.selectList(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.vo; |
||||
|
|
||||
|
import lombok.*; |
||||
|
import java.util.*; |
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import cn.iocoder.yudao.framework.common.pojo.PageParam; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
import java.time.LocalDateTime; |
||||
|
|
||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 人员信息分页 Request VO") |
||||
|
@Data |
||||
|
public class PersonnelPageReqVO extends PageParam { |
||||
|
|
||||
|
@Schema(description = "姓名", example = "王五") |
||||
|
private String name; |
||||
|
|
||||
|
@Schema(description = "工号", example = "32467") |
||||
|
private String employeeId; |
||||
|
|
||||
|
@Schema(description = "关联的系统用户ID (关联系统用户表, 可为空)", example = "14813") |
||||
|
private Long userId; |
||||
|
|
||||
|
@Schema(description = "联系电话") |
||||
|
private String phone; |
||||
|
|
||||
|
@Schema(description = "电子邮箱") |
||||
|
private String email; |
||||
|
|
||||
|
@Schema(description = "状态 (1-在职, 0-离职)", example = "2") |
||||
|
private Integer status; |
||||
|
|
||||
|
@Schema(description = "创建时间") |
||||
|
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) |
||||
|
private LocalDateTime[] createTime; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,47 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.*; |
||||
|
import java.util.*; |
||||
|
import org.springframework.format.annotation.DateTimeFormat; |
||||
|
import java.time.LocalDateTime; |
||||
|
import com.alibaba.excel.annotation.*; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 人员信息 Response VO") |
||||
|
@Data |
||||
|
@ExcelIgnoreUnannotated |
||||
|
public class PersonnelRespVO { |
||||
|
|
||||
|
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19452") |
||||
|
@ExcelProperty("主键ID") |
||||
|
private Long id; |
||||
|
|
||||
|
@Schema(description = "姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") |
||||
|
@ExcelProperty("姓名") |
||||
|
private String name; |
||||
|
|
||||
|
@Schema(description = "工号", example = "32467") |
||||
|
@ExcelProperty("工号") |
||||
|
private String employeeId; |
||||
|
|
||||
|
@Schema(description = "关联的系统用户ID (关联系统用户表, 可为空)", example = "14813") |
||||
|
@ExcelProperty("关联的系统用户ID (关联系统用户表, 可为空)") |
||||
|
private Long userId; |
||||
|
|
||||
|
@Schema(description = "联系电话") |
||||
|
@ExcelProperty("联系电话") |
||||
|
private String phone; |
||||
|
|
||||
|
@Schema(description = "电子邮箱") |
||||
|
@ExcelProperty("电子邮箱") |
||||
|
private String email; |
||||
|
|
||||
|
@Schema(description = "状态 (1-在职, 0-离职)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
||||
|
@ExcelProperty("状态 (1-在职, 0-离职)") |
||||
|
private Integer status; |
||||
|
|
||||
|
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) |
||||
|
@ExcelProperty("创建时间") |
||||
|
private LocalDateTime createTime; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
package cn.iocoder.yudao.module.hand.vo; |
||||
|
|
||||
|
import io.swagger.v3.oas.annotations.media.Schema; |
||||
|
import lombok.*; |
||||
|
import java.util.*; |
||||
|
import jakarta.validation.constraints.*; |
||||
|
|
||||
|
@Schema(description = "管理后台 - 人员信息新增/修改 Request VO") |
||||
|
@Data |
||||
|
public class PersonnelSaveReqVO { |
||||
|
|
||||
|
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19452") |
||||
|
private Long id; |
||||
|
|
||||
|
@Schema(description = "姓名", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") |
||||
|
@NotEmpty(message = "姓名不能为空") |
||||
|
private String name; |
||||
|
|
||||
|
@Schema(description = "工号", example = "32467") |
||||
|
private String employeeId; |
||||
|
|
||||
|
@Schema(description = "关联的系统用户ID (关联系统用户表, 可为空)", example = "14813") |
||||
|
private Long userId; |
||||
|
|
||||
|
@Schema(description = "联系电话") |
||||
|
private String phone; |
||||
|
|
||||
|
@Schema(description = "电子邮箱") |
||||
|
private String email; |
||||
|
|
||||
|
@Schema(description = "状态 (1-在职, 0-离职)", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") |
||||
|
@NotNull(message = "状态 (1-在职, 0-离职)不能为空") |
||||
|
private Integer status; |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,12 @@ |
|||||
|
<?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="cn.iocoder.yudao.module.hand.mapper.PersonnelMapper"> |
||||
|
|
||||
|
<!-- |
||||
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。 |
||||
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。 |
||||
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。 |
||||
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/ |
||||
|
--> |
||||
|
|
||||
|
</mapper> |
||||
Loading…
Reference in new issue