소스 검색

人员管理增删改查功能完成

fanghuisheng 1 주 전
부모
커밋
b67990b2fd

+ 25 - 0
base-modules/service-system/service-system-api/src/main/java/com/usky/system/domain/SysPerson.java

@@ -106,6 +106,31 @@ public class SysPerson implements Serializable {
      */
     private Date updateTime;
 
+    /**
+     * 图片数据(base64编码)
+     */
+    private String faceBase;
+
+    /**
+     * 验证次数(默认0)
+     */
+    private Integer vefNum;
+
+    /**
+     * 人脸备注
+     */
+    private String remark;
+
+    /**
+     * 人脸状态(0=可用,1=不可用)
+     */
+    private Integer faceStatus;
+
+    /**
+     * 卡号
+     */
+    private String cardNum;
+
     public static long getSerialVersionUID() {
         return serialVersionUID;
     }

+ 24 - 0
base-modules/service-system/service-system-api/src/main/java/com/usky/system/domain/SysPersonVo.java

@@ -105,5 +105,29 @@ public class SysPersonVo implements Serializable {
      */
     private LocalDateTime updateTime;
 
+    /**
+     * 图片数据(base64编码)
+     */
+    private String faceBase;
+
+    /**
+     * 验证次数(默认0)
+     */
+    private Integer vefNum;
+
+    /**
+     * 人脸备注
+     */
+    private String remark;
+
+    /**
+     * 人脸状态(0=可用,1=不可用)
+     */
+    private Integer faceStatus;
+
+    /**
+     * 卡号
+     */
+    private String cardNum;
 
 }

+ 170 - 4
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/controller/web/SysPersonController.java

@@ -1,9 +1,26 @@
 package com.usky.system.controller.web;
 
 
-import org.springframework.web.bind.annotation.RequestMapping;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.usky.common.core.exception.BusinessException;
+import com.usky.common.core.bean.ApiResult;
+import com.usky.system.controller.web.page.TableDataInfo;
+import com.usky.system.domain.SysPerson;
+import com.usky.system.domain.SysUserPerson;
+import com.usky.system.service.SysPersonService;
+import com.usky.system.service.SysUserPersonService;
+import com.usky.common.core.util.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.BeanUtils;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.*;
 
-import org.springframework.stereotype.Controller;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -13,9 +30,158 @@ import org.springframework.stereotype.Controller;
  * @author JCB
  * @since 2022-08-22
  */
-@Controller
+@RestController
 @RequestMapping("/sysPerson")
-public class SysPersonController {
+public class SysPersonController extends BaseController {
 
+    @Autowired
+    private SysPersonService sysPersonService;
+    @Autowired
+    private SysUserPersonService sysUserPersonService;
+
+    /**
+     * 人员列表(分页)
+     */
+    @GetMapping("/list")
+    public ApiResult<TableDataInfo> list(SysPerson person) {
+        startPage();
+        // 支持 fullName 模糊查询;其他字段保持按传入条件精确匹配
+        SysPerson queryEntity = new SysPerson();
+        if (person != null) {
+            BeanUtils.copyProperties(person, queryEntity);
+            // fullName 用 like 查询,避免 Wrappers.query(entity) 产生 fullName=xxx 的精确条件
+            queryEntity.setFullName(null);
+        }
+        QueryWrapper<SysPerson> queryWrapper = Wrappers.query(queryEntity);
+        queryWrapper.lambda()
+                .like(person != null && StringUtils.isNotBlank(person.getFullName()),
+                        SysPerson::getFullName, person.getFullName());
+        List<SysPerson> list = sysPersonService.list(queryWrapper);
+        // 回显每个人员对应的 userId
+        if (list != null && !list.isEmpty()) {
+            List<Integer> personIds = list.stream()
+                    .map(SysPerson::getId)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toList());
+            if (!personIds.isEmpty()) {
+                List<SysUserPerson> relations = sysUserPersonService.list(
+                        Wrappers.<SysUserPerson>lambdaQuery()
+                                .in(SysUserPerson::getPersonId, personIds)
+                );
+                if (relations != null && !relations.isEmpty()) {
+                    Map<Integer, Long> personUserMap = relations.stream()
+                            .collect(Collectors.toMap(
+                                    SysUserPerson::getPersonId,
+                                    SysUserPerson::getUserId,
+                                    (u1, u2) -> u1
+                            ));
+                    list.forEach(p -> {
+                        Long userId = personUserMap.get(p.getId());
+                        if (userId != null) {
+                            p.setUserId(userId);
+                        }
+                    });
+                }
+            }
+        }
+        return ApiResult.success(getDataTable(list));
+    }
+
+    /**
+     * 根据主键获取人员详情
+     */
+    @GetMapping("/{id}")
+    public ApiResult<SysPerson> getInfo(@PathVariable("id") Integer id) {
+        SysPerson person = sysPersonService.getById(id);
+        if (person != null) {
+            SysUserPerson userPerson = sysUserPersonService.getOne(
+                    Wrappers.<SysUserPerson>lambdaQuery()
+                            .eq(SysUserPerson::getPersonId, id)
+                            .last("limit 1")
+            );
+            if (userPerson != null) {
+                person.setUserId(userPerson.getUserId());
+            }
+        }
+        return ApiResult.success(person);
+    }
+
+    /**
+     * 新增人员并绑定用户
+     */
+    @PostMapping
+    @Transactional
+    public ApiResult<Void> add(@RequestBody SysPerson person) {
+        Long userId = person.getUserId();
+        if (Objects.isNull(userId)) {
+            throw new BusinessException("lack necessary param:userId is required!");
+        }
+        // 校验账户是否已被其他人员绑定
+        SysUserPerson existBind = sysUserPersonService.getOne(
+                Wrappers.<SysUserPerson>lambdaQuery()
+                        .eq(SysUserPerson::getUserId, userId)
+                        .last("limit 1")
+        );
+        if (existBind != null) {
+            throw new BusinessException("此账户已被其它人员绑定,请解绑后重试!");
+        }
+        // 先保存人员信息
+        sysPersonService.save(person);
+        // 新增用户-人员关联
+        SysUserPerson userPerson = new SysUserPerson();
+        userPerson.setUserId(userId);
+        userPerson.setPersonId(person.getId());
+        userPerson.setIsLoginNotify(0);
+        sysUserPersonService.save(userPerson);
+        return ApiResult.success();
+    }
+
+    /**
+     * 修改人员并更新绑定用户
+     */
+    @PutMapping
+    @Transactional
+    public ApiResult<Void> edit(@RequestBody SysPerson person) {
+        Long userId = person.getUserId();
+        if (Objects.isNull(userId)) {
+            throw new BusinessException("lack necessary param:userId is required!");
+        }
+        // 校验账户是否已被其他人员绑定(排除当前人员本身)
+        SysUserPerson existBind = sysUserPersonService.getOne(
+                Wrappers.<SysUserPerson>lambdaQuery()
+                        .eq(SysUserPerson::getUserId, userId)
+                        .last("limit 1")
+        );
+        if (existBind != null && !Objects.equals(existBind.getPersonId(), person.getId())) {
+            throw new BusinessException("此账户已被其它人员绑定,请解绑后重试!");
+        }
+        // 更新人员信息
+        sysPersonService.updateById(person);
+        // 先删除原有关联,再按当前传入的 userId 重新绑定
+        QueryWrapper<SysUserPerson> wrapper = Wrappers.query();
+        wrapper.eq("person_id", person.getId());
+        sysUserPersonService.remove(wrapper);
+
+        SysUserPerson userPerson = new SysUserPerson();
+        userPerson.setUserId(userId);
+        userPerson.setPersonId(person.getId());
+        userPerson.setIsLoginNotify(0);
+        sysUserPersonService.save(userPerson);
+        return ApiResult.success();
+    }
+
+    /**
+     * 删除人员(支持批量,逗号分隔),并解绑与用户的关联
+     */
+    @DeleteMapping("/{ids}")
+    public ApiResult<Void> remove(@PathVariable("ids") Integer[] ids) {
+        // 先删除关联关系
+        QueryWrapper<SysUserPerson> wrapper = Wrappers.query();
+        wrapper.in("person_id", Arrays.asList(ids));
+        sysUserPersonService.remove(wrapper);
+        // 再删除人员
+        sysPersonService.removeByIds(Arrays.asList(ids));
+        return ApiResult.success();
+    }
 }
 

+ 32 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/domain/SysPerson.java

@@ -1,6 +1,7 @@
 package com.usky.system.domain;
 
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -113,5 +114,36 @@ public class SysPerson implements Serializable {
      */
     private Date updateTime;
 
+    /**
+     * 图片数据(base64编码)
+     */
+    private String faceBase;
+
+    /**
+     * 验证次数(默认0)
+     */
+    private Integer vefNum;
+
+    /**
+     * 人脸备注
+     */
+    private String remark;
+
+    /**
+     * 人脸状态(0=可用,1=不可用)
+     */
+    private Integer faceStatus;
+
+    /**
+     * 卡号
+     */
+    private String cardNum;
+
+    /**
+     * 关联的用户ID(非持久化字段,仅用于回显)
+     */
+    @TableField(exist = false)
+    private Long userId;
+
 
 }

+ 25 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/vo/SysPersonVo.java

@@ -105,6 +105,31 @@ public class SysPersonVo{
      */
     private LocalDateTime updateTime;
 
+    /**
+     * 图片数据(base64编码)
+     */
+    private String faceBase;
+
+    /**
+     * 验证次数(默认0)
+     */
+    private Integer vefNum;
+
+    /**
+     * 人脸备注
+     */
+    private String remark;
+
+    /**
+     * 人脸状态(0=可用,1=不可用)
+     */
+    private Integer faceStatus;
+
+    /**
+     * 卡号
+     */
+    private String cardNum;
+
     public static long getSerialVersionUID() {
         return serialVersionUID;
     }

+ 5 - 0
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysPersonMapper.xml

@@ -22,6 +22,11 @@
         <result column="create_time" property="createTime" />
         <result column="update_person" property="updatePerson" />
         <result column="update_time" property="updateTime" />
+        <result column="face_base" property="faceBase" />
+        <result column="vef_num" property="vefNum" />
+        <result column="remark" property="remark" />
+        <result column="face_status" property="faceStatus" />
+        <result column="card_num" property="cardNum" />
     </resultMap>
 
 </mapper>