Explorar o código

Merge remote-tracking branch 'origin/master'

hill9868 %!s(int64=6) %!d(string=hai) anos
pai
achega
1f6d53b5e1

+ 42 - 0
.gitignore

@ -0,0 +1,42 @@
#project files
ehr.ipr
ehr.iws
ehr.ids
*.html
*.iml
*/target/*
*/*/target/*
.idea/*
# ---> Java
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*#
# thrift generate code
commons-thrift-services/src/main/java/com/yihu/ehr/adaption
commons-thrift-services/src/main/java/com/yihu/ehr/app
commons-thrift-services/src/main/java/com/yihu/ehr/browser
commons-thrift-services/src/main/java/com/yihu/ehr/data/domain
commons-thrift-services/src/main/java/com/yihu/ehr/dict
commons-thrift-services/src/main/java/com/yihu/ehr/geography
commons-thrift-services/src/main/java/com/yihu/ehr/hadoop
commons-thrift-services/src/main/java/com/yihu/ehr/lang
commons-thrift-services/src/main/java/com/yihu/ehr/org
commons-thrift-services/src/main/java/com/yihu/ehr/pack
commons-thrift-services/src/main/java/com/yihu/ehr/patient
commons-thrift-services/src/main/java/com/yihu/ehr/profile
commons-thrift-services/src/main/java/com/yihu/ehr/resolve
commons-thrift-services/src/main/java/com/yihu/ehr/resource
commons-thrift-services/src/main/java/com/yihu/ehr/security
commons-thrift-services/src/main/java/com/yihu/ehr/std
commons-thrift-services/src/main/java/com/yihu/ehr/user

+ 8 - 0
src/main/java/com/yihu/ehr/resolve/common/ResolveApi.java

@ -0,0 +1,8 @@
package com.yihu.ehr.resolve.common;
public class ResolveApi {
    public class Packages {
        public static final String DeletePackages = "/packages/delete";
    }
}

+ 92 - 0
src/main/java/com/yihu/ehr/resolve/controller/PackageEndPoint.java

@ -0,0 +1,92 @@
package com.yihu.ehr.resolve.controller;
import com.yihu.ehr.constants.ApiVersion;
import com.yihu.ehr.controller.EnvelopRestEndPoint;
import com.yihu.ehr.elasticsearch.ElasticSearchUtil;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.resolve.common.ResolveApi;
import com.yihu.ehr.resolve.service.profile.PackageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(ApiVersion.Version1_0)
@Api(value = "PackageEndPoint", description = "档案包相关操作(主要用于清理脏数据),此操作会涉及到fastdfs,hbase同步删除", tags = {"档案相关服务"})
public class PackageEndPoint extends EnvelopRestEndPoint {
    @Autowired
    private FastDFSUtil fastDFSUtil;
    @Autowired
    private ElasticSearchUtil elasticSearchUtil;
    @Autowired
    private PackageService packageService;
    private static final String INDEX = "json_archives";
    private static final String TYPE = "info";
    @RequestMapping(value = ResolveApi.Packages.DeletePackages, method = RequestMethod.DELETE)
    @ApiOperation(value = "批量删除非结构化/影像档案包", notes = "批量删除非结构化/影像档案包,[结构化数据档案,最好手动删除,涉及到质控,太多东西了]")
    public long deletePackages(
            @ApiParam(name = "packType", value = "2:非结构化档案 ||  3:影像档案", required = true )
            @RequestParam(value = "packType",required = true) String packType,
            @ApiParam(name = "startDate", value = "接收时间(eg:2017-01-01 00:00:00)", required = false )
            @RequestParam(value = "startDate",required = false) String startDate,
            @ApiParam(name = "endDate", value = "接收时间(eg:2017-01-01 00:00:00)", required = false )
            @RequestParam(value = "endDate",required = false) String endDate,
            @ApiParam(name = "orgCode", value = "机构编码", required = false )
            @RequestParam(value = "orgCode",required = false) String orgCode,
            @ApiParam(name = "eventNo", value = "事件号", required = false )
            @RequestParam(value = "eventNo",required = false) String eventNo) throws Exception {
        String filters = "pack_type="+packType+";";
        if(StringUtils.isNotBlank(startDate)){
            filters+="receive_date>="+startDate+";";
        }
        if(StringUtils.isNotBlank(endDate)){
            filters+="receive_date<="+endDate+";";
        }
        if(StringUtils.isNotBlank(orgCode)){
            filters += "org_code="+orgCode+";";
        }
        if(StringUtils.isNotBlank(eventNo)){
            filters += "event_no="+eventNo+";";
        }
        long count = elasticSearchUtil.count(INDEX, TYPE, filters);
        Page<Map<String, Object>> result = elasticSearchUtil.page(INDEX, TYPE, filters, 1, 10000);
        while (CollectionUtils.isNotEmpty(result.getContent())) {
            List<String> idList = new ArrayList<>();
            for (Map<String, Object> temp : result) {
                String[] tokens =  String.valueOf(temp.get("remote_path")).split(":");
                String profileId = String.valueOf(temp.get("profile_id"));
                if(StringUtils.isNotBlank(profileId) && !profileId.equals("null")){
                    packageService.deleteFilePack(profileId);
                }
                //删除fastdfs档案包
                fastDFSUtil.delete(tokens[0], tokens[1]);
                idList.add(String.valueOf(temp.get("_id")));
            }
            //删除es记录
            if (idList.size() > 0) {
                String[] _id = new String[idList.size()];
                elasticSearchUtil.bulkDelete(INDEX, TYPE, idList.toArray(_id));
            }
            result = elasticSearchUtil.page(INDEX, TYPE, filters, 1, 10000);
        }
        return count;
    }
}

+ 2 - 2
src/main/java/com/yihu/ehr/resolve/dao/MasterResourceDao.java

@ -40,9 +40,9 @@ public class MasterResourceDao {
            String profileId = originalPackage.getProfileId().toString();
            String rowkey = profileId.substring(2,profileId.length());
            Map<String, String> originResult = hbaseDao.get(ResourceCore.MasterTable, rowkey, resourceBucket.getdFamily());
            /*if (!originResult.isEmpty()) {
            if (!originResult.isEmpty()) {
                throw new IllegalJsonFileException("Please upload the struct package(" + rowkey + ") first !");
            }*/
            }
        }
        String rowKey = resourceBucket.getId();
        TableBundle bundle = new TableBundle();

+ 1 - 2
src/main/java/com/yihu/ehr/resolve/job/PackageResolveJob.java

@ -73,8 +73,6 @@ public class PackageResolveJob implements InterruptableJob {
                //判断是否已经解析成功,或者正在解析(由于部署多个服务,运行的时间差可能导致多次加入队列,造成多次解析)
                Map<String, Object> map = statusReportService.getJsonArchiveById(pack.get_id());
                if(map != null && ("3".equals(map.get("archive_status")+"") || "1".equals(map.get("archive_status")+""))){
                    logger.error(map.get("archive_status")+"");
                    logger.error("==================stop archive:"+map.get("_id"));
                    return;
                }
                PackResolveLogger.info("开始入库:" + pack.get_id() + ", Timestamp:" + new Date());
@ -148,6 +146,7 @@ public class PackageResolveJob implements InterruptableJob {
        pack.setOrg_area(resourceBucket.getBasicRecord(ResourceCells.ORG_AREA));
        pack.setPatient_name(resourceBucket.getBasicRecord(ResourceCells.PATIENT_NAME));
        pack.setIdcard_no(resourceBucket.getBasicRecord(ResourceCells.DEMOGRAPHIC_ID));
        pack.setVersion(originalPackage.getCdaVersion());
        return originalPackage;
    }

+ 73 - 0
src/main/java/com/yihu/ehr/resolve/service/profile/PackageService.java

@ -0,0 +1,73 @@
package com.yihu.ehr.resolve.service.profile;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.hbase.HBaseDao;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.csource.common.MyException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Service
public class PackageService {
    @Autowired
    private HBaseDao hbaseDao;
    @Autowired
    protected ObjectMapper objectMapper;
    @Autowired
    private FastDFSUtil fastDFSUtil;
    private static final String MasterTable = "HealthFile";
    private static final String SubTable = "HealthFileSub";
    /**
     *
     * 通过 主表的rowkey,删除hbase主细表数据,以及删除已经入库到fast dfs的文件
     * 该方法目前只对非结构化和影像档案有作用
     * @param profileId
     * @throws IOException
     */
    public void deleteFilePack(String profileId) throws IOException, MyException {
        Map<String, Object> obj = hbaseDao.getResultMap(MasterTable,profileId);
        if (obj != null) {
            if (obj.get("file_list") != null) {
                String file_list = (String) obj.get("file_list");
                List<Map<String, String>> list = objectMapper.readValue(file_list, List.class);
                //删除 fast dfs 中非结构化文档
                if(CollectionUtils.isNotEmpty(list)){
                    for(Map<String,String> map:list){
                        String url = map.get("url");
                        if(StringUtils.isNotBlank(url)){
                            int index = url.indexOf("/");
                            String groupName = url.substring(0,index);
                            String fileName = url.substring(index+1,url.length()-1);
                            //删除fastdfs档案包
                            fastDFSUtil.delete(groupName, fileName);
                        }
                    }
                }
            }
            if (obj.get("sub_rowkeys") != null) {
                String sub_rowkeys = (String) obj.get("sub_rowkeys");
                List<String> list = objectMapper.readValue(sub_rowkeys, List.class);
                //删除细表数据
                if(CollectionUtils.isNotEmpty(list)){
                    for(String subRow:list){
                        //删除主表档案
                        hbaseDao.delete(MasterTable,SubTable);
                    }
                }
            }
            //删除主表档案
            hbaseDao.delete(MasterTable,profileId);
        }
    }
}