Browse Source

添加用户人脸图像

zyl 2 months ago
parent
commit
e5a8e13226

+ 26 - 0
liutongyi-admin/src/main/java/com/citygis/web/controller/TabFileInfoController.java

@@ -123,5 +123,31 @@ public class TabFileInfoController extends BaseController {
                 .body(new InputStreamResource(file.getInputStream()));
     }
 
+    @Log(title = "接入标准管理", businessType = BusinessType.EXPORT)
+    @ApiOperation("下载接入标准")
+    @PostMapping("/downloadFile")
+    @ResponseBody
+    public void downloadFile(@RequestParam("fileId") Long fileId, HttpServletResponse response) throws Exception {
+        OutputStream os;//新建一个输出流对象
+        String uploadPath = CitygisConfig.getUploadPath();
+        String filePath = iTabFileInfoService.getFilePathByUserId(fileId);
+        if (StrUtil.isEmpty(filePath)) {
+            System.out.println("文件不存在");
+        }
+        try {
+            if (StrUtil.isNotEmpty(filePath)) {
+                response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filePath, "UTF-8"));
+                response.setContentType("application/octet-stream");
+                byte[] bytes = FileUtil.readBytes(filePath);//通过文件的路径读取文件字节流
+                os = response.getOutputStream();//通过response的输出流返回文件
+                os.write(bytes);
+                os.flush();
+                os.close();
+            }
+        } catch (Exception e) {
+            System.out.println("文件下载失败");
+        }
+    }
+
 }
 

+ 42 - 66
liutongyi-admin/src/main/java/com/citygis/web/controller/system/SysUserController.java

@@ -1,21 +1,5 @@
 package com.citygis.web.controller.system;
 
-import java.util.List;
-import java.util.stream.Collectors;
-import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.lang3.ArrayUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.multipart.MultipartFile;
 import com.citygis.common.annotation.Log;
 import com.citygis.common.core.controller.BaseController;
 import com.citygis.common.core.domain.AjaxResult;
@@ -31,16 +15,26 @@ import com.citygis.system.service.ISysDeptService;
 import com.citygis.system.service.ISysPostService;
 import com.citygis.system.service.ISysRoleService;
 import com.citygis.system.service.ISysUserService;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.ArrayUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 用户信息
- * 
+ *
  * @author citygis
  */
 @RestController
 @RequestMapping("/system/user")
-public class SysUserController extends BaseController
-{
+public class SysUserController extends BaseController {
     @Autowired
     private ISysUserService userService;
 
@@ -58,8 +52,7 @@ public class SysUserController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:user:list')")
     @GetMapping("/list")
-    public TableDataInfo list(SysUser user)
-    {
+    public TableDataInfo list(SysUser user) {
         startPage();
         List<SysUser> list = userService.selectUserList(user);
         return getDataTable(list);
@@ -68,8 +61,7 @@ public class SysUserController extends BaseController
     @Log(title = "用户管理", businessType = BusinessType.EXPORT)
     @PreAuthorize("@ss.hasPermi('system:user:export')")
     @PostMapping("/export")
-    public void export(HttpServletResponse response, SysUser user)
-    {
+    public void export(HttpServletResponse response, SysUser user) {
         List<SysUser> list = userService.selectUserList(user);
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
         util.exportExcel(response, list, "用户数据");
@@ -78,8 +70,7 @@ public class SysUserController extends BaseController
     @Log(title = "用户管理", businessType = BusinessType.IMPORT)
     @PreAuthorize("@ss.hasPermi('system:user:import')")
     @PostMapping("/importData")
-    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
-    {
+    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
         List<SysUser> userList = util.importExcel(file.getInputStream());
         String operName = getUsername();
@@ -88,8 +79,7 @@ public class SysUserController extends BaseController
     }
 
     @PostMapping("/importTemplate")
-    public void importTemplate(HttpServletResponse response)
-    {
+    public void importTemplate(HttpServletResponse response) {
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
         util.importTemplateExcel(response, "用户数据");
     }
@@ -98,16 +88,14 @@ public class SysUserController extends BaseController
      * 根据用户编号获取详细信息
      */
     @PreAuthorize("@ss.hasPermi('system:user:query')")
-    @GetMapping(value = { "/", "/{userId}" })
-    public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
-    {
+    @GetMapping(value = {"/", "/{userId}"})
+    public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {
         userService.checkUserDataScope(userId);
         AjaxResult ajax = AjaxResult.success();
         List<SysRole> roles = roleService.selectRoleAll();
         ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
         ajax.put("posts", postService.selectPostAll());
-        if (StringUtils.isNotNull(userId))
-        {
+        if (StringUtils.isNotNull(userId)) {
             SysUser sysUser = userService.selectUserById(userId);
             ajax.put(AjaxResult.DATA_TAG, sysUser);
             ajax.put("postIds", postService.selectPostListByUserId(userId));
@@ -122,20 +110,14 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:add')")
     @Log(title = "用户管理", businessType = BusinessType.INSERT)
     @PostMapping
-    public AjaxResult add(@Validated @RequestBody SysUser user)
-    {
+    public AjaxResult add(@Validated @RequestBody SysUser user) {
         deptService.checkDeptDataScope(user.getDeptId());
         roleService.checkRoleDataScope(user.getRoleIds());
-        if (!userService.checkUserNameUnique(user))
-        {
+        if (!userService.checkUserNameUnique(user)) {
             return error("新增用户'" + user.getUserName() + "'失败,登录账号已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
             return error("新增用户'" + user.getUserName() + "'失败,手机号码已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
             return error("新增用户'" + user.getUserName() + "'失败,邮箱账号已存在");
         }
         user.setCreateBy(getUsername());
@@ -149,22 +131,16 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:edit')")
     @Log(title = "用户管理", businessType = BusinessType.UPDATE)
     @PutMapping
-    public AjaxResult edit(@Validated @RequestBody SysUser user)
-    {
+    public AjaxResult edit(@Validated @RequestBody SysUser user) {
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getUserId());
         deptService.checkDeptDataScope(user.getDeptId());
         roleService.checkRoleDataScope(user.getRoleIds());
-        if (!userService.checkUserNameUnique(user))
-        {
+        if (!userService.checkUserNameUnique(user)) {
             return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getPhonenumber()) && !userService.checkPhoneUnique(user)) {
             return error("修改用户'" + user.getUserName() + "'失败,手机号码已存在");
-        }
-        else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user))
-        {
+        } else if (StringUtils.isNotEmpty(user.getEmail()) && !userService.checkEmailUnique(user)) {
             return error("修改用户'" + user.getUserName() + "'失败,邮箱账号已存在");
         }
         user.setUpdateBy(getUsername());
@@ -177,10 +153,8 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:remove')")
     @Log(title = "用户管理", businessType = BusinessType.DELETE)
     @DeleteMapping("/{userIds}")
-    public AjaxResult remove(@PathVariable Long[] userIds)
-    {
-        if (ArrayUtils.contains(userIds, getUserId()))
-        {
+    public AjaxResult remove(@PathVariable Long[] userIds) {
+        if (ArrayUtils.contains(userIds, getUserId())) {
             return error("当前用户不能删除");
         }
         return toAjax(userService.deleteUserByIds(userIds));
@@ -192,8 +166,7 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:resetPwd')")
     @Log(title = "用户管理", businessType = BusinessType.UPDATE)
     @PutMapping("/resetPwd")
-    public AjaxResult resetPwd(@RequestBody SysUser user)
-    {
+    public AjaxResult resetPwd(@RequestBody SysUser user) {
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getUserId());
         user.setPassword(SecurityUtils.encryptPassword(user.getPassword()));
@@ -207,8 +180,7 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:edit')")
     @Log(title = "用户管理", businessType = BusinessType.UPDATE)
     @PutMapping("/changeStatus")
-    public AjaxResult changeStatus(@RequestBody SysUser user)
-    {
+    public AjaxResult changeStatus(@RequestBody SysUser user) {
         userService.checkUserAllowed(user);
         userService.checkUserDataScope(user.getUserId());
         user.setUpdateBy(getUsername());
@@ -220,8 +192,7 @@ public class SysUserController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:user:query')")
     @GetMapping("/authRole/{userId}")
-    public AjaxResult authRole(@PathVariable("userId") Long userId)
-    {
+    public AjaxResult authRole(@PathVariable("userId") Long userId) {
         AjaxResult ajax = AjaxResult.success();
         SysUser user = userService.selectUserById(userId);
         List<SysRole> roles = roleService.selectRolesByUserId(userId);
@@ -236,8 +207,7 @@ public class SysUserController extends BaseController
     @PreAuthorize("@ss.hasPermi('system:user:edit')")
     @Log(title = "用户管理", businessType = BusinessType.GRANT)
     @PutMapping("/authRole")
-    public AjaxResult insertAuthRole(Long userId, Long[] roleIds)
-    {
+    public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
         userService.checkUserDataScope(userId);
         roleService.checkRoleDataScope(roleIds);
         userService.insertUserAuth(userId, roleIds);
@@ -249,8 +219,14 @@ public class SysUserController extends BaseController
      */
     @PreAuthorize("@ss.hasPermi('system:user:list')")
     @GetMapping("/deptTree")
-    public AjaxResult deptTree(SysDept dept)
-    {
+    public AjaxResult deptTree(SysDept dept) {
         return success(deptService.selectDeptTreeList(dept));
     }
+
+    @Log(title = "用户人脸图像", businessType = BusinessType.IMPORT)
+    @ApiOperation("用户人脸图像")
+    @PostMapping("/upload")
+    public AjaxResult uploadUserFace(@RequestParam("file") MultipartFile file) throws Exception {
+        return userService.uploadUserFace(file);
+    }
 }

+ 2 - 0
liutongyi-admin/src/main/java/com/citygis/web/service/ITabFileInfoService.java

@@ -28,4 +28,6 @@ public interface ITabFileInfoService extends IService<TabFileInfo> {
 
     AjaxResult falseDeleteTabFileInfoById(Integer fileId);
 
+    String getFilePathByUserId(Long userId);
+
 }

+ 14 - 0
liutongyi-admin/src/main/java/com/citygis/web/service/impl/TabFileInfoServiceImpl.java

@@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.citygis.common.annotation.DataScope;
 import com.citygis.common.config.CitygisConfig;
 import com.citygis.common.core.domain.AjaxResult;
+import com.citygis.common.core.domain.entity.SysUser;
 import com.citygis.common.utils.file.FileUploadUtils;
+import com.citygis.system.service.ISysUserService;
 import com.citygis.web.domain.TabFileInfo;
 import com.citygis.web.mapper.TabFileInfoMapper;
 import com.citygis.web.service.ITabFileInfoService;
@@ -32,6 +34,9 @@ public class TabFileInfoServiceImpl extends ServiceImpl<TabFileInfoMapper, TabFi
     @Resource
     TabFileInfoMapper tabFileInfoMapper;
 
+    @Resource
+    ISysUserService sysUserService;
+
     @Override
     @DataScope(deptAlias = "tfi", userAlias = "tfi")
     public List<TabFileInfo> getTabFileInfoList(TabFileInfo tabFileInfo) {
@@ -93,4 +98,13 @@ public class TabFileInfoServiceImpl extends ServiceImpl<TabFileInfoMapper, TabFi
             return AjaxResult.success("删除失败");
         }
     }
+
+    @Override
+    public String getFilePathByUserId(Long userId) {
+        SysUser sysUser = sysUserService.selectUserById(userId);
+        if (sysUser == null) {
+            return null;
+        }
+        return sysUser.getPhoto();
+    }
 }

+ 26 - 0
liutongyi-common/src/main/java/com/citygis/common/core/domain/entity/SysUser.java

@@ -138,6 +138,32 @@ public class SysUser extends BaseEntity {
      */
     private Long roleId;
 
+    /**
+     * 用户人脸图像下载地址
+     */
+    private String photoUrl;
+
+    /**
+     * 用户人脸图像存储地址
+     */
+    private String photo;
+
+    public String getPhoto() {
+        return photo;
+    }
+
+    public void setPhoto(String photo) {
+        this.photo = photo;
+    }
+
+    public String getPhotoUrl() {
+        return photoUrl;
+    }
+
+    public void setPhotoUrl(String photoUrl) {
+        this.photoUrl = photoUrl;
+    }
+
     public SysUser() {
 
     }

+ 2 - 0
liutongyi-common/src/main/java/com/citygis/common/core/domain/entity/SysUserSync.java

@@ -36,4 +36,6 @@ public class SysUserSync {
     // 逻辑删除标记(0-正常 1-删除)
     private Integer isDel;
 
+    private String photoUrl;
+
 }

+ 2 - 0
liutongyi-system/src/main/java/com/citygis/system/mapper/SysUserMapper.java

@@ -77,6 +77,8 @@ public interface SysUserMapper {
      */
     public int updateUserAvatar(@Param("userName") String userName, @Param("avatar") String avatar);
 
+    int updateUserPhotoUrl(@Param("userId") Long userId, @Param("photoUrl") String photoUrl,@Param("photo") String photo);
+
     /**
      * 重置用户密码
      *

+ 6 - 0
liutongyi-system/src/main/java/com/citygis/system/service/ISysUserService.java

@@ -1,7 +1,9 @@
 package com.citygis.system.service;
 
+import com.citygis.common.core.domain.AjaxResult;
 import com.citygis.common.core.domain.entity.SysUser;
 import com.citygis.common.core.domain.entity.SysUserSync;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -162,6 +164,8 @@ public interface ISysUserService {
      */
     public boolean updateUserAvatar(String userName, String avatar);
 
+    boolean updateUserPhotoUrl(Long userId, String photoUrl);
+
     /**
      * 重置用户密码
      *
@@ -208,4 +212,6 @@ public interface ISysUserService {
     SysUser getUserByMail(String mail);
 
     List<SysUserSync> getAllUserSync(String startTime, String accountNo, String identityType);
+
+    AjaxResult uploadUserFace(MultipartFile file) throws Exception;
 }

+ 49 - 0
liutongyi-system/src/main/java/com/citygis/system/service/impl/SysUserServiceImpl.java

@@ -1,12 +1,15 @@
 package com.citygis.system.service.impl;
 
 import com.citygis.common.annotation.DataScope;
+import com.citygis.common.config.CitygisConfig;
 import com.citygis.common.constant.UserConstants;
+import com.citygis.common.core.domain.AjaxResult;
 import com.citygis.common.core.domain.entity.*;
 import com.citygis.common.exception.ServiceException;
 import com.citygis.common.utils.SecurityUtils;
 import com.citygis.common.utils.StringUtils;
 import com.citygis.common.utils.bean.BeanValidators;
+import com.citygis.common.utils.file.FileUploadUtils;
 import com.citygis.common.utils.spring.SpringUtils;
 import com.citygis.system.domain.SysPost;
 import com.citygis.system.domain.SysUserPost;
@@ -18,15 +21,21 @@ import com.citygis.system.service.ISysUserService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.validation.Validator;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 import java.util.*;
 import java.util.function.Function;
 import java.util.stream.Collectors;
 
+import static com.citygis.common.utils.SecurityUtils.*;
+
 /**
  * 用户 业务层处理
  *
@@ -60,6 +69,9 @@ public class SysUserServiceImpl implements ISysUserService {
     @Autowired
     protected Validator validator;
 
+    @Value("${server.port}")
+    private String port;
+
     /**
      * 根据条件分页查询用户列表
      *
@@ -322,6 +334,11 @@ public class SysUserServiceImpl implements ISysUserService {
         return userMapper.updateUserAvatar(userName, avatar) > 0;
     }
 
+    @Override
+    public boolean updateUserPhotoUrl(Long userId, String photoUrl) {
+        return false;
+    }
+
     /**
      * 重置用户密码
      *
@@ -577,4 +594,36 @@ public class SysUserServiceImpl implements ISysUserService {
                     .ifPresent(user::setOrgs);
         });
     }
+
+    @Override
+    @Transactional
+    public AjaxResult uploadUserFace(MultipartFile file) throws Exception {
+        String filePath = CitygisConfig.getUploadPath();
+        // 上传并返回新文件名称
+        String fileName = FileUploadUtils.upload(filePath, file);
+
+        String s = filePath + fileName.replace("/upload", "");
+
+        String s1 = "http://" + getIp() + ":" + port + "/web/tab-file-info/downloadFile?fileId=" + getUserId();
+
+        boolean b1 = userMapper.updateUserPhotoUrl(getUserId(), s1, s) > 0;
+
+        if (b1) {
+            return AjaxResult.success("上传成功");
+        } else {
+            return AjaxResult.success("上传失败");
+        }
+    }
+
+    private String getIp() {
+        try {
+            // 获取本地主机的InetAddress对象
+            InetAddress localHost = InetAddress.getLocalHost();
+
+            return localHost.getHostAddress();
+        } catch (UnknownHostException e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
 }

+ 8 - 2
liutongyi-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -23,6 +23,7 @@
         <result property="updateBy" column="update_by"/>
         <result property="updateTime" column="update_time"/>
         <result property="remark" column="remark"/>
+        <result property="photo" column="PHOTO"/>
         <association property="dept" javaType="SysDept" resultMap="deptResult"/>
         <collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
     </resultMap>
@@ -50,7 +51,7 @@
         select u.user_id, u.dept_id, u.user_name, u.nick_name, u.email, u.avatar, u.phonenumber, u.password, u.sex,
         u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark,
         d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.status as dept_status,
-        r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status
+        r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.status as role_status,u.PHOTO as photo
         from "LIU_TONG_YI"."sys_user" u
         left join "LIU_TONG_YI"."sys_dept" d on u.dept_id = d.dept_id
         left join "LIU_TONG_YI"."sys_user_role" ur on u.user_id = ur.user_id
@@ -243,7 +244,8 @@
         "DEL_FLAG" isDel,
         "CREATE_TIME" createTime,
         "UPDATE_TIME" updateTime,
-        "REMARK" remark
+        "REMARK" remark,
+        su.PHOTO_URL
         from "LIU_TONG_YI"."sys_user" su
         LEFT JOIN "LIU_TONG_YI"."sys_user_role" sur
         ON su.USER_ID = SUR.USER_ID
@@ -263,4 +265,8 @@
         </if>
     </select>
 
+    <update id="updateUserPhotoUrl">
+            update "LIU_TONG_YI"."sys_user" set PHOTO_URL = #{photoUrl},PHOTO = #{photo} where USER_ID = #{userId}
+    </update>
+
 </mapper>