| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysDept; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.system.domain.Employee; |
| | | import com.ruoyi.system.domain.SysVisitArea; |
| | | import com.ruoyi.system.domain.SysVisitorRecord; |
| | | import com.ruoyi.system.dto.SysVisitorIdCardOutRequest; |
| | | import com.ruoyi.system.dto.SysVisitorRecordAddRequest; |
| | | import com.ruoyi.system.mapper.EmployeeMapper; |
| | | import com.ruoyi.system.mapper.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.SysVisitAreaMapper; |
| | | import com.ruoyi.system.mapper.SysVisitorRecordMapper; |
| | | import com.ruoyi.system.service.ISysVisitAreaService; |
| | | import com.ruoyi.web.controller.service.SysVisitorRecordService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api/visitorRecord") |
| | | @Api(tags = "访客登记") |
| | | @Api(tags = "现场访客登记-签离") |
| | | public class SysApiVisitorRecordController extends BaseController { |
| | | |
| | | @Autowired |
| | | private SysVisitorRecordService sysVisitorRecordService; |
| | | @Autowired |
| | | private SysVisitorRecordMapper visitorRecordMapper; |
| | | @Autowired |
| | | private SysVisitAreaMapper sysVisitAreaMapper; |
| | | @Autowired |
| | | private EmployeeMapper employeeMapper; |
| | | @Autowired |
| | | private SysDeptMapper sysDeptMapper; |
| | | |
| | | @PostMapping("/add") |
| | | @ApiOperation(value = "访客登记", notes = "现场访客登记") |
| | |
| | | return AjaxResult.error("被访人不能为空"); |
| | | } |
| | | |
| | | // 签离的当天不能再次进入 签到 |
| | | LambdaQueryWrapper<SysVisitorRecord> yqwrapper = new LambdaQueryWrapper<>(); |
| | | Date todayStart = DateUtils.truncate(new Date(), Calendar.DAY_OF_MONTH); // 当天 00:00:00 |
| | | Date todayEnd = DateUtils.addMilliseconds(DateUtils.addDays(todayStart, 1), -1); // 当天 23:59:59 |
| | | yqwrapper.eq(SysVisitorRecord::getIdCard, request.getIdCard()) |
| | | .eq(SysVisitorRecord::getStatus, "VISITING") |
| | | .ge(SysVisitorRecord::getSignTime, todayStart) //签离时间 >= 00:00:00 |
| | | .le(SysVisitorRecord::getSignTime, todayEnd) //签离时间 <= 23:59:59 |
| | | .orderByDesc(SysVisitorRecord::getRegisterTime) |
| | | .last("limit 1"); |
| | | SysVisitorRecord sysVisitorRecordYQ = visitorRecordMapper.selectOne(yqwrapper); |
| | | if (sysVisitorRecordYQ != null) { |
| | | throw new ServiceException("权限已回收,当天不可再次访问"); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(request.getIdCard())) { |
| | | |
| | | LambdaQueryWrapper<SysVisitorRecord> wrapper = Wrappers.lambdaQuery(); |
| | | |
| | | wrapper.eq(SysVisitorRecord::getIdCard, request.getIdCard()) |
| | | .eq(SysVisitorRecord::getVisitorName, request.getVisitorName()) |
| | | .eq(SysVisitorRecord::getDelFlag, "0") |
| | | .in(SysVisitorRecord::getStatus, |
| | | "VISITING", |
| | |
| | | SysVisitorRecord record = new SysVisitorRecord(); |
| | | BeanUtils.copyProperties(request, record); |
| | | |
| | | record.setRegisterNo(generateRegisterNo()); |
| | | record.setRegisterType("ONSITE"); |
| | | //查询地区 |
| | | if (StringUtils.isNotEmpty(record.getVisitAreaIds())) { |
| | | String[] visitAreaIds = record.getVisitAreaIds().split(","); |
| | | String visitArea = Arrays.stream(visitAreaIds) |
| | | .map(id -> { |
| | | SysVisitArea area = sysVisitAreaMapper.selectById(Long.parseLong(id.trim())); |
| | | return area != null ? area.getAreaName() : null; |
| | | }) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.joining(",")); |
| | | |
| | | // 使用 visitArea |
| | | if (StringUtils.isNotEmpty(visitArea)) { |
| | | record.setVisitAreaNames(visitArea); |
| | | record.setRemark("来访中,允许访问区域:" + visitArea); |
| | | } |
| | | } |
| | | |
| | | //查询接待人的部门 |
| | | if (StringUtils.isNotEmpty(record.getIntervieweeName())) { |
| | | Employee employee = employeeMapper.selectEnabledByEmployeeName(record.getIntervieweeName()); |
| | | if (employee != null && employee.getDeptId() != null) { |
| | | SysDept sysDept = sysDeptMapper.selectDeptById(employee.getDeptId()); |
| | | if (sysDept != null) { |
| | | record.setIntervieweeDept(sysDept.getDeptName()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | record.setRegisterNo(generateRegisterNo());//登记编号 |
| | | record.setRegisterType("ONSITE");//现场登记 |
| | | record.setRegisterSource("访客机"); |
| | | record.setStatus("VISITING"); |
| | | record.setStatus("VISITING");//来访中 |
| | | record.setRegisterTime(new Date()); |
| | | record.setCreateTime(new Date()); |
| | | record.setDelFlag("0"); |
| | | |
| | | int rows = visitorRecordMapper.insert(record); |
| | | |
| | | sysVisitorRecordService.registerVisitor(record); |
| | | if (rows > 0) { |
| | | return AjaxResult.success(record.getRegisterNo()); |
| | | return AjaxResult.success(record); |
| | | } |
| | | |
| | | return AjaxResult.error("登记失败"); |
| | | } |
| | | |
| | | |
| | | @PostMapping("/add1") |
| | | @ApiOperation(value = "身份证签离", notes = "身份证签离") |
| | | public AjaxResult idCardOut( |
| | | @PostMapping("/idCardSingOut") |
| | | @ApiOperation(value = "访客身份证签离", notes = "访客身份证签离") |
| | | public AjaxResult idCardSingOut( |
| | | @RequestBody |
| | | @ApiParam(value = "", required = true) |
| | | SysVisitorRecordAddRequest request){ |
| | | @ApiParam(value = "访客身份证签离", required = true) |
| | | SysVisitorIdCardOutRequest request){ |
| | | |
| | | if (StringUtils.isEmpty(request.getIdCard())) { |
| | | throw new ServiceException("请刷身份证"); |
| | | } |
| | | |
| | | //todo 身份证号签离逻辑 |
| | | LambdaQueryWrapper<SysVisitorRecord> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(SysVisitorRecord::getIdCard, request.getIdCard()) |
| | | .eq(SysVisitorRecord::getStatus, "VISITING") // status = 'VISITING' |
| | | .orderByDesc(SysVisitorRecord::getRegisterTime) // register_time 倒序 |
| | | .last("limit 1"); // 只取第一条 |
| | | |
| | | SysVisitorRecord record = visitorRecordMapper.selectOne(wrapper); |
| | | |
| | | if (record == null) { |
| | | throw new ServiceException("请使用签到身份证"); |
| | | } |
| | | |
| | | // 2. 校验状态 - 只有来访中或逾期滞留才能签离 |
| | | String status = record.getStatus(); |
| | | if (!"VISITING".equals(status) && !"PENDING_CONFIRM".equals(status)) { |
| | | throw new ServiceException("当前状态不允许签离,状态为:" + status); |
| | | } |
| | | |
| | | // 3. 校验有效期(可选:检查是否在有效期内) |
| | | Date now = new Date(); |
| | | if (record.getValidEndTime() != null && now.after(record.getValidEndTime())) { |
| | | // 如果已过期,自动转为逾期签离状态 |
| | | record.setStatus("OVERDUE_AUTO_SIGNED_OUT"); |
| | | } else { |
| | | record.setStatus("SIGNED_OUT"); |
| | | } |
| | | record.setSignVerifyMethod("MANUAL"); |
| | | |
| | | SysVisitorRecord visitorRecord = new SysVisitorRecord(); |
| | | BeanUtils.copyBeanProp(visitorRecord, request); |
| | | visitorRecord.setSignVerifyMethod(record.getSignVerifyMethod()); |
| | | visitorRecord.setStatus(record.getStatus()); |
| | | visitorRecord.setRecordId(record.getRecordId()); |
| | | visitorRecord.setSignTime(new Date()); |
| | | visitorRecordMapper.updateById(visitorRecord); |
| | | |
| | | return success(); |
| | | } |
| | | |
| | |
| | | * VIS20260707123456 |
| | | */ |
| | | private String generateRegisterNo() { |
| | | |
| | | String date = |
| | | new java.text.SimpleDateFormat("yyyyMMddHHmmss") |
| | | .format(new Date()); |
| | | |
| | | String random = |
| | | String.valueOf((int)((Math.random() * 900000) + 100000)); |
| | | |
| | | String date = new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | String random = String.valueOf((int)((Math.random() * 900000) + 100000)); |
| | | return "VIS" + date + random; |
| | | } |
| | | } |