Просмотр исходного кода

Merge branch 'fhs' of uskycloud/usky-cloud into master

FIY
gez 1 день назад
Родитель
Сommit
72fe261703

+ 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;
 
 }

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

@@ -1,9 +1,28 @@
 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.domain.SysDept;
+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.ISysDeptService;
+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 +32,194 @@ 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;
+    @Autowired
+    private ISysDeptService sysDeptService;
+
+    /**
+     * 人员列表(分页)
+     */
+    @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);
+
+        // 回显部门名称
+        if (list != null && !list.isEmpty()) {
+            List<Long> deptIds = list.stream()
+                    .map(SysPerson::getDeptId)
+                    .filter(Objects::nonNull)
+                    .distinct()
+                    .collect(Collectors.toList());
+            if (!deptIds.isEmpty()) {
+                List<SysDept> depts = sysDeptService.selectDeptByIds(deptIds);
+                if (depts != null && !depts.isEmpty()) {
+                    Map<Long, String> deptNameMap = depts.stream()
+                            .collect(Collectors.toMap(
+                                    SysDept::getDeptId,
+                                    SysDept::getDeptName,
+                                    (n1, n2) -> n1
+                            ));
+                    list.forEach(p -> {
+                        String deptName = deptNameMap.get(p.getDeptId());
+                        if (deptName != null) {
+                            p.setDeptName(deptName);
+                        }
+                    });
+                }
+            }
+        }
+
+        // 回显每个人员对应的 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());
+            }
+
+            if (person.getDeptId() != null) {
+                SysDept dept = sysDeptService.selectDeptById(person.getDeptId());
+                if (dept != null) {
+                    person.setDeptName(dept.getDeptName());
+                }
+            }
+        }
+        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();
+    }
 }
 

+ 37 - 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,41 @@ 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;
+
+    /**
+     * 部门名称(非持久化字段,仅用于回显)
+     */
+    @TableField(exist = false)
+    private String deptName;
 
 }

+ 8 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/mapper/SysDeptMapper.java

@@ -46,6 +46,14 @@ public interface SysDeptMapper extends BaseMapper<SysDept>
      */
     public SysDept selectDeptById(@Param("deptId") Long deptId);
 
+    /**
+     * 根据部门ID列表批量查询部门信息
+     *
+     * @param deptIds 部门ID列表
+     * @return 部门信息列表
+     */
+    public List<SysDept> selectDeptByIds(@Param("deptIds") List<Long> deptIds);
+
     /**
      * 根据ID查询所有子部门
      * 

+ 8 - 0
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/ISysDeptService.java

@@ -70,6 +70,14 @@ public interface ISysDeptService extends IService<SysDept>
      */
     public SysDept selectDeptById(Long deptId);
 
+    /**
+     * 根据部门ID列表批量查询部门信息
+     *
+     * @param deptIds 部门ID列表
+     * @return 部门信息列表
+     */
+    public List<SysDept> selectDeptByIds(List<Long> deptIds);
+
     /**
      * 根据ID查询所有子部门(正常状态)
      * 

+ 8 - 4
base-modules/service-system/service-system-biz/src/main/java/com/usky/system/service/impl/SysDeptServiceImpl.java

@@ -18,8 +18,6 @@ import com.usky.system.service.ISysDeptService;
 import com.usky.system.service.vo.TreeNode;
 import com.usky.system.service.vo.TreeSelect;
 import com.usky.system.service.vo.UserPostVo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -35,8 +33,6 @@ import java.util.stream.Collectors;
 @Service
 public class SysDeptServiceImpl extends AbstractCrudService<SysDeptMapper, SysDept> implements ISysDeptService {
 
-    private static final Logger log = LoggerFactory.getLogger(SysDeptServiceImpl.class);//还原代码
-
     @Autowired
     private SysDeptMapper deptMapper;
 
@@ -212,6 +208,14 @@ public class SysDeptServiceImpl extends AbstractCrudService<SysDeptMapper, SysDe
         return deptMapper.selectDeptById(deptId);
     }
 
+    @Override
+    public List<SysDept> selectDeptByIds(List<Long> deptIds) {
+        if (deptIds == null || deptIds.isEmpty()) {
+            return Collections.emptyList();
+        }
+        return deptMapper.selectDeptByIds(deptIds);
+    }
+
     /**
      * 根据ID查询所有子部门(正常状态)
      *

+ 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;
     }

+ 9 - 0
base-modules/service-system/service-system-biz/src/main/resources/mapper/system/SysDeptMapper.xml

@@ -83,6 +83,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 		<include refid="selectDeptVo"/>
 		where dept_id = #{deptId}
 	</select>
+
+	<select id="selectDeptByIds" resultMap="SysDeptResult">
+		<include refid="selectDeptVo"/>
+		where d.del_flag = '0'
+		and d.dept_id in
+		<foreach collection="deptIds" item="deptId" open="(" separator="," close=")">
+			#{deptId}
+		</foreach>
+	</select>
     
     <select id="checkDeptExistUser" parameterType="Long" resultType="int">
 		select count(1) from sys_user where dept_id = #{deptId} and del_flag = '0'

+ 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>