¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.dry.controller; |
| | | |
| | | |
| | | import ai.djl.modality.Classifications; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jeecg.common.api.vo.Result; |
| | | |
| | | import org.jeecg.modules.dry.entity.DryHerbInfo; |
| | | import org.jeecg.modules.dry.service.*; |
| | | |
| | | import org.jeecg.modules.dry.util.HerbUtil; |
| | | import org.jeecg.modules.dry.vo.CommandMessageVo; |
| | | import org.jeecg.modules.dry.vo.DryHerbInfoVo; |
| | | import org.jeecg.modules.dry.vo.RealTimeDataVo; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.InputStream; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | |
| | | @Api(tags = "宿¶æ°æ®å¤çæ§å¶å¨") |
| | | @RestController |
| | | @RequestMapping("/dry/real") |
| | | @Slf4j |
| | | public class DryRealTimeDataController { |
| | | |
| | | @Autowired |
| | | private IDryRealTimeDataService dryRealTimeDataService; |
| | | |
| | | @Autowired |
| | | private HerbUtil herbUtil; |
| | | |
| | | @Autowired |
| | | private IDryHerbInfoService herbInfoService; |
| | | |
| | | |
| | | @ApiOperation(value="æµè¯", notes="è¿åHello") |
| | | @GetMapping("/hello") |
| | | public Result<?> sayHello() { |
| | | return Result.ok("Hello"); |
| | | } |
| | | |
| | | @ApiOperation(value="æ¥æ¶å®æ¶æ°æ®Json", notes="设å¤å®æ¶æ°æ®ä¸ä¼ ") |
| | | @PostMapping("/sendRealTimeDataJson") |
| | | public Result<?> realTimeDataJson(@RequestBody RealTimeDataVo realTimeDataVo) { |
| | | return dryRealTimeDataService.realTimeDataHandle(realTimeDataVo); |
| | | } |
| | | |
| | | |
| | | |
| | | @ApiOperation(value="è·å设å¤å®æ¶æ°æ®", notes="éè¿ç§æ·IDå设å¤ç¼ç è·å宿¶æ°æ®") |
| | | @GetMapping("/getRealTimeData") |
| | | public Result<?> queryMachineRealTimeData(RealTimeDataVo realTimeDataVo) { |
| | | return dryRealTimeDataService.queryMachineRealTImeData(realTimeDataVo); |
| | | } |
| | | |
| | | @ApiOperation(value="è·å车é´ç»è®¡æ°æ®", notes="éè¿ç§æ·IDè·å车é´ç»è®¡æ°æ®") |
| | | @GetMapping("/workshopStatistics") |
| | | public Result<?> workshopStatistics(RealTimeDataVo realTimeDataVo) { |
| | | return dryRealTimeDataService.queryWorkshopStatistics(realTimeDataVo); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 1001 é£ç®±å 1002 é£ç®±é |
| | | * 1003 æ»çå 1004 æ»çé |
| | | * 1005 æ»çæ£è½¬ 1006 æ»çå转 |
| | | * 1007 设å¤åæ¢ 1010 å¹²ç¥å¯å¨ |
| | | * 1011 åé¨å¼å
³ 1012 åé¨å¼å
³ |
| | | * 1013 çé£å¯å¨ 1014 å¼é¨è§å¯ |
| | | * 1015 åºææé® |
| | | */ |
| | | @ApiOperation(value="å鿧嶿令", notes="åæå¡ç«¯å鿧嶿令ï¼ç±æå¡ç«¯éè¿socket转åç»æ§å¶æ¨¡å") |
| | | @PostMapping("/sendCommand") |
| | | public Result<?> sendCommand(@RequestBody CommandMessageVo msgVo) { |
| | | return dryRealTimeDataService.sendSocketMsg(msgVo); |
| | | } |
| | | |
| | | |
| | | @ApiOperation(value = "è¯æè¯å«") |
| | | @PostMapping("/identify") |
| | | public Result<?> identify(@RequestParam("file") MultipartFile file) throws Exception { |
| | | try { |
| | | if (file.isEmpty()) { |
| | | throw new RuntimeException("ä¸ä¼ æä»¶ä¸è½ä¸ºç©º"); |
| | | } |
| | | InputStream inputStream = file.getInputStream(); |
| | | List<Classifications.Classification> predict = herbUtil.predict(inputStream); |
| | | |
| | | if(predict.size()>0) { |
| | | Map<String, Double> collect = predict.stream().collect(Collectors.toMap(Classifications.Classification::getClassName, Classifications.Classification::getProbability)); |
| | | |
| | | |
| | | List<DryHerbInfoVo> voList = new ArrayList<>(); |
| | | Set<String> strings = collect.keySet(); |
| | | List<DryHerbInfo> list = herbInfoService.list(new LambdaQueryWrapper<DryHerbInfo>().in(DryHerbInfo::getPinyin, strings)); |
| | | list.forEach(item -> { |
| | | DryHerbInfoVo dryHerbInfoVo = new DryHerbInfoVo(); |
| | | BeanUtil.copyProperties(item, dryHerbInfoVo); |
| | | dryHerbInfoVo.setProbabily(collect.get(item.getPinyin())); |
| | | voList.add(dryHerbInfoVo); |
| | | }); |
| | | |
| | | List<DryHerbInfoVo> collect1 = voList.stream().sorted(Comparator.comparing(DryHerbInfoVo::getProbabily, Comparator.reverseOrder())). |
| | | collect(Collectors.toList()); |
| | | |
| | | return Result.ok(collect1); |
| | | } else { |
| | | return Result.error("AIè¯å«æå¡å¼å¸¸"); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return Result.error("AIè¯å«æå¡å¼å¸¸"); |
| | | } |
| | | } |
| | | |
| | | } |