소스 검색

医生表与用户表的头像同步

zdm 6 년 전
부모
커밋
55af01c2f7

+ 23 - 3
src/main/java/com.yihu.ehr/basic/fileresource/controller/FileResourceEndPoint.java

@ -7,6 +7,7 @@ import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.util.id.BizObject;
import com.yihu.ehr.util.rest.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -105,11 +106,11 @@ public class FileResourceEndPoint extends EnvelopRestEndPoint {
            @ApiParam(name = "mime", value = "所有者", required = true)
            @RequestParam(value = "mime", required = false) String mime) throws Exception {
        List<FileResource> fileResources;
        if (StringUtils.isEmpty(mime))
        if (StringUtils.isEmpty(mime)) {
            fileResources = fileResourceManager.findByObjectId(objectId);
        else
        }else {
            fileResources = fileResourceManager.findByObjectIdAndMime(objectId, mime);
        }
        List<String> filesStrs = new ArrayList<>();
        for (FileResource fileResource : fileResources) {
            String storagePath = fileResource.getStoragePath();
@ -172,4 +173,23 @@ public class FileResourceEndPoint extends EnvelopRestEndPoint {
        return realPath;
    }
    @ApiOperation(value = "根据文件ID,获取文件")
    @RequestMapping(value = "/file/getFileStorage", method = RequestMethod.GET)
    public Envelop getFileStorage(
            @ApiParam(name = "fileId", value = "文件ID", required = true)
            @RequestParam(value = "fileId") String fileId) throws Exception {
        Envelop envelop =new Envelop();
        String s = java.net.URLDecoder.decode(fileId, "UTF-8");
        String path = fileResourceManager.getStoragePathById(s);
        if(StringUtils.isNotEmpty(path)){
            String groupName = path.split(":")[0];
            String remoteFileName = path.split(":")[1];
            byte[] bytes = fastDFSUtil.download(groupName, remoteFileName);
            String fileStream = new String(Base64.getEncoder().encode(bytes));
            envelop.setObj(fileStream);
        }
        envelop.setSuccessFlg(true);
        return envelop;
    }
}

+ 6 - 3
src/main/java/com.yihu.ehr/basic/fileresource/service/XFileResourceRepository.java

@ -1,6 +1,8 @@
package com.yihu.ehr.basic.fileresource.service;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import java.util.List;
@ -9,12 +11,13 @@ import java.util.List;
 * @created 2016.05.12 8:53
 */
public interface XFileResourceRepository extends PagingAndSortingRepository<FileResource, String> {
    List<FileResource> findByObjectId(String objectId);
    @Query("select fileResource from FileResource fileResource where fileResource.objectId = :objectId")
    List<FileResource> findByObjectId(@Param("objectId")String objectId);
    List<FileResource> findByStoragePath(String storagePath);
    List<FileResource> findByObjectIdAndMime(String objectId, String mime);
    @Query("select fileResource from FileResource fileResource where fileResource.objectId = :objectId and fileResource.mime = :mime ")
    List<FileResource> findByObjectIdAndMime(@Param ("objectId")String objectId, @Param ("mime")String mime);
    FileResource findById(String id);
}

+ 30 - 1
src/main/java/com.yihu.ehr/basic/user/controller/DoctorEndPoint.java

@ -1,6 +1,8 @@
package com.yihu.ehr.basic.user.controller;
import com.fasterxml.jackson.core.type.TypeReference;
import com.yihu.ehr.basic.fileresource.service.FileResource;
import com.yihu.ehr.basic.fileresource.service.XFileResourceRepository;
import com.yihu.ehr.basic.getui.ConstantUtil;
import com.yihu.ehr.basic.org.model.OrgDept;
import com.yihu.ehr.basic.org.model.OrgMemberRelation;
@ -81,6 +83,9 @@ public class DoctorEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private IdcardValidator idcardValidator;
    @Autowired
    private XFileResourceRepository resourceRepository;
    @RequestMapping(value = ServiceApi.Doctors.Doctors, method = RequestMethod.GET)
    @ApiOperation(value = "获取医生列表", notes = "根据查询条件获取医生列表在前端表格展示")
    public List<MDoctor> searchDoctors(
@ -265,6 +270,7 @@ public class DoctorEndPoint extends EnvelopRestEndPoint {
            user.setRealName(doctors.getName());
            user.setGender(doctors.getSex());
            user.setTelephone(doctors.getPhone());
            user.setImgRemotePath(doctors.getPhoto());
            userManager.save(user);
        }
        //修改居民
@ -564,7 +570,7 @@ public class DoctorEndPoint extends EnvelopRestEndPoint {
            @RequestParam(value = "workPortal", required = false) String workPortal) throws Exception {
        Doctors doctors = doctorService.getDoctor(id);
        if (!StringUtils.isEmpty(photo)) {
            doctors.setPhoto(photo);
            doctors.setPhoto(saveImgFileSource(photo));
        }
        if (!StringUtils.isEmpty(skill)) {
            doctors.setSkill(skill);
@ -596,4 +602,27 @@ public class DoctorEndPoint extends EnvelopRestEndPoint {
        MDoctor doctorModel = convertToModel(doctors, MDoctor.class);
        return doctorModel;
    }
    /**
     * 健康上饶app,前端单独调用头像上传接口,将头像的路径传到后端。后端需要将路径保存到fileResource表中,再将id存到用户表
     * http://172.19.103.52:80/group1/M00/26/AF/rBFuWFr5BkWAZfYmAAAeqtdiKIY039.png
     *
     * @param path
     * @return
     */
    public String saveImgFileSource(String path) throws Exception {
        //获取用户头像,保存至file_resource
        FileResource fileResource = new FileResource();
        fileResource.setId(getObjectId(BizObject.FileResource));
        //获取groupName
        String[] str = path.split("/");
        String groupName = str[3];
        String remoteFileName = path.substring(path.indexOf(groupName)+ groupName.length()+1);
        //保存到resource表中
        fileResource.setStoragePath(groupName + ":" + remoteFileName);
        fileResource.setCreateDate(new Date());
        fileResource.setMime("user");
        fileResource.setObjectId("");
        return resourceRepository.save(fileResource).getId();
    }
}

+ 14 - 1
src/main/java/com.yihu.ehr/basic/user/controller/UserEndPoint.java

@ -195,6 +195,7 @@ public class UserEndPoint extends EnvelopRestEndPoint {
            doctors.setPyCode(PinyinUtil.getPinYinHeadChar(user.getRealName(), false));
            doctors.setSex(user.getGender());
            doctors.setPhone(user.getTelephone());
            doctors.setPhoto(user.getImgRemotePath());
            doctorService.save(doctors);
        }
        DemographicInfo demographicInfo = demographicService.getDemographicInfoByIdCardNo(user.getIdCardNo());
@ -539,6 +540,16 @@ public class UserEndPoint extends EnvelopRestEndPoint {
            }
        }
        userService.saveUser(user);
        //将基础信息同步到医生表
        Doctors doctors = doctorService.getByIdCardNo(user.getIdCardNo());
        if (!StringUtils.isEmpty(doctors)) {
            doctors.setName(user.getRealName());
            doctors.setPyCode(PinyinUtil.getPinYinHeadChar(user.getRealName(), false));
            doctors.setSex(user.getGender());
            doctors.setPhone(user.getTelephone());
            doctors.setPhoto(user.getImgRemotePath());
            doctorService.save(doctors);
        }
        return convertToModel(user, MUser.class);
    }
@ -688,6 +699,7 @@ public class UserEndPoint extends EnvelopRestEndPoint {
            doctor.setPyCode(PinyinUtil.getPinYinHeadChar(detailModel.getRealName(), false));
            doctor.setSex(detailModel.getGender());
            doctor.setPhone(detailModel.getTelephone());
            doctor.setPhoto(detailModel.getImgRemotePath());
        }
        DemographicInfo demographicInfo = demographicService.getDemographicInfoByIdCardNo(detailModel.getIdCardNo());
        if (demographicInfo != null) {
@ -1200,6 +1212,7 @@ public class UserEndPoint extends EnvelopRestEndPoint {
            doctors.setPyCode(PinyinUtil.getPinYinHeadChar(user.getRealName(), false));
            doctors.setSex(user.getGender());
            doctors.setPhone(user.getTelephone());
            doctors.setPhoto(user.getImgRemotePath());
            doctorService.save(doctors);
        }
        DemographicInfo demographicInfo = demographicService.getDemographicInfoByIdCardNo(user.getIdCardNo());
@ -1228,7 +1241,7 @@ public class UserEndPoint extends EnvelopRestEndPoint {
        //获取groupName
        String[] str = path.split("/");
        String groupName = str[3];
        String remoteFileName = path.substring(path.indexOf(groupName) + groupName.length());
        String remoteFileName = path.substring(path.indexOf(groupName)+ groupName.length()+1);
        //保存到resource表中
        fileResource.setStoragePath(groupName + ":" + remoteFileName);
        fileResource.setCreateDate(new Date());