Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

humingfen 5 years ago
parent
commit
c8e0ff0203
31 changed files with 2747 additions and 1302 deletions
  1. 12 0
      business/base-service/pom.xml
  2. 1 1
      business/base-service/src/main/java/com/yihu/jw/area/service/BaseCityService.java
  3. 2 0
      business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorHospitalDao.java
  4. 76 0
      business/base-service/src/main/java/com/yihu/jw/doctor/service/excel/DoctorWorkTimeExcelDO.java
  5. 187 0
      business/base-service/src/main/java/com/yihu/jw/doctor/service/excel/DoctorWorkTimeExcelReader.java
  6. 57 0
      business/base-service/src/main/java/com/yihu/jw/doctor/service/excel/DoctorWorkTimeMainExcelDO.java
  7. 2 0
      business/base-service/src/main/java/com/yihu/jw/hospital/dict/WlyyChargeDictDao.java
  8. 1 0
      business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/DoctorWorkTimeDao.java
  9. 822 633
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java
  10. 247 10
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/WorkTimeService.java
  11. 388 519
      business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/XzzxEntranceService.java
  12. 4 4
      common/common-entity/src/main/java/com/yihu/jw/entity/IntegerIdentityEntity.java
  13. 2 0
      common/common-entity/src/main/java/com/yihu/jw/entity/base/dict/DictDoctorDutyDO.java
  14. 5 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/hospital/BaseHospitalRequestMapping.java
  15. 15 0
      common/common-util/pom.xml
  16. 67 67
      common/common-util/src/main/java/com/yihu/jw/util/excel/AExcelReader.java
  17. 40 40
      common/common-util/src/main/java/com/yihu/jw/util/excel/AExcelWriter.java
  18. 83 0
      common/common-util/src/main/java/com/yihu/jw/util/excel/poi/AExcelReader.java
  19. 71 0
      common/common-util/src/main/java/com/yihu/jw/util/excel/poi/AExcelWriter.java
  20. 546 0
      common/common-util/src/main/java/com/yihu/jw/util/excel/poi/ExcelUtils.java
  21. 1 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/populationBatchImport/PopulationMsg.java
  22. 1 0
      svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WechatController.java
  23. 1 1
      svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorService.java
  24. 2 4
      svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/excelImport/BaseDoctorExcelDOReader.java
  25. 21 2
      svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/controller/XzzxCotroller.java
  26. 1 0
      svr/svr-internet-hospital-job/pom.xml
  27. 65 11
      svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java
  28. 6 4
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/rehabilitation/RehabilitationManageController.java
  29. 2 2
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/rehabilitation/RehabilitationPlanController.java
  30. 2 0
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/rehabilitation/RehabilitationOperateRecordsDao.java
  31. 17 4
      svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/rehabilitation/RehabilitationManageService.java

+ 12 - 0
business/base-service/pom.xml

@ -91,7 +91,19 @@
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
            <version>2.4</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>xom</groupId>
            <artifactId>xom</artifactId>
            <version>1.2.5</version>
        </dependency>
        <!-- mq消息 end -->
        <!-- webService start -->

+ 1 - 1
business/base-service/src/main/java/com/yihu/jw/area/service/BaseCityService.java

@ -16,7 +16,7 @@ import java.util.List;
 *          litaohong    1.0  2018年08月31日 Created
 *
 *          </pre>
 * @since 1.
 * @since 1 .
 */
@Service
public class BaseCityService extends BaseJpaService<BaseCityDO, BaseCityDao> {

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/dao/BaseDoctorHospitalDao.java

@ -13,6 +13,8 @@ public interface BaseDoctorHospitalDao extends PagingAndSortingRepository<BaseDo
    List<BaseDoctorHospitalDO> findByOrgCodeAndDoctorCode(String orgCode, String doctorCode);
    List<BaseDoctorHospitalDO> findByDeptCodeAndDoctorCode(String deptCode, String doctorCode);
    @Query("select id from BaseDoctorHospitalDO where doctorCode = ?1")
    Set<Object> findIdListByOrgCodeAndDoctorCode(String doctorCode);

+ 76 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/service/excel/DoctorWorkTimeExcelDO.java

@ -0,0 +1,76 @@
package com.yihu.jw.doctor.service.excel;
import java.util.List;
import java.util.Map;
/**
 * Created by Trick on 2020/3/26.
 */
public class DoctorWorkTimeExcelDO {
    private String idCard;
    private String name;
    private String type;//1.早上,2.下午,3.晚上
    private String dateOfMonth;//月中的第几天
    private Integer row;
    private Integer col;
    private String errorMes;
    public String getIdCard() {
        return idCard;
    }
    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getDateOfMonth() {
        return dateOfMonth;
    }
    public void setDateOfMonth(String dateOfMonth) {
        this.dateOfMonth = dateOfMonth;
    }
    public Integer getRow() {
        return row;
    }
    public void setRow(Integer row) {
        this.row = row;
    }
    public Integer getCol() {
        return col;
    }
    public void setCol(Integer col) {
        this.col = col;
    }
    public String getErrorMes() {
        return errorMes;
    }
    public void setErrorMes(String errorMes) {
        this.errorMes = errorMes;
    }
}

+ 187 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/service/excel/DoctorWorkTimeExcelReader.java

@ -0,0 +1,187 @@
package com.yihu.jw.doctor.service.excel;
import com.yihu.jw.util.excel.poi.AExcelReader;
import com.yihu.jw.utils.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.stereotype.Component;
import java.util.*;
/**
 * Created by Trick on 2020/3/26.
 */
@Component
public class DoctorWorkTimeExcelReader extends AExcelReader {
    @Override
    public void read(Workbook rwb) throws Exception {
        try{
            Iterator<Sheet> sheets = rwb.sheetIterator();
            int j = 0, rows;
            while (sheets.hasNext()){
                Sheet sheet = sheets.next();
                if(sheet.getLastRowNum()>202){
                    setCode("-1");
                    setMes("目前仅支持200位医生同时导入");
                    return;
                }
                if ((rows = sheet.getLastRowNum()) == 0) {
                    continue;
                }
                for (int i = 3; i <= rows; i++) {
                    //1.获取医生信息
                    String idCard = replaceBlank(getCellCont(sheet, i, 0));
                    String name = replaceBlank(getCellCont(sheet, i, 1));
                    DoctorWorkTimeMainExcelDO main = new DoctorWorkTimeMainExcelDO();
                    main.setName(name);
                    main.setIdCard(idCard);
                    main.setRow(i);
                    List<DoctorWorkTimeExcelDO> list = new ArrayList<>();
                    //2.构造每天排班记录
                    //遍历上午排班信息
                    int sw = 2;
                    while (sw<=92){
//                        System.out.println("col:"+sw);
//                        System.out.println("day:"+(sw+1)/3);
                        String workflag =  replaceBlank(getCellCont(sheet,i,sw));
                        //判断是否有排班
                        if("1".equals(workflag)){
                            //如果有排班,生成当天排班记录
                            DoctorWorkTimeExcelDO excelDO = new DoctorWorkTimeExcelDO();
                            excelDO.setName(name);
                            excelDO.setIdCard(idCard);
                            //标记行列
                            excelDO.setRow(i);
                            excelDO.setCol(sw);
                            Integer day = (sw+1)/3;
                            excelDO.setDateOfMonth(day+"");
                            excelDO.setType("1");
                            list.add(excelDO);
                        }
                        sw = sw+3;
                    }
                    //遍历下午排班信息
                    int xw = 3;
                    while (xw<=93){
                        //
//                        System.out.println("col:"+xw);
//                        System.out.println("day:"+(xw)/3);
                        String workflag =  replaceBlank(getCellCont(sheet,i,xw));
                        //判断是否有排班
                        if("1".equals(workflag)){
                            //如果有排班,生成当天排班记录
                            DoctorWorkTimeExcelDO excelDO = new DoctorWorkTimeExcelDO();
                            excelDO.setName(name);
                            excelDO.setIdCard(idCard);
                            //标记行列
                            excelDO.setRow(i);
                            excelDO.setCol(xw);
                            Integer day = (xw+1)/3;
                            excelDO.setDateOfMonth(day+"");
                            excelDO.setType("2");
                            list.add(excelDO);
                        }
                        xw = xw+3;
                    }
                    //遍历晚上排班信息
                    int ws = 4;
                    while (ws<=94){
                        //
//                        System.out.println("col:"+ws);
//                        System.out.println("day:"+(ws-1)/3);
                        String workflag =  replaceBlank(getCellCont(sheet,i,ws));
                        //判断是否有排班
                        if("1".equals(workflag)){
                            //如果有排班,生成当天排班记录
                            DoctorWorkTimeExcelDO excelDO = new DoctorWorkTimeExcelDO();
                            excelDO.setName(name);
                            excelDO.setIdCard(idCard);
                            //标记行列
                            excelDO.setRow(i);
                            excelDO.setCol(ws);
                            Integer day = (ws+1)/3;
                            excelDO.setDateOfMonth(day+"");
                            excelDO.setType("3");
                            list.add(excelDO);
                        }
                        ws = ws+3;
                    }
                    //设置本月排班
                    main.setWorkTime(list);
                    String rs = checkMain(main);
                    if("1".equals(rs)){
                        getCorrectLs().add(main);
                    }else {
                        getErrorLs().add(main);
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            throw e;
        }finally {
            if (rwb != null) {
                rwb.close();
            }
        }
    }
    public String checkMain(DoctorWorkTimeMainExcelDO main){
        String idCard = main.getIdCard();
        String name = main.getName();
        if(StringUtils.isBlank(idCard)){
            main.setErrorMes("第"+(main.getRow()+1)+"行,身份证号为空!\n");
            return "0";
        }
        if(StringUtils.isBlank(name)){
            main.setErrorMes("第"+(main.getRow()+1)+"行,姓名为空!\n");
            return "0";
        }
        return "1";
    }
//    public static void main(String ag[]){
//        int sw = 2;
//        while (sw<=92){
//            //
//            System.out.println("col:"+sw);
//            System.out.println("day:"+(sw+1)/3);
//            sw = sw+3;
//        }
//
//        int xw = 3;
//        while (xw<=93){
//            //
//            System.out.println("col:"+xw);
//            System.out.println("day:"+(xw)/3);
//            xw = xw+3;
//        }
//
//        int ws = 4;
//        while (ws<=94){
//            //
//            System.out.println("col:"+ws);
//            System.out.println("day:"+(ws-1)/3);
//            ws = ws+3;
//        }
//    }
}

+ 57 - 0
business/base-service/src/main/java/com/yihu/jw/doctor/service/excel/DoctorWorkTimeMainExcelDO.java

@ -0,0 +1,57 @@
package com.yihu.jw.doctor.service.excel;
import java.util.List;
/**
 * Created by Trick on 2020/3/27.
 */
public class DoctorWorkTimeMainExcelDO {
    private String idCard;
    private String name;
    private List<DoctorWorkTimeExcelDO> workTime;
    private String errorMes;
    private Integer row;//行标识
    public String getIdCard() {
        return idCard;
    }
    public void setIdCard(String idCard) {
        this.idCard = idCard;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public List<DoctorWorkTimeExcelDO> getWorkTime() {
        return workTime;
    }
    public void setWorkTime(List<DoctorWorkTimeExcelDO> workTime) {
        this.workTime = workTime;
    }
    public String getErrorMes() {
        return errorMes;
    }
    public void setErrorMes(String errorMes) {
        this.errorMes = errorMes;
    }
    public Integer getRow() {
        return row;
    }
    public void setRow(Integer row) {
        this.row = row;
    }
}

+ 2 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/dict/WlyyChargeDictDao.java

@ -16,4 +16,6 @@ public interface WlyyChargeDictDao extends PagingAndSortingRepository<WlyyCharge
    List<WlyyChargeDictDO>  findByDeptTypeCode(String deptTypeCode);
    WlyyChargeDictDO  findByChargeTypeAndDeptTypeCode(String chargeType,String deptTypeCode);
    WlyyChargeDictDO  findByChargeType(String chargeType);
}

+ 1 - 0
business/base-service/src/main/java/com/yihu/jw/hospital/doctor/dao/DoctorWorkTimeDao.java

@ -21,4 +21,5 @@ public interface DoctorWorkTimeDao extends PagingAndSortingRepository<WlyyDoctor
    @Query("from WlyyDoctorWorkTimeDO a where a.doctor = ?1 and a.startTime >= ?2 and a.startTime <= ?3 order by a.startTime asc")
    List<WlyyDoctorWorkTimeDO> findDoctorWorkTimeByTime(String doctor, Date startDate,Date endDate);
}

+ 822 - 633
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -162,6 +162,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseDoctorPatientFollowDao baseOrgPatientDao;
    @Autowired
    private WlyyHospitalWorkRuleDao wlyyHospitalWorkRuleDao;
    @Value("${demo.flag}")
@ -819,10 +821,10 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @return
     */
    public List<BaseOrgVO> findAllHospital(Integer level,String keyWord){
    
        if (StringUtils.isNoneEmpty(keyWord)) {
            keyWord = "%" + keyWord + "%";
    
            if(level!=null){
                List<BaseOrgDO> list = baseOrgDao.findByLevelAndName(level,"1",keyWord);
                List<BaseOrgVO> rs = new ArrayList<>();
@ -833,7 +835,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                return convertToModels(list,rs,BaseOrgVO.class);
            }
        }else{
    
            if(level!=null){
                List<BaseOrgDO> list = baseOrgDao.findByLevelAndDel(level,"1");
                List<BaseOrgVO> rs = new ArrayList<>();
@ -849,24 +851,25 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 获取机构下部门信息
     *
     * @param orgCode
     * @return
     */
    public List<DictHospitalDeptVO> findDeptByHospital(String orgCode,String dept,String consultDeptFlag){
    public List<DictHospitalDeptVO> findDeptByHospital(String orgCode, String dept, String consultDeptFlag) {
        List<DictHospitalDeptDO> list;
        if(StringUtils.isNotBlank(consultDeptFlag)&&"1".equals(consultDeptFlag)){
            list = dictHospitalDeptDao.findByOrgCodeAndConsultDeptFlag(orgCode,consultDeptFlag);
        }else {
            list =  dictHospitalDeptDao.findByOrgCodeIn(orgCode);
        if (StringUtils.isNotBlank(consultDeptFlag) && "1".equals(consultDeptFlag)) {
            list = dictHospitalDeptDao.findByOrgCodeAndConsultDeptFlag(orgCode, consultDeptFlag);
        } else {
            list = dictHospitalDeptDao.findByOrgCodeIn(orgCode);
        }
        List<DictHospitalDeptVO> rs = new ArrayList<>();
        convertToModels(list,rs,DictHospitalDeptVO.class);
        if(rs!=null&&rs.size()>0&&StringUtils.isNotBlank(dept)){
        convertToModels(list, rs, DictHospitalDeptVO.class);
        if (rs != null && rs.size() > 0 && StringUtils.isNotBlank(dept)) {
            //排序
            for(int i=0;i<rs.size();i++){
            for (int i = 0; i < rs.size(); i++) {
                String id = rs.get(i).getCode();
                if(dept.equals(id)){
                    Collections.swap(rs,0,i);
                if (dept.equals(id)) {
                    Collections.swap(rs, 0, i);
                }
            }
        }
@ -875,6 +878,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 获取医生列表.
     *
     * @param orgCode
     * @param dept
     * @return
@ -896,59 +900,59 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " WHERE  " +
                " 1=1";
        if(StringUtils.isNotBlank(dept)){
            sql+= " AND h.dept_code = '"+dept+"'";
        if (StringUtils.isNotBlank(dept)) {
            sql += " AND h.dept_code = '" + dept + "'";
        }
        if(StringUtils.isNotBlank(orgCode)){
            sql+= " AND h.org_code = '"+orgCode+"'";
        if (StringUtils.isNotBlank(orgCode)) {
            sql += " AND h.org_code = '" + orgCode + "'";
        }
        if(StringUtils.isNotBlank(chargeType)){
            if("all".equals(chargeType)){
        if (StringUtils.isNotBlank(chargeType)) {
            if ("all".equals(chargeType)) {
                //查询全部号源
            }else{
                sql+=" AND d.charge_type ='"+chargeType+"'";
            } else {
                sql += " AND d.charge_type ='" + chargeType + "'";
            }
        }else{
            sql+=" AND d.charge_type is not null ";
        } else {
            sql += " AND d.charge_type is not null ";
        }
        if(StringUtils.isNotBlank(outpatientType)){
            if("all".equals(outpatientType)){
        if (StringUtils.isNotBlank(outpatientType)) {
            if ("all".equals(outpatientType)) {
                //查询全部权限
            }else{
                sql+=" AND d.outpatient_type like'%"+outpatientType+"%'";
            } else {
                sql += " AND d.outpatient_type like'%" + outpatientType + "%'";
            }
        }else{
            sql+=" AND d.outpatient_type is not null ";
        } else {
            sql += " AND d.outpatient_type is not null ";
        }
        if(StringUtils.isNotBlank(key)){
            sql+=" AND (h.dept_name like '%"+key+"%' OR d.name like '%"+key+"%' OR d.expertise like '%"+key+"%') ";
        if (StringUtils.isNotBlank(key)) {
            sql += " AND (h.dept_name like '%" + key + "%' OR d.name like '%" + key + "%' OR d.expertise like '%" + key + "%') ";
        }
        if(StringUtils.isNotBlank(consultStatus)){
            sql+=" AND d.consult_status = '"+consultStatus+"'";
        if (StringUtils.isNotBlank(consultStatus)) {
            sql += " AND d.consult_status = '" + consultStatus + "'";
        }
        if(StringUtils.isNotBlank(endDate)&&StringUtils.isNotBlank(startDate)){
            sql+=" AND EXISTS ( " +
        if (StringUtils.isNotBlank(endDate) && StringUtils.isNotBlank(startDate)) {
            sql += " AND EXISTS ( " +
                    " SELECT " +
                    "  1 " +
                    " FROM " +
                    "  wlyy_doctor_work_time t " +
                    " WHERE " +
                    "  t.doctor = d.id " +
                    " AND t.start_time >='" +startDate+"'" +
                    " AND t.start_time <='"+endDate+"'"+
                    " AND t.start_time >='" + startDate + "'" +
                    " AND t.start_time <='" + endDate + "'" +
                    " )";
        }
        logger.info("findDoctorByHospitalAndDept sql:"+sql);
        logger.info("findDoctorByHospitalAndDept sql:" + sql);
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if(list!=null&&list.size()>0&&StringUtils.isNotBlank(doctorCode)){
        if (list != null && list.size() > 0 && StringUtils.isNotBlank(doctorCode)) {
            //排序
            for(int i=0;i<list.size();i++){
                String id = (String)list.get(i).get("id");
                if(doctorCode.equals(id)){
                    Collections.swap(list,0,i);
            for (int i = 0; i < list.size(); i++) {
                String id = (String) list.get(i).get("id");
                if (doctorCode.equals(id)) {
                    Collections.swap(list, 0, i);
                }
            }
        }
@ -958,64 +962,65 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 获取医生列表带排班
     *
     * @param orgCode
     * @param dept
     * @return
     */
    public MixEnvelop findDoctorWithWork(String orgCode,String dept,String chargeType,String doctorCode,String outpatientType,String startDate,String endDate,String key,String consultStatus,Integer page,Integer size){
    public MixEnvelop findDoctorWithWork(String orgCode, String dept, String chargeType, String doctorCode, String outpatientType, String startDate, String endDate, String key, String consultStatus, Integer page, Integer size) {
        String totalSql ="SELECT " +
        String totalSql = "SELECT " +
                " count(1) AS total " +
                " FROM " +
                " base_doctor d " +
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " WHERE  " +
                " 1=1 ";
        if(StringUtils.isNotBlank(dept)){
            totalSql+= " AND h.dept_code = '"+dept+"'";
        if (StringUtils.isNotBlank(dept)) {
            totalSql += " AND h.dept_code = '" + dept + "'";
        }
        if(StringUtils.isNotBlank(orgCode)){
            totalSql+= " AND h.org_code = '"+orgCode+"'";
        if (StringUtils.isNotBlank(orgCode)) {
            totalSql += " AND h.org_code = '" + orgCode + "'";
        }
        if(StringUtils.isNotBlank(chargeType)){
            totalSql+= " AND d.charge_type ='"+chargeType+"'";
        }else{
            totalSql+= " AND d.charge_type is not null ";
        if (StringUtils.isNotBlank(chargeType)) {
            totalSql += " AND d.charge_type ='" + chargeType + "'";
        } else {
            totalSql += " AND d.charge_type is not null ";
        }
        if(StringUtils.isNotBlank(outpatientType)){
            if(outpatientType.contains("or")){
        if (StringUtils.isNotBlank(outpatientType)) {
            if (outpatientType.contains("or")) {
                String[] outpatientTypeArray = outpatientType.split("or");
                totalSql+= " AND ( ";
    
                totalSql += " AND ( ";
                for (int i = 0; i < outpatientTypeArray.length; i++) {
                    totalSql +=" d.outpatient_type like'%"+outpatientTypeArray[i]+"%'";
                    if(i != outpatientTypeArray.length -1){
                    totalSql += " d.outpatient_type like'%" + outpatientTypeArray[i] + "%'";
                    if (i != outpatientTypeArray.length - 1) {
                        totalSql += " or ";
                    }
                }
                totalSql+= "  ) ";
            }else{
                totalSql+= " AND d.outpatient_type like'%"+outpatientType+"%'";
                totalSql += "  ) ";
            } else {
                totalSql += " AND d.outpatient_type like'%" + outpatientType + "%'";
            }
        }else{
            totalSql+=" AND d.outpatient_type is not null ";
        } else {
            totalSql += " AND d.outpatient_type is not null ";
        }
        if(StringUtils.isNotBlank(key)){
            totalSql+=" AND (h.dept_name like '%"+key+"%' OR d.name like '%"+key+"%' OR d.expertise like '%"+key+"%') ";
        if (StringUtils.isNotBlank(key)) {
            totalSql += " AND (h.dept_name like '%" + key + "%' OR d.name like '%" + key + "%' OR d.expertise like '%" + key + "%') ";
        }
        if(StringUtils.isNotBlank(consultStatus)){
            totalSql+=" AND d.consult_status = '"+consultStatus+"'";
        if (StringUtils.isNotBlank(consultStatus)) {
            totalSql += " AND d.consult_status = '" + consultStatus + "'";
        }
        if(StringUtils.isNotBlank(endDate)&&StringUtils.isNotBlank(startDate)){
            totalSql+=" AND EXISTS ( " +
        if (StringUtils.isNotBlank(endDate) && StringUtils.isNotBlank(startDate)) {
            totalSql += " AND EXISTS ( " +
                    " SELECT " +
                    "  1 " +
                    " FROM " +
                    "  wlyy_doctor_work_time t " +
                    " WHERE " +
                    "  t.doctor = d.id " +
                    " AND t.start_time >='" +startDate+"'" +
                    " AND t.start_time <='"+endDate+"'"+
                    " AND t.start_time >='" + startDate + "'" +
                    " AND t.start_time <='" + endDate + "'" +
                    " )";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -1025,7 +1030,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            count = (Long) rstotal.get(0).get("total");
        }
        String sql ="SELECT " +
        String sql = "SELECT " +
                " d.id, " +
                " d.photo, " +
                " d.`name`, " +
@ -1042,72 +1047,73 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " base_doctor d " +
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " WHERE " +
                " 1=1" ;
        if(StringUtils.isNotBlank(dept)){
            sql+= " AND h.dept_code = '"+dept+"'";
                " 1=1";
        if (StringUtils.isNotBlank(dept)) {
            sql += " AND h.dept_code = '" + dept + "'";
        }
        if(StringUtils.isNotBlank(orgCode)){
            sql+= " AND h.org_code = '"+orgCode+"'";
        if (StringUtils.isNotBlank(orgCode)) {
            sql += " AND h.org_code = '" + orgCode + "'";
        }
    
        if(StringUtils.isNotBlank(chargeType)){
            sql+= " AND d.charge_type ='"+chargeType+"'";
        }else{
            sql+= " AND d.charge_type is not null";
        if (StringUtils.isNotBlank(chargeType)) {
            sql += " AND d.charge_type ='" + chargeType + "'";
        } else {
            sql += " AND d.charge_type is not null";
        }
        
        if(StringUtils.isNotBlank(outpatientType)){
            if(outpatientType.contains("or")){
        if (StringUtils.isNotBlank(outpatientType)) {
            if (outpatientType.contains("or")) {
                String[] outpatientTypeArray = outpatientType.split("or");
                sql+= " AND ( ";
            
                sql += " AND ( ";
                for (int i = 0; i < outpatientTypeArray.length; i++) {
                    sql +=" d.outpatient_type like'%"+outpatientTypeArray[i]+"%'";
                    if(i != outpatientTypeArray.length -1){
                    sql += " d.outpatient_type like'%" + outpatientTypeArray[i] + "%'";
                    if (i != outpatientTypeArray.length - 1) {
                        sql += " or ";
                    }
                }
                sql+= " ) ";
            }else{
                sql+= " AND d.outpatient_type like'%"+outpatientType+"%'";
                sql += " ) ";
            } else {
                sql += " AND d.outpatient_type like'%" + outpatientType + "%'";
            }
        }else{
            sql+=" AND d.outpatient_type is not null ";
        } else {
            sql += " AND d.outpatient_type is not null ";
        }
        
        if(StringUtils.isNotBlank(key)){
            sql+=" AND (h.dept_name like '%"+key+"%' OR d.name like '%"+key+"%' OR d.expertise like '%"+key+"%') ";
        if (StringUtils.isNotBlank(key)) {
            sql += " AND (h.dept_name like '%" + key + "%' OR d.name like '%" + key + "%' OR d.expertise like '%" + key + "%') ";
        }
        if(StringUtils.isNotBlank(consultStatus)){
            sql+=" AND d.consult_status = '"+consultStatus+"'";
        if (StringUtils.isNotBlank(consultStatus)) {
            sql += " AND d.consult_status = '" + consultStatus + "'";
        }
        if(StringUtils.isNotBlank(endDate)&&StringUtils.isNotBlank(startDate)){
            sql+=" AND EXISTS ( " +
        if (StringUtils.isNotBlank(endDate) && StringUtils.isNotBlank(startDate)) {
            sql += " AND EXISTS ( " +
                    " SELECT " +
                    "  1 " +
                    " FROM " +
                    "  wlyy_doctor_work_time t " +
                    " WHERE " +
                    "  t.doctor = d.id " +
                    " AND t.start_time >='" +startDate+"'" +
                    " AND t.start_time <='"+endDate+"'"+
                    " AND t.start_time >='" + startDate + "'" +
                    " AND t.start_time <='" + endDate + "'" +
                    " )";
        }
        sql += " AND d.del='1' AND d.outpatient_type is not null LIMIT " + (page - 1) * size + "," + size + "";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if(list!=null&&list.size()>0){
        logger.info("withwork sql:" +sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0) {
            //获取排班
            for(Map<String,Object> doctor :list){
                String id = (String)doctor.get("id");
                List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(id);
                doctor.put("workTime",times);
            for (Map<String, Object> doctor : list) {
                String id = (String) doctor.get("id");
                List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(id, orgCode);
                doctor.put("workTime", times);
            }
            if(StringUtils.isNotBlank(doctorCode)){
            if (StringUtils.isNotBlank(doctorCode)) {
                //排序
                for(int i=0;i<list.size();i++){
                    String id = (String)list.get(i).get("id");
                    if(doctorCode.equals(id)){
                        Collections.swap(list,0,i);
                for (int i = 0; i < list.size(); i++) {
                    String id = (String) list.get(i).get("id");
                    if (doctorCode.equals(id)) {
                        Collections.swap(list, 0, i);
                    }
                }
            }
@ -1115,8 +1121,45 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
    }
    public List<WlyyDoctorWorkTimeVO> findDoctorWorkTime(String doctor, String hospital) {
        List<WlyyHospitalWorkRuleDO> list = wlyyHospitalWorkRuleDao.findByHospital(hospital);
        if (list != null && list.size() > 0) {
            WlyyHospitalWorkRuleDO rule = list.get(0);
            String openTimeString = DateUtil.dateToStr(new Date(), "yyyy-MM-dd")+ " " + rule.getMaxDayOpenTime() + ":00";
            logger.info("today openTimeString :"+openTimeString);
            Date openTime = DateUtil.strToDate(openTimeString, "yyyy-MM-dd HH:mm:ss");
            Integer openDay = rule.getMaxDay();
            if (openTime.before(new Date())) {
                openDay = openDay - 1;
            }
            Date preDate =  DateUtil.getPreDays(new Date(), openDay);
            String maxDateString = DateUtil.dateToStr(preDate,"yyyy-MM-dd")+" 23:59:59";
            logger.info("maxDateString :"+maxDateString);
            Date endDate = DateUtil.stringToDate(maxDateString, "yyyy-MM-dd HH:mm:ss");
            List<WlyyDoctorWorkTimeVO> timeVOs = new ArrayList<>();
            List<WlyyDoctorWorkTimeDO> timeDOs = doctorWorkTimeDao.findDoctorWorkTime(doctor, new Date(), endDate);
            if(timeDOs!=null&&timeDOs.size()>0){
                convertToModels(timeDOs, timeVOs, WlyyDoctorWorkTimeVO.class);
                if (timeVOs != null && timeVOs.size() > 0) {
                    for (WlyyDoctorWorkTimeVO timeVO : timeVOs) {
                        timeVO.setCount(findWorkTimeInfoCout(timeVO.getId()));
                    }
                }
            }
            return timeVOs;
        }
        return null;
    }
    /**
     * 查询医生列表带月份排班状态
     *
     * @param orgCode
     * @param dept
     * @param chargeType
@ -1125,33 +1168,33 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @param size
     * @return
     */
    public MixEnvelop findDoctorWithMouthWork(String orgCode,String dept,String chargeType,String date,String nameKey,Integer page,Integer size){
    public MixEnvelop findDoctorWithMouthWork(String orgCode, String dept, String chargeType, String date, String nameKey, Integer page, Integer size) {
        String totalSql ="SELECT " +
        String totalSql = "SELECT " +
                " count(1) AS total " +
                " FROM " +
                " base_doctor d " +
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " JOIN base_doctor_role r ON r.doctor_code = d.id " +
                " WHERE  " +
                " h.org_code = '"+orgCode+"'" +
                " h.org_code = '" + orgCode + "'" +
                " AND r.role_code ='specialist'";
        if(StringUtils.isNotBlank(chargeType)){
            if("all".equals(chargeType)){
        if (StringUtils.isNotBlank(chargeType)) {
            if ("all".equals(chargeType)) {
                //不过滤号别
            }else{
                totalSql+=" AND d.charge_type ='"+chargeType+"'";
            } else {
                totalSql += " AND d.charge_type ='" + chargeType + "'";
            }
        }else{
        } else {
            //不传号别过滤不为为空
            totalSql+=" AND d.charge_type is not null ";
            totalSql += " AND d.charge_type is not null ";
        }
        if(StringUtils.isNotBlank(dept)){
            totalSql+= " AND h.dept_code = '"+dept+"' " ;
        if (StringUtils.isNotBlank(dept)) {
            totalSql += " AND h.dept_code = '" + dept + "' ";
        }
        if(StringUtils.isNotBlank(nameKey)){
            totalSql+= " AND d.name like '%"+nameKey+"%' " ;
        if (StringUtils.isNotBlank(nameKey)) {
            totalSql += " AND d.name like '%" + nameKey + "%' ";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -1160,7 +1203,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            count = (Long) rstotal.get(0).get("total");
        }
        String sql ="SELECT " +
        String sql = "SELECT " +
                " d.id, " +
                " d.photo, " +
                " d.`name`, " +
@ -1176,72 +1219,72 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN base_doctor_hospital h ON h.doctor_code = d.id " +
                " JOIN base_doctor_role r ON r.doctor_code = d.id " +
                " WHERE  " +
                " h.org_code = '"+orgCode+"'"+
                " h.org_code = '" + orgCode + "'" +
                " AND r.role_code ='specialist'";
        if(StringUtils.isNotBlank(chargeType)){
            if("all".equals(chargeType)){
        if (StringUtils.isNotBlank(chargeType)) {
            if ("all".equals(chargeType)) {
                //不过滤号别
            }else{
                sql+=" AND d.charge_type ='"+chargeType+"'";
            } else {
                sql += " AND d.charge_type ='" + chargeType + "'";
            }
        }else{
        } else {
            //不传号别过滤不为为空
            sql+=" AND d.charge_type is not null ";
            sql += " AND d.charge_type is not null ";
        }
        if(StringUtils.isNotBlank(dept)){
            sql+= " AND h.dept_code = '"+dept+"' " ;
        if (StringUtils.isNotBlank(dept)) {
            sql += " AND h.dept_code = '" + dept + "' ";
        }
        if(StringUtils.isNotBlank(nameKey)){
            sql+= " AND d.name like '%"+nameKey+"%' " ;
        if (StringUtils.isNotBlank(nameKey)) {
            sql += " AND d.name like '%" + nameKey + "%' ";
        }
        sql += " LIMIT " + (page - 1) * size + "," + size + "";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        if(list!=null&&list.size()>0){
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        if (list != null && list.size() > 0) {
            //获取排班
            for(Map<String,Object> doctor :list){
                String id = (String)doctor.get("id");
                List<WlyyDoctorWorkTimeDO> workTimeDOs = doctorWorkTimeDao.findDoctorWorkTimeByMonth(id,"%"+date+"%");
                if(workTimeDOs!=null&&workTimeDOs.size()>0){
                    doctor.put("isScheduling",true);
                }else{
                    doctor.put("isScheduling",false);
            for (Map<String, Object> doctor : list) {
                String id = (String) doctor.get("id");
                List<WlyyDoctorWorkTimeDO> workTimeDOs = doctorWorkTimeDao.findDoctorWorkTimeByMonth(id, "%" + date + "%");
                if (workTimeDOs != null && workTimeDOs.size() > 0) {
                    doctor.put("isScheduling", true);
                } else {
                    doctor.put("isScheduling", false);
                }
            }
        }
        logger.info("findDoctorWithMouthWork :"+sql);
        logger.info("findDoctorWithMouthWork :" + sql);
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
    }
    /**
     * 挂号
     *
     * @return
     */
    public net.sf.json.JSONObject registerOutPatient(String outPatientId,String doctor)throws Exception{
    public net.sf.json.JSONObject registerOutPatient(String outPatientId, String doctor) throws Exception {
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outPatientId);
        
        
        DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(doctor,outpatientDO.getHospital());
        if(doctorMappingDO==null){
        DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(doctor, outpatientDO.getHospital());
        if (doctorMappingDO == null) {
            throw new RuntimeException("未找到医生映射信息");
        }
        
        BasePatientDO basePatientDO = basePatientDao.findById(outpatientDO.getPatient());
    
        Integer manageType = 1;//处理类型(1-新增 2-修改 3-删除) 必填
        //查找居民当天挂号记录
        String date = DateUtil.dateToStr(new Date(),"yyyy-MM-dd");
        List<WlyyPatientRegisterDO>  patientRegisterDOs = patientRegisterDao.findByPatientAndDateAndDoctor(outpatientDO.getPatient(),date,doctor);
        if(patientRegisterDOs!=null&&patientRegisterDOs.size()>0){
        String date = DateUtil.dateToStr(new Date(), "yyyy-MM-dd");
        List<WlyyPatientRegisterDO> patientRegisterDOs = patientRegisterDao.findByPatientAndDateAndDoctor(outpatientDO.getPatient(), date, doctor);
        if (patientRegisterDOs != null && patientRegisterDOs.size() > 0) {
            WlyyPatientRegisterDO registerDO = patientRegisterDOs.get(0);
            //判断是否已经挂号,如果已经挂号
            if(StringUtils.isNotBlank(registerDO.getConNo())&&StringUtils.isNotBlank(registerDO.getRegisterNo())){
            if (StringUtils.isNotBlank(registerDO.getConNo()) && StringUtils.isNotBlank(registerDO.getRegisterNo())) {
                net.sf.json.JSONObject res = new JSONObject();
                res.put("@RESULT","0");
                logger.info("已经挂号 res: " +res.toString());
                res.put("@RESULT", "0");
                logger.info("已经挂号 res: " + res.toString());
                //更新挂号流水号
                outpatientDO.setConNo(registerDO.getConNo());
@ -1249,27 +1292,27 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                outpatientDO.setAdmDate(registerDO.getCreateTime());
                outpatientDao.save(outpatientDO);
                //调用电子病历注册
                manageType =2;
//                registDianziBingli(outpatientDO,basePatientDO,manageType,registerDO.getRegisterNo(),registerDO.getConNo());
                manageType = 2;
                registDianziBingli(outpatientDO, basePatientDO, manageType, registerDO.getRegisterNo(), registerDO.getConNo());
                return res;
            }
        }
        net.sf.json.JSONObject rs = entranceService.BS10111(outpatientDO.getCardNo(),doctorMappingDO.getMappingCode(),outpatientDO.getDept(),null,outpatientDO.getWinNo(),demoFlag);
        net.sf.json.JSONObject rs = entranceService.BS10111(outpatientDO.getCardNo(), doctorMappingDO.getMappingCode(), outpatientDO.getDept(), null, outpatientDO.getWinNo(), demoFlag);
        net.sf.json.JSONObject res = rs.getJSONObject("resquest");
        logger.info("挂号结果 res: " +res.toString());
        logger.info("挂号结果 res: " + res.toString());
        String rsCode = res.getString("@RESULT");
        
        if("0".equals(rsCode)){
        if ("0".equals(rsCode)) {
            //存储挂号号
            // {"resquest":{"@RESULT":"0","@MSG":"完成","@serial_no":"47770476","@times":"28"}}
            String serialNo = (String)res.get("@serial_no");
            String serialNo = (String) res.get("@serial_no");
            outpatientDO.setRegisterNo(serialNo);
            String conNo = (String)res.get("@times");
            String conNo = (String) res.get("@times");
            outpatientDO.setConNo(conNo);
            outpatientDO.setAdmDate(new Date());
            logger.info("挂号流水 @serial_no: " +serialNo+" @times: "+conNo);
            logger.info("挂号流水 @serial_no: " + serialNo + " @times: " + conNo);
            outpatientDao.save(outpatientDO);
            //存储就诊记录
@ -1286,21 +1329,21 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            registerDO.setRegisterNo(serialNo);
            registerDO.setConNo(conNo);
            registerDO.setCreateTime(new Date());
            registerDO.setDate(DateUtil.dateToStr(new Date(),"yyyy-MM-dd"));
            registerDO.setDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
            patientRegisterDao.save(registerDO);
    
            //调用电子病历注册
            manageType = 1;//处理类型(1-新增 2-修改 3-删除) 必填
//            registDianziBingli(outpatientDO,basePatientDO,manageType,registerDO.getRegisterNo(),registerDO.getConNo());
            
        }else if("-2".equals(rsCode)){
            registDianziBingli(outpatientDO, basePatientDO, manageType, registerDO.getRegisterNo(), registerDO.getConNo());
        } else if ("-2".equals(rsCode)) {
            String serialNo = (String)res.get("@serial_no");
            String serialNo = (String) res.get("@serial_no");
            outpatientDO.setRegisterNo(serialNo);
            String conNo = (String)res.get("@times");
            String conNo = (String) res.get("@times");
            outpatientDO.setConNo(conNo);
            outpatientDO.setAdmDate(new Date());
            logger.info("挂号流水 @serial_no: " +serialNo+" @times: "+conNo);
            logger.info("挂号流水 @serial_no: " + serialNo + " @times: " + conNo);
            outpatientDao.save(outpatientDO);
            //存储就诊记录
@ -1316,112 +1359,111 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            registerDO.setRegisterNo(serialNo);
            registerDO.setConNo(conNo);
            registerDO.setCreateTime(new Date());
            registerDO.setDate(DateUtil.dateToStr(new Date(),"yyyy-MM-dd"));
            registerDO.setDate(DateUtil.dateToStr(new Date(), "yyyy-MM-dd"));
            patientRegisterDao.save(registerDO);
    
            //调用电子病历注册
            manageType = 1;//处理类型(1-新增 2-修改 3-删除) 必填
//            registDianziBingli(outpatientDO,basePatientDO,manageType,registerDO.getRegisterNo(),registerDO.getConNo());
            registDianziBingli(outpatientDO, basePatientDO, manageType, registerDO.getRegisterNo(), registerDO.getConNo());
        }
    
        
            //保存日志
        //保存日志
        WlyyHttpLogDO log = new WlyyHttpLogDO();
        log.setCode("registerOutPatient");
        log.setName("挂号");
        log.setPatient(outpatientDO.getPatient());
        log.setDoctor(doctor);
        log.setResponse(rs.toString());
        log.setRequest("outPatientId="+outPatientId+"&doctor="+doctor);
        log.setRequest("outPatientId=" + outPatientId + "&doctor=" + doctor);
        log.setStatus(rsCode);
        log.setCreateTime(new Date());
        wlyyHttpLogDao.save(log);
        return res;
    }
    
    public String registDianziBingli(WlyyOutpatientDO outpatientDO,BasePatientDO basePatientDO,Integer manageType,String RegisterSN,String registerCon) throws Exception {
    
    public String registDianziBingli(WlyyOutpatientDO outpatientDO, BasePatientDO basePatientDO, Integer manageType, String RegisterSN, String registerCon) throws Exception {
        //调用电子病历接口注册居民信息
            String patientMappingCode =  patientMappingService.findHisPatNoByIdCard(basePatientDO.getIdcard());
            DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(),outpatientDO.getHospital());
            Map<String,String> params = new HashedMap();
            params.put("type","PatientInfo");
            
            String _xmlStr="<?xml version='1.0' encoding='UTF-8'?>" +
                    "<HtRequest>" +
                    "<OutRegister>" +
                    "<RecordFlow>"+outpatientDO.getId()+"</RecordFlow>" +
                    "<RegisterSN>"+RegisterSN+"</RegisterSN>" +
                    "<TreatDate>"+DateUtil.getStringDate("yyyyMMdd")+"</TreatDate>" +
                    "<RegisterDeptCode>"+outpatientDO.getDept()+"</RegisterDeptCode>" +
                    "<RegisterDeptName>"+outpatientDO.getDeptName()+"</RegisterDeptName>" +
                    "<RegisterDoctorID>"+doctorMappingDO.getMappingCode()+"</RegisterDoctorID>" +
                    "<RegisterDoctorName>"+doctorMappingDO.getDoctorName()+"</RegisterDoctorName>" +
                    "<DutyID></DutyID>" +
                    "<DutyName></DutyName>" +
                    "<OutPatientTime></OutPatientTime>" +
                    "<NumClassCode></NumClassCode>" +
                    "<NumClassName></NumClassName>" +
                    "<JoinGroupCode></JoinGroupCode>" +
                    "<JoinGroupName></JoinGroupName>" +
                    "<NumClassNO></NumClassNO>" +
                    "<AppointmentDateTime></AppointmentDateTime>" +
                    "<AppointSN></AppointSN>" +
                    "<Pid>"+patientMappingCode+"</Pid>" +
                    "<CardNO>"+outpatientDO.getCardNo()+"</CardNO>\n" +
                    "<PatientName>"+basePatientDO.getName()+"</PatientName>"+
                    "<SexCode>"+basePatientDO.getSex()+"</SexCode>";
                    if(1 == basePatientDO.getSex()){
                        _xmlStr = _xmlStr + "<Sex>男</Sex>";
                    }else{
                        _xmlStr = _xmlStr +  "<Sex>女</Sex>";
                    }
                    _xmlStr = _xmlStr + "<Age>"+IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard())+"</Age>" +
                    "<AgeDesc>"+IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard())+"岁</AgeDesc>" +
                    "<PatientClass></PatientClass>" +
                    "<FeeTypeCode></FeeTypeCode>" +
                    "<FeeTypeName></FeeTypeName>" +
                    "<MedicalInsuranceType></MedicalInsuranceType>" +
                    "<IsFirst>N</IsFirst>" +
                    "<RegisterDateTime>20200121</RegisterDateTime>" +
                    "<RegisterUserID>"+patientMappingCode+"</RegisterUserID>" +
                    "<RegisterUserName></RegisterUserName>" +
                    "<OutStatus>20</OutStatus>" +
                    "<ModifierID></ModifierID>" +
                    "<Modifier></Modifier>" +
                    "<ModifyTime></ModifyTime>" +
                    "<RetreatDateTime></RetreatDateTime>" +
                    "<RetreatUserID></RetreatUserID>" +
                    "<RetreatUserName></RetreatUserName>" +
                    "<PaymentMethodCode></PaymentMethodCode>" +
                    "<PaymentMethod></PaymentMethod>" +
                    "<RegisterFee></RegisterFee>" +
                    "<MedicalFee></MedicalFee>" +
                    "<OtherFee></OtherFee>" +
                    "<TotalFee></TotalFee>" +
                    "<MedicalFloor>N</MedicalFloor>" +
                    "<MedicalAddress></MedicalAddress>" +
                    "<LastDeptCode></LastDeptCode>" +
                    "<LastDeptName></LastDeptName>" +
                    "<LastDoctorID></LastDoctorID>" +
                    "<LastDoctorName></LastDoctorName>" +
                    "<LastTreatDateTime></LastTreatDateTime>" +
                    "<LastOpid></LastOpid>" +
                    "<NumTypeCode>0</NumTypeCode>" +
                    "<NumTypeName></NumTypeName>" +
                    "<RegisterSource>1</RegisterSource>" +
                    "<AcctNO></AcctNO>" +
                    "<IsAcct>N</IsAcct>" +
                    "<ManageType>"+manageType+"</ManageType>" +
                    "<Times>"+registerCon+"</Times>" +
                    "</OutRegister>" +
                    "<PatientInfo>" +
                    "<RecordFlow>"+outpatientDO.getId()+"</RecordFlow>" +
                    "<PID>"+patientMappingCode+"</PID></PatientInfo></HtRequest>";
            
            
        String patientMappingCode = patientMappingService.findHisPatNoByIdCard(basePatientDO.getIdcard());
        DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(), outpatientDO.getHospital());
        Map<String, String> params = new HashedMap();
        params.put("type", "PatientInfo");
        String _xmlStr = "<?xml version='1.0' encoding='UTF-8'?>" +
                "<HtRequest>" +
                "<OutRegister>" +
                "<RecordFlow>" + outpatientDO.getId() + "</RecordFlow>" +
                "<RegisterSN>" + RegisterSN + "</RegisterSN>" +
                "<TreatDate>" + DateUtil.getStringDate("yyyyMMdd") + "</TreatDate>" +
                "<RegisterDeptCode>" + outpatientDO.getDept() + "</RegisterDeptCode>" +
                "<RegisterDeptName>" + outpatientDO.getDeptName() + "</RegisterDeptName>" +
                "<RegisterDoctorID>" + doctorMappingDO.getMappingCode() + "</RegisterDoctorID>" +
                "<RegisterDoctorName>" + doctorMappingDO.getDoctorName() + "</RegisterDoctorName>" +
                "<DutyID></DutyID>" +
                "<DutyName></DutyName>" +
                "<OutPatientTime></OutPatientTime>" +
                "<NumClassCode></NumClassCode>" +
                "<NumClassName></NumClassName>" +
                "<JoinGroupCode></JoinGroupCode>" +
                "<JoinGroupName></JoinGroupName>" +
                "<NumClassNO></NumClassNO>" +
                "<AppointmentDateTime></AppointmentDateTime>" +
                "<AppointSN></AppointSN>" +
                "<Pid>" + patientMappingCode + "</Pid>" +
                "<CardNO>" + outpatientDO.getCardNo() + "</CardNO>\n" +
                "<PatientName>" + basePatientDO.getName() + "</PatientName>" +
                "<SexCode>" + basePatientDO.getSex() + "</SexCode>";
        if (1 == basePatientDO.getSex()) {
            _xmlStr = _xmlStr + "<Sex>男</Sex>";
        } else {
            _xmlStr = _xmlStr + "<Sex>女</Sex>";
        }
        _xmlStr = _xmlStr + "<Age>" + IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard()) + "</Age>" +
                "<AgeDesc>" + IdCardUtil.getAgeForIdcard(basePatientDO.getIdcard()) + "岁</AgeDesc>" +
                "<PatientClass></PatientClass>" +
                "<FeeTypeCode></FeeTypeCode>" +
                "<FeeTypeName></FeeTypeName>" +
                "<MedicalInsuranceType></MedicalInsuranceType>" +
                "<IsFirst>N</IsFirst>" +
                "<RegisterDateTime>20200121</RegisterDateTime>" +
                "<RegisterUserID>" + patientMappingCode + "</RegisterUserID>" +
                "<RegisterUserName></RegisterUserName>" +
                "<OutStatus>20</OutStatus>" +
                "<ModifierID></ModifierID>" +
                "<Modifier></Modifier>" +
                "<ModifyTime></ModifyTime>" +
                "<RetreatDateTime></RetreatDateTime>" +
                "<RetreatUserID></RetreatUserID>" +
                "<RetreatUserName></RetreatUserName>" +
                "<PaymentMethodCode></PaymentMethodCode>" +
                "<PaymentMethod></PaymentMethod>" +
                "<RegisterFee></RegisterFee>" +
                "<MedicalFee></MedicalFee>" +
                "<OtherFee></OtherFee>" +
                "<TotalFee></TotalFee>" +
                "<MedicalFloor>N</MedicalFloor>" +
                "<MedicalAddress></MedicalAddress>" +
                "<LastDeptCode></LastDeptCode>" +
                "<LastDeptName></LastDeptName>" +
                "<LastDoctorID></LastDoctorID>" +
                "<LastDoctorName></LastDoctorName>" +
                "<LastTreatDateTime></LastTreatDateTime>" +
                "<LastOpid></LastOpid>" +
                "<NumTypeCode>0</NumTypeCode>" +
                "<NumTypeName></NumTypeName>" +
                "<RegisterSource>1</RegisterSource>" +
                "<AcctNO></AcctNO>" +
                "<IsAcct>N</IsAcct>" +
                "<ManageType>" + manageType + "</ManageType>" +
                "<Times>" + registerCon + "</Times>" +
                "</OutRegister>" +
                "<PatientInfo>" +
                "<RecordFlow>" + outpatientDO.getId() + "</RecordFlow>" +
                "<PID>" + patientMappingCode + "</PID></PatientInfo></HtRequest>";
//            String xmlStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
//                    "<HtRequest >" +
//                    "<PatientInfo>" +
@ -1501,134 +1543,142 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
//                    "<RhBloodType></RhBloodType>" +
//                    "</PatientInfo>" +
//                    "</HtRequest>";
            String returnValue = "";
            params.put("xmlStr",_xmlStr);
        
            returnValue = WebserviceUtil.post("http://192.10.33.34:9080/HtMzWebService/services/Manage",
                    "http://business.htemr.haitaiinc.com",
                    "manageAdt",
                    params);
        
            logger.info("调用电子病历注册接口请求成功,返回值xmlstr:"+returnValue);
            
            return returnValue;
        String returnValue = "";
        params.put("xmlStr", _xmlStr);
        returnValue = WebserviceUtil.post("http://192.10.33.34:9080/HtMzWebService/services/Manage",
                "http://business.htemr.haitaiinc.com",
                "manageAdt",
                params);
        logger.info("调用电子病历注册接口请求成功,返回值xmlstr:" + returnValue);
        return returnValue;
    }
    /**
     * 获取诊断
     *
     * @param pyKey
     * @return
     * @throws Exception
     */
    public JSONArray getICD10(String pyKey)throws Exception{
        return entranceService.MS25001(pyKey,demoFlag);
    public JSONArray getICD10(String pyKey) throws Exception {
        return entranceService.MS25001(pyKey, demoFlag);
    }
    /**
     * 获取药品
     *
     * @return
     */
    public JSONArray getDrugDictionary(String chargeCode,String pyKey,String winNo,String groupNo)throws Exception{
        return entranceService.MS53001(chargeCode,pyKey,"0",winNo,"0",groupNo,demoFlag);
    public JSONArray getDrugDictionary(String chargeCode, String pyKey, String winNo, String groupNo) throws Exception {
        return entranceService.MS53001(chargeCode, pyKey, "0", winNo, "0", groupNo, demoFlag);
    }
    /**
     * 获取药品用法
     */
    public JSONArray getDrugUse(String drugNo,String pyKey)throws Exception{
        return entranceService.BS10110(drugNo,pyKey,demoFlag);
    public JSONArray getDrugUse(String drugNo, String pyKey) throws Exception {
        return entranceService.BS10110(drugNo, pyKey, demoFlag);
    }
    /**
     * 医院频次
     *
     * @return
     */
    public JSONArray getDrugFrequency()throws Exception{
    public JSONArray getDrugFrequency() throws Exception {
        return entranceService.MS30012(demoFlag);
    }
    /**
     * 检查模板选择接口
     *
     * @param bz_code
     * @param flag
     * @return
     * @throws Exception
     */
    public JSONArray getJcmb(String bz_code,String tc_no,String flag)throws Exception{
        return entranceService.BS25033(bz_code,tc_no,flag,demoFlag);
    public JSONArray getJcmb(String bz_code, String tc_no, String flag) throws Exception {
        return entranceService.BS25033(bz_code, tc_no, flag, demoFlag);
    }
    /**
     * 检验选择接口
     *
     * @param bz_code
     * @param flag
     * @return
     * @throws Exception
     */
    public JSONArray getJymb(String bz_code,String tc_no,String flag)throws Exception{
        return entranceService.BS20030(bz_code,tc_no,flag,demoFlag);
    public JSONArray getJymb(String bz_code, String tc_no, String flag) throws Exception {
        return entranceService.BS20030(bz_code, tc_no, flag, demoFlag);
    }
    /**
     * 套餐选择接口
     *
     * @param bz_code
     * @param flag
     * @return
     * @throws Exception
     */
    public JSONArray getTcxz(String bz_code,String tc_no,String flag)throws Exception{
        return entranceService.MS02017(bz_code,tc_no,flag,demoFlag);
    public JSONArray getTcxz(String bz_code, String tc_no, String flag) throws Exception {
        return entranceService.MS02017(bz_code, tc_no, flag, demoFlag);
    }
    /**
     * 套餐子项目接口
     *
     * @param parent_code 检查检验项目的charge_code
     * @return
     * @throws Exception
     */
    public JSONArray getTcChild(String parent_code)throws Exception{
        return entranceService.MS02015(parent_code,demoFlag);
    public JSONArray getTcChild(String parent_code) throws Exception {
        return entranceService.MS02015(parent_code, demoFlag);
    }
    /**
     * 项目子项目接口
     *
     * @param zd_charge_code
     * @return
     * @throws Exception
     */
    public JSONArray getInsChild(String zd_charge_code)throws Exception{
        return entranceService.MS02016(zd_charge_code,demoFlag);
    public JSONArray getInsChild(String zd_charge_code) throws Exception {
        return entranceService.MS02016(zd_charge_code, demoFlag);
    }
    /**
     * 获取检查检验
     *
     * @return
     */
    public JSONArray getInspectionDictionary(String pyKey,String codes,String winNo)throws Exception{
        JSONArray rs = entranceService.MS25002(pyKey,codes,winNo,demoFlag);
        if(rs!=null&&rs.size()>0){
    public JSONArray getInspectionDictionary(String pyKey, String codes, String winNo) throws Exception {
        JSONArray rs = entranceService.MS25002(pyKey, codes, winNo, demoFlag);
        if (rs != null && rs.size() > 0) {
            //设置科室翻译名称字典,减少循环层级降低循环次数
            List<DictHospitalDeptDO> depts =dictHospitalDeptDao.findByOrgCode("350211A1002");
            Map<String,String> deptDictMap = new HashedMap();
            for(DictHospitalDeptDO dp:depts){
                deptDictMap.put(dp.getCode(),dp.getName());
            List<DictHospitalDeptDO> depts = dictHospitalDeptDao.findByOrgCode("350211A1002");
            Map<String, String> deptDictMap = new HashedMap();
            for (DictHospitalDeptDO dp : depts) {
                deptDictMap.put(dp.getCode(), dp.getName());
            }
            //翻译执行科室
            for(int i=0;i<rs.size();i++){
                JSONObject dict = (JSONObject)rs.get(i);
            for (int i = 0; i < rs.size(); i++) {
                JSONObject dict = (JSONObject) rs.get(i);
                String dept = dict.getString("exec_unit");
                if(StringUtils.isNotBlank(dept)){
                if (StringUtils.isNotBlank(dept)) {
                    String deptName = deptDictMap.get(dept);
                    if(StringUtils.isNotBlank(deptName)){
                        dict.put("exec_unit_name",deptName);
                    }else{
                        dict.put("exec_unit_name","");
                    if (StringUtils.isNotBlank(deptName)) {
                        dict.put("exec_unit_name", deptName);
                    } else {
                        dict.put("exec_unit_name", "");
                    }
                }
            }
@ -1638,16 +1688,17 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 下诊断,线上开方
     *
     * @param outPatientId
     * @param advice
     * @param type 1带处方,2不带处方
     * @param type          1带处方,2不带处方
     * @param infoJsons
     * @param diagnosisJson
     * @return
     */
    public Map<String,Object> makeDiagnosis(String outPatientId,String advice,String type,String infoJsons,String diagnosisJson,String inspectionJson)throws Exception{
    public Map<String, Object> makeDiagnosis(String outPatientId, String advice, String type, String infoJsons, String diagnosisJson, String inspectionJson) throws Exception {
        Map<String,Object> result = new HashedMap();
        Map<String, Object> result = new HashedMap();
        //获取门诊记录
        WlyyOutpatientDO outpatientDO = outpatientDao.findOne(outPatientId);
@ -1658,9 +1709,9 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        //创建处方记录
        List<WlyyPrescriptionDO> prescriptionDOs = prescriptionDao.findByOutpatientId(outPatientId);
        WlyyPrescriptionDO prescriptionDO = null;
        if(prescriptionDOs!=null&&prescriptionDOs.size()>0){
        if (prescriptionDOs != null && prescriptionDOs.size() > 0) {
            prescriptionDO = prescriptionDOs.get(0);
        }else{
        } else {
            prescriptionDO = new WlyyPrescriptionDO();
            prescriptionDO.setOutpatientId(outPatientId);
        }
@ -1675,44 +1726,44 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        //========================处方操作结束=============================================================
        //加入处方状态变更流水日志
        prescriptionLogService.addPrescriptionLog(prescription.getId(),10,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
        prescriptionLogService.addPrescriptionLog(prescription.getId(), 10, 2, outpatientDO.getDoctor(), outpatientDO.getDoctorName(), "", new Date());
        //============================下诊断==============================================================
        //删除之前诊断
        List<WlyyPrescriptionDiagnosisDO> ds = prescriptionDiagnosisDao.findByPrescriptionId(prescription.getId());
        if(ds!=null&&ds.size()>0){
        if (ds != null && ds.size() > 0) {
            prescriptionDiagnosisDao.delete(ds);
        }
        List<WlyyPrescriptionDiagnosisDO> diagnosisDOs = (List<WlyyPrescriptionDiagnosisDO>) com.alibaba.fastjson.JSONArray.parseArray(diagnosisJson, WlyyPrescriptionDiagnosisDO.class);
        String Icd10 = "";
        String Icd10Name = "";
        for(WlyyPrescriptionDiagnosisDO diagnosisDO:diagnosisDOs){
            if("1".equals(diagnosisDO.getType())){
                Icd10 = diagnosisDO.getCode()+","+Icd10;
                Icd10Name+=diagnosisDO.getName()+","+Icd10Name;
            }else {
                Icd10+=diagnosisDO.getCode()+",";
                Icd10Name+=diagnosisDO.getName()+",";
        for (WlyyPrescriptionDiagnosisDO diagnosisDO : diagnosisDOs) {
            if ("1".equals(diagnosisDO.getType())) {
                Icd10 = diagnosisDO.getCode() + "," + Icd10;
                Icd10Name += diagnosisDO.getName() + "," + Icd10Name;
            } else {
                Icd10 += diagnosisDO.getCode() + ",";
                Icd10Name += diagnosisDO.getName() + ",";
            }
            diagnosisDO.setPrescriptionId(prescription.getId());
        }
        prescriptionDiagnosisDao.save(diagnosisDOs);
        //存储icd10
        Icd10 = Icd10.substring(0,Icd10.length()-1);
        Icd10Name = Icd10Name.substring(0,Icd10Name.length()-1);
        Icd10 = Icd10.substring(0, Icd10.length() - 1);
        Icd10Name = Icd10Name.substring(0, Icd10Name.length() - 1);
        outpatientDO.setIcd10(Icd10);
        outpatientDO.setIcd10Name(Icd10Name);
        outpatientDao.save(outpatientDO);
        //============================下诊断end==============================================================
        //判断是否有检查检验或药品开方
        if("1".equals(type)){
        if ("1".equals(type)) {
            //doctor转换为his医生
            DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(),outpatientDO.getHospital());
            if(doctorMappingDO==null){
            DoctorMappingDO doctorMappingDO = doctorMappingService.findMappingCode(outpatientDO.getDoctor(), outpatientDO.getHospital());
            if (doctorMappingDO == null) {
                throw new RuntimeException("未找到医生映射信息");
            }
@ -1722,22 +1773,22 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            //===================药品操作======================================================
            // 删除原有药品信息
            List<WlyyPrescriptionInfoDO> oldInfos = prescriptionInfoDao.findByPrescriptionId(prescription.getId());
            if(oldInfos!=null&&oldInfos.size()>0){
            if (oldInfos != null && oldInfos.size() > 0) {
                prescriptionInfoDao.delete(oldInfos);
            }
            //存储药品,构建his开方入参
            if(StringUtils.isNotBlank(infoJsons)){
            if (StringUtils.isNotBlank(infoJsons)) {
                //药品
                List<WlyyPrescriptionInfoDO> infoDOs = (List<WlyyPrescriptionInfoDO>) com.alibaba.fastjson.JSONArray.parseArray(infoJsons, WlyyPrescriptionInfoDO.class);
                for(WlyyPrescriptionInfoDO info:infoDOs){
                for (WlyyPrescriptionInfoDO info : infoDOs) {
                    info.setDel(1);
                    info.setPrescriptionId(prescription.getId());
                    //设置his药品查询条件
                    setInfoJsonParam(jsonData,doctorMappingDO,outpatientDO,prescriptionDO,info,Icd10);
                    setInfoJsonParam(jsonData, doctorMappingDO, outpatientDO, prescriptionDO, info, Icd10);
                }
                //保存药品信息
                prescriptionInfoDao.save(infoDOs);
@ -1752,20 +1803,20 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            //存储检查检验,构建his开方入参
            //删除之前检查检验
            List<WlyyInspectionDO> inspectionDels = wlyyInspectionDao.findByOutpatientId(outPatientId);
            if(inspectionDels!=null&&inspectionDels.size()>0){
            if (inspectionDels != null && inspectionDels.size() > 0) {
                wlyyInspectionDao.delete(inspectionDels);
            }
            if(StringUtils.isNotBlank(inspectionJson)){
            if (StringUtils.isNotBlank(inspectionJson)) {
                List<WlyyInspectionDO> inspections = (List<WlyyInspectionDO>) com.alibaba.fastjson.JSONArray.parseArray(inspectionJson, WlyyInspectionDO.class);
                for(WlyyInspectionDO ins:inspections){
                for (WlyyInspectionDO ins : inspections) {
                    ins.setCreateTime(new Date());
                    ins.setPrescriptionId(prescription.getId());
                    ins.setOutpatientId(outPatientId);
                    //设置his药品查询条件
                    setInspectionParam(jsonData,doctorMappingDO,outpatientDO,prescriptionDO,ins,Icd10);
                    setInspectionParam(jsonData, doctorMappingDO, outpatientDO, prescriptionDO, ins, Icd10);
                }
                //保存检查检验。
                wlyyInspectionDao.save(inspections);
@ -1781,14 +1832,14 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            prescriptionDao.save(prescription);
            //上传his开方
            return sendHisDiagnosis(jsonData,outpatientDO,prescription);
            return sendHisDiagnosis(jsonData, outpatientDO, prescription);
        }else{
        } else {
            outpatientDO.setStatus("2");
            outpatientDao.save(outpatientDO);
            result.put("code",1);
            result.put("mes","诊断完成");
            result.put("code", 1);
            result.put("mes", "诊断完成");
            return result;
        }
@ -1796,57 +1847,60 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 计算药品费用
     *
     * @param infoDOs
     * @return
     */
    public Double getInfoFee(List<WlyyPrescriptionInfoDO> infoDOs){
    public Double getInfoFee(List<WlyyPrescriptionInfoDO> infoDOs) {
        Double fee = 0D;
        try {
            if(infoDOs!=null&&infoDOs.size()>0){
                for(WlyyPrescriptionInfoDO info:infoDOs){
            if (infoDOs != null && infoDOs.size() > 0) {
                for (WlyyPrescriptionInfoDO info : infoDOs) {
                    Integer quantity = Integer.parseInt(info.getQuantity());
                    fee += info.getPackRetprice()*quantity;
                    fee += info.getPackRetprice() * quantity;
                }
            }
        }catch (Exception e){
            logger.error("getInfoFee:"+e.toString());
        } catch (Exception e) {
            logger.error("getInfoFee:" + e.toString());
        }
        return fee;
    }
    /**
     * 计算检查检验费用
     *
     * @param inspections
     * @return
     */
    public Double getInsFee(List<WlyyInspectionDO> inspections){
    public Double getInsFee(List<WlyyInspectionDO> inspections) {
        Double fee = 0D;
        try {
            if(inspections!=null&&inspections.size()>0){
                for(WlyyInspectionDO ins:inspections){
            if (inspections != null && inspections.size() > 0) {
                for (WlyyInspectionDO ins : inspections) {
                    Double chargeAmount = Double.parseDouble(ins.getChargeAmount());
                    fee += chargeAmount*ins.getQuantity();
                    fee += chargeAmount * ins.getQuantity();
                }
            }
        }catch (Exception e){
            logger.error("getInsFee:"+e.toString());
        } catch (Exception e) {
            logger.error("getInsFee:" + e.toString());
        }
        return fee;
    }
    /**
     * 计算挂号费用
     *
     * @param doctor
     * @return
     */
    public Double getChargeFee(String doctor){
    public Double getChargeFee(String doctor) {
        Double fee = 0D;
        try{
        try {
            BaseDoctorDO doctorDO = baseDoctorDao.findById(doctor);
            WlyyChargeDictDO chargeDictDO = wlyyChargeDictDao.findByChargeTypeAndDeptTypeCode(doctorDO.getChargeType(),"6");
            WlyyChargeDictDO chargeDictDO = wlyyChargeDictDao.findByChargeTypeAndDeptTypeCode(doctorDO.getChargeType(), "6");
            return chargeDictDO.getReqFee();
        }catch (Exception e){
            logger.error("getChargeFee:"+e.toString());
        } catch (Exception e) {
            logger.error("getChargeFee:" + e.toString());
        }
        return fee;
@ -1854,18 +1908,19 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 上传his开方
     *
     * @param jsonData
     * @param outpatientDO
     * @param prescription
     * @return
     * @throws Exception
     */
    public Map<String,Object> sendHisDiagnosis(com.alibaba.fastjson.JSONArray jsonData,WlyyOutpatientDO outpatientDO,WlyyPrescriptionDO prescription)throws Exception{
        Map<String,Object> result = new HashedMap();
    public Map<String, Object> sendHisDiagnosis(com.alibaba.fastjson.JSONArray jsonData, WlyyOutpatientDO outpatientDO, WlyyPrescriptionDO prescription) throws Exception {
        Map<String, Object> result = new HashedMap();
        //调用his开方接口
        net.sf.json.JSONObject jsonObject = entranceService.BS10112(jsonData.toJSONString(),demoFlag);
        net.sf.json.JSONObject jsonObject = entranceService.BS10112(jsonData.toJSONString(), demoFlag);
        //如果无法解析his系统报文,his系统报错
        if(jsonObject==null){
        if (jsonObject == null) {
            //记录http日志
            WlyyHttpLogDO log = new WlyyHttpLogDO();
            log.setCode("makeDiagnosis");
@ -1882,15 +1937,15 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            prescription.setStatus(13);
            prescriptionDao.save(prescription);
            //记录开发失败日志
            prescriptionLogService.addPrescriptionLog(prescription.getId(),13,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
            prescriptionLogService.addPrescriptionLog(prescription.getId(), 13, 2, outpatientDO.getDoctor(), outpatientDO.getDoctorName(), "", new Date());
            //开方失败返回值
            result.put("code",-1);
            result.put("mes","开方失败,his系统异常");
            result.put("code", -1);
            result.put("mes", "开方失败,his系统异常");
            return result;
        }
        logger.info("调用his开方接口: "+jsonObject.toString());
        logger.info("调用his开方接口: " + jsonObject.toString());
        //判断返回结果
        String rs = jsonObject.getString("@RESULT");
        //保存日志
@ -1905,7 +1960,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        log.setCreateTime(new Date());
        wlyyHttpLogDao.save(log);
        if("0".equals(rs)){
        if ("0".equals(rs)) {
            String admNo = jsonObject.getString("@ADM_NO");
            String realOrder = jsonObject.getString("@real_order");
@ -1915,19 +1970,19 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            outpatientDO.setAdmNo(admNo);
            outpatientDao.save(outpatientDO);
            result.put("code",1);
            result.put("mes","开方提交成功");
            result.put("code", 1);
            result.put("mes", "开方提交成功");
            return result;
        }else{
        } else {
            //开方失败
            result.put("code",-1);
            result.put("mes",jsonObject.getString("@MSG"));
            result.put("code", -1);
            result.put("mes", jsonObject.getString("@MSG"));
            //更新处方状态
            prescription.setStatus(13);
            prescriptionDao.save(prescription);
            //记录开发失败日志
            prescriptionLogService.addPrescriptionLog(prescription.getId(),13,2,outpatientDO.getDoctor(),outpatientDO.getDoctorName(),"",new Date());
            prescriptionLogService.addPrescriptionLog(prescription.getId(), 13, 2, outpatientDO.getDoctor(), outpatientDO.getDoctorName(), "", new Date());
            return result;
        }
@ -1935,132 +1990,135 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    /**
     * 设置检查检验his入参
     *
     * @param jsonData
     * @param doctorMappingDO
     * @param outpatientDO
     * @param inspectionDO
     * @param Icd10
     */
    public void setInspectionParam(com.alibaba.fastjson.JSONArray jsonData,DoctorMappingDO doctorMappingDO,WlyyOutpatientDO outpatientDO,WlyyPrescriptionDO prescriptionDO,WlyyInspectionDO inspectionDO,String Icd10){
    public void setInspectionParam(com.alibaba.fastjson.JSONArray jsonData, DoctorMappingDO doctorMappingDO, WlyyOutpatientDO outpatientDO, WlyyPrescriptionDO prescriptionDO, WlyyInspectionDO inspectionDO, String Icd10) {
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        if(StringUtils.isNotBlank(prescriptionDO.getRealOrder())){
            json.put("realOrder",prescriptionDO.getRealOrder());
        if (StringUtils.isNotBlank(prescriptionDO.getRealOrder())) {
            json.put("realOrder", prescriptionDO.getRealOrder());
        }
        json.put("cardNo",outpatientDO.getCardNo());
        json.put("doctor",doctorMappingDO.getMappingCode());
        json.put("dept",outpatientDO.getDept());
        json.put("cardNo", outpatientDO.getCardNo());
        json.put("doctor", doctorMappingDO.getMappingCode());
        json.put("dept", outpatientDO.getDept());
        json.put("frequency",inspectionDO.getFrequency()); //组号
        json.put("quantity",inspectionDO.getQuantity()); //数量
        json.put("serialNo",outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo","00"); //-库房号
        json.put("serial","00"); //药品序列号-必输
        json.put("frequency", inspectionDO.getFrequency()); //组号
        json.put("quantity", inspectionDO.getQuantity()); //数量
        json.put("serialNo", outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo", "00"); //-库房号
        json.put("serial", "00"); //药品序列号-必输
        json.put("winNo",outpatientDO.getWinNo());
        json.put("chargeFlag",2); //项目类别-必输  1-药品 2检验检查
        json.put("winNo", outpatientDO.getWinNo());
        json.put("chargeFlag", 2); //项目类别-必输  1-药品 2检验检查
        /**
          *  code;//项目编码',
          *  name;//(检查方法)',
          *  information;//病史与体征',
          *  checkEquip;//类别',
          *  checkPart;//部位',
          *  adresult;//辅助检查治疗',
          *  goal;//检查目的',
          *  opview;//手术所见-病理申请单必填',
          *  specimenName;//标本名称-病理申请单必填',
          *  specimenNum;//标本数量-病理申请单必填',
          *  ywjcResult;//以往检查结果-病理申请单选填',
          *  ywjcDate;//以往检查时间-病理申请单选填 格式:yyyy-mm-dd',
          *  blzd;//病理诊断-病理申请单选填',
          *  fixationfluid;//固定液
         *  code;//项目编码',
         *  name;//(检查方法)',
         *  information;//病史与体征',
         *  checkEquip;//类别',
         *  checkPart;//部位',
         *  adresult;//辅助检查治疗',
         *  goal;//检查目的',
         *  opview;//手术所见-病理申请单必填',
         *  specimenName;//标本名称-病理申请单必填',
         *  specimenNum;//标本数量-病理申请单必填',
         *  ywjcResult;//以往检查结果-病理申请单选填',
         *  ywjcDate;//以往检查时间-病理申请单选填 格式:yyyy-mm-dd',
         *  blzd;//病理诊断-病理申请单选填',
         *  fixationfluid;//固定液
         */
        json.put("parentCode",inspectionDO.getParentCode()); //父节点
        json.put("chargeCode",inspectionDO.getCode()); //项目编码
        json.put("name",inspectionDO.getName()); //挂号流水号-必输
        json.put("information",inspectionDO.getInformation());//库房号-必输
        json.put("checkEquip",inspectionDO.getCheckEquip()); //药品序列号-必输
        json.put("checkPart",inspectionDO.getCheckPart());
        json.put("adresult",inspectionDO.getAdresult());
        json.put("goal",inspectionDO.getGoal());
        json.put("opview",inspectionDO.getOpview());
        json.put("specimenName",inspectionDO.getSpecimenName());
        json.put("specimenNum",inspectionDO.getSpecimenNum());
        json.put("ywjcResult",inspectionDO.getYwjcResult());
        json.put("ywjcDate",inspectionDO.getYwjcDate());
        json.put("blzd",inspectionDO.getBlzd());
        json.put("fixationfluid",inspectionDO.getFixationfluid());
        json.put("parentCode", inspectionDO.getParentCode()); //父节点
        json.put("chargeCode", inspectionDO.getCode()); //项目编码
        json.put("name", inspectionDO.getName()); //挂号流水号-必输
        json.put("information", inspectionDO.getInformation());//库房号-必输
        json.put("checkEquip", inspectionDO.getCheckEquip()); //药品序列号-必输
        json.put("checkPart", inspectionDO.getCheckPart());
        json.put("adresult", inspectionDO.getAdresult());
        json.put("goal", inspectionDO.getGoal());
        json.put("opview", inspectionDO.getOpview());
        json.put("specimenName", inspectionDO.getSpecimenName());
        json.put("specimenNum", inspectionDO.getSpecimenNum());
        json.put("ywjcResult", inspectionDO.getYwjcResult());
        json.put("ywjcDate", inspectionDO.getYwjcDate());
        json.put("blzd", inspectionDO.getBlzd());
        json.put("fixationfluid", inspectionDO.getFixationfluid());
        //设置诊断
        setIcd10(json,Icd10);
        setIcd10(json, Icd10);
        jsonData.add(json);
        logger.info("json:" +json.toString());
        logger.info("json:" + json.toString());
    }
    /**
     * 设置药品his入参
     *
     * @param jsonData
     * @param doctorMappingDO
     * @param outpatientDO
     * @param info
     * @param Icd10
     */
    public void setInfoJsonParam(com.alibaba.fastjson.JSONArray jsonData,DoctorMappingDO doctorMappingDO,WlyyOutpatientDO outpatientDO,WlyyPrescriptionDO prescriptionDO,WlyyPrescriptionInfoDO info,String Icd10){
    public void setInfoJsonParam(com.alibaba.fastjson.JSONArray jsonData, DoctorMappingDO doctorMappingDO, WlyyOutpatientDO outpatientDO, WlyyPrescriptionDO prescriptionDO, WlyyPrescriptionInfoDO info, String Icd10) {
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        if(StringUtils.isNotBlank(prescriptionDO.getRealOrder())){
            json.put("realOrder",prescriptionDO.getRealOrder());
        }
        json.put("cardNo",outpatientDO.getCardNo());
        json.put("doctor",doctorMappingDO.getMappingCode());
        json.put("dept",outpatientDO.getDept());
        json.put("chargeCode",info.getDrugNo());
        json.put("winNo",outpatientDO.getWinNo());
        json.put("chargeFlag",1); //项目类别-必输  1-药品 2检验检查
        json.put("quantity",info.getQuantity()); //数量-必输
        json.put("serialNo",outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo",info.getGroupNo());//库房号-必输
        json.put("serial",info.getSerial()); //药品序列号-必输
        json.put("dosage",info.getDosage());
        json.put("unit",info.getUnit());
        json.put("usage",info.getUsageCode());
        json.put("supplyCode",info.getSupplyCode());
        if(StringUtils.isNotBlank(info.getDays())){
            json.put("days",info.getDays());
        }else{
        if (StringUtils.isNotBlank(prescriptionDO.getRealOrder())) {
            json.put("realOrder", prescriptionDO.getRealOrder());
        }
        json.put("cardNo", outpatientDO.getCardNo());
        json.put("doctor", doctorMappingDO.getMappingCode());
        json.put("dept", outpatientDO.getDept());
        json.put("chargeCode", info.getDrugNo());
        json.put("winNo", outpatientDO.getWinNo());
        json.put("chargeFlag", 1); //项目类别-必输  1-药品 2检验检查
        json.put("quantity", info.getQuantity()); //数量-必输
        json.put("serialNo", outpatientDO.getRegisterNo()); //挂号流水号-必输
        json.put("groupNo", info.getGroupNo());//库房号-必输
        json.put("serial", info.getSerial()); //药品序列号-必输
        json.put("dosage", info.getDosage());
        json.put("unit", info.getUnit());
        json.put("usage", info.getUsageCode());
        json.put("supplyCode", info.getSupplyCode());
        if (StringUtils.isNotBlank(info.getDays())) {
            json.put("days", info.getDays());
        } else {
            //如果是中草药,贴数为天数,没有默认1天
            json.put("days",StringUtils.isNotBlank(info.getPostCount())?info.getPostCount():"1");
            json.put("days", StringUtils.isNotBlank(info.getPostCount()) ? info.getPostCount() : "1");
        }
        json.put("frequency",info.getFrequency());
        json.put("comm",info.getComm());
        json.put("frequency", info.getFrequency());
        json.put("comm", info.getComm());
        //设置诊断
        setIcd10(json,Icd10);
        setIcd10(json, Icd10);
        jsonData.add(json);
        logger.info("json:" +json.toString());
        logger.info("json:" + json.toString());
    }
    public void setIcd10(com.alibaba.fastjson.JSONObject json,String Icd10){
    public void setIcd10(com.alibaba.fastjson.JSONObject json, String Icd10) {
        String Icd10s[] = Icd10.split(",");
        for(int i=0;i<Icd10s.length;i++){
            if(i==0){
                json.put("icdCode",Icd10s[i]);
            }else if(i==1){
                json.put("diagTwo",Icd10s[i]);
            }else if(i==2){
                json.put("diagThree",Icd10s[i]);
            }else if(i==3){
                json.put("diagFour",Icd10s[i]);
            }else if(i==4){
                json.put("diagFive",Icd10s[i]);
        for (int i = 0; i < Icd10s.length; i++) {
            if (i == 0) {
                json.put("icdCode", Icd10s[i]);
            } else if (i == 1) {
                json.put("diagTwo", Icd10s[i]);
            } else if (i == 2) {
                json.put("diagThree", Icd10s[i]);
            } else if (i == 3) {
                json.put("diagFour", Icd10s[i]);
            } else if (i == 4) {
                json.put("diagFive", Icd10s[i]);
            }
        }
    }
    /**
     * 订单查询
     *
     * @param status
     * @param oneselfPickupFlg
     * @param nameKey
@ -2070,8 +2128,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @param size
     * @return
     */
    public MixEnvelop findExpressageList(String status,String oneselfPickupFlg,String nameKey,String startTime,String endTime,Integer page,Integer size){
        String totalSql="SELECT " +
    public MixEnvelop findExpressageList(String status, String oneselfPickupFlg, String nameKey, String startTime, String endTime, Integer page, Integer size) {
        String totalSql = "SELECT " +
                " COUNT(1) AS total " +
                " FROM " +
                " wlyy_outpatient o " +
@ -2079,20 +2137,20 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id" +
                " WHERE" +
                " 1=1";
        if(StringUtils.isNotBlank(status)){
            totalSql+=" AND p.status in("+status+")";
        if (StringUtils.isNotBlank(status)) {
            totalSql += " AND p.status in(" + status + ")";
        }
        if(StringUtils.isNotBlank(oneselfPickupFlg)){
            totalSql+=" AND e.oneself_pickup_flg ="+oneselfPickupFlg;
        if (StringUtils.isNotBlank(oneselfPickupFlg)) {
            totalSql += " AND e.oneself_pickup_flg =" + oneselfPickupFlg;
        }
        if(StringUtils.isNotBlank(nameKey)){
            totalSql+=" AND e.name like '%"+nameKey+"%'";
        if (StringUtils.isNotBlank(nameKey)) {
            totalSql += " AND e.name like '%" + nameKey + "%'";
        }
        if(StringUtils.isNotBlank(startTime)){
            totalSql+=" AND e.create_time >='"+startTime+" 00:00:00'";
        if (StringUtils.isNotBlank(startTime)) {
            totalSql += " AND e.create_time >='" + startTime + " 00:00:00'";
        }
        if(StringUtils.isNotBlank(endTime)){
            totalSql+=" AND e.create_time <='"+endTime+" 23:59:59'";
        if (StringUtils.isNotBlank(endTime)) {
            totalSql += " AND e.create_time <='" + endTime + " 23:59:59'";
        }
        List<Map<String, Object>> rstotal = jdbcTemplate.queryForList(totalSql);
@ -2100,7 +2158,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if (rstotal != null && rstotal.size() > 0) {
            count = (Long) rstotal.get(0).get("total");
        }
        String sql ="SELECT " +
        String sql = "SELECT " +
                " e.create_time AS createTime, " +
                " e.`name`, " +
                " e.oneself_pickup_flg AS oneselfPickupFlg, " +
@ -2115,44 +2173,44 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                " JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id " +
                " WHERE" +
                " 1=1";
        if(StringUtils.isNotBlank(status)){
            sql+=" AND p.status in("+status+")";
        if (StringUtils.isNotBlank(status)) {
            sql += " AND p.status in(" + status + ")";
        }
        if(StringUtils.isNotBlank(oneselfPickupFlg)){
            sql+=" AND e.oneself_pickup_flg ="+oneselfPickupFlg;
        if (StringUtils.isNotBlank(oneselfPickupFlg)) {
            sql += " AND e.oneself_pickup_flg =" + oneselfPickupFlg;
        }
        if(StringUtils.isNotBlank(nameKey)){
            sql+=" AND e.name like '%"+nameKey+"%'";
        if (StringUtils.isNotBlank(nameKey)) {
            sql += " AND e.name like '%" + nameKey + "%'";
        }
        if(StringUtils.isNotBlank(startTime)){
            sql+=" AND e.create_time >='"+startTime+" 00:00:00'";
        if (StringUtils.isNotBlank(startTime)) {
            sql += " AND e.create_time >='" + startTime + " 00:00:00'";
        }
        if(StringUtils.isNotBlank(endTime)){
            sql+=" AND e.create_time <='"+endTime+" 23:59:59'";
        if (StringUtils.isNotBlank(endTime)) {
            sql += " AND e.create_time <='" + endTime + " 23:59:59'";
        }
        sql += " LIMIT " + (page - 1) * size + "," + size + "";
        List<Map<String,Object>> list = jdbcTemplate.queryForList(sql);
        List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
        return MixEnvelop.getSuccessListWithPage(BaseHospitalRequestMapping.Prescription.api_success, list, page, size, count);
    }
    public Boolean setMailno(String mailno, String expressageId){
        WlyyPrescriptionExpressageDO expressageDO =  prescriptionExpressageDao.findOne(expressageId);
    public Boolean setMailno(String mailno, String expressageId) {
        WlyyPrescriptionExpressageDO expressageDO = prescriptionExpressageDao.findOne(expressageId);
        expressageDO.setMailno(mailno);
        prescriptionExpressageDao.save(expressageDO);
        return true;
    }
    public void pushListWrite(OutputStream os, List<Map<String,Object>> ls) throws Exception{
    public void pushListWrite(OutputStream os, List<Map<String, Object>> ls) throws Exception {
        WritableWorkbook wwb = jxl.Workbook.createWorkbook(os);
        try {
            WritableSheet ws;
            ws = wwb.createSheet("sheet",1);
            ws = wwb.createSheet("sheet", 1);
            String[] header = {"订单日期","收货人","诊断结果","配送方式", "订单状态"};
            String[] header = {"订单日期", "收货人", "诊断结果", "配送方式", "订单状态"};
            int k = 0;
            for (String h : header) {
                addCell(ws, 0, k, h);//表名,行,列,header
@ -2160,12 +2218,12 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            }
            int i = 1;
            for (Map<String,Object> m : ls) {
                addCell(ws, i, 0, DateUtil.dateToStr((Date)m.get("createTime"),"yyyy-MM-dd HH:mm:ss"),"");
                addCell(ws, i, 1, (String)m.get("name"),"");
                addCell(ws, i, 2, (String)m.get("icd10Name"),"");
                addCell(ws, i, 3, getOneselfPickupFlgString((Integer)m.get("oneselfPickupFlg")),"");
                addCell(ws, i, 4, getStatusName((Integer)m.get("status")),"");
            for (Map<String, Object> m : ls) {
                addCell(ws, i, 0, DateUtil.dateToStr((Date) m.get("createTime"), "yyyy-MM-dd HH:mm:ss"), "");
                addCell(ws, i, 1, (String) m.get("name"), "");
                addCell(ws, i, 2, (String) m.get("icd10Name"), "");
                addCell(ws, i, 3, getOneselfPickupFlgString((Integer) m.get("oneselfPickupFlg")), "");
                addCell(ws, i, 4, getStatusName((Integer) m.get("status")), "");
                i++;
            }
            wwb.write();
@ -2178,45 +2236,44 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
    }
    /**
     *
     * @return
     */
    public String getOneselfPickupFlgString(Integer oneselfPickupFlg){
        if(1 == oneselfPickupFlg){
    public String getOneselfPickupFlgString(Integer oneselfPickupFlg) {
        if (1 == oneselfPickupFlg) {
            return "自取";
        }else if(0 == oneselfPickupFlg){
        } else if (0 == oneselfPickupFlg) {
            return "快递";
        }else{
        } else {
            return "其他";
        }
    }
    /**
     *
     * @param status
     * @return
     */
    public String getStatusName(Integer status){
        if(31==status){
    public String getStatusName(Integer status) {
        if (31 == status) {
            return "待配送";
        }else if(32==status){
        } else if (32 == status) {
            return "配送中";
        }else if(100==status){
        } else if (100 == status) {
            return "已完成";
        }else{
        } else {
            return "其他";
        }
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column,  String data) throws WriteException {
        Label label = new Label(column ,row, data);
    public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
        Label label = new Label(column, row, data);
        ws.addCell(label);
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data, String memo) throws WriteException {
        Label label = new Label(column ,row, data);
        if(!org.springframework.util.StringUtils.isEmpty(memo)){
        Label label = new Label(column, row, data);
        if (!org.springframework.util.StringUtils.isEmpty(memo)) {
            WritableCellFeatures cellFeatures = new WritableCellFeatures();
            cellFeatures.setComment(memo);
            label.setCellFeatures(cellFeatures);
@ -2224,147 +2281,274 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        ws.addCell(label);
    }
    public List<WlyyChargeDictVO> findByDeptTypeCode(String deptTypeCode){
    public List<WlyyChargeDictVO> findByDeptTypeCode(String deptTypeCode) {
        List<WlyyChargeDictDO> dictDOs = wlyyChargeDictDao.findByDeptTypeCode(deptTypeCode);
        List<WlyyChargeDictVO> dictVOs = new ArrayList<>();
        return convertToModels(dictDOs,dictVOs,WlyyChargeDictVO.class);
        return convertToModels(dictDOs, dictVOs, WlyyChargeDictVO.class);
    }
    public List<WlyyDoctorWorkTimeVO> findDoctorWorkTime(String doctor){
        //获取医生排班规则
        List<WlyyHospitalSysDictDO> list = sysDictDao.findByDictName("Scheduling");
        Calendar ncTime = Calendar.getInstance();
        ncTime.setTime(new Date());
//      过时
//    public List<WlyyDoctorWorkTimeVO> findDoctorWorkTime(String doctor) {
//        //获取医生排班规则
//        List<WlyyHospitalSysDictDO> list = sysDictDao.findByDictName("Scheduling");
//
//        Calendar ncTime = Calendar.getInstance();
//        ncTime.setTime(new Date());
//
//        Calendar scTime = Calendar.getInstance();
//        scTime.setTime(new Date());
//
//        Calendar ecTime = Calendar.getInstance();
//        ecTime.setTime(new Date());
//
//        //设置几天号源,及最后天号源的开放时间
//        int days = Integer.parseInt(findHospitalSysDictValue(list, "OpenDays"));
//        String closeTime = findHospitalSysDictValue(list, "CloseTime");
//
//        //比较当前时间是否超过开放时间
//        if (DateUtil.strToDate(DateUtil.getTimeShort(), DateUtil.HH_MM_SS).after(DateUtil.strToDate(closeTime, DateUtil.HH_MM))) {
//            //当前时间超过开放时间,可以预约最后一天全部号源
//            ecTime.add(Calendar.DAY_OF_MONTH, days);
//            ecTime.set(ecTime.get(Calendar.YEAR), ecTime.get(Calendar.MONTH), ecTime.get(Calendar.DATE), 23, 59, 59);
//        } else {
//            //当前时间没超过开放时间,可以预约最后一天前一天全部号源
//            ecTime.add(Calendar.DAY_OF_MONTH, days > 1 ? days - 1 : 0);
//            ecTime.set(ecTime.get(Calendar.YEAR), ecTime.get(Calendar.MONTH), ecTime.get(Calendar.DATE), 23, 59, 59);
//        }
//
//
//        List<WlyyDoctorWorkTimeDO> times = doctorWorkTimeDao.findDoctorWorkTime(doctor, scTime.getTime(), ecTime.getTime());
//
//        workTimeFilter(list, times);
//
//        List<WlyyDoctorWorkTimeVO> timeVOs = new ArrayList<>();
//
//        convertToModels(times, timeVOs, WlyyDoctorWorkTimeVO.class);
//
//        if (timeVOs != null && timeVOs.size() > 0) {
//            for (WlyyDoctorWorkTimeVO timeVO : timeVOs) {
//                timeVO.setCount(findWorkTimeCount(timeVO.getId()));
//            }
//        }
//        return timeVOs;
//    }
        Calendar scTime = Calendar.getInstance();
        scTime.setTime(new Date());
//    public List<WlyyDoctorWorkTimeDO> workTimeFilter(List<WlyyHospitalSysDictDO> sys, List<WlyyDoctorWorkTimeDO> times) {
//
//        if (times != null && times.size() > 0) {
//            //上午号源开放的最早天数
//            int AMCloseDays = Integer.parseInt(findHospitalSysDictValue(sys, "AMCloseDays"));
//            //每一天上午的最早预约的过号时间
//            String AMCloseTime = findHospitalSysDictValue(sys, "AMCloseTime");
//            //下午号源开放的最早天数
//            int PMCloseDays = Integer.parseInt(findHospitalSysDictValue(sys, "PMCloseDays"));
//            //每一天下午的最早预约的过号时间
//            String PMCloseTime = findHospitalSysDictValue(sys, "PMCloseTime");
//
//            Iterator it = times.iterator();
//            while (it.hasNext()) {
//                //设置上午过号时间
//                Calendar scAMTime = Calendar.getInstance();
//                scAMTime.setTime(new Date());
//                scAMTime.add(Calendar.DAY_OF_MONTH, AMCloseDays);
//
//                //设置下午午过号时间
//                Calendar scPMTime = Calendar.getInstance();
//                scPMTime.setTime(new Date());
//                scPMTime.add(Calendar.DAY_OF_MONTH, PMCloseDays);
//
//                WlyyDoctorWorkTimeDO time = (WlyyDoctorWorkTimeDO) it.next();
//
//                Boolean filter = true;
//
//                //1.【上午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除
//                if (filter && "1".equals(time.getTimeType()) && time.getEndTime().before(scAMTime.getTime())) {
//                    it.remove();
//                    filter = false;
//                }
//
//                //2.【下午午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除该排班
//                if (filter && "2".equals(time.getTimeType()) && time.getEndTime().before(scPMTime.getTime())) {
//                    it.remove();
//                    filter = false;
//                }
//
//                //3.如果【当前时间】过了【上午放号时间】,则移除所有上午的排班
//                if (filter && "1".equals(time.getTimeType()) &&
//                        DateUtil.strToDate(DateUtil.getTimeShort(), DateUtil.HH_MM_SS).after(DateUtil.strToDate(AMCloseTime, DateUtil.HH_MM))) {
//                    scAMTime.set(scAMTime.get(Calendar.YEAR), scAMTime.get(Calendar.MONTH), scAMTime.get(Calendar.DATE), 12, 00, 00);
//
//                    if (time.getEndTime().before(scAMTime.getTime())) {
//                        it.remove();
//                        filter = false;
//                    }
//                }
//                //4.如果【当前时间】过了【下午午放号时间】,则移除所有下午的排班
//                if (filter && "2".equals(time.getTimeType()) &&
//                        DateUtil.strToDate(DateUtil.getTimeShort(), DateUtil.HH_MM_SS).after(DateUtil.strToDate(PMCloseTime, DateUtil.HH_MM))) {
//                    scPMTime.set(scAMTime.get(Calendar.YEAR), scAMTime.get(Calendar.MONTH), scAMTime.get(Calendar.DATE), 12, 00, 00);
//
//                    if (time.getEndTime().before(scPMTime.getTime())) {
//                        it.remove();
//                    }
//                }
//            }
//        }
//        return times;
//    }
        Calendar ecTime = Calendar.getInstance();
        ecTime.setTime(new Date());
        //设置几天号源,及最后天号源的开放时间
        int days =Integer.parseInt(findHospitalSysDictValue(list,"OpenDays"));
        String closeTime = findHospitalSysDictValue(list,"CloseTime");
    public String findHospitalSysDictValue(List<WlyyHospitalSysDictDO> list, String dictCode) {
        //比较当前时间是否超过开放时间
        if(DateUtil.strToDate(DateUtil.getTimeShort(),DateUtil.HH_MM_SS).after(DateUtil.strToDate(closeTime,DateUtil.HH_MM))){
            //当前时间超过开放时间,可以预约最后一天全部号源
            ecTime.add(Calendar.DAY_OF_MONTH,days);
            ecTime.set(ecTime.get(Calendar.YEAR),ecTime.get(Calendar.MONTH),ecTime.get(Calendar.DATE),23,59,59);
        }else{
            //当前时间没超过开放时间,可以预约最后一天前一天全部号源
            ecTime.add(Calendar.DAY_OF_MONTH,days>1?days-1:0);
            ecTime.set(ecTime.get(Calendar.YEAR),ecTime.get(Calendar.MONTH),ecTime.get(Calendar.DATE),23,59,59);
        if (list != null && list.size() > 0) {
            for (WlyyHospitalSysDictDO sysDictDO : list) {
                if (dictCode.equals(sysDictDO.getDictCode())) {
                    return sysDictDO.getDictValue();
                }
            }
        }
        return "";
    }
    /**
     * 获取卡信息
     *
     * @param cardNo
     * @param demoFlag
     * @return
     * @throws Exception
     */
    public net.sf.json.JSONObject getCardInfo(String cardNo, boolean demoFlag) throws Exception {
        return entranceService.qutpatientBalance(cardNo, demoFlag);
    }
        List<WlyyDoctorWorkTimeDO> times =  doctorWorkTimeDao.findDoctorWorkTime(doctor,scTime.getTime(),ecTime.getTime());
    /**
     * 新排班号源详情
     * @param id
     * @return
     */
    public List<Map<String,Object>> findWorkTimeInfo(String id){
        WlyyDoctorWorkTimeDO timeDO = doctorWorkTimeDao.findOne(id);
        workTimeFilter(list,times);
        Long ss = timeDO.getEndTime().getTime()-timeDO.getStartTime().getTime();
        Long s = ss/timeDO.getSourceNumber();
        List<WlyyDoctorWorkTimeVO> timeVOs = new ArrayList<>();
        Calendar sc = Calendar.getInstance();
        sc.setTime(timeDO.getStartTime());
        convertToModels(times,timeVOs,WlyyDoctorWorkTimeVO.class);
        List<Map<String,Object>> rs = new ArrayList<>();
        if(timeVOs!=null&&timeVOs.size()>0){
            for(WlyyDoctorWorkTimeVO timeVO : timeVOs){
                timeVO.setCount(findWorkTimeCount(timeVO.getId()));
        //1.根据当前时间,去取已过时间的号源
        while (sc.getTime().before(timeDO.getEndTime())){
            if(new Date().before(sc.getTime())){
                break;
            }
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
        }
        return timeVOs;
    }
    public List<WlyyDoctorWorkTimeDO> workTimeFilter(List<WlyyHospitalSysDictDO> sys,List<WlyyDoctorWorkTimeDO> times){
        if(times!=null&&times.size()>0){
            //上午号源开放的最早天数
            int AMCloseDays =Integer.parseInt(findHospitalSysDictValue(sys,"AMCloseDays"));
            //每一天上午的最早预约的过号时间
            String AMCloseTime = findHospitalSysDictValue(sys,"AMCloseTime");
            //下午号源开放的最早天数
            int PMCloseDays =Integer.parseInt(findHospitalSysDictValue(sys,"PMCloseDays"));
            //每一天下午的最早预约的过号时间
            String PMCloseTime = findHospitalSysDictValue(sys,"PMCloseTime");
            Iterator it = times.iterator();
            while (it.hasNext()){
                //设置上午过号时间
                Calendar scAMTime = Calendar.getInstance();
                scAMTime.setTime(new Date());
                scAMTime.add(Calendar.DAY_OF_MONTH,AMCloseDays);
                //设置下午午过号时间
                Calendar scPMTime = Calendar.getInstance();
                scPMTime.setTime(new Date());
                scPMTime.add(Calendar.DAY_OF_MONTH,PMCloseDays);
                WlyyDoctorWorkTimeDO time = (WlyyDoctorWorkTimeDO)it.next();
                Boolean filter = true;
                //1.【上午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除
                if(filter&&"1".equals(time.getTimeType())&&time.getEndTime().before(scAMTime.getTime())){
                    it.remove();
                    filter=false;
                }
                //2.【下午午的排班中】 且 【排班结束时间】如果在【开放时间】前,则移除该排班
                if(filter&&"2".equals(time.getTimeType())&&time.getEndTime().before(scPMTime.getTime())){
                    it.remove();
                    filter=false;
                }
        List<WlyyPatientRegisterTimeDO> registerTimeDOs = patientRegisterTimeDao.findByDoctorAndWorkId(timeDO.getDoctor(),id);
                //3.如果【当前时间】过了【上午放号时间】,则移除所有上午的排班
                if(filter&&"1".equals(time.getTimeType())&&
                        DateUtil.strToDate(DateUtil.getTimeShort(),DateUtil.HH_MM_SS).after(DateUtil.strToDate(AMCloseTime,DateUtil.HH_MM))){
                    scAMTime.set(scAMTime.get(Calendar.YEAR),scAMTime.get(Calendar.MONTH),scAMTime.get(Calendar.DATE),12,00,00);
        //2.根据时间间隔拆分号源
        while (sc.getTime().before(timeDO.getEndTime())){
                    if(time.getEndTime().before(scAMTime.getTime())){
                        it.remove();
                        filter=false;
                    }
                }
                //4.如果【当前时间】过了【下午午放号时间】,则移除所有下午的排班
                if(filter&&"2".equals(time.getTimeType())&&
                        DateUtil.strToDate(DateUtil.getTimeShort(),DateUtil.HH_MM_SS).after(DateUtil.strToDate(PMCloseTime,DateUtil.HH_MM))){
                    scPMTime.set(scAMTime.get(Calendar.YEAR),scAMTime.get(Calendar.MONTH),scAMTime.get(Calendar.DATE),12,00,00);
            Map<String,Object> t = new HashedMap();
            t.put("startTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
            //如果结束时间大于排班时间则不再拆分号源
            if(sc.getTime().after(timeDO.getEndTime())){
                break;
            }
            t.put("endTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
                    if(time.getEndTime().before(scPMTime.getTime())){
                        it.remove();
            //如果号源被预约了,标记为true
            Boolean registered = false;
            if(registerTimeDOs!=null&&registerTimeDOs.size()>0){
                for(WlyyPatientRegisterTimeDO registerTimeDO : registerTimeDOs){
                    if(t.get("startTime").equals(DateUtil.dateToStr(registerTimeDO.getStartTime(),"yyyy-MM-dd HH:mm:ss"))){
                        registered = true;
                    }
                }
            }
            t.put("registered",registered);
            rs.add(t);
        }
        return times;
        return rs;
    }
    /**
     * 计算号源数目
     * @param id
     * @return
     */
    public Integer findWorkTimeInfoCout(String id){
        WlyyDoctorWorkTimeDO timeDO = doctorWorkTimeDao.findOne(id);
    public String findHospitalSysDictValue(List<WlyyHospitalSysDictDO> list,String dictCode){
        if(timeDO.getSourceNumber()==null||timeDO.getStartTime()==null||timeDO.getEndTime()==null){
            return 0;
        }
        if(list!=null&&list.size()>0){
            for(WlyyHospitalSysDictDO sysDictDO : list){
                if(dictCode.equals(sysDictDO.getDictCode())){
                    return sysDictDO.getDictValue();
                }
        Long ss = timeDO.getEndTime().getTime()-timeDO.getStartTime().getTime();
        Long s = ss/timeDO.getSourceNumber();
        Calendar sc = Calendar.getInstance();
        sc.setTime(timeDO.getStartTime());
        List<Map<String,Object>> rs = new ArrayList<>();
        //1.根据当前时间,去取已过时间的号源
        while (sc.getTime().before(timeDO.getEndTime())){
            if(new Date().before(sc.getTime())){
                break;
            }
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
        }
        return "";
    }
    /**
     * 获取卡信息
     * @param cardNo
     * @param demoFlag
     * @return
     * @throws Exception
     */
    public net.sf.json.JSONObject getCardInfo(String cardNo, boolean demoFlag) throws Exception {
        return entranceService.qutpatientBalance(cardNo,demoFlag);
        List<WlyyPatientRegisterTimeDO> registerTimeDOs = patientRegisterTimeDao.findByDoctorAndWorkId(timeDO.getDoctor(),id);
        //2.根据时间间隔拆分号源
        while (sc.getTime().before(timeDO.getEndTime())){
            Map<String,Object> t = new HashedMap();
            t.put("startTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
            //加上时间间隔
            Date temp =new Date();
            temp.setTime(sc.getTime().getTime()+s);
            sc.setTime(temp);
            //如果结束时间大于排班时间则不再拆分号源
            if(sc.getTime().after(timeDO.getEndTime())){
                break;
            }
            t.put("endTime",DateUtil.dateToStr(sc.getTime(),"yyyy-MM-dd HH:mm:ss"));
            //如果号源被预约了,标记为true
            Boolean registered = false;
            if(registerTimeDOs!=null&&registerTimeDOs.size()>0){
                for(WlyyPatientRegisterTimeDO registerTimeDO : registerTimeDOs){
                    if(t.get("startTime").equals(DateUtil.dateToStr(registerTimeDO.getStartTime(),"yyyy-MM-dd HH:mm:ss"))){
                        registered = true;
                    }
                }
            }
            if(!registered){
                rs.add(t);
            }
        }
        return rs.size();
    }
    public List<Map<String,Object>> findWorkTimeInfo(String id){
    @Deprecated
    public List<Map<String,Object>> findWorkTimeInfoOld(String id){
        WlyyDoctorWorkTimeDO timeDO = doctorWorkTimeDao.findOne(id);
        Calendar sc = Calendar.getInstance();
        sc.setTime(timeDO.getStartTime());
@ -2491,11 +2675,17 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
               rs.put("winNo",org.getWinNo());
               rs.put("deptName",hospitalDOs.get(0).getDeptName());
               rs.put("dept",hospitalDOs.get(0).getDeptCode());
               if(StringUtils.isNotBlank(withWork)&&"1".equals(withWork)){
                  List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(doctor,hospitalDOs.get(0).getOrgCode());
                  rs.put("workTime",times);
               }
            }else{
               rs.put("hospital",null);
               rs.put("winNo",null);
               rs.put("deptName",null);
               rs.put("dept",null);
                rs.put("workTime",null);
            }
@ -2523,21 +2713,18 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                rs.put("registerCount",0);
            }
            //医生问诊量
//            List<WlyyOutpatientDO> wlyyOutpatientDOs = outpatientDao.findByDoctorAndStatus(doctor,"2");
//            if(wlyyOutpatientDOs!=null&&wlyyOutpatientDOs.size()>0){
//                rs.put("outpatientCount",wlyyOutpatientDOs.size());
//            }else{
//                rs.put("outpatientCount",0);
//            }
            List<WlyyOutpatientDO> wlyyOutpatientDOs = outpatientDao.findByDoctorAndStatus(doctor,"2");
            if(wlyyOutpatientDOs!=null&&wlyyOutpatientDOs.size()>0){
                rs.put("outpatientCount",wlyyOutpatientDOs.size());
            }else{
                rs.put("outpatientCount",0);
            }
            //协同门诊量
//            Integer coordinationCout = outpatientDao.countByDoctorAndStatusAndOutpatientType(doctor,"2","2");
//            rs.put("coordinationCout",coordinationCout);
            Integer coordinationCout = outpatientDao.countByDoctorAndStatusAndOutpatientType(doctor,"2","2");
            rs.put("coordinationCout",coordinationCout);
//            if(StringUtils.isNotBlank(withWork)&&"1".equals(withWork)){
//                List<WlyyDoctorWorkTimeVO> times = findDoctorWorkTime(doctor);
//                rs.put("workTime",times);
//            }
    
            //专家咨询
            String zjCountsql = "SELECT id FROM wlyy_consult_team WHERE doctor='"+doctor+"' AND (type=1 OR type=15)";
@ -3204,18 +3391,19 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if(StringUtils.isNotBlank(iswork)&&"1".equals(iswork)){
            logger.info("iswork:"+iswork);
            String startDate = DateUtil.dateToStr(new Date(),"yyyy-MM-dd"+" 00:00:00");
            String endDate = DateUtil.dateToStr(new Date(),"yyyy-MM-dd")+" 23:59:59";
            sql+=" AND EXISTS ( " +
            String date = DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss");
            sql+=" AND (" +
                    " EXISTS ( " +
                    " SELECT " +
                    "  1 " +
                    " FROM " +
                    "  wlyy_doctor_work_time t " +
                    " WHERE " +
                    "  t.doctor = d.id " +
                    " AND t.start_time >='" +startDate+"'" +
                    " AND t.start_time <='"+endDate+"'"+
                    " )";
                    " AND t.start_time <='" +date+"'" +
                    " AND t.end_time >='"+date+"'"+
                    " ) OR " +
                    " d.consult_status = '1') ";
        }
        if(StringUtils.isNotBlank(orgCode)){
            sql += " AND  h.org_code = '"+orgCode+"'";
@ -3346,7 +3534,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            List<Map<String,Object>> doctors = jdbcTemplate.queryForList(sql);
            List<WlyyDoctorWorkTimeDO> workTimeDOs =makeDoctorWorkTimeDOList(doctors,wlyyDoctorWorkTimeDOs);
            saveDoctorWorkTime(workTimeDOs,date,doctors);
            //科室
        //科室
        }else if("2".equals(type)){
            String sql ="SELECT " +
@ -3415,6 +3603,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                    t.setEndTime(time.getEndTime());
                    t.setDate(time.getDate());
                    t.setTimeInterval(time.getTimeInterval());
                    t.setSourceNumber(time.getSourceNumber());
                    rs.add(t);
                }
                logger.info(rs.size()+"");

+ 247 - 10
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/WorkTimeService.java

@ -1,15 +1,27 @@
package com.yihu.jw.hospital.prescription.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.doctor.service.excel.DoctorWorkTimeExcelDO;
import com.yihu.jw.doctor.service.excel.DoctorWorkTimeMainExcelDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.hospital.doctor.WlyyDoctorWorkTimeDO;
import com.yihu.jw.entity.hospital.prescription.WlyyHospitalWorkRuleDO;
import com.yihu.jw.hospital.doctor.dao.DoctorWorkTimeDao;
import com.yihu.jw.hospital.prescription.dao.WlyyHospitalWorkRuleDao;
import com.yihu.jw.org.dao.BaseOrgDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import org.apache.commons.collections.map.HashedMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.*;
/**
 * Created by Trick on 2020/3/24.
@ -26,6 +38,21 @@ public class WorkTimeService {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private DoctorWorkTimeDao doctorWorkTimeDao;
    @Autowired
    private HibenateUtils hibenateUtils;
    @Autowired
    private BaseDoctorDao baseDoctorDao;
    @Autowired
    private BaseDoctorHospitalDao hospitalDao;
    @Autowired
    private BaseOrgDao baseOrgDao;
    /**
     * 保存排班规则
     * @param workTimeRuleJson
@ -49,23 +76,233 @@ public class WorkTimeService {
     */
    public WlyyHospitalWorkRuleDO findWorkTimeRule(String hospital){
        List<WlyyHospitalWorkRuleDO> orgRules = wlyyHospitalWorkRuleDao.findByHospital(hospital);
        return orgRules.get(0);
        if(orgRules!=null&&orgRules.size()>0){
            return orgRules.get(0);
        }
        return null;
    }
    /**
     * 判断医生是否在班
     * @param doctor
     * @return
     */
    public Boolean checkDoctorWork(String doctor){
        String sql = "SELECT " +
                " d.id " +
                " FROM " +
                " base_doctor d " +
                " WHERE " +
                " d.id =:doctor " +
                " AND ( " +
                " EXISTS ( " +
                "  SELECT " +
                "   t.id " +
                "  FROM " +
                "   wlyy_doctor_work_time t " +
                "  WHERE " +
                "   t.doctor = d.id " +
                "  AND t.start_time <=:startTime " +
                "  AND t.end_time >=:endTime" +
                " ) " +
                " OR d.consult_status = '1' " +
                ")";
        Map<String,Object> params = new HashedMap();
        params.put("doctor",doctor);
        Date date = new Date();
        params.put("startTime",date);
        params.put("endTime",date);
        List<Map<String,Object>> list = hibenateUtils.createSQLQuery(sql,params);
        if(list!=null&&list.size()>0){
            return true;
        }
        return false;
    }
    public Map<String,Object> getExcelWorkInfo(List<DoctorWorkTimeMainExcelDO> list,String date,String hospital){
//    public static void main(String ag[]){
//
//        Date start = DateUtil.stringToDate("2020-03-24 08:00:00","yyyy-MM-dd HH:mm:ss");
        Map<String,Object> rs = new HashedMap();
        List<DoctorWorkTimeMainExcelDO> error =new ArrayList<>();
        List<WlyyDoctorWorkTimeDO> succ = new ArrayList<>();
        Integer total = 0;
        Integer errorTotal = 0;
        Integer succTotal =0;
        if(list!=null&&list.size()>0){
            for(DoctorWorkTimeMainExcelDO excelDO:list){
                List<BaseDoctorDO> doctorDOs = baseDoctorDao.findByIdcard(excelDO.getIdCard());
                if(doctorDOs==null||doctorDOs.size()==0){
                    excelDO.setErrorMes("第"+(excelDO.getRow()+1)+"行,医生身份证号不存在!");
                    error.add(excelDO);
                    continue;
                }
                BaseDoctorDO doctorDO = doctorDOs.get(0);
                BaseOrgDO orgDO = baseOrgDao.findByCode(hospital);
                WlyyHospitalWorkRuleDO ruleDO = findWorkTimeRule(hospital);
                //判断是否为本月
                String dm = DateUtil.dateToStr(new Date(),"yyyy-MM");
                if(dm.equals(date)){
                    Calendar calendar = Calendar.getInstance();
                    Date today = new Date();
                    calendar.setTime(today);
                    // 获取一月中第几天
                    int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
                    //获取该月份一共几天
                    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
                    calendar.add(1,Calendar.DATE);
                    //更新时间范围
                    //开始时间
                    String st = DateUtil.dateToStr(calendar.getTime(),"yyyy-MM-dd");
                    Date startDate = DateUtil.strToDate(st+" 00:00:00");
                    //结束时间
                    String et = date+":"+maxDay+" 23:59:59";
                    Date endDate = DateUtil.strToDate(et);
                    //删除明天开始的排班记录
                    List<WlyyDoctorWorkTimeDO> timeDOs = doctorWorkTimeDao.findDoctorWorkTimeByTime(doctorDO.getId(),startDate,endDate);
                    if(timeDOs!=null&&timeDOs.size()>0){
                        doctorWorkTimeDao.delete(timeDOs);
                    }
                    //解析具体排班
                    List<DoctorWorkTimeExcelDO> worktimes = excelDO.getWorkTime();
                    if(worktimes!=null&&worktimes.size()>0){
                        for(DoctorWorkTimeExcelDO worktime:worktimes){
                            //要排班的日期
                            String day = worktime.getDateOfMonth();
                            Integer dfm = Integer.parseInt(day);
                            //排班从明天开始
                            if(dfm >= (monthDay+1)){
                                WlyyDoctorWorkTimeDO workTimeDO = getWorkTimeDO(date,worktime,ruleDO,orgDO,doctorDO);
                                succ.add(workTimeDO);
                            }
                        }
                    }
                }else{
                    //判断日期是否大于本月
                    Date now = DateUtil.strToDate(dm,"yyyy-MM");
                    Date work = DateUtil.strToDate(date,"yyyy-MM");
                    if(now.before(work)){
                        //导入的月份大于当前月份,删除导入月份所有历史排班记录
                        List<WlyyDoctorWorkTimeDO> timeDOs = doctorWorkTimeDao.findDoctorWorkTimeByMonth(doctorDO.getId(),"%"+date+"%");
                        if(timeDOs!=null&&timeDOs.size()>0){
                            doctorWorkTimeDao.delete(timeDOs);
                        }
                        //解析具体排班
                        List<DoctorWorkTimeExcelDO> worktimes = excelDO.getWorkTime();
                        if(worktimes!=null&&worktimes.size()>0){
                            for(DoctorWorkTimeExcelDO worktime:worktimes){
                                WlyyDoctorWorkTimeDO workTimeDO = getWorkTimeDO(date,worktime,ruleDO,orgDO,doctorDO);
                                succ.add(workTimeDO);
                            }
                        }
                    }
                }
            }
            total = list.size();
            if(error!=null&&error.size()>0){
                errorTotal = error.size();
            }
            succTotal = total-errorTotal;
            if(succ!=null&&succ.size()>0){
                //保存排班
                doctorWorkTimeDao.save(succ);
            }
        }
        rs.put("error",error);
        rs.put("succ",succ);
        rs.put("total",total);
        rs.put("errorTotal",errorTotal);
        rs.put("succTotal",succTotal);
        return rs;
    }
    public WlyyDoctorWorkTimeDO getWorkTimeDO(String date,DoctorWorkTimeExcelDO worktime,WlyyHospitalWorkRuleDO ruleDO,BaseOrgDO orgDO,BaseDoctorDO doctorDO){
        WlyyDoctorWorkTimeDO workTimeDO = new WlyyDoctorWorkTimeDO();
        workTimeDO.setDoctor(doctorDO.getId());
        workTimeDO.setDoctorName(doctorDO.getName());
        workTimeDO.setHospital(orgDO.getCode());
        workTimeDO.setHospitalName(orgDO.getName());
        String day = worktime.getDateOfMonth();
        if(day.length()<2){
            day ="0"+day;
        }
        String workDate = date+"-"+day;
        logger.info("workDate:"+workDate);
        workTimeDO.setDate(workDate);
        workTimeDO.setCreateTime(new Date());
        //上午
        if("1".equals(worktime.getType())){
            workTimeDO.setTimeType("1");
            workTimeDO.setType("1");
            workTimeDO.setSourceNumber(ruleDO.getSwSourceNum());
            workTimeDO.setStartTime(DateUtil.strToDate(workDate+" "+ruleDO.getSwStartTime()+":00"));
            workTimeDO.setEndTime(DateUtil.strToDate(workDate+" "+ruleDO.getSwEndTime()+" :00"));
        }else if("2".equals(worktime.getType())){
            workTimeDO.setTimeType("2");
            workTimeDO.setType("1");
            workTimeDO.setSourceNumber(ruleDO.getXwSourceNum());
            workTimeDO.setStartTime(DateUtil.strToDate(workDate+" "+ruleDO.getXwStartTime()+":00"));
            workTimeDO.setEndTime(DateUtil.strToDate(workDate+" "+ruleDO.getXwEndTime()+" :00"));
        }else if("3".equals(worktime.getType())){
            workTimeDO.setTimeType("3");
            workTimeDO.setType("1");
            workTimeDO.setSourceNumber(ruleDO.getWsSourceNum());
            workTimeDO.setStartTime(DateUtil.strToDate(workDate+" "+ruleDO.getWsStartTime()+":00"));
            workTimeDO.setEndTime(DateUtil.strToDate(workDate+" "+ruleDO.getWsEndTime()+":00"));
        }
        return workTimeDO;
    }
//    public String saveDoctorWorkTime(List<WlyyDoctorWorkTimeDO> workTimeDOs){
//
//        Date end = DateUtil.stringToDate("2020-03-24 12:00:00","yyyy-MM-dd HH:mm:ss");
//    }
//    public static void main(String ag[]){
//
//        Long total =end.getTime()-start.getTime();
////        Date start = DateUtil.stringToDate("2020-03-24 08:00:00","yyyy-MM-dd HH:mm:ss");
////
////        Date end = DateUtil.stringToDate("2020-03-24 12:00:00","yyyy-MM-dd HH:mm:ss");
////
////        Long total =end.getTime()-start.getTime();
////
////        Long jg = total/100;
////
////        start.setTime(start.getTime()+jg);
//
//        Long jg = total/100;
////        Date now = DateUtil.strToDate("2020-04","yyyy-MM");
////        Date work = DateUtil.strToDate("2020-04","yyyy-MM");
//
//        start.setTime(start.getTime()+jg);
//        Calendar calendar = Calendar.getInstance();
//        Date today = new Date();
//        calendar.setTime(today);// 此处可换为具体某一时间
//        int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
//        int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
//
//        System.out.println(DateUtil.dateToStr(start,"yyyy-MM-dd HH:mm:ss"));
//        System.out.println(monthDay);
//    }
}

+ 388 - 519
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/entrance/XzzxEntranceService.java

@ -1,20 +1,44 @@
package com.yihu.jw.hospital.prescription.service.entrance;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yihu.jw.dict.dao.BaseDictJobTitleDao;
import com.yihu.jw.dict.dao.DictDoctorDutyDao;
import com.yihu.jw.dict.dao.DictHospitalDeptDao;
import com.yihu.jw.doctor.dao.BaseDoctorDao;
import com.yihu.jw.doctor.dao.BaseDoctorHospitalDao;
import com.yihu.jw.doctor.dao.BaseDoctorRoleDao;
import com.yihu.jw.entity.base.dict.DictDoctorDutyDO;
import com.yihu.jw.entity.base.dict.DictHospitalDeptDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorHospitalDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.entity.hospital.dict.WlyyChargeDictDO;
import com.yihu.jw.entity.hospital.mapping.DoctorMappingDO;
import com.yihu.jw.hospital.dict.WlyyChargeDictDao;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.hospital.mapping.dao.DoctorMappingDao;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.util.common.IdCardUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.WebserviceUtil;
import com.yihu.utils.security.MD5;
import net.sf.json.xml.XMLSerializer;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang3.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Random;
/**
 * 心脏中心内网his对接服务
@ -29,6 +53,21 @@ public class XzzxEntranceService {
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    @Autowired
    private DictHospitalDeptDao dictHospitalDeptDao;
    @Autowired
    private DictDoctorDutyDao dictDoctorDutyDao;
    @Autowired
    private WlyyChargeDictDao chargeDictDao;
    @Autowired
    private BaseDoctorDao doctorDao;
    @Autowired
    private BaseDoctorHospitalDao doctorHospitalDao;
    @Autowired
    private BaseDoctorRoleDao doctorRoleDao;
    @Autowired
    private DoctorMappingDao doctorMappingDao;
    public String getXzzxWebServiceInfo(String api, Map<String,String> params)throws Exception{
        List<WlyyHospitalSysDictDO> list =  wlyyHospitalSysDictDao.findByDictName("xzzxWebService");
@ -50,7 +89,7 @@ public class XzzxEntranceService {
     * 获取部门信息
     * @return
     */
    public String getDeptInfo()throws Exception{
    public String getDeptInfo(String code)throws Exception{
        String api = "GetDeptInfo";
        String key ="bvvsf3JA0mUXMU+mVnMaOQ==";
        String msgHeader ="<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
@ -60,8 +99,12 @@ public class XzzxEntranceService {
                "   <callOperator></callOperator> " +
                "   <certificate>"+key+"</certificate> " +
                "</root>";
        String condition ="";
        if (StringUtils.isNoneBlank(code)){
            condition = "<code>"+code+"</code>";
        }
        String msgBody ="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<root></root>";
                "<root>"+condition+"</root>";
        Map<String,String> params = new HashedMap();
        params.put("msgHeader",msgHeader);
@ -70,529 +113,355 @@ public class XzzxEntranceService {
        String xml = getXzzxWebServiceInfo("CallInterface",params);
        XMLSerializer xmlSerializer = new XMLSerializer();
        String json = xmlSerializer.read(xml).toString();
        logger.info("getDeptInfo json:"+json);
        JSONArray depts = JSONArray.parseArray(json).getJSONArray(0);
        if(depts!=null&&depts.size()>0){
            for(int i=0;i<depts.size();i++){
                JSONObject dept = depts.getJSONObject(i);
                String deptCode = dept.getString("code");
        return "";
                List<DictHospitalDeptDO> list = dictHospitalDeptDao.findByOrgCodeAndCode(deptCode,"350211A5010");
                String consultDeptFlag=null;
                if (!dept.getString("consultDeptFlag").equalsIgnoreCase("[]")){
                    consultDeptFlag = dept.getString("consultDeptFlag");
                }
                if(list!=null&&list.size()>0){
                    DictHospitalDeptDO deptDO = list.get(0);
                    deptDO.setCode(deptCode);
                    deptDO.setName(dept.getString("name"));
                    if (StringUtils.isNoneBlank(consultDeptFlag)){
                        deptDO.setConsultDeptFlag(consultDeptFlag);
                    }
                    deptDO.setCreateTime(new Date());
                    dictHospitalDeptDao.save(deptDO);
                }else {
                    DictHospitalDeptDO deptDO = new DictHospitalDeptDO();
                    deptDO.setCode(deptCode);
                    deptDO.setName(dept.getString("name"));
                    if (StringUtils.isNoneBlank(consultDeptFlag)){
                        deptDO.setConsultDeptFlag(consultDeptFlag);
                    }
                    deptDO.setOrgCode("350211A5010");
                    deptDO.setCreateTime(new Date());
                    dictHospitalDeptDao.save(deptDO);
                }
            }
        }
        return json;
    }
    public static void main(String ag[]){
        String xml ="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<root>" +
                "    <returnContents>" +
                "        <returnContent>" +
                "            <code>20100</code>" +
                "            <name>后勤部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>20200</code>" +
                "            <name>消毒中转站</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>30100</code>" +
                "            <name>心内科门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>30200</code>" +
                "            <name>心外科门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>30300</code>" +
                "            <name>客户服务部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>30400</code>" +
                "            <name>超声科门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>3140000</code>" +
                "            <name>计算机中心</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>31500</code>" +
                "            <name>人事部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>31600</code>" +
                "            <name>护理部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>31700</code>" +
                "            <name>医保办</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>31800</code>" +
                "            <name>财务科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>3180001</code>" +
                "            <name>门诊收费处</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>3180002</code>" +
                "            <name>住院收费处</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>31900</code>" +
                "            <name>医务科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>32000</code>" +
                "            <name>院长室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>32100</code>" +
                "            <name>中心办公室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>32200</code>" +
                "            <name>院感科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>32300</code>" +
                "            <name>保障保卫部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>32400</code>" +
                "            <name>全院</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>32500</code>" +
                "            <name>综合办公室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>32600</code>" +
                "            <name>科教部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4010001</code>" +
                "            <name>心内一区</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4010002</code>" +
                "            <name>心内二区</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4010003</code>" +
                "            <name>CCU</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4010004</code>" +
                "            <name>心内三区</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4010005</code>" +
                "            <name>心内四区</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4010006</code>" +
                "            <name>特需病区</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40200</code>" +
                "            <name>心内三区病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4020001</code>" +
                "            <name>心外病区</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4020002</code>" +
                "            <name>ICU</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40300</code>" +
                "            <name>心外手术室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4030001</code>" +
                "            <name>小儿心脏科/综合科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40400</code>" +
                "            <name>心内导管室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>4040001</code>" +
                "            <name>急诊科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40500</code>" +
                "            <name>CCU病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40600</code>" +
                "            <name>ICU病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40700</code>" +
                "            <name>心内一区病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40800</code>" +
                "            <name>心内二区病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>40900</code>" +
                "            <name>心外病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41000</code>" +
                "            <name>胸痛中心</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41100</code>" +
                "            <name>起搏器门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41200</code>" +
                "            <name>麻醉科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41300</code>" +
                "            <name>急诊门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41400</code>" +
                "            <name>心内四区病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41500</code>" +
                "            <name>小儿心脏科/综合科病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41600</code>" +
                "            <name>急诊科病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41700</code>" +
                "            <name>心脏康复门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41800</code>" +
                "            <name>先天性心脏病门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>41900</code>" +
                "            <name>心衰专病门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>42000</code>" +
                "            <name>特需病房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>42100</code>" +
                "            <name>体检门诊</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>50100</code>" +
                "            <name>药房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>50200</code>" +
                "            <name>药库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>50300</code>" +
                "            <name>静配药房</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60100</code>" +
                "            <name>影像科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60200</code>" +
                "            <name>检验科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60300</code>" +
                "            <name>心脏彩超室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60400</code>" +
                "            <name>心功能室(心脏中心)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60500</code>" +
                "            <name>输血科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60600</code>" +
                "            <name>内窥镜室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60700</code>" +
                "            <name>肺功能室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60800</code>" +
                "            <name>血透室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>60900</code>" +
                "            <name>检验科(总院)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61000</code>" +
                "            <name>高压氧室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61100</code>" +
                "            <name>脑电图室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61200</code>" +
                "            <name>核医学科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61300</code>" +
                "            <name>放射科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61400</code>" +
                "            <name>CT室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61500</code>" +
                "            <name>核磁共振科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61600</code>" +
                "            <name>病理科</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61700</code>" +
                "            <name>心功能室(总院)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61800</code>" +
                "            <name>B超室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>61900</code>" +
                "            <name>药学部(总院)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62000</code>" +
                "            <name>急诊ICU(总院)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62100</code>" +
                "            <name>中心ICU(总院)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62200</code>" +
                "            <name>心电图室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62300</code>" +
                "            <name>心脏彩超室(心脏中心)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62400</code>" +
                "            <name>检验部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62500</code>" +
                "            <name>体检部</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62600</code>" +
                "            <name>心功能室(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62700</code>" +
                "            <name>心脏彩超室(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62800</code>" +
                "            <name>输血科(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>62900</code>" +
                "            <name>院外诊疗</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>63000</code>" +
                "            <name>血透(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>63100</code>" +
                "            <name>放射科(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>63200</code>" +
                "            <name>运动心肺室(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>63300</code>" +
                "            <name>核医学科(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>63400</code>" +
                "            <name>CT(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>63500</code>" +
                "            <name>MR(新)</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>70100</code>" +
                "            <name>病案室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>70200</code>" +
                "            <name>离职人员</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>80100</code>" +
                "            <name>心内实验室</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>80200</code>" +
                "            <name>临床试验组</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90100</code>" +
                "            <name>设备科仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90200</code>" +
                "            <name>总务仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90300</code>" +
                "            <name>高值仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90400</code>" +
                "            <name>科研仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90500</code>" +
                "            <name>软件仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90600</code>" +
                "            <name>五金仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90700</code>" +
                "            <name>信息科仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90800</code>" +
                "            <name>报废仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "        <returnContent>" +
                "            <code>90900</code>" +
                "            <name>报损仓库</name>" +
                "            <consultDeptFlag/>" +
                "        </returnContent>" +
                "    </returnContents>" +
    /**
     * 同步医生信息
     * @return
     */
    public String getDoctorInfo(String idcard)throws Exception{
        String api = "GetDoctorInfo";
        String key ="bvvsf3JA0mUXMU+mVnMaOQ==";
        String msgHeader ="<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
                "<root> " +
                "   <serverName>"+api+"</serverName>  " +
                "   <format>xml</format>" +
                "   <callOperator></callOperator> " +
                "   <certificate>"+key+"</certificate> " +
                "</root>";
        String condition ="";
        if (StringUtils.isNoneBlank(idcard)){
            condition = "<Idcard>"+idcard+"</Idcard>";
        }
        String msgBody ="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<root>"+condition+"</root>";
        Map<String,String> params = new HashedMap();
        params.put("msgHeader",msgHeader);
        params.put("msgBody",msgBody);
        logger.info("getDoctorInfo params:"+params.toString());
        String xml = getXzzxWebServiceInfo("CallInterface",params);
        XMLSerializer xmlSerializer = new XMLSerializer();
        String json = xmlSerializer.read(xml).toString();
        JSONObject jsonObject = JSON.parseObject(json);
        logger.info("getDoctorInfo json:"+json);
        JSONArray doctors = JSONArray.parseArray(json);
        findWlyyDoctor(doctors);
        return json;
    }
    public String findWlyyDoctor(JSONArray doctors)throws Exception{
        logger.info("doctors size:"+doctors.size());
        if(doctors!=null&&doctors.size()>0){
            Integer count = 0;
            for(int i=0;i<doctors.size();i++){
                try {
                    JSONObject doctorJson = doctors.getJSONObject(i);
                    String idcard = doctorJson.getString("idcard");
                    if(StringUtils.isNotBlank(idcard)) {
                        List<BaseDoctorDO> ds = doctorDao.findByIdcard(idcard);
                        if (ds != null && ds.size() > 0) {
                            //已有账号更新
                            BaseDoctorDO doctor = ds.get(0);
                            doctor.setName(doctorJson.getString("name"));
                            doctor.setIdcard(doctorJson.getString("idcard"));
                            doctor.setMobile(doctorJson.getString("mobile"));
                            doctor.setSex(Integer.parseInt(IdCardUtil.getSexForIdcard_new(idcard)));
                            doctor.setBirthday(IdCardUtil.getBirthdayForIdcard(idcard));
                            doctor.setProvinceCode("350000");
                            doctor.setProvinceName("福建省");
                            doctor.setTownCode("350203");
                            doctor.setTownName("思明区");
                            doctor.setCityCode("350200");
                            doctor.setCityName("厦门市");
                            doctor.setExpertise(doctorJson.getString("expertise"));
                            doctor.setIntroduce(doctorJson.getString("introduce"));
                            doctor.setPhoto(doctorJson.getString("photo"));
                            doctor.setIscertified(doctorJson.getString("iscertified"));
                            doctor.setSpell(doctorJson.getString("spell"));
//                                String salt = randomString(5);
//                                String pw = idcard.substring(idcard.length() - 6);
//                                doctor.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
//                                doctor.setSalt(salt);
                            doctor.setJobTitleCode(doctorJson.getString("jobTitleCode"));
                            doctor.setJobTitleName(doctorJson.getString("jobTitleName"));
                            doctor.setChargeType(doctorJson.getString("chargeType"));
                            doctorDao.save(doctor);
                            //更新机构科室信息
                            String dept =doctorJson.getString("dept");
                            if(StringUtils.isNotBlank(dept)){
                                List<BaseDoctorHospitalDO> hospitalDOs = doctorHospitalDao.findByDeptCodeAndDoctorCode(dept,doctor.getId());
                                if(hospitalDOs!=null&&hospitalDOs.size()>0){
                                    BaseDoctorHospitalDO hospitalDO = hospitalDOs.get(0);
                                    hospitalDO.setOrgCode("350211A5010");
                                    hospitalDO.setOrgName("厦门大学附属心血管病医院");
                                    hospitalDO.setDeptCode(doctorJson.getString("dept"));
                                    hospitalDO.setDeptName(doctorJson.getString("deptName"));
                                    doctorHospitalDao.save(hospitalDO);
                                }
                            }
                            List<DoctorMappingDO> doctorMappingDOS = doctorMappingDao.findByOrgCodeAndMappingCode("350211A5010",doctorJson.getString("code"));
                            if (doctorMappingDOS!=null&&doctorMappingDOS.size()!=0){
                                DoctorMappingDO doctorMappingDO = doctorMappingDOS.get(0);
                                doctorMappingDO.setIdcard(idcard);
                                doctorMappingDO.setDoctor(doctor.getId());
                                doctorMappingDO.setOrgCode("350211A5010");
                                doctorMappingDO.setOrgName("厦门大学附属心血管病医院");
                                doctorMappingDO.setMappingCode(doctorJson.getString("code"));
                                doctorMappingDO.setMappingName(doctorJson.getString("name"));
                                doctorMappingDO.setDoctorName(doctor.getName());
                                doctorMappingDO.setMappingDeptName(doctorJson.getString("deptName"));
                                doctorMappingDO.setMappingDept(doctorJson.getString("dept"));
                                doctorMappingDO.setMappingJob(doctorJson.getString("jobTitleCode"));
                                doctorMappingDO.setMappingJobName(doctorJson.getString("jobTitleName"));
                                doctorMappingDO.setCreateTime(new Date());
                                doctorMappingDao.save(doctorMappingDO);
                            }
                        } else {
                            BaseDoctorDO doctor = new BaseDoctorDO();
                            doctor.setName(doctorJson.getString("name"));
                            doctor.setIdcard(doctorJson.getString("idcard"));
                            doctor.setMobile(doctorJson.getString("mobile"));
                            doctor.setSex(Integer.parseInt(IdCardUtil.getSexForIdcard_new(idcard)));
                            doctor.setBirthday(IdCardUtil.getBirthdayForIdcard(idcard));
                            doctor.setProvinceCode("350000");
                            doctor.setProvinceName("福建省");
                            doctor.setTownCode("350203");
                            doctor.setTownName("思明区");
                            doctor.setCityCode("350200");
                            doctor.setCityName("厦门市");
                            doctor.setExpertise(doctorJson.getString("expertise"));
                            doctor.setIntroduce(doctorJson.getString("introduce"));
                            doctor.setPhoto(doctorJson.getString("photo"));
                            doctor.setIscertified(doctorJson.getString("iscertified"));
                            doctor.setSpell(doctorJson.getString("spell"));
                            doctor.setOutpatientType("zj");
                            //认证信息设置
                            String salt = randomString(5);
                            String pw = idcard.substring(idcard.length() - 6);
                            doctor.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
                            doctor.setSalt(salt);
                            doctor.setDel("1");
                            doctor.setEnabled(1);
                            doctor.setLocked(0);
                            doctor.setCreateTime(new Date());
                            doctor.setJobTitleCode(doctorJson.getString("jobTitleCode"));
                            doctor.setJobTitleName(doctorJson.getString("jobTitleName"));
                            BaseDoctorDO temp = doctorDao.save(doctor);
                            //机构信息部门信息
                            BaseDoctorHospitalDO hospitalDO = new BaseDoctorHospitalDO();
                            hospitalDO.setDoctorCode(temp.getId());
                            hospitalDO.setOrgCode("350211A5010");
                            hospitalDO.setOrgName("厦门大学附属心血管病医院");
                            hospitalDO.setDeptCode(doctorJson.getString("dept"));
                            hospitalDO.setDeptName(doctorJson.getString("deptName"));
                            hospitalDO.setDel("1");
                            doctorHospitalDao.save(hospitalDO);
                            BaseDoctorRoleDO role = new BaseDoctorRoleDO();
                            role.setDoctorCode(temp.getId());
                            role.setRoleCode("specialist");
                            doctorRoleDao.save(role);
                            DoctorMappingDO mappingDO = new DoctorMappingDO();
                            mappingDO.setIdcard(idcard);
                            mappingDO.setDoctor(temp.getId());
                            mappingDO.setOrgCode("350211A5010");
                            mappingDO.setOrgName("厦门大学附属心血管病医院");
                            mappingDO.setMappingCode(doctorJson.getString("code"));
                            mappingDO.setMappingName(doctorJson.getString("name"));
                            mappingDO.setDoctorName(temp.getName());
                            mappingDO.setMappingDeptName(doctorJson.getString("deptName"));
                            mappingDO.setMappingDept(doctorJson.getString("dept"));
                            mappingDO.setMappingJob(doctorJson.getString("jobTitleCode"));
                            mappingDO.setMappingJobName(doctorJson.getString("jobTitleName"));
                            mappingDO.setCreateTime(new Date());
                            doctorMappingDao.save(mappingDO);
                            count++;
                        }
                    }
                }catch (Exception e){
                    logger.info("data error");
                }
            }
            logger.info("add count:"+count);
        }
        return "ok";
    }
    public String randomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        StringBuffer buffer = new StringBuffer();
        Random random = new Random();
        for(int i = 0; i < length; ++i) {
            int pos = random.nextInt(str.length());
            buffer.append(str.charAt(pos));
        }
        return buffer.toString();
    }
    /**
     * 获取职称字典
     * @return
     */
    public String getJobTitle()throws Exception{
        String api = "GetTitleInfo";
        String key ="bvvsf3JA0mUXMU+mVnMaOQ==";
        String msgHeader ="<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
                "<root> " +
                "   <serverName>"+api+"</serverName>  " +
                "   <format>xml</format>" +
                "   <callOperator></callOperator> " +
                "   <certificate>"+key+"</certificate> " +
                "</root>";
        String msgBody ="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<root></root>";
        Map<String,String> params = new HashedMap();
        params.put("msgHeader",msgHeader);
        params.put("msgBody",msgBody);
        logger.info("getJobTitleInfo params:"+params.toString());
        String xml = getXzzxWebServiceInfo("CallInterface",params);
        XMLSerializer xmlSerializer = new XMLSerializer();
        String json = xmlSerializer.read(xml).toString();
        logger.info("getJobTitleInfo json:"+json);
        JSONArray list = JSONArray.parseArray(json).getJSONArray(0);
        if(list!=null&&list.size()>0){
            for(int i=0;i<list.size();i++){
                JSONObject object = list.getJSONObject(i);
                logger.info("getJobTitleInfo object:"+object.toJSONString());
                String code = object.getString("code");
                String name = object.getString("name");
                DictDoctorDutyDO dictDoctorDutyDO = dictDoctorDutyDao.findByCode(code);
                if (dictDoctorDutyDO!=null){
                    dictDoctorDutyDO.setName(name);
                    dictDoctorDutyDao.save(dictDoctorDutyDO);
                }else {
                    DictDoctorDutyDO dictDoctorDutyDO1 = new DictDoctorDutyDO();
                    dictDoctorDutyDO1.setCode(code);
                    dictDoctorDutyDO1.setName(name);
                    dictDoctorDutyDO1.setCreateTime(new Date());
                    dictDoctorDutyDao.save(dictDoctorDutyDO1);
                }
            }
        }
        return json;
    }
    /**
     * 获取号别字典
     * @return
     */
    public String getChargeDict()throws Exception{
        String api = "GetScheduleType";
        String key ="bvvsf3JA0mUXMU+mVnMaOQ==";
        String msgHeader ="<?xml version=\"1.0\" encoding=\"utf-8\"?> " +
                "<root> " +
                "   <serverName>"+api+"</serverName>  " +
                "   <format>xml</format>" +
                "   <callOperator></callOperator> " +
                "   <certificate>"+key+"</certificate> " +
                "</root>";
        String msgBody ="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
                "<root></root>";
        Map<String,String> params = new HashedMap();
        params.put("msgHeader",msgHeader);
        params.put("msgBody",msgBody);
        logger.info("getChargeDictInfo params:"+params.toString());
        String xml = getXzzxWebServiceInfo("CallInterface",params);
        XMLSerializer xmlSerializer = new XMLSerializer();
        String json = xmlSerializer.read(xml).toString();
        logger.info("getChargeDictInfo json:"+json);
        JSONArray list = JSONArray.parseArray(json).getJSONArray(0);
        if(list!=null&&list.size()>0){
            for(int i=0;i<list.size();i++){
                JSONObject object = list.getJSONObject(i);
                logger.info("getJobTitleInfo object:"+object.toJSONString());
                String code = object.getString("chargeType");
                String name = object.getString("chargeTypeName");
                String reqFee = object.getString("reqFee");
                Double reqFees = 0.0;
                if (StringUtils.isNoneBlank(reqFee)&&!reqFee.equalsIgnoreCase("[]")){
                    reqFees= Double.parseDouble(reqFee);
                }
                WlyyChargeDictDO chargeDictDO = chargeDictDao.findByChargeType(code);
                if (chargeDictDO!=null){
                    chargeDictDO.setChargeType(code);
                    chargeDictDO.setChargeName(name);
                    chargeDictDO.setReqFee(reqFees);
                    chargeDictDao.save(chargeDictDO);
                }else {
                    WlyyChargeDictDO chargeDictDO1 = new WlyyChargeDictDO();
                    chargeDictDO1.setChargeType(code);
                    chargeDictDO1.setChargeName(name);
                    chargeDictDO1.setReqFee(reqFees);
                    chargeDictDO1.setCreateTime(new Date());
                    chargeDictDao.save(chargeDictDO1);
                }
            }
        }
        return json;
    }
}

+ 4 - 4
common/common-entity/src/main/java/com/yihu/jw/entity/IntegerIdentityEntity.java

@ -19,13 +19,13 @@ public abstract class IntegerIdentityEntity implements Serializable {
    @Id
//==========mysql 环境 id策略======================================================
//    @GeneratedValue(generator = "generator")
//    @GenericGenerator(name = "generator", strategy = "identity")
//    @Column(name = "id", unique = true, nullable = false)
    @GeneratedValue(generator = "generator")
    @GenericGenerator(name = "generator", strategy = "identity")
    @Column(name = "id", unique = true, nullable = false)
//==========mysql 环境 id策略 end======================================================
//==========Oracle 环境id策略 =========================================================
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="id_generated")
   /* @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="id_generated")*/
//==========Oracle 环境id策略 =========================================================
    public Integer getId() {
        return id;

+ 2 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/dict/DictDoctorDutyDO.java

@ -23,11 +23,13 @@ public class DictDoctorDutyDO extends IntegerIdentityEntity {
    /**
	 * 职务标识
	 */
    @Column(name = "code")
	private String code;
    /**
	 * 职务名称(院长/科室主任等等)
	 */
    @Column(name = "name")
	private String name;
    /**

+ 5 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/hospital/BaseHospitalRequestMapping.java

@ -362,6 +362,11 @@ public class BaseHospitalRequestMapping {
        public static final String findWorkTimeRule = "/findWorkTimeRule";
        public static final String saveWorkTimeRule = "/saveWorkTimeRule";
        public static final String checkDoctorWork = "/checkDoctorWork";
        public static final String importDoctorWork = "/importDoctorWork";
    }

+ 15 - 0
common/common-util/pom.xml

@ -87,5 +87,20 @@
            <artifactId>spring-web</artifactId>
            <version>4.3.13.RELEASE</version>
        </dependency>
        <!--   poi xml导入导出工具 start-->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
        </dependency>
        <!-- xlsx  依赖这个包 -->
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml-schemas</artifactId>
        </dependency>
    </dependencies>
</project>

+ 67 - 67
common/common-util/src/main/java/com/yihu/jw/util/excel/AExcelReader.java

@ -1,67 +1,67 @@
package com.yihu.jw.util.excel;
import jxl.Sheet;
import jxl.Workbook;
import java.io.File;
import java.io.InputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class AExcelReader {
    protected List errorLs = new ArrayList<>();
    protected List correctLs = new ArrayList<>();
    protected Map<String, Set> repeat = new HashMap<>();
    public abstract void read(Workbook rwb) throws Exception;
    public void read(File file) throws Exception {
        read(Workbook.getWorkbook(file));
    }
    public void read(InputStream is) throws Exception {
        read(Workbook.getWorkbook(is));
    }
    public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            str = str.replaceAll("\\u00A0" ," ");
            //去除字符串中的空格、回车、换行符、制表符
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
    protected String getCellCont(Sheet sheet, int row, int col){
        return sheet.getCell(col, row).getContents();
    }
    public List getErrorLs() {
        return errorLs;
    }
    public void setErrorLs(List errorLs) {
        this.errorLs = errorLs;
    }
    public List getCorrectLs() {
        return correctLs;
    }
    public void setCorrectLs(List correctLs) {
        this.correctLs = correctLs;
    }
    public Map<String, Set> getRepeat() {
        return repeat;
    }
    public void setRepeat(Map<String, Set> repeat) {
        this.repeat = repeat;
    }
}
//package com.yihu.jw.util.excel;
//
//import jxl.Sheet;
//import jxl.Workbook;
//
//import java.io.File;
//import java.io.InputStream;
//import java.util.*;
//import java.util.regex.Matcher;
//import java.util.regex.Pattern;
//
//public abstract class AExcelReader {
//    protected List errorLs = new ArrayList<>();
//    protected List correctLs = new ArrayList<>();
//    protected Map<String, Set> repeat = new HashMap<>();
//
//    public abstract void read(Workbook rwb) throws Exception;
//
//    public void read(File file) throws Exception {
//        read(Workbook.getWorkbook(file));
//    }
//
//    public void read(InputStream is) throws Exception {
//        read(Workbook.getWorkbook(is));
//    }
//
//    public static String replaceBlank(String str) {
//        String dest = "";
//        if (str!=null) {
//            str = str.replaceAll("\\u00A0" ," ");
//            //去除字符串中的空格、回车、换行符、制表符
//            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
//            Matcher m = p.matcher(str);
//            dest = m.replaceAll("");
//        }
//        return dest;
//    }
//
//    protected String getCellCont(Sheet sheet, int row, int col){
//        return sheet.getCell(col, row).getContents();
//    }
//
//    public List getErrorLs() {
//        return errorLs;
//    }
//
//    public void setErrorLs(List errorLs) {
//        this.errorLs = errorLs;
//    }
//
//    public List getCorrectLs() {
//        return correctLs;
//    }
//
//    public void setCorrectLs(List correctLs) {
//        this.correctLs = correctLs;
//    }
//
//    public Map<String, Set> getRepeat() {
//        return repeat;
//    }
//
//    public void setRepeat(Map<String, Set> repeat) {
//        this.repeat = repeat;
//    }
//
//}

+ 40 - 40
common/common-util/src/main/java/com/yihu/jw/util/excel/AExcelWriter.java

@ -1,40 +1,40 @@
package com.yihu.jw.util.excel;
import jxl.Workbook;
import jxl.write.*;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.io.OutputStream;
import java.util.List;
public abstract class AExcelWriter {
    public abstract void write(WritableWorkbook wwb, List ls) throws Exception;
    public void write(OutputStream os, List ls) throws Exception{
        write(Workbook.createWorkbook(os), ls);
    };
    public void write(File file, List ls) throws Exception{
        write(Workbook.createWorkbook(file), ls);
    };
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
        Label label = new Label(column ,row, data);
        ws.addCell(label);
    }
    //添加单元格内容
    public void addCell(WritableSheet ws, int row, int column, String data, String memo) throws WriteException {
        Label label = new Label(column ,row, data);
        if(!StringUtils.isEmpty(memo)){
            WritableCellFeatures cellFeatures = new WritableCellFeatures();
            cellFeatures.setComment(memo);
            label.setCellFeatures(cellFeatures);
        }
        ws.addCell(label);
    }
}
//package com.yihu.jw.util.excel;
//
//import jxl.Workbook;
//import jxl.write.*;
//import org.apache.commons.lang3.StringUtils;
//
//import java.io.File;
//import java.io.OutputStream;
//import java.util.List;
//
//public abstract class AExcelWriter {
//
//    public abstract void write(WritableWorkbook wwb, List ls) throws Exception;
//
//    public void write(OutputStream os, List ls) throws Exception{
//        write(Workbook.createWorkbook(os), ls);
//    };
//
//    public void write(File file, List ls) throws Exception{
//        write(Workbook.createWorkbook(file), ls);
//    };
//
//    //添加单元格内容
//    public void addCell(WritableSheet ws, int row, int column, String data) throws WriteException {
//        Label label = new Label(column ,row, data);
//        ws.addCell(label);
//    }
//
//    //添加单元格内容
//    public void addCell(WritableSheet ws, int row, int column, String data, String memo) throws WriteException {
//
//        Label label = new Label(column ,row, data);
//        if(!StringUtils.isEmpty(memo)){
//            WritableCellFeatures cellFeatures = new WritableCellFeatures();
//            cellFeatures.setComment(memo);
//            label.setCellFeatures(cellFeatures);
//        }
//        ws.addCell(label);
//    }
//}

+ 83 - 0
common/common-util/src/main/java/com/yihu/jw/util/excel/poi/AExcelReader.java

@ -0,0 +1,83 @@
package com.yihu.jw.util.excel.poi;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.multipart.MultipartFile;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class AExcelReader {
    protected String code="200";//-1行数超过限制
    protected String mes;
    protected List errorLs = new ArrayList<>();
    protected List correctLs = new ArrayList<>();
    protected Map<String, Set> repeat = new HashMap<>();
    public abstract void read(Workbook rwb) throws Exception;
    public void read(MultipartFile file) throws Exception {
        read(ExcelUtils.getWorkBook(file));
    }
    public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            str = str.replaceAll("\\u00A0" ," ");
            //去除字符串中的空格、回车、换行符、制表符
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
    protected String getCellCont(Sheet sheet, int row, int col){
        Cell cell = sheet.getRow(row).getCell(col);
        return ExcelUtils.getCellValue(cell);
    }
    public List getErrorLs() {
        return errorLs;
    }
    public void setErrorLs(List errorLs) {
        this.errorLs = errorLs;
    }
    public List getCorrectLs() {
        return correctLs;
    }
    public void setCorrectLs(List correctLs) {
        this.correctLs = correctLs;
    }
    public Map<String, Set> getRepeat() {
        return repeat;
    }
    public void setRepeat(Map<String, Set> repeat) {
        this.repeat = repeat;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getMes() {
        return mes;
    }
    public void setMes(String mes) {
        this.mes = mes;
    }
}

+ 71 - 0
common/common-util/src/main/java/com/yihu/jw/util/excel/poi/AExcelWriter.java

@ -0,0 +1,71 @@
package com.yihu.jw.util.excel.poi;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.*;
import java.io.File;
import java.util.List;
public abstract class AExcelWriter {
    public abstract void write(Workbook wwb, List ls, File file) throws Exception;
//    public void write(OutputStream os, List ls) throws Exception{
//        write(Workbook.createWorkbook(os), ls);
//    };
    public void write( File file, List ls) throws Exception{
        write(ExcelUtils.getWorkBook(file),ls,file);
    };
    //添加单元格内容
    public void addCell(Sheet ws, int row, int column, String data )  {
        Row row1 = ws.getRow(row) ;
        row1 = row1==null? ws.createRow(row) : row1;
        Cell cell = row1.createCell(column);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(data);
    }
    //添加单元格内容
    public  void addCell(Sheet ws, int row, int column, String data , String memo)  {
        Row row1 = ws.getRow(row) ;
        row1 = row1==null? ws.createRow(row) : row1;
        Cell cell = row1.createCell(column);
        cell.setCellValue(data);
    }
    //添加单元格内容
    public void addCell(Workbook wb,Sheet ws, int row, int column, String data, String memo)  {
        //1.得到一个POI的工具类
        CreationHelper factory = wb.getCreationHelper();
        //2 得到一个换图的对象
        Drawing drawing = ws.createDrawingPatriarch();
        //3. ClientAnchor是附属在WorkSheet上的一个对象,  其固定在一个单元格的左上角和右下角.
        ClientAnchor anchor = factory.createClientAnchor();
        //4  获取行
        Row row1 = ws.getRow(row) ;
        row1 = row1==null? ws.createRow(row) : row1;
        Cell cell = row1.createCell(column);
        cell.setCellValue(data);
        //5 设置注释
        anchor.setCol1(cell.getColumnIndex());
        anchor.setCol2(cell.getColumnIndex() + 2);
        anchor.setRow1(row1.getRowNum());
        anchor.setRow2(row1.getRowNum() + 3);
        if(!StringUtils.isEmpty(memo)){
            Comment comment0 = drawing.createCellComment(anchor);
            RichTextString richTextString = factory.createRichTextString(memo);
            comment0.setString(richTextString);
            cell.setCellComment(comment0);
        }
    }
}

+ 546 - 0
common/common-util/src/main/java/com/yihu/jw/util/excel/poi/ExcelUtils.java

@ -0,0 +1,546 @@
package com.yihu.jw.util.excel.poi;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * excel 工具类
 *
 * @author HZY
 * @vsrsion 1.0
 * Created at 2017/3/2.
 */
public class ExcelUtils extends AExcelWriter {
    private static Logger logger = LoggerFactory.getLogger(ExcelUtils.class);
    private final static String xls = "xls";
    private final static String xlsx = "xlsx";
    /**
     * 总行数
     */
    private int totalRows = 0;
    /**
     * 总列数
     */
    private int totalCells = 0;
    public int getTotalRows() {
        return totalRows;
    }
    public int getTotalCells() {
        return totalCells;
    }
    /**
     * 创建Excel文档
     *
     * @return
     */
    public static HSSFWorkbook createWorkBook() {
        return new HSSFWorkbook();
    }
    /**
     * 创建sheet
     *
     * @param wb
     * @param sheetName
     * @return
     */
    public static HSSFSheet createSheet(HSSFWorkbook wb, String sheetName) {
        return wb.createSheet(sheetName);
    }
    /**
     * 创建一行多列
     *
     * @param sheet
     * @param rowNum
     * @param columnNum
     * @param cellStyle
     * @return
     */
    public static HSSFRow createRow(HSSFSheet sheet, int rowNum, int columnNum, HSSFCellStyle cellStyle) {
        HSSFRow row = sheet.createRow(rowNum);
        if (columnNum > 0) {
            for (int i = 0; i < columnNum; i++) {
                HSSFCell cell = row.createCell(i);
                if (cellStyle != null) {
                    cell.setCellStyle(cellStyle);
                }
            }
        }
        return row;
    }
    /**
     * 创建多行多列
     *
     * @param sheet`
     * @param rowNum
     * @param rowCount
     * @param columnNum
     * @param cellStyle
     * @return
     */
    public static boolean createRows(HSSFSheet sheet, int rowNum, int rowCount, int columnNum, HSSFCellStyle cellStyle) {
        for (int i = 0; i < rowCount; i++) {
            HSSFRow row = sheet.createRow(rowNum + i);
            if (columnNum > 0) {
                for (int j = 0; j < columnNum; j++) {
                    HSSFCell cell = row.createCell(j);
                    if (cellStyle != null) {
                        cell.setCellStyle(cellStyle);
                    }
                }
            }
        }
        return true;
    }
    /**
     * 合并单元格
     *
     * @param sheet
     * @param firstRow
     * @param lastRow
     * @param firstCol
     * @param lastCol
     * @return
     */
    public static int mergeRegion(HSSFSheet sheet, int firstRow, int lastRow, int firstCol, int lastCol) {
        int num = sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, firstCol, lastCol));
        return num;
    }
    /**
     * 创建单元格样式
     *
     * @param wb
     * @param align
     * @param bold
     * @param border
     * @param backColor
     * @return
     */
    public static HSSFCellStyle createCellStyle(HSSFWorkbook wb, short align, boolean bold, boolean border, short backColor) {
        HSSFCellStyle style = wb.createCellStyle();
        //字体
        HSSFFont font = wb.createFont();
        font.setBold(bold);
        font.setFontName("宋体");
        font.setFontHeight((short) 220);
        style.setFont(font);
        //设置对齐
//        style.setAlignment(align);
//        style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
        if (border) {
            // 设置边框
//            style.setBottomBorderColor(HSSFColor.BLACK.index);
//            style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//            style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
//            style.setBorderRight(HSSFCellStyle.BORDER_THIN);
//            style.setBorderTop(HSSFCellStyle.BORDER_THIN);
        }
        if (backColor > 0) {
            style.setFillBackgroundColor((short) backColor);
        }
        return style;
    }
    /* **************************************** Excel 读取 *************************************************************** */
    /**
     * 读取Excel内容
     *
     * @param is       Excel文件流
     * @param fileName excel文件名,包括后缀
     * @return
     * @throws IOException
     */
    public static List<Map<Object, Object>> readExcel(InputStream is, String fileName) throws IOException {
        List<Map<Object, Object>> list = null;
        boolean isExcel2007 = isExcel2007(fileName);
        if (isExcel2007) {
            list = readExcel2007(is);
        } else {
            list = readExcel2003(is);
        }
        return list;
    }
    /**
     *  读取Excel2003内容
     * @param is  Excel文件流
     * @return
     * @throws IOException
     */
    public static List<Map<Object, Object>> readExcel2003(InputStream is) throws IOException {
        HSSFWorkbook hssfWorkbook = new HSSFWorkbook(is);
        Map<Object, Object> student = null;
        List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
        // 循环工作表Sheet
        for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
            HSSFSheet hssfSheet = hssfWorkbook.getSheetAt(numSheet);
            if (hssfSheet == null) {
                continue;
            }
            //获取表头字段
            HSSFRow columnName = hssfSheet.getRow(0);
            // 循环行Row
            for (int rowNum = 1; rowNum <= hssfSheet.getLastRowNum(); rowNum++) {
                HSSFRow hssfRow = hssfSheet.getRow(rowNum);
                if (hssfRow != null) {
                    student = setCellVal(columnName, hssfRow);
                    list.add(student);
                }
            }
        }
        return list;
    }
    /**
     * 获取Excel单元格的值
     * @param hssfCell  单元格对象
     * @return
     */
    @SuppressWarnings("static-access")
    public static Object getExcelValue(HSSFCell hssfCell) {
        if(hssfCell==null){
            return null;
        }else  if (hssfCell.getCellType() == hssfCell.CELL_TYPE_BOOLEAN) {
            // 返回布尔类型的值
            return hssfCell.getBooleanCellValue();
        } else if (hssfCell.getCellType() == hssfCell.CELL_TYPE_NUMERIC) {
            // 返回数值类型的值
            return (int)hssfCell.getNumericCellValue();
        } else {
            // 返回字符串类型的值
            return hssfCell.getStringCellValue();
        }
    }
    /**
     * 获取Excel2007的内容
     * @param is    输入流
     * @return
     */
    public static List<Map<Object, Object>> readExcel2007(InputStream is) {
        XSSFWorkbook hssfWorkbook = null;
        List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
        try {
            hssfWorkbook = new XSSFWorkbook(is);
            Map<Object, Object> result = null;
            // 循环工作表Sheet
            for (int numSheet = 0; numSheet < hssfWorkbook.getNumberOfSheets(); numSheet++) {
                XSSFSheet xssfSheet = hssfWorkbook.getSheetAt(numSheet);
                if (xssfSheet == null) {
                    continue;
                }
                //获取表头字段
                XSSFRow columnName = xssfSheet.getRow(0);
                // 循环行Row
                for (int rowNum = 1; rowNum <= xssfSheet.getLastRowNum(); rowNum++) {
                    XSSFRow hssfRow = xssfSheet.getRow(rowNum);
                    if (hssfRow != null) {
                        result = setCellVal(columnName, hssfRow);
                        list.add(result);
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
    @SuppressWarnings("static-access")
    public static Object getExcelValue(XSSFCell xssfCell) {
        if(xssfCell==null){
            return null;
        }else if (xssfCell.getCellType() == xssfCell.CELL_TYPE_BOOLEAN) {
            // 返回布尔类型的值
            return xssfCell.getBooleanCellValue();
        } else if (xssfCell.getCellType() == xssfCell.CELL_TYPE_NUMERIC) {
            // 返回数值类型的值
            return (int)xssfCell.getNumericCellValue();
        } else {
            // 返回字符串类型的值
            return xssfCell.getStringCellValue();
        }
    }
    public static Map<Object, Object> setCellVal(XSSFRow names, XSSFRow values) {
        Map<Object, Object> map = new HashMap<>();
        Object name = null;
        Object value = null;
        for (int i = 0; i < names.getLastCellNum(); i++) {
            name = getExcelValue(names.getCell(i));
            value = getExcelValue(values.getCell(i));
            map.put(name, value);
        }
        return map;
    }
    public static Map<Object, Object> setCellVal(HSSFRow names, HSSFRow values) {
        Map<Object, Object> map = new HashMap<>();
        Object name = null;
        Object value = null;
        for (int i = 0; i < names.getLastCellNum(); i++) {
            name = getExcelValue(names.getCell(i));
            value = getExcelValue(values.getCell(i));
            map.put(name, value);
        }
        return map;
    }
    public static boolean isExcel2007(String filePath) {
        return filePath.matches("^.+\\.(?i)(xlsx)$");
    }
    /* ********************************  重写poi,2018-05-16 by hzy   ******************************************* */
    /**
     * 获取excel对象
     * @param file
     * @return
     */
    public static Workbook getWorkBook(MultipartFile file) {
        //获得文件名
        String fileName = file.getOriginalFilename();
        //创建Workbook工作薄对象,表示整个excel
        Workbook workbook = null;
        try {
            //获取excel文件的io流
            InputStream is = file.getInputStream();
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
            if(fileName.toLowerCase().endsWith(xls)){
                //2003
                workbook = new HSSFWorkbook(is);
            }else if(fileName.toLowerCase().endsWith(xlsx)){
                //2007
                workbook = new XSSFWorkbook(is);
            }
        } catch (IOException e) {
            e.printStackTrace();
            logger.info(e.getMessage());
        }
        return workbook;
    }
    /**
     * 获取Excel的内容
     * @param file    上传的文件
     * @return
     */
    public static List<Map<Object, Object>> readExcel (File file) {
        Workbook workBook = null;
        List<Map<Object, Object>> list = new ArrayList<Map<Object, Object>>();
        try {
            workBook = getWorkBook(file);
            Map<Object, Object> result = null;
            // 循环工作表Sheet
            for (int numSheet = 0; numSheet < workBook.getNumberOfSheets(); numSheet++) {
                Sheet sheet = workBook.getSheetAt(numSheet);
                if (sheet == null) {
                    continue;
                }
                //获取表头字段
                Row columnName = sheet.getRow(0);
                // 循环行Row
                for (int rowNum = 1; rowNum <= sheet.getLastRowNum(); rowNum++) {
                    Row hssfRow = sheet.getRow(rowNum);
                    if (hssfRow != null) {
                        result = setCellVal(columnName, hssfRow);
                        list.add(result);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
    /**
     * 设置单元格值
     * @param names
     * @param values
     * @return
     */
    public static Map<Object, Object> setCellVal(Row names, Row values) {
        Map<Object, Object> map = new HashMap<>();
        Object name = null;
        Object value = null;
        for (int i = 0; i < names.getLastCellNum(); i++) {
            name = getCellValue(names.getCell(i));
            value = getCellValue(values.getCell(i));
            map.put(name, value);
        }
        return map;
    }
    /**
     * 获取excel对象
     * @param file
     * @return
     */
    public static Workbook getWorkBook(File file) throws IOException {
        //创建Workbook工作薄对象,表示整个excel
        Workbook workbook = null;
        FileOutputStream fileOut = null;
        try {
            //获得文件名
            String fileName = file.getName();
            //创建excel文件的out流
             fileOut = new FileOutputStream(file);
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
            if(fileName.toLowerCase().endsWith(xls)){
                //2003
                workbook = new HSSFWorkbook();
            }else if(fileName.toLowerCase().endsWith(xlsx)){
                //2007
                workbook = new XSSFWorkbook();
            }
            workbook.write(fileOut);
        } catch (IOException e) {
            e.printStackTrace();
            logger.info(e.getMessage());
        }finally {
            if (fileOut!=null){
                fileOut.flush();
                fileOut.close();
            }
        }
        return workbook;
    }
    /**
     * 获取excel对象
     * @param is
     * @return
     */
    public static Workbook getWorkBook(String fileName,InputStream is) {
        //创建Workbook工作薄对象,表示整个excel
        Workbook workbook = null;
        try {
            //根据文件后缀名不同(xls和xlsx)获得不同的Workbook实现类对象
            if(fileName.toLowerCase().endsWith(xls)){
                //2003
                workbook = new HSSFWorkbook(is);
            }else if(fileName.toLowerCase().endsWith(xlsx)){
                //2007
                workbook = new XSSFWorkbook(is);
            }
        } catch (IOException e) {
            logger.info(e.getMessage());
        }
        return workbook;
    }
    /**
     *   获取单元格值
     * @param cell     excel单元格对象
     * @return
     */
    public static String getCellValue(Cell cell){
        String cellValue = "";
        if(cell == null){
            return cellValue;
        }
        //把数字当成String来读,避免出现1读成1.0的情况
        if(cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
            cell.setCellType(Cell.CELL_TYPE_STRING);
        }
        //判断数据的类型
        switch (cell.getCellType()){
            case Cell.CELL_TYPE_NUMERIC: //数字
                cellValue = String.valueOf(cell.getNumericCellValue());
                break;
            case Cell.CELL_TYPE_STRING: //字符串
                cellValue = String.valueOf(cell.getStringCellValue());
                break;
            case Cell.CELL_TYPE_BOOLEAN: //Boolean
                cellValue = String.valueOf(cell.getBooleanCellValue());
                break;
            case Cell.CELL_TYPE_FORMULA: //公式
                cellValue = String.valueOf(cell.getCellFormula());
                break;
            case Cell.CELL_TYPE_BLANK: //空值
                cellValue = "";
                break;
            case Cell.CELL_TYPE_ERROR: //故障
                cellValue = "非法字符";
                break;
            default:
                cellValue = "未知类型";
                break;
        }
        return cellValue;
    }
    public void addCell(Sheet ws, int row, int column, String data )  {
        Row row1 = ws.createRow(row);
        Cell cell = row1.createCell(column);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(data);
    }
    //添加单元格内容
    public static void addCellData(Sheet sheet, int column, int row, String data){
        Row sheetRow = sheet.getRow(row);
        if(sheetRow==null){
            sheetRow = sheet.createRow(row);
        }
        Cell cell= sheetRow.createCell(column);
        cell.setCellValue(data);
    }
    //添加单元格内容带样式
    public static void addCellData(Sheet sheet, int column, int row, String data, CellStyle cellStyle){
        Row sheetRow = sheet.getRow(row);
        if(sheetRow==null){
            sheetRow = sheet.createRow(row);
        }
        Cell cell= sheetRow.createCell(column);
        cell.setCellValue(data);
        cell.setCellStyle(cellStyle);
    }
    @Override
    public void write(Workbook wwb, List ls, File file) throws Exception {
    }
}

+ 1 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/common/populationBatchImport/PopulationMsg.java

@ -8,6 +8,7 @@ import com.yihu.jw.util.excel.annotation.Location;
import com.yihu.jw.util.excel.annotation.Row;
import com.yihu.jw.util.excel.annotation.Title;
import com.yihu.jw.util.excel.annotation.ValidRepeat;
import org.apache.commons.lang3.StringUtils;
import javax.persistence.Column;

+ 1 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/wx/WechatController.java

@ -10,6 +10,7 @@ import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.wechat.service.WxTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

+ 1 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/BaseDoctorService.java

@ -36,6 +36,7 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.*;
/**
@ -663,5 +664,4 @@ public class BaseDoctorService extends BaseJpaService<BaseDoctorDO, BaseDoctorDa
        return result;
    }
}

+ 2 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/service/doctor/excelImport/BaseDoctorExcelDOReader.java

@ -6,17 +6,15 @@ import com.yihu.jw.base.dao.doctor.BaseDoctorRoleInfoDao;
import com.yihu.jw.base.endpoint.common.excel.AExcelReader;
import com.yihu.jw.dict.dao.DictDoctorDutyDao;
import com.yihu.jw.dict.dao.DictHospitalDeptDao;
import com.yihu.jw.entity.base.dict.DictJobTitleDO;
import com.yihu.jw.entity.base.doctor.BaseDoctorRoleDO;
import com.yihu.jw.org.dao.BaseOrgDao;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import java.util.*;
import java.util.HashSet;
import java.util.Iterator;
/**
 * 医生信息列表-excel解析类

+ 21 - 2
svr/svr-internet-hospital-entrance/src/main/java/com/yihu/jw/entrance/controller/XzzxCotroller.java

@ -24,7 +24,26 @@ public class XzzxCotroller extends EnvelopRestEndpoint {
    @GetMapping(value = "/getDeptInfo")
    @ApiOperation(value = "获取部门信息", notes = "获取部门信息")
    public ObjEnvelop getDeptInfo()throws Exception{
        return ObjEnvelop.getSuccess("ok",xzzxEntranceService.getDeptInfo());
    public ObjEnvelop getDeptInfo(String code)throws Exception{
        return ObjEnvelop.getSuccess("ok",xzzxEntranceService.getDeptInfo(code));
    }
    @GetMapping(value = "/getDoctorInfo")
    @ApiOperation(value = "获取医生信息", notes = "获取医生信息")
    public ObjEnvelop getDoctorInfo(String idcard)throws Exception{
        return ObjEnvelop.getSuccess("ok",xzzxEntranceService.getDoctorInfo(idcard));
    }
    @GetMapping(value = "/getJobTitle")
    @ApiOperation(value = "同步职称", notes = "同步职称")
    public ObjEnvelop getJobTitle()throws Exception{
        return ObjEnvelop.getSuccess("ok",xzzxEntranceService.getJobTitle());
    }
    @GetMapping(value = "/getChargeDict")
    @ApiOperation(value = "同步号别", notes = "同步号别")
    public ObjEnvelop getChargeDict()throws Exception{
        return ObjEnvelop.getSuccess("ok",xzzxEntranceService.getChargeDict());
    }
}

+ 1 - 0
svr/svr-internet-hospital-job/pom.xml

@ -67,6 +67,7 @@
            <version>2.4</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.jw</groupId>
            <artifactId>common-entity</artifactId>

+ 65 - 11
svr/svr-internet-hospital/src/main/java/com/yihu/jw/hospital/endpoint/prescription/PrescriptionEndpoint.java

@ -1,6 +1,7 @@
package com.yihu.jw.hospital.endpoint.prescription;
import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
import com.yihu.jw.doctor.service.excel.DoctorWorkTimeExcelReader;
import com.yihu.jw.doctor.service.excel.DoctorWorkTimeMainExcelDO;
import com.yihu.jw.entity.hospital.message.SystemMessageDO;
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
import com.yihu.jw.entity.hospital.prescription.WlyyPrescriptionDiagnosisDO;
@ -12,10 +13,6 @@ import com.yihu.jw.hospital.prescription.service.WorkTimeService;
import com.yihu.jw.hospital.prescription.service.entrance.DoctorPreSignService;
import com.yihu.jw.hospital.service.SystemMessage.HospitalSystemMessageService;
import com.yihu.jw.im.service.ImService;
import com.yihu.jw.restmodel.base.dict.DictHospitalDeptVO;
import com.yihu.jw.restmodel.base.org.BaseOrgVO;
import com.yihu.jw.restmodel.hospital.consult.WlyyHospitalSysDictVO;
import com.yihu.jw.restmodel.hospital.doctor.WlyyDoctorWorkTimeVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyOutpatientVO;
import com.yihu.jw.restmodel.hospital.prescription.WlyyPrescriptionVO;
import com.yihu.jw.restmodel.im.ConsultVO;
@ -30,21 +27,20 @@ import com.yihu.jw.wlyy.service.WlyyBusinessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import oracle.jdbc.proxy.annotation.Post;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;
/**
 * Created by Trick on 2019/5/16.
 * Created by Trick on 2019/5/16
 */
@RestController
@RequestMapping(value = BaseHospitalRequestMapping.Prescription.PREFIX)
@ -1008,14 +1004,72 @@ public class PrescriptionEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value= BaseHospitalRequestMapping.Prescription.findWorkTimeRule)
    @ApiOperation(value = "查询排班规则")
    public ObjEnvelop findWorkTimeRule(@ApiParam(name = "hospital", value = "医院code")
                                       @RequestParam(value = "hospital",required = false)String hospital) {
                                       @RequestParam(value = "hospital",required = true)String hospital) {
        return success(workTimeService.findWorkTimeRule(hospital));
    }
    @PostMapping(value= BaseHospitalRequestMapping.Prescription.saveWorkTimeRule)
    @ApiOperation(value = "保存排班规则")
    public ObjEnvelop saveWorkTimeRule(@ApiParam(name = "workTimeRuleJson", value = "保存排班规则")
                                       @RequestParam(value = "workTimeRuleJson",required = false)String workTimeRuleJson) throws Exception{
                                           @RequestParam(value = "workTimeRuleJson",required = true)String workTimeRuleJson) throws Exception{
        return success(workTimeService.saveWorkTimeRule(workTimeRuleJson));
    }
    @PostMapping(value= BaseHospitalRequestMapping.Prescription.checkDoctorWork)
    @ApiOperation(value = "判断医生是否在班")
    public ObjEnvelop checkDoctorWork(@ApiParam(name = "doctor", value = "判断医生是否在班")
                                      @RequestParam(value = "doctor",required = true)String doctor) throws Exception{
        return success(workTimeService.checkDoctorWork(doctor));
    }
    @PostMapping(value= BaseHospitalRequestMapping.Prescription.importDoctorWork)
    @ApiOperation(value = "导入排班信息")
    public ListEnvelop importDoctorWork(@ApiParam(name = "file", value = "文件", required = true)
                                        @RequestPart(value = "file") MultipartFile file,
                                        @ApiParam(name = "hospital", value = "医院编码")
                                        @RequestParam(value = "hospital",required = true)String hospital,
                                        @ApiParam(name = "dateMoth", value = "年-月,格式:2020-03")
                                        @RequestParam(value = "dateMoth",required = true)String dateMoth,
                                        HttpServletRequest request)throws Exception{
        request.setCharacterEncoding("UTF-8");
        DoctorWorkTimeExcelReader reader = new DoctorWorkTimeExcelReader();
        reader.read(file);
        if("-1".equals(reader.getCode())) {
            ListEnvelop envelop = new ListEnvelop();
            envelop.setStatus(-1);
            envelop.setMessage("目前仅支持200位医生同时导入!");
            return envelop;
        }
        List<DoctorWorkTimeMainExcelDO> errorLs = reader.getErrorLs();
        List<DoctorWorkTimeMainExcelDO> correctLs = reader.getCorrectLs();
        if(errorLs!=null&&errorLs.size()>0){
            ListEnvelop envelop = new ListEnvelop();
            envelop.setStatus(-1);
            envelop.setMessage("格式错误!");
            envelop.setDetailModelList(errorLs);
            return envelop;
        }
        Map<String,Object> rs = workTimeService.getExcelWorkInfo(correctLs,dateMoth,hospital);
        List<DoctorWorkTimeMainExcelDO> error = (List<DoctorWorkTimeMainExcelDO>)rs.get("error");
        Integer errorTotal = (Integer) rs.get("errorTotal");
        Integer succTotal = (Integer) rs.get("succTotal");
        if(error!=null&&error.size()>0){
            ListEnvelop envelop = new ListEnvelop();
            envelop.setStatus(-1);
            envelop.setMessage(succTotal+"位医生,更新成功!"+","+errorTotal+"位医生,身份信息错误!更新失败!");
            envelop.setDetailModelList(error);
            return envelop;
        }
        ListEnvelop envelop = new ListEnvelop();
        envelop.setStatus(200);
        envelop.setMessage("导入成功!"+succTotal+"位医生排班数据!");
        envelop.setDetailModelList(error);
        return envelop;
    }
}

+ 6 - 4
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/rehabilitation/RehabilitationManageController.java

@ -140,9 +140,11 @@ public class RehabilitationManageController {
    public ObjEnvelop serviceItem(@ApiParam(name = "planDetailId", value = "服务项目id", required = true)
                                  @RequestParam(value = "planDetailId", required = true)String planDetailId,
                                  @ApiParam(name = "doctorCode", value = "医生code", required = false)
                                  @RequestParam(value = "doctorCode", required = false)String doctorCode){
                                  @RequestParam(value = "doctorCode", required = false)String doctorCode,
                                  @ApiParam(name = "recordId", value = "记录id", required = false)
                                      @RequestParam(value = "recordId", required = false)String recordId){
        try {
            return rehabilitationManageService.serviceItem(planDetailId,doctorCode);
            return rehabilitationManageService.serviceItem(planDetailId,doctorCode,recordId);
        }catch (Exception e){
            e.printStackTrace();
            tracer.getCurrentSpan().logEvent(e.getMessage());
@ -257,9 +259,9 @@ public class RehabilitationManageController {
    @GetMapping(value = SpecialistMapping.rehabilitation.appCalendarPlanDetailList)
    @ApiOperation(value = "康复管理-app端、微信端计划的服务项目列表")
    public ObjEnvelop appCalendarPlanDetailList(@ApiParam(name = "executeStartTime", value = "日历开始时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                             @RequestParam(value = "executeStartTime", required = true)String executeStartTime,
                                             @RequestParam(value = "executeStartTime", required = false)String executeStartTime,
                                             @ApiParam(name = "executeEndTime", value = "日历结束时间(格式:yyyy-MM-dd HH:mm:ss)", required = true)
                                             @RequestParam(value = "executeEndTime", required = true)String executeEndTime,
                                             @RequestParam(value = "executeEndTime", required = false)String executeEndTime,
                                             @ApiParam(name = "planId", value = "计划id", required = true)
                                             @RequestParam(value = "planId", required = true)String planId,
                                             @ApiParam(name = "searchTask", value = "快速查找任务:(1、我的任务,2、随访,3、复诊,4、健康教育)", required = false)

+ 2 - 2
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/controller/rehabilitation/RehabilitationPlanController.java

@ -256,9 +256,9 @@ public class RehabilitationPlanController extends EnvelopRestEndpoint {
        try {
            RehabilitationOperateRecordsDO rehabilitationOperateRecordsDO= toEntity(dataJson, RehabilitationOperateRecordsDO.class);
            List<RehabilitationOperateRecordsDO> list = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(rehabilitationOperateRecordsDO.getRehabilitationDetailId());
            if (list!=null && list.size()>0){
           /* if (list!=null && list.size()>0){
                return MixEnvelop.getError("该明细日志已存在!");
            }
            }*/
            return MixEnvelop.getSuccess(SpecialistMapping.api_success,rehabilitationPlanService.saveRehabilitationRecord(rehabilitationOperateRecordsDO));
        }catch (Exception e){
            e.printStackTrace();

+ 2 - 0
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/dao/rehabilitation/RehabilitationOperateRecordsDao.java

@ -15,6 +15,8 @@ public interface RehabilitationOperateRecordsDao extends PagingAndSortingReposit
    List<RehabilitationOperateRecordsDO> findByRehabilitationDetailId(String rehabilitationDetailId);
    List<RehabilitationOperateRecordsDO> findByRehabilitationDetailIdAndId(String rehabilitationDetailId,String id);
    @Modifying
    @Query("update RehabilitationOperateRecordsDO a set a.status=?1 where a.rehabilitationDetailId =?2 ")
    int updateStatus(Integer status,String rehabilitationDetailId);

+ 17 - 4
svr/svr-wlyy-specialist/src/main/java/com/yihu/jw/service/rehabilitation/RehabilitationManageService.java

@ -460,7 +460,7 @@ public class RehabilitationManageService {
        String sql = " select d.*,DATE_FORMAT(d.execute_time,'%Y/%m/%d %H:%i') as executeTime ,i.code,i.name from wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
                " LEFT JOIN wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id  " +
                " where d.execute_time>='"+executeStartTime+"' and d.execute_time<='"+executeEndTime+"' and d.plan_id='"+planId+"' " ;
                " where  d.plan_id='"+planId+"' " ;
        if(searchTask!=null){
            if(searchTask==8){
                sql+="and d.doctor='"+doctorCode+"' ";
@ -470,6 +470,9 @@ public class RehabilitationManageService {
                sql+=" and i.reserve=1 " ;
            }*/
        }
        if (StringUtils.isNoneBlank(executeEndTime)&&StringUtils.isNoneBlank(executeStartTime)){
            sql+="and d.execute_time>='"+executeStartTime+"' and d.execute_time<='"+executeEndTime+"' ";
        }
        if(status!=null){
            sql+= "and d.status="+status;
        }
@ -595,7 +598,7 @@ public class RehabilitationManageService {
        }
        String planDetailResult = StringUtils.isNotEmpty(planDetailList)?planDetailList.substring(1):"";
        String sql = "select i.name,i.code,i.content,d.execute_time,d.hospital_name,d.id,d.status,d.type as detailType,d.expense,d.doctor as executeDoctor," +
                " d.doctor_name as executeDoctorName,p.patient ,p.create_user as createDoctor,p.create_user_name as createDoctorName, p.status as planStatus  " +
                " d.doctor_name as executeDoctorName,p.patient ,p.id AS planId,p.create_user as createDoctor,p.create_user_name as createDoctorName, p.status as planStatus  " +
                " from wlyy_specialist.wlyy_rehabilitation_plan_detail d " +
                " LEFT JOIN wlyy_specialist.wlyy_rehabilitation_service_item i on i.code = d.hospital_service_item_id " +
                " LEFT JOIN wlyy_specialist.wlyy_patient_rehabilitation_plan p on d.plan_id=p.id " +
@ -623,6 +626,7 @@ public class RehabilitationManageService {
            resultMap.put("specialistDoctorName",one.get("createDoctorName")+"");//创建人(专科)医生名字
            resultMap.put("title",one.get("name"));//项目标题
            resultMap.put("planDetaiId",one.get("id"));//计划服务项目id
            resultMap.put("planId",one.get("planId"));//计划id
            resultMap.put("shortExecuteTime",DateUtil.dateToStr((Date) one.get("execute_time"),DateUtil.HH_MM));//项目标题
            resultMap.put("content",one.get("content"));//项目内容
            resultMap.put("hospitalName",one.get("hospital_name"));//地点
@ -688,7 +692,7 @@ public class RehabilitationManageService {
     * @throws Exception
     *
     */
    public ObjEnvelop serviceItem(String planDetailId,String doctorCode) throws Exception{
    public ObjEnvelop serviceItem(String planDetailId,String doctorCode,String recordId) throws Exception{
        String sql = "select h.name as title,h.content as content,h.code as itemType,d.id,d.execute_time,d.hospital_name,d.status,d.type,d.expense,d.doctor as executeDoctor, " +
                " d.doctor_name as executeDoctorName,p.patient ,p.name as patientName,p.create_user as createDoctor,p.create_user_name as createDoctorName, p.status as planStatus," +
                " p.disease,p.disease_name as diseaseName,p.title as planTitle,d.plan_id as planId,d.relation_code as relationCode "+
@ -756,7 +760,13 @@ public class RehabilitationManageService {
        resultMap.put("type",one.get("itemType"));//1扫码、0上传附件、2、健康教育,3、健康指导,4、随访
        //是否完成任务
        List<RehabilitationOperateRecordsDO> operateList = rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
        List<RehabilitationOperateRecordsDO> operateList = new ArrayList<>();
        if(StringUtils.isNoneBlank(recordId)){
            operateList= rehabilitationOperateRecordsDao.findByRehabilitationDetailIdAndId(one.get("id").toString(),recordId);
        }else {
            operateList= rehabilitationOperateRecordsDao.findByRehabilitationDetailId(one.get("id").toString());
        }
        Integer operate = 0;
        if(operateList.size()>0){
            RehabilitationOperateRecordsDO temp = operateList.get(0);
@ -1076,6 +1086,7 @@ public class RehabilitationManageService {
        guidanceMessageLogDO.setAdminTeamName(adminTeamName);
        guidanceMessageLogDO.setDoctorName(doctorName);
        guidanceMessageLogDO.setCreateTime(new Date());
        guidanceMessageLogDO.setUpdateTime(new Date());
        guidanceMessageLogDao.save(guidanceMessageLogDO);
        return Envelop.getSuccess(SpecialistMapping.api_success);
    }
@ -1353,8 +1364,10 @@ public class RehabilitationManageService {
        Integer allCount = rehabilitationDetailDao.findAllByPlanId(planId);//计划总服务项目数
        Integer finishedCount = rehabilitationDetailDao.findByStatusAndPlanId(1,planId);
        PatientRehabilitationPlanDO p =patientRehabilitationPlanDao.findById(planId);
        SpecialistPatientRelationDO specialistPatientRelationDO = specialistPatientRelationDao.findByDoctorAndPatient(p.getCreateUser(),p.getPatient());
        resultMap.put("allCount",allCount);
        resultMap.put("finishedCount",finishedCount);
        resultMap.put("specialistPatientRelationDO",specialistPatientRelationDO);
        if (p!=null){
            resultMap.put("disease",p.getDisease());
            resultMap.put("diseaseName",p.getDiseaseName());