forEach中的continue ==> "return"
| @Test |
| public void test(){ |
| ArrayList<String> str=new ArrayList<String>(): |
| str.add("1") |
| str.add("2") |
| str.add("3") |
| str.forEach(e->{ |
| if("2".equals(e)){ |
| return; |
| } |
| System.out.println("d: "+d); |
| }); |
| |
| for(String s:str){ |
| if("2".equals(s)){ |
| return; |
| } |
| System.out.println("d: "+s); |
| } |
| |
| } |
得到一个List,将List中一个对象的其中一个字段进行修改并返回
| @Override |
| public PageInfoDto<BasicMonitorUpdateVo> page(BasicMonitoring basicMonitoringParam){ |
| PageHelper.startPage(DscConstant.PAGE_NO_DEFAULT,DcsConstant.PAGE_SIZE_DEFAULT); |
| List<BasicMonitoring> list= |
| this.list(new QueryWrapper<> basicMonitoringParam.lambda().orderByDesc(BasicMonitoring::getCreateTime)); |
| PageInfoDto page=new PageInfoDto(list); |
| |
| List<BasicMonitorUpdateVo> basicMonitorUpdateVoList=null; |
| if(CollectionUtil.isNotEmpty(list)){ |
| basicMonitoringUpdateVoList=ColaBeanUtils.copyListProperties(list,BasicMonitorUpdateVo::new,(bm,basicMonitorUpdateVo)->{ |
| |
| basicMonitorUpdateVo.setValue(String.format("%.2f",bm.getValue))); |
| }); |
| } |
| page.setList(basicMonitoringUpdateVoList); |
| return page; |
| } |
进行浮点数据类型的格式化
| Double rate01=2.544; |
| Double rate02=2.545; |
| Double rate03=2.546; |
| log.info("rate01, {}",String.format("%.2f",rate01)); |
| log.info("rate02, {}",String.format("%.2f",rate02)); |
| log.info("rate03, {}",String.format("%.2f",rate03)); |
远程接口调用 + JSON(FastJson)处理 【核心代码】
| |
| private JSONObject getJsonObjectFromLatestInsectMonitoring(String deviceNumber) { |
| |
| String requestUrl = IoTConstant.GET_CURRENT_INSECT_MONITORING; |
| |
| HttpHeaders headers = new HttpHeaders(); |
| headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| |
| MultiValueMap<String, String> map = new LinkedMultiValueMap<>(); |
| map.add("token", IoTConstant.INSECT_IOT_TOKEN); |
| map.add("userName", IoTConstant.INSECT_IOT_USER_NAME); |
| map.add("deviceNumber", deviceNumber); |
| |
| HttpEntity<MultiValueMap<String, String>> request = |
| new HttpEntity<MultiValueMap<String, String>>(map, headers); |
| |
| return restTemplate.postForObject(requestUrl, request, JSONObject.class); |
| } |
| |
| |
| |
| |
| public void queryCurrentInsectSituation(BasicDevice basicDevice) { |
| JSONObject jsonObject = getJsonObjectFromLatestInsectMonitoring(basicDevice.getCode()); |
| if (ObjectUtil.isNotNull(jsonObject) && SUCCESS.equals(jsonObject.getString(STATE))) { |
| InsectMonitoringDto data = |
| JSONObject.parseObject(JSONObject.toJSONString(jsonObject.get("data")), InsectMonitoringDto.class); |
| log.info("data, {}", data); |
| if (StringUtils.isNotEmpty(data.getResults()) && data.getNewCount() > 0) { |
| String filePath = getFilePath(data.getTaggingImgUrlCompress()); |
| |
| if (isExists(filePath)) return; |
| |
| AgrInsectPic insectPic = saveInsectPic(basicDevice, filePath); |
| String[] insects = getInsects(data); |
| if (ArrayUtil.isNotEmpty(insects)) { |
| Arrays.stream(insects).forEach(e -> { |
| String insectNum = getInsectNum(e); |
| String insectName = getInsectName(e); |
| |
| saveBasicMonitoring(basicDevice.getId(), insectName, insectNum); |
| |
| saveAgrInsect(insectPic, insectNum, insectName); |
| }); |
| } |
| } |
| } |
| } |
🌈查询一条记录,如果数据库中存在则更新否则插入
| LambdaQueryWrapper<BasicMonitoring> lqWrapper = new LambdaQueryWrapper<BasicMonitoring>() |
| .eq(BasicMonitoring::getBasicDeviceId, e.getBasicDeviceId()) |
| .eq(BasicMonitoring::getTypeName, e.getTypeName()) |
| .eq(BasicMonitoring::getDelFlag, DelFlagEnum.YES.getCode()); |
| |
| if (Objects.nonNull(bmService.getOne(lqWrapper))) { |
| BasicMonitoring bm = bmService.getOne(lqWrapper); |
| BeanUtils.copyBeanProp(e, bm); |
| bm.setUpdateTime(new Date()); |
| bmService.updateById(bm); |
| } else { |
| bmService.save(e); |
| } |
🌈 保存或更新
| |
| if (Objects.nonNull(fcService.getOne(fclQueryWrapper))) { |
| ForewarningCondition condition = fcService.getOne(fclQueryWrapper); |
| BeanUtils.copyProperties(e, condition); |
| fcService.updateById(condition); |
| |
| } else { |
| saveForewarningCondition(warning, e); |
| } |
| |
🌈使用LambdaUpdateWrapper进行更新操作
| params.forEach(e -> { |
| |
| Long deptId = e.getDeptId(); |
| |
| String warningContent = getWarningContent(e.getWarningType(), e.getWarningContentType()); |
| LambdaUpdateWrapper<ForewarningCondition> fclUpdateWrapper = new LambdaUpdateWrapper<ForewarningCondition>() |
| .eq(ForewarningCondition::getDeptId, e.getDeptId()) |
| .eq(ForewarningCondition::getWarningContent, warningContent) |
| .set(ForewarningCondition::getDelFlag, DelFlagEnum.DELETED.getCode()); |
| fcService.update(fclUpdateWrapper); |
| }); |
🌈 使用LambdaUpdateWrapper进行逻辑删除
| List<Long> collect = params.stream().map(ForewarningParam::getId).collect(Collectors.toList()); |
| LambdaUpdateWrapper<Forewarning> updateWrapper = new LambdaUpdateWrapper<>(); |
| updateWrapper.in(Forewarning::getId, collect) |
| .set(Forewarning::getDelFlag, DelFlagEnum.DELETED.getCode()); |
| this.update(updateWrapper); |
🌈 检索过滤之后数据的第一条
| Device lastDevice = this.getOne(new QueryWrapper<Device>().lambda() |
| .eq(Device::getDelFlag, 0) |
| .orderByDesc(Device::getDeviceNo) |
| .last("LIMIT 1") |
| ); |
🌈 异常处理
| if(Objects.isNull(talentWork.getId())){ |
| throw new BizzException(ResponseCode.PARAM_IS_BLANK.getCode(), "请传入就业信息id"); |
| } |
isNotEmpty和isNotBlank区别
| isNotEmpty(str)等价于 str != null && str.length > 0 |
| isNotBlank(str) 等价于 str != null && str.length > 0 && str.trim().length > 0 |
| 同理 |
| isEmpty 等价于 str == null || str.length == 0 |
| isBlank 等价于 str == null || str.length == 0 || str.trim().length == 0 |
| |
| str.length > 0 && str.trim().length > 0 ---> str.length > 0 |
commit模板
| feat: 新功能 |
| fix: 修复Bug |
| doc: 文档改变 |
| style: 代码格式改变 |
| refactor: 某个已有代码重构 |
| pref: 性能优化 |
| test: 增加测试 |
| build: 改变了build工具 eg: grunt换成npm |
| revert: 撤销上一次commit |
Java8中过滤一个集合(排除掉一个集合里面的多余内容)
| 创建两个集合: list01 和 list02 |
| public class FilterListByAnotherList { |
| public static void main(String[] args) { |
| List<String> list01 = Arrays.asList("1", "2", "3"); |
| List<String> list02 = Arrays.asList("1"); |
| List<String> filteredList = list01.stream().filter(e -> !list02.contains(e)) |
| .collect(Collectors.toList()); |
| System.out.println(filteredList); // [2, 3] |
| } |
| } |
| |
| data.stream().filter(m -> !m.getSerialId().equals(setting.getSerialId())) |
| .collect(Collectors.toList()) |
| .size() |
枚举工具类
| package vip.xiaonuo.modular.forewarning.enums; |
| |
| import lombok.Getter; |
| |
| import java.util.stream.Stream; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| public enum WarningTypeEnum { |
| NA("-1", "未知"), |
| STOCK_CONTROL("1", "库存管理"), |
| PRODUCTION_CONTROL("2", "生产管理"), |
| BIO_SAFETY("3", "生物安全"); |
| |
| @Getter |
| private final String code; |
| @Getter |
| private final String name; |
| |
| WarningTypeEnum(String code, String name) { |
| this.code = code; |
| this.name = name; |
| } |
| |
| public static WarningTypeEnum of(String code) { |
| return Stream.of(values()).filter(r -> r.code.equals(code)).findFirst().orElse(NA); |
| } |
| |
| public static WarningTypeEnum from(String code) { |
| return Stream.of(values()).filter(r -> r.code.equals(code)).findFirst() |
| .orElseThrow(() -> new RuntimeException("未知枚举类型[" + code + "]")); |
| } |
| |
| public static String toText(String code) { |
| return of(code).getName(); |
| } |
| |
| public static boolean isNa(String code) { |
| return of(code).equals(WarningTypeEnum.NA); |
| } |
| } |
| public PageResult<SysOnlineUserResult> list = CollectionUtil.newArrayList(){ |
| |
| Map<String, SysLoginUser> allKeyValues = userCache.getAllKeyValues(); |
| for(Map.Entry<String, SysLoginUser> sysLoginUserEntry : allKeyValues.entrySet()){ |
| SysOnlineUserResult sysOnlineUserResult = new SysOnlineUserResult(); |
| sysOnlineUserResult.setSessionId sysLoginUserEntry.getKey(); |
| BeanUtil.copyProperties(sysLoginUserEntry.getValue(), sysOnlineUserResult); |
| tempList.add(sysOnlineUserResult); |
| } |
| List<SysOnlineResult> listAll = tempList.stream() |
| .sorted(Comparator.comparing(SysOnlineUserResult::getLastLoginTime, Compartor.comparing)) |
| .collect(Collectors.toList()); |
| Page<SysOnlineUserResult> page = PageFactory.defaultPage(); |
| page.setTotal(tempList.size()); |
| List<SysOnlineUserResult> resultList = PageUtil.page(page, listAll); |
| return new PageResult<>(page, resultList); |
| } |
数据库根据数据类型为datatime去找到最大值
| <select id="getParityNumTooManyDetail" resultType="vip.xiaonuo.modular.forewarning.param.dto.ParityNumTooManyDto"> |
| SELECT t.id, |
| t.pig_id AS pigId, |
| t.ear_number AS earNumber, |
| t.dept_id AS deptId, |
| t.dept_name AS deptName, |
| t.location AS location, |
| t.fetuses_number AS parity |
| FROM sow_record t, |
| (SELECT id, MAX(create_time) AS create_time |
| FROM sow_record |
| WHERE del_flag = 0 |
| GROUP BY ear_number, dept_id) t1 |
| WHERE t.id = t1.id |
| AND t.create_time = t1.create_time |
| AND t.del_flag = 0; |
| </select> |
数据库获得最近一个月的内容
| <select id="getBackToLoveOverHighDtoDetail" |
| resultType="vip.xiaonuo.modular.forewarning.param.dto.BackToLoveOverHighDto"> |
| SELECT COUNT(*) AS sowNum, |
| t1.backToLoveNum, |
| t.dept_id AS deptId, |
| t.dept_name AS deptName |
| FROM sow_record t, |
| ( |
| SELECT COUNT(result) AS backToLoveNum, |
| dept_id, |
| dept_name |
| FROM sow_record |
| WHERE result = 3 |
| AND del_flag = 0 |
| AND create_time >= DATE_SUB(NOW(), INTERVAL 1 MONTH ) |
| GROUP BY dept_id |
| ) t1 |
| WHERE t.del_flag = 0 |
| AND t.create_time >= DATE_SUB(NOW(), INTERVAL 1 MONTH ) |
| AND t.dept_id = t1.dept_id |
| AND t.dept_name = t1.dept_name |
| GROUP BY t1.dept_id; |
| </select> |
| MySQL:查询最近一个月的记录 |
| 查询近一段时间的记录,首先,表结构中需要一个时间字段,这个是必须的,然后根据条件去查询,有两种方式 |
| |
| 关键字 >= (大于等于) date_sub ( 时间函数) |
| 思路:我们只需要筛选出 规定时间内的数据, 半开区间查询,先把开始时间计算出来,只要大于这个开始时间即可。 |
| |
| 查询近一周的记录 |
| 例: |
| select * from test_table where create_time >= DATE_SUB(NOW(),INTERVAL 7 DAY) |
| |
| 查询近一个月的记录 |
| |
| select * from test_table where create_time >= DATE_SUB(NOW(),INTERVAL 1 MONTH) |
| |
| 方法2: |
| 关键字 : BETWEEN (比较 … && … 区间) |
| |
| 思路:我们只需要筛选出 规定时间内的数据, 闭合区间查询,设置好开始和结束时间,设置好之后 ,用BETWEEN 关键字 查询这个时间段的记录即可。 |
| |
| //查询近一周的记录 |
| select * from test_table where create_time BETWEEN DATE_SUB(NOW(),INTERVAL 7 DAY) and NOW(); |
| ———————————————— |
| 版权声明:本文为CSDN博主「jane_小白」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 |
| 原文链接:https://blog.csdn.net/qq_38637728/article/details/104694190 |
MySQL日期间隔计算 ===> DATEDIFF(CURRENT_DATE(), status_date) AS jackDate
DATEDIFF(d1, d2) 计算日期d1与d2之间的天数
函数 |
说明 |
CURDATE()、CURRENT_DATE() |
返回当前日期,格式: yyyy-MM-dd |
CURTIME()、CURRENT_TIME() |
返回当前时间,格式:HH:mm:ss |
NOW()、CURRENT_TIMESTAMP()、LOCALTIME()、SYSDATE()、LOCALTIMESTAMP() |
返回当前日期和时间, 格式:yyyy-MM-dd HH:mm:ss |
利用HuTools工具类计算日期间隔
| Date collectDate = c.getCollectDate(); |
| Date currentDate = new Date(); |
| long betweenDay = DateUtil.between(collectDate, currentDate, DateUnit.DAY); |
以对象形式传递参数别忘了使用【@RequestBody】注解
| import org.springframework.validation.annotation.Validated; |
| |
| @PostMapping("/forewarning/detail") |
| public ResponseData detail(@RequestBody ForewarningParam forewarningParam){ |
| return new SuccessResponseData(forewarningService.detail(forewarningParam)); |
| } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
2021-03-29 Docker中部署SpringBoot项目并运行
2021-03-29 Failed to execute goal com.spotify:docker-maven-plugin:1.0.0:build (default-cli) on project boot-docker-demo: Exception caught: ADD failed: file not found in build context or...