持续更新ing...
1.JAVA基础
1.String类型数据操作
1.字符串类型时间 转换 显示格式 (比如 HH:mm:ss 格式换成 HH:mm)
//格式化时间 //1.获取 string类型 时间 String str = "8:00:00"; Date date = null; try { //2.字符串时间转换成date类型 date = (Date) new SimpleDateFormat("HH:mm:ss").parse(str); } catch (ParseException e) { e.printStackTrace(); } //3.设置日期格式 SimpleDateFormat df = new SimpleDateFormat("HH:mm"); //4.在转换成String类型 str= df.format(date);
2.字符串类型判空
null != str && str.equals("1")
length(); 判断数组长度 size(); 判断集合长度
3.去除字符串前后空格, 替换
.trim()
把字符串中a替换成b
.replaceAll("a","b")
4.字符串类型 数字比较大小
public int calculate(String s) { //下面两种方法效果一样,任选其一 BigDecimal a = BigDecimal.valueOf(Double.valueOf(s)); BigDecimal c = new BigDecimal(s); // 将获取的 BigDecimal值 乘以1000 a = a.multiply(BigDecimal.valueOf(1000)); int result = a.intValue(); return result; }
2.集合的操作
1.List
1.List获取 交集, 差集, 并集, 去重并集
public static void main(String[] args) { List<String> list1 = new ArrayList<>(); list1.add("1"); list1.add("2"); list1.add("3"); list1.add("5"); list1.add("6"); List<String> list2 = new ArrayList<>(); list2.add("2"); list2.add("3"); list2.add("7"); list2.add("8"); //------------------------- 交集 --------------------------------------- List<String> intersection = list1.stream().filter(item -> list2.contains(item)).collect(toList()); System.out.println("---交集 intersection---"); intersection.parallelStream().forEach(System.out :: println); //------------------------- 差集 --------------------------------------- List<String> reduce1 = list1.stream().filter(item -> !list2.contains(item)).collect(toList()); System.out.println("---差集 reduce1 (list1 - list2)---"); reduce1.parallelStream().forEach(System.out :: println); //------------------------- 并集 --------------------------------------- List<String> listAll = list1.parallelStream().collect(toList()); List<String> listAll2 = list2.parallelStream().collect(toList()); listAll.addAll(listAll2); System.out.println("---并集 listAll---"); listAll.parallelStream().forEachOrdered(System.out :: println); //------------------------- 去重并集 --------------------------------------- List<String> listAllDistinct = listAll.stream().distinct().collect(toList()); System.out.println("---得到去重并集 listAllDistinct---"); listAllDistinct.parallelStream().forEachOrdered(System.out :: println); System.out.println("---原来的List1---"); list1.parallelStream().forEachOrdered(System.out :: println); System.out.println("---原来的List2---"); list2.parallelStream().forEachOrdered(System.out :: println); }
2.List集合删除数据
(推荐使用迭代器, for循环会改变集合结构, 迭代器无需关心这个问题)
1.使用迭代器 2.for循环倒着删除 3.正向删除每次集合长度要减一
Iterator<String> it = list.iterator(); while(it.hasNext()){ String str = it.next(); it.remove(); }
3.List集合排序
1. TreeSet特性(有序不重复集合)
去重加顺序排序, *注意 数据类型String 或者int
List<String> listTime = new ArrayList(new TreeSet(thisExecTimes));
2.先根据 Name属性 排序再根据Age属性排序 , 升序如下, java8新特性
list.sort(Comparator.comparing(User::getName).thenComparing(User::getAge));
List<User> a= list.sort(Comparator.comparing(User::getName).thenComparing(User::getAge)).collect(Collectors.toList());
降序
list.sort(Comparator.comparing(User::getName).thenComparing(User::getAge).reversed());
3.原生方法-自定义 Comparator
1.重写compare
Collections.sort(list, new Comparator<TestA>() { @Override public int compare(TestA o1, TestA o2) { //升序 return o1.getAge().compareTo(o2.getAge()); } });
2.通过compare方法
// 4.排序 /* 按巡视时间排序时,优先倒序排序已到巡视时间的患者,剩余患者按床号排序 按床号排序时,只按床号排序 */ String sort = req.getSort(); Comparator<PatrolIntervalPack> sortComparat = null; final String bed = "bed"; if (StrUtil.isNotBlank(sort) && sort.equals(bed)) { sortComparat = Comparator.comparing(PatrolIntervalPack::getBedName) .thenComparing(PatrolIntervalPack::getTimeInterval); } else { sortComparat = Comparator.comparing(PatrolIntervalPack::getTimeInterval) .thenComparing(PatrolIntervalPack::getBedName); } patrolIntervalPackList = patrolIntervalPackList.stream() .sorted(sortComparat) .collect(Collectors.toList());
4.字符串复杂排序整合(工具类)
(方法一 调用 方法二)
list.sort((o1, o2) -> { LetterNumberComparator letterNumberComparator = new LetterNumberComparator(); return letterNumberComparator.compare(o1.getBedName(), o2.getBedName()); });
package unicom.mobile.nersu.console.util; import cn.hutool.core.util.StrUtil; import java.util.Comparator; /** * @author Kit * @date 2020/6/11 16:38 */ public class LetterNumberComparator implements Comparator<String> { /** * ASCII编码 0 */ private static final Integer MIN_NUMBER = 48; /** * ASCII编码 9 */ private static final Integer MAX_NUMBER = 57; @Override public int compare(String s1, String s2) { if (StrUtil.isAllBlank(s1, s2)) { return 0; } if (StrUtil.isBlank(s1)) { return 1; } if (StrUtil.isBlank(s2)) { return -1; } // 特殊字符开头 char s1Index = s1.charAt(0); char s2Index = s2.charAt(0); boolean flag; // s1字符 s2数字 flag = (s1Index < MIN_NUMBER || s1Index > MAX_NUMBER) && (s2Index >= MIN_NUMBER && s2Index <= MAX_NUMBER); if (flag) { return s1.compareTo(s2); } flag = (s2Index < MIN_NUMBER || s2Index > MAX_NUMBER) && (s1Index >= MIN_NUMBER && s1Index <= MAX_NUMBER); // s1数字 s2字符 if (flag) { return s1.compareTo(s2); } // s1字符 s2字符 flag = (s2Index < MIN_NUMBER || s2Index > MAX_NUMBER) && (s1Index < MIN_NUMBER || s1Index > MAX_NUMBER); if (flag) { return s1.compareTo(s2); } // [^(0-9)]+ 这个正则含义: 不是数字的所有内容视为一个整体替换成 _ String[] str1Arr = s1.replaceAll("[^(0-9)]+", "_").split("[^(0-9)]"); String[] str2Arr = s2.replaceAll("[^(0-9)]+", "_").split("[^(0-9)]"); int lim = Math.min(str1Arr.length, str2Arr.length); for (int i = 0; i < lim; i++) { int int1 = Integer.parseInt(str1Arr[i]); int int2 = Integer.parseInt(str2Arr[i]); if (int1 != int2) { return int1 - int2; } } return 0; } }
-
String 类型集合排序
Collections.sort(list)
2.Map
1.遍历
public static void main(String[] args) { Map<Integer, String> map = new HashMap<Integer, String>(); map.put(1, "a"); map.put(2, "b"); map.put(3, "ab"); map.put(4, "ab"); map.put(4, "ab");// 和上面相同 , 会自己筛选 System.out.println(map.size());
System.out.println("第一种:通过Map.keySet遍历key和value:"); for (Integer in : map.keySet()) { //map.keySet()返回的是所有key的值 String str = map.get(in);//得到每个key多对用value的值 System.out.println(in + " " + str); }
System.out.println("第二种:通过Map.entrySet使用iterator遍历key和value:"); Iterator<Map.Entry<Integer, String>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Integer, String> entry = it.next(); System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue()); } // 第三种:推荐,尤其是容量大时 System.out.println("第三种:通过Map.entrySet遍历key和value"); for (Map.Entry<Integer, String> entry : map.entrySet()) { //Map.entry<Integer,String> 映射项(键-值对) 有几个方法:用上面的名字entry //entry.getKey() ;entry.getValue(); entry.setValue(); //map.entrySet() 返回此映射中包含的映射关系的 Set视图。 System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue()); } System.out.println("第四种:通过Map.values()遍历所有的value,但不能遍历key"); for (String v : map.values()) { System.out.println("value= " + v); } }
3.实体类操作: 拷贝对象属性
通过此方法可以拷贝不同类中,相同类型和相同的名字 的属性值
//a拷贝到b BeanUtils.copyProperties(a, b);
只要拷贝非空的值到目标对象。BeanUtils.copyProperties不支持。
1.hutool开源库为我们提供了更为强大的Bean工具-BeanUtil
<dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>4.1.14</version> </dependency>
2.那要想拷贝非空的值到目标对象,只需要使用如下语句
BeanUtil.copyProperties(newBean,oldBean,CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
3.CopyOptions配置项:
ignoreNullValue 是否忽略空值,当源对象的值为null时,true: 忽略而不注入此值,false: 注入null
ignoreProperties 忽略的属性列表,设置一个属性列表,不拷贝这些属性值
ignoreError 是否忽略字段注入错误
可以通过CopyOptions.create()方法创建一个默认的配置项,通过setXXX方法设置每个配置项。
// 当源对象的值为null时,是否忽略空值 CopyOptions copyOptions = CopyOptions.create().setIgnoreNullValue(true); // 是否忽略字段注入错误 CopyOptions.create().setIgnoreError(true); // 为空或默认值(0)设置为null ObjectDefaultUtil.setFieldValueNull(temperature); BeanUtil.copyProperties(temperature, firstTemperatureTemp, copyOptions);
4.打印日志
log.info( "打印textList" + textList.toString() );
5.xpath操作xml
public Map<String, Object> getNeonatalBirth(String xml) throws DocumentException { //xml字符串转Document对象 Document document = DocumentHelper.parseText(xml); String xpath = "//Element[@xsi:type='XInputField']"; List<Node> list = document.selectNodes(xpath); String innerValue; //组建放回对象 Map<String, Object> map = new HashMap<>(); for (Node node : list) { Element element = (Element) node; String name = element.element("Name").getText(); switch (name) { case "姓名": innerValue = element.element("InnerValue").getText(); map.put("name", innerValue); break; case "床号": innerValue = element.element("InnerValue").getText(); map.put("bedName", innerValue); break; case "住院号": innerValue = element.element("InnerValue").getText(); map.put("hospitalId", innerValue); break; case "科室": innerValue = element.element("InnerValue").getText(); map.put("wardName", innerValue); break; case "新生儿转科原因": Element innerValue1 = element.element("InnerValue"); map.put("reason", innerValue1 != null ? innerValue1.getText() : ""); break; case "接生者": innerValue = element.element("InnerValue").getText(); map.put("midwife", innerValue); break; } } return map; }
6.关于时间的操作
1.使用hutool工具类将时间转换为指定的格式
DateUtil.format(patientTemperature.getCreateTime(), DatePattern.NORM_DATETIME_MINUTE_PATTERN)
7.关于Calendar 日历类
Calendar 类常用方法的记录:
1.获取时间
// 使用默认时区和语言环境获得一个日历 Calendar cal = Calendar.getInstance(); // 赋值时年月日时分秒常用的6个值,注意月份下标从0开始,所以取月份要+1 System.out.println("年:" + cal.get(Calendar.YEAR)); System.out.println("月:" + (cal.get(Calendar.MONTH) + 1)); System.out.println("日:" + cal.get(Calendar.DAY_OF_MONTH)); System.out.println("时:" + cal.get(Calendar.HOUR_OF_DAY)); System.out.println("分:" + cal.get(Calendar.MINUTE)); System.out.println("秒:" + cal.get(Calendar.SECOND));
2.设置时间
月份的下标从 0 开始,设置时同样需要注意,比如我们设置为 2 月 15 日除夕当晚的倒计时的最后一秒: 2018-02-15 23:59:59 可以这样:
Calendar cal = Calendar.getInstance(); // 如果想设置为某个日期,可以一次设置年月日时分秒,由于月份下标从0开始赋值月份要-1 // cal.set(year, month, date, hourOfDay, minute, second); cal.set(2018, 1, 15, 23, 59, 59);
或者也可以单个字段一一设置:
// 或者6个字段分别进行设置,由于月份下标从0开始赋值月份要-1 cal.set(Calendar.YEAR, 2018); cal.set(Calendar.MONTH, Calendar.FEBRUARY); cal.set(Calendar.DAY_OF_MONTH, 15); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); System.out.println(cal.getTime());
打印的时间结果为:
Thu Feb 15 23:59:59 CST 2018
3.时间计算
add方法: 比如在除夕当晚最后一秒,add 一秒:
Calendar cal = Calendar.getInstance(); System.out.println(cal.getTime()); cal.set(2018, 1, 15, 23, 59, 59); cal.add(Calendar.SECOND, 1); System.out.println(cal.getTime());
打印时间结果如下,日期会自动进入下一天:
Thu Feb 15 23:59:59 CST 2018 Fri Feb 16 00:00:00 CST 2018
再比如 1 月 31 号的时候,月份加一,会出现怎样结果:
Calendar cal = Calendar.getInstance(); cal.set(2018, 1, 31, 8, 0, 0); System.out.println(cal.getTime()); cal.add(Calendar.MONTH, 1); System.out.println(cal.getTime());
运行结果:
Wed Jan 31 08:00:00 CST 2018 Wed Feb 28 08:00:00 CST 2018
说明 add 月份时,会将不存在的日期归为当月日历的最后一天。
8.compareTo 比较时间大小
NursingSchedulingHandover latestCfg = handoverList.stream().sorted(Comparator.comparing(NursingSchedulingHandover::getEndTime).reversed()) .filter(x -> nowTime.compareTo(x.getEndTime()) > 0 ).findFirst().orElseThrow(() -> new ValidateException("没有合适的班次,请先配置交接班次!"));
比如 2021-1-1 compareTo 2021-1-2 < 0
2.MySql
1.调优
sql语句 gruop by 用来分组, 一般用来求和 大量数据会导致查询变慢,如果无意义 可以删除
2.增加表字段
ALTER TABLE `nursing_quality_control_score` ADD `used` tinyint(1) NOT NULL DEFAULT '1' COMMENT '是否使用 0 未使用 1 使用'; 实体类对应字段 @ApiModelProperty("是否启用 0未启用 1 已启用") private Boolean used;
alter table `patient_temperature` add `pacemaker_heart_rate` varchar(20) DEFAULT NULL COMMENT '起搏器心率(次/分)';
3.MybatisPlus框架
1.排序
使用方法是在查询条件中添加,一共三个
1.升序, 降序
//升序 .orderByAsc(PatientTemperature::getTime) //降序 .orderByDesc(PatientTemperature::getInputTime) //默认 .orderBy(true,true,PatientTemperature::getTime)
2.根据实体类快速生成其他层
public static void main(String[] args) throws IOException { CodeGenerator generator = new CodeGenerator(NursingQualityControlScore.class, CommonTemplatesPath.class); generator.setAuthor("zl"); generator.setComment("护理质控评分表"); generator.setModule("NursingQualityControlScore"); generator.generate(); }
package unicom.mobile.nurse.code.generator; import cn.hutool.core.annotation.AnnotationUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateTime; import cn.hutool.core.io.FileUtil; import cn.hutool.core.lang.Assert; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ClassUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.template.Template; import cn.hutool.extra.template.TemplateConfig; import cn.hutool.extra.template.TemplateEngine; import cn.hutool.extra.template.TemplateUtil; import com.baomidou.mybatisplus.core.metadata.TableFieldInfo; import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.core.toolkit.TableInfoHelper; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import unicom.mobile.nurse.code.generator.templates.info.Field; import unicom.mobile.nurse.code.generator.templates.info.Table; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @author nurse-unicom */ @Slf4j @Setter public class CodeGenerator { private static final String TARGET_CLASSES = "/target/classes/"; private static final String SRC_MAIN_JAVA = "/src/main/java/"; private String comment; /** * 模块 */ private String module; /** * 开发人员 */ private String author; /** * 生成文件的输出目录【默认 D 盘根目录】 */ private String outputDir = "D://"; private String bashPath = ""; private Table table; private Field idField = null; private List<Field> superFields; private List<Field> fields; private TableInfo tableInfo; private Class entityClass; private String templatePath; private List<String> templates; public CodeGenerator(Class entityClass, Class templatePathClass) throws IOException { this.entityClass = entityClass; this.tableInfo = TableInfoHelper.initTableInfo(null, entityClass); loadTable(); loadIdFields(); loadSuperFields(); loadFields(); loadOutputDir(); loadTemplates(templatePathClass); } public void generate() { Assert.notBlank(this.author, "作者不能为空,请使用 setAuthor(Sting str)"); Assert.notBlank(this.module, "模块不能为空,请使用 setModule(Sting str)"); Map<String, Object> bindingMap = buildBindingMap(); TemplateEngine engine = TemplateUtil.createEngine( new TemplateConfig(templatePath, TemplateConfig.ResourceMode.FILE)); for (String templateName : templates) { Template template = engine.getTemplate(templateName); File outPutFile = getOutPutFile(templateName); template.render(bindingMap, outPutFile); log.info("{} 已创建", outPutFile.getName()); } } private Map<String, Object> buildBindingMap() { Map<String, Object> bindingMap = MapUtil.newHashMap(); bindingMap.put("author", author); bindingMap.put("date", new DateTime().toString()); bindingMap.put("module", module); bindingMap.put("basePackage", table.getPackageName()); bindingMap.put("table", table); bindingMap.put("allSqlSelect", getAllSqlSelect()); bindingMap.put("Eo", table.getSimpleName()); bindingMap.put("eo", table.getLowName()); bindingMap.put("hasId", idField != null); bindingMap.put("idField", idField); bindingMap.put("superFields", superFields); bindingMap.put("fields", fields); bindingMap.put("bashPath", StrUtil.isNotBlank(bashPath) ? bashPath : table.getLowName()); bindingMap.put("staticMethod",getStaticMethod()); return bindingMap; } private Object getStaticMethod() { return "import static cn.hutool.core.collection.CollUtil.isEmpty;\n" + "import static cn.hutool.core.collection.CollUtil.isNotEmpty;\n" + "import static cn.hutool.core.collection.CollUtil.newArrayList;\n" + "import static cn.hutool.core.collection.CollUtil.newHashSet;\n" + "import static cn.hutool.core.collection.CollUtil.newHashMap;\n" + "import static cn.hutool.core.util.StrUtil.isBlank;\n" + "import static cn.hutool.core.util.StrUtil.isNotBlank;\n" + "import static cn.hutool.core.util.ObjectUtil.isNull;\n" + "import static cn.hutool.core.util.ObjectUtil.isNotNull;\n" + "import static cn.hutool.core.util.ObjectUtil.equal;\n" + "import static cn.hutool.core.util.ObjectUtil.notEqual;"; } private Object getAllSqlSelect() { List<String> list = new ArrayList<>(); if (ObjectUtil.isNotNull(idField)) { list.add(idField.getColumn()); } if (CollUtil.isNotEmpty(superFields)) { list.addAll( superFields.stream() .map(Field::getColumn) .collect(Collectors.toList()) ); } if (CollUtil.isNotEmpty(fields)) { list.addAll( fields.stream() .map(Field::getColumn) .collect(Collectors.toList()) ); } return CollUtil.join(list, ",\n\t\t"); } private void loadSuperFields() { List<TableFieldInfo> tableFieldInfos = TableInfoHelper .initTableInfo(null, entityClass.getSuperclass()) .getFieldList(); this.superFields = tableFieldInfos.stream() .map(this::getField) .collect(Collectors.toList()); } private Field getField(TableFieldInfo tableFieldInfo) { Field f = new Field(); f.setColumn(tableFieldInfo.getColumn()); f.setProperty(tableFieldInfo.getProperty()); f.setUpProperty(StrUtil.upperFirst(tableFieldInfo.getProperty())); java.lang.reflect.Field field = ReflectUtil.getField(entityClass, tableFieldInfo.getProperty()); f.setComment(AnnotationUtil.getAnnotationValue(field, ApiModelProperty.class)); f.setRequired(AnnotationUtil.getAnnotationValue(field, ApiModelProperty.class, "required")); f.setTypeFullName(tableFieldInfo.getPropertyType().getName()); f.setTypeSimpleName(tableFieldInfo.getPropertyType().getSimpleName()); f.setTypeLowName(StrUtil.lowerFirst(tableFieldInfo.getPropertyType().getSimpleName())); f.setTypePackageName(ClassUtil.getPackage(tableFieldInfo.getPropertyType())); f.initCondition(table); f.initValidator(); log.info(f.toString()); return f; } private void loadIdFields() { String keyProperty = tableInfo.getKeyProperty(); if (StrUtil.isNotBlank(keyProperty)) { this.idField = new Field(); this.idField.setColumn(tableInfo.getKeyColumn()); this.idField.setProperty(tableInfo.getKeyProperty()); this.idField.setUpProperty(StrUtil.upperFirst(tableInfo.getKeyProperty())); java.lang.reflect.Field field = ReflectUtil.getField(entityClass, tableInfo.getKeyProperty()); this.idField.setComment(AnnotationUtil.getAnnotationValue(field, ApiModelProperty.class)); this.idField.setRequired(AnnotationUtil.getAnnotationValue(field, ApiModelProperty.class, "required")); this.idField.setTypeFullName(field.getType().getName()); this.idField.setTypeSimpleName(field.getType().getSimpleName()); this.idField.setTypeLowName(StrUtil.lowerFirst(field.getType().getSimpleName())); this.idField.setTypePackageName(ClassUtil.getPackage(field.getType())); } } private void loadTable() { this.table = new Table(); table.setTableName(tableInfo.getTableName()); table.setFullName(entityClass.getName()); table.setSimpleName(entityClass.getSimpleName()); table.setLowName(StrUtil.lowerFirst(entityClass.getSimpleName())); table.setComment(AnnotationUtil.getAnnotationValue(entityClass, ApiModel.class)); table.setPackageName(ClassUtil.getPackage(entityClass)); log.info(table.toString()); } private void loadFields() { List<TableFieldInfo> allFieldList = tableInfo.getFieldList(); List<String> superProperties = superFields.stream() .map(Field::getProperty) .collect(Collectors.toList()); this.fields = allFieldList.stream() .filter(x -> !superProperties.contains(x.getProperty())) .map(this::getField) .collect(Collectors.toList()); } private File getOutPutFile(String templateName) { return FileUtil.newFile( this.outputDir + this.entityClass.getSimpleName() + StrUtil.removeSuffix(templateName, ".ftl") ); } private void loadOutputDir() { this.outputDir = getClassJavaFilePath(entityClass); } private String getClassJavaFilePath(Class clazz) { return clazz.getResource("").getFile().replace(TARGET_CLASSES, SRC_MAIN_JAVA); } private void loadTemplates(Class templatePathClass) { this.templatePath = getClassJavaFilePath(templatePathClass); this.templates = CollUtil.newArrayList(); File[] fs = new File(templatePath).listFiles(); for (File f : fs) { if (f.isDirectory()) { continue; } if (f.getName().toLowerCase().endsWith(".ftl")) { templates.add(f.getName()); } } } }
3.
4.naocs配置
1.配置本地配置覆盖远程配置
#配置本地配置覆盖远程配置 spring.cloud.config.override-none= true spring.cloud.config.allow-override= true spring.cloud.config.override-system-properties= false
5.工具篇
1.fiddler (抓包工具)
1.通过命令 ipconfig 获取ipv4地址,
2.并在手机wifi代理中填写代理(ipv4地址),默认端口8888
3.按照图片设置好fildder后, 手机访问ipv4地址+8888, 并下载证书手机安装
工作任务
1.关于一个比较难的任务代码
//1.确定最终分页数量 返回false ,true+1 public Boolean countPage(HospReq req, long l) { // 获取患患者所有40度以上文字时间 格式: yyyy-MM-dd T + 6个时间节点 List<String> inputDateTimes = inputDateTimeList(req); if (inputDateTimes.size() < 1) { return false; } final Map<String, Integer> map = new HashMap<>(); for (String str : inputDateTimes) { //计数器,用来记录数据的个数 Integer i = 1; if (map.get(str) != null) { i = map.get(str) + 1; } map.put(str, i); } SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //当前日期 Date todayTime = new Date(System.currentTimeMillis()); String today = sdf.format(todayTime); //使用默认时区和语言环境获得一个日历。 Calendar cal = Calendar.getInstance(); //入院时间 LoginUser loginUser = LoginUserContext.get(); cal.setTime(patientHospitalizedInfoService.lambdaQuery() .eq(PatientHospitalizedInfo::getOrgCode, loginUser.getOrgCode()) .eq(PatientHospitalizedInfo::getHospNo, req.getHospNo()) .one().getAdmitDate()); cal.add(Calendar.DAY_OF_MONTH, -1); Integer count = 0; Iterator<String> iterator = inputDateTimes.iterator(); //遍历每页 体温单 一页体温单有七天所以循环七次 for (int i = 0; i < 1000; i++) { //取当前日期的后 i 天.(每次循环增加一天) cal.add(Calendar.DAY_OF_MONTH, +1); String countTime = sdf.format(cal.getTime()); String s1 = countTime + "T" + "02:00:00".trim(); String s2 = countTime + "T" + "06:00:00".trim(); String s3 = countTime + "T" + "10:00:00".trim(); String s4 = countTime + "T" + "14:00:00".trim(); String s5 = countTime + "T" + "18:00:00".trim(); String s6 = countTime + "T" + "22:00:00".trim(); String s = inputDateTimes.get(0); boolean b = s1.equals(s) || s2.equals(s) || s3.equals(s) || s4.equals(s) || s5.equals(s) || s6.equals(s); //如果上面都不匹配计数器-1 if (!b) { count = count - 6; if (count < 0) { count = 0; } } else { if (inputDateTimes.get(0).equals(s1)) { int a = map.get(inputDateTimes.get(0)); if (count < 0) { count = 0; } count = count + (a - 1); for (int j = 0; j < a; j++) { if (iterator.next().equals(inputDateTimes.get(0))) { iterator.remove(); } } if (inputDateTimes.size() < 1) { count = count - 5; return lastResult(count, countTime, today,l); } } else { count = count - 1; if (count < 0) { count = 0; } } if (inputDateTimes.get(0).equals(s2)) { int a = map.get(inputDateTimes.get(0)); if (count < 0) { count = 0; } count = count + (a - 1); for (int j = 0; j < a; j++) { if (iterator.next().equals(inputDateTimes.get(0))) { iterator.remove(); } } if (inputDateTimes.size() < 1) { count = count - 4; return lastResult(count, countTime, today,l); } } else { count = count - 1; if (count < 0) { count = 0; } } if (inputDateTimes.get(0).equals(s3)) { int a = map.get(inputDateTimes.get(0)); if (count < 0) { count = 0; } count = count + (a - 1); for (int j = 0; j < a; j++) { if (iterator.next().equals(inputDateTimes.get(0))) { iterator.remove(); } } if (inputDateTimes.size() < 1) { count = count - 3; return lastResult(count, countTime, today,l); } } else { count = count - 1; if (count < 0) { count = 0; } } if (inputDateTimes.get(0).equals(s4)) { int a = map.get(inputDateTimes.get(0)); if (count < 0) { count = 0; } count = count + (a - 1); for (int j = 0; j < a; j++) { if (iterator.next().equals(inputDateTimes.get(0))) { iterator.remove(); } } if (inputDateTimes.size() < 1) { count = count - 2; return lastResult(count, countTime, today,l); } } else { count = count - 1; if (count < 0) { count = 0; } } if (inputDateTimes.get(0).equals(s5)) { int a = map.get(inputDateTimes.get(0)); if (count < 0) { count = 0; } count = count + (a - 1); for (int j = 0; j < a; j++) { if (iterator.next().equals(inputDateTimes.get(0))) { iterator.remove(); } } if (inputDateTimes.size() < 1) { count = count - 1; return lastResult(count, countTime, today,l); } } else { count = count - 1; if (count < 0) { count = 0; } } if (inputDateTimes.get(0).equals(s6)) { int a = map.get(inputDateTimes.get(0)); if (count < 0) { count = 0; } count = count + (a - 1); for (int j = 0; j < a; j++) { if (iterator.next().equals(inputDateTimes.get(0))) { iterator.remove(); } } if (inputDateTimes.size() < 1) { return lastResult(count, countTime, today,l); } } else { count = count - 1; if (count < 0) { count = 0; } } } } return false; } //2. 返回分页 是否加一 结果 public boolean lastResult(Integer count, String countTime, String today, long i2) { Long between_dayInteger = between_days(countTime, today); //最后一页页还剩下几天 i2 = i2 * 6; if (count > 0) { //判断是不是今天 if (countTime.equals(today)) { //是今天 , 当前页还剩下几天 if (i2 >= count) { return false; } else { return true; } } //不是当天 else { if (between_dayInteger > 0) { if (i2 >= count) { return false; } else { return true; } } else { long l = count - (between_dayInteger * 6); if (i2 >= l) { return false; } else { return true; } } } } else { //计数器=0 return false; } } //3.获取两个字符串时间相隔天数 public static Long between_days(String a, String b) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// 自定义时间格式 Calendar calendar_a = Calendar.getInstance();// 获取日历对象 Calendar calendar_b = Calendar.getInstance(); Date date_a = null; Date date_b = null; try { date_a = simpleDateFormat.parse(a);//字符串转Date date_b = simpleDateFormat.parse(b); calendar_a.setTime(date_a);// 设置日历 calendar_b.setTime(date_b); } catch (ParseException e) { e.printStackTrace();//格式化异常 } long time_a = calendar_a.getTimeInMillis(); long time_b = calendar_b.getTimeInMillis(); long between_days = (time_b - time_a) / (1000 * 3600 * 24);//计算相差天数 return between_days; } //4.获取所有录入过 40度往上文字 时间集合 public List<String> inputDateTimeList(HospReq req) { LoginUser loginUser = LoginUserContext.get(); // 机构配置的体征时间点,20210608应PM要求写死这几个时间点 List<String> signTimesList = CollUtil.newArrayList("04:00", "08:00", "12:00", "16:00", "20:00", "24:00"); // 具体的显示时间点 List<String> specificTimesList = CollUtil.newArrayList("02:00", "06:00", "10:00", "14:00", "18:00", "22:00"); // 得到每个时间点对应的时间段map Map<String, DateDto> signTimesMap = CollUtil.newHashMap(signTimesList.size()); for (int i = 0, signTimesListSize = signTimesList.size(); i < signTimesListSize; i++) { String time = signTimesList.get(i); String keyTime = specificTimesList.get(i); if (i == 0) { signTimesMap.put(keyTime, new DateDto(signTimesList.get(signTimesListSize - 1), time)); } else { signTimesMap.put(keyTime, new DateDto(signTimesList.get(i - 1), time)); } } // 是否24小时制 SysConfig sysConfigByCode = sysConfigService.getSysConfigByCode(loginUser.getOrgCode(), SysConfigModuleEnum.IS24_HOUR_CLOCK.code); boolean is24HourClock = BooleanUtil.toBoolean(sysConfigByCode.getContent()); PatientHospitalizedInfo one = patientHospitalizedInfoService.lambdaQuery() .eq(PatientHospitalizedInfo::getOrgCode, loginUser.getOrgCode()) .eq(PatientHospitalizedInfo::getHospNo, req.getHospNo()) .one(); List<PatientTemperature> list1 = patientTemperatureService.lambdaQuery() .eq(PatientTemperature::getOrgCode, loginUser.getOrgCode()) .eq(PatientTemperature::getHospNo, req.getHospNo()) .orderByAsc(PatientTemperature::getTime) .list(); // 统一设置成机构时间点 list1.forEach(x -> x.setTime(getTimeForOrg(signTimesMap, x.getTime()))); Map<String, List<PatientTemperature>> timeTemperatureMap = list1.stream() .collect(Collectors.groupingBy(PatientTemperature::getTime, LinkedHashMap::new, Collectors.toList())); // List<PatientTemperature> finalList = new ArrayList<>(); // 多个40度以上文字都要展示 List<PatientTemperatureVo> textList = new ArrayList<>(); List<PatientTemperatureVo> finalListVo = new ArrayList<>(); timeTemperatureMap.forEach((k, v) -> { // 取数据逻辑 PatientTemperature firstTemperatureTemp = getFirstTemperature(v, finalListVo, one, is24HourClock); // finalList.add(firstTemperatureTemp); }); textList = finalListVo.stream().sorted(Comparator.comparing(PatientTemperatureVo::getInputDateTime)).collect(Collectors.toList()); //所有录入时间 final List<String> inputDateTimes = new ArrayList<>(); for (PatientTemperatureVo x : textList) { inputDateTimes.add(x.getInputDateTime()); } Collections.sort(inputDateTimes); return inputDateTimes; }
持续更新ing...