|
|
@@ -1,36 +1,103 @@
|
|
|
package com.sckw.access.controller;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.sckw.access.domain.para.TVisitorQuery;
|
|
|
+import com.sckw.access.domain.para.TVisitorSave;
|
|
|
+import com.sckw.access.domain.para.VisitorApproveSave;
|
|
|
+import com.sckw.access.domain.vo.VisitorVo;
|
|
|
import com.sckw.access.entity.TVisitor;
|
|
|
+import com.sckw.access.exception.BusinessException;
|
|
|
import com.sckw.access.service.TVisitorService;
|
|
|
+import com.sckw.access.util.R;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import jakarta.annotation.Resource;
|
|
|
+import org.springdoc.core.annotations.ParameterObject;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 访客管理表
|
|
|
- *
|
|
|
- * @author xxxxx
|
|
|
*/
|
|
|
@RestController
|
|
|
@RequestMapping("/visitor")
|
|
|
@Tag(name = "访客管理")
|
|
|
public class TVisitorController {
|
|
|
- /**
|
|
|
- * 服务对象
|
|
|
- */
|
|
|
@Resource
|
|
|
private TVisitorService tVisitorService;
|
|
|
|
|
|
/**
|
|
|
- * 通过主键查询单条数据
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param visitorQuery 查询参数
|
|
|
+ * @return 分页数据
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ @Operation(summary = "分页查询")
|
|
|
+ public R<Object> page(@ParameterObject TVisitorQuery visitorQuery) {
|
|
|
+ Page<TVisitor> page = tVisitorService.page(new Page<>(visitorQuery.getPageNo(), visitorQuery.getPageSize()), new LambdaQueryWrapper<TVisitor>().like(StrUtil.isNotBlank(visitorQuery.getName()), TVisitor::getName, visitorQuery.getName()).like(StrUtil.isNotBlank(visitorQuery.getLicensePlate()), TVisitor::getLicensePlate, visitorQuery.getLicensePlate()).eq(Objects.nonNull(visitorQuery.getVehicleType()), TVisitor::getVehicleType, visitorQuery.getVehicleType()).like(StrUtil.isNotBlank(visitorQuery.getApproverName()), TVisitor::getApproverName, visitorQuery.getApproverName()).like(StrUtil.isNotBlank(visitorQuery.getApproverMobile()), TVisitor::getApproverMobile, visitorQuery.getApproverMobile()).eq(Objects.nonNull(visitorQuery.getApprovalStatus()), TVisitor::getApprovalStatus, visitorQuery.getApprovalStatus()));
|
|
|
+ List<VisitorVo> list = page.getRecords().stream().map(d -> {
|
|
|
+ VisitorVo bean = BeanUtil.toBean(d, VisitorVo.class);
|
|
|
+ if (StrUtil.isNotBlank(d.getBarrierIds())) {
|
|
|
+ bean.setBarrierIds(JSONArray.parseArray(d.getBarrierIds(), String.class));
|
|
|
+ }
|
|
|
+ return bean;
|
|
|
+ }).toList();
|
|
|
+ Page<VisitorVo> visitorVoPage = new Page<>(page.getCurrent(), page.getSize(), page.getTotal());
|
|
|
+ visitorVoPage.setRecords(list);
|
|
|
+ return R.ok(visitorVoPage);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增访客记录
|
|
|
*
|
|
|
- * @param id 主键
|
|
|
- * @return 单条数据
|
|
|
+ * @param visitorSave
|
|
|
*/
|
|
|
- @GetMapping("selectOne")
|
|
|
- public TVisitor selectOne(Integer id) {
|
|
|
- return tVisitorService.getById(id);
|
|
|
+ @Operation(summary = "新增访客记录")
|
|
|
+ @PostMapping("/save")
|
|
|
+ public R<Boolean> save(@RequestBody @Validated TVisitorSave visitorSave) {
|
|
|
+ TVisitor save = BeanUtil.toBean(visitorSave, TVisitor.class);
|
|
|
+ save.setApplyTime(LocalDateTime.now());
|
|
|
+ save.setCreateTime(LocalDateTime.now());
|
|
|
+ save.setBarrierIds(JSONObject.toJSONString(visitorSave.getBarrierIds()));
|
|
|
+ return R.ok(tVisitorService.save(save));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 审批
|
|
|
+ *
|
|
|
+ * @param visitorApproveSave
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Operation(summary = "审批", description = "访客审批")
|
|
|
+ @PostMapping("/approve")
|
|
|
+ public R<Boolean> approve(@RequestBody @Validated VisitorApproveSave visitorApproveSave) {
|
|
|
+ TVisitor byId = tVisitorService.getById(visitorApproveSave.getId());
|
|
|
+ if (Objects.isNull(byId)) {
|
|
|
+ throw new BusinessException("访客记录不存在");
|
|
|
+ }
|
|
|
+ byId.setApprovalStatus(visitorApproveSave.getApprovalStatus());
|
|
|
+ byId.setApprovalReason(visitorApproveSave.getApprovalReason());
|
|
|
+ byId.setUpdateTime(LocalDateTime.now());
|
|
|
+ return R.ok(tVisitorService.updateById(byId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+ @Operation(summary = "删除")
|
|
|
+ @DeleteMapping("/delete")
|
|
|
+ public R<Boolean> delete(@RequestParam("id") Long id) {
|
|
|
+ return R.ok(tVisitorService.removeById(id));
|
|
|
+ }
|
|
|
}
|