diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 97031c7..308c744 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,183 +5,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + - - - diff --git a/bonus-modules/bonus-protection/bonus-protection.iml b/bonus-modules/bonus-protection/bonus-protection.iml index 58bd392..dcd399e 100644 --- a/bonus-modules/bonus-protection/bonus-protection.iml +++ b/bonus-modules/bonus-protection/bonus-protection.iml @@ -11,12 +11,12 @@ - - - - - - + + + + + + @@ -373,7 +373,7 @@ - + @@ -382,7 +382,7 @@ - + @@ -391,7 +391,7 @@ - + @@ -400,7 +400,7 @@ - + @@ -409,7 +409,7 @@ - + @@ -418,7 +418,7 @@ - + @@ -427,7 +427,7 @@ - + diff --git a/bonus-modules/bonus-protection/pom.xml b/bonus-modules/bonus-protection/pom.xml index 379b207..efacc20 100644 --- a/bonus-modules/bonus-protection/pom.xml +++ b/bonus-modules/bonus-protection/pom.xml @@ -9,10 +9,10 @@ 4.0.0 - bonus-zjgl + bonus-protection - bonus-modules-smart-canteen智慧食堂 + bonus-modules-smart-canteen保护定值 diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/BonusProtectionApplication.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/BonusProtectionApplication.java index cc420fd..1e0475d 100644 --- a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/BonusProtectionApplication.java +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/BonusProtectionApplication.java @@ -17,7 +17,6 @@ import org.springframework.scheduling.annotation.EnableScheduling; @EnableCustomConfig @EnableCustomSwagger2 @EnableScheduling -@EnableRyFeignClients @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) public class BonusProtectionApplication { diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/controller/ProtectionAppManageController.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/controller/ProtectionAppManageController.java new file mode 100644 index 0000000..c771659 --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/controller/ProtectionAppManageController.java @@ -0,0 +1,133 @@ +package com.bonus.canteen.core.protection.controller; + +import com.bonus.canteen.core.protection.service.ProtectionManageService; +import com.bonus.canteen.core.protection.vo.ProtectionVo; +import com.bonus.canteen.core.protection.vo.SubstationVo; +import com.bonus.common.core.web.controller.BaseController; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.core.web.page.TableDataInfo; +import com.bonus.common.log.annotation.SysLog; +import com.bonus.common.log.enums.OperaType; +import com.bonus.common.security.utils.SecurityUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Api(tags = "App保护定值接口") +@RestController +@RequestMapping("/protection_app_manage") +public class ProtectionAppManageController extends BaseController { + @Resource + private ProtectionManageService protectionManageService; + + /** + * 查询变电站信息列表 + */ + @ApiOperation(value = "查询变电站信息列表") + @GetMapping("/substation/list") + public Map list(SubstationVo substationVo) { + Map map=new HashMap<>(); + List list=null; + try { + list= protectionManageService.selectSubstationList(substationVo); + map.put("data",list); + map.put("code",200); + map.put("res","成功"); + }catch (Exception e){ + map.put("data",list); + map.put("code",400); + map.put("res","失败"); + } + return map; + } + /** + * 新增变电站信息 + */ + @ApiOperation(value = "新增变电站信息") + @SysLog(title = "变电站信息", businessType = OperaType.INSERT, logType = 1,module = "变电站管理->新增变电站信息") + @PostMapping("/substation/add") + public AjaxResult add(@RequestBody SubstationVo substationVo) { + String username = SecurityUtils.getUsername(); + String userId=SecurityUtils.getUserId()+""; + Map map=new HashMap<>(); + try { + substationVo.setCreateBy(userId); + return toAjax(protectionManageService.insertSubstation(substationVo)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + /** + * 编辑变电站信息 + */ + @ApiOperation(value = "编辑变电站信息") + @SysLog(title = "变电站信息", businessType = OperaType.INSERT, logType = 1,module = "变电站管理->编辑变电站信息") + @PostMapping("/substation/edit") + public AjaxResult edit(@RequestBody SubstationVo substationVo) { + Map map=new HashMap<>(); + try { + return toAjax(protectionManageService.updateSubstation(substationVo)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + @ApiOperation(value = "删除变电站信息") + @SysLog(title = "变电站信息", businessType = OperaType.DELETE, logType = 1,module = "变电站管理->删除变电站信息") + @PostMapping("/substation/del") + public AjaxResult remove(@RequestBody SubstationVo substationVo) { + AjaxResult ar=new AjaxResult(); + System.out.println(substationVo.getSubstationIds().toString()); + Map map=new HashMap<>(); + map=protectionManageService.deleteSubstation(substationVo.getSubstationIds()); + int code=(int)map.get("code"); + if(code==1){ + return AjaxResult.success((String)map.get("msg")); + }else{ + return AjaxResult.error((String)map.get("msg")); + } + } + + /** + * 查询保护定值单信息列表 + */ + @ApiOperation(value = "查询保护定值单信息列表") + @GetMapping("/protectionOrder/list") + public Map orderlist(ProtectionVo protectionVo) { + Map map=new HashMap<>(); + List list=null; + try { + list= protectionManageService.selectProtectionOrderList(protectionVo); + map.put("data",list); + map.put("code",200); + map.put("res","成功"); + }catch (Exception e){ + map.put("data",list); + map.put("code",400); + map.put("res","失败"); + } + return map; + } + + /** + * 新增/编辑保护定值单信息 + */ + @ApiOperation(value = "编辑保护定值单信息") + @SysLog(title = "保护定值单信息", businessType = OperaType.INSERT, logType = 1,module = "保护定值单管理->新增/编辑保护定值单信息") + @PostMapping("/protectionOrder/edit") + public AjaxResult editProtection(@RequestBody ProtectionVo protectionVo) { + Map map=new HashMap<>(); + try { + return null; + } catch (Exception e) { + return error(e.getMessage()); + } + } + +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/controller/ProtectionManageController.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/controller/ProtectionManageController.java new file mode 100644 index 0000000..6d27edd --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/controller/ProtectionManageController.java @@ -0,0 +1,167 @@ +package com.bonus.canteen.core.protection.controller; + +import com.bonus.canteen.core.certificate.vo.CertificateInfo; +import com.bonus.canteen.core.protection.service.ProtectionManageService; +import com.bonus.canteen.core.protection.vo.ProtectionVo; +import com.bonus.canteen.core.protection.vo.SubstationVo; +import com.bonus.common.core.web.controller.BaseController; +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.core.web.page.TableDataInfo; +import com.bonus.common.log.annotation.SysLog; +import com.bonus.common.log.enums.OperaType; +import com.bonus.common.security.utils.SecurityUtils; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Api(tags = "保护定值接口") +@RestController +@RequestMapping("/protection_manage") +public class ProtectionManageController extends BaseController { + @Resource + private ProtectionManageService protectionManageService; + + /** + * 查询变电站信息列表 + */ + @ApiOperation(value = "查询变电站信息列表") + @GetMapping("/substation/list") + public TableDataInfo list(SubstationVo substationVo) { + startPage(); + List list = protectionManageService.selectSubstationList(substationVo); + return getDataTable(list); + } + /** + * 新增变电站信息 + */ + @ApiOperation(value = "新增变电站信息") + @SysLog(title = "变电站信息", businessType = OperaType.INSERT, logType = 1,module = "变电站管理->新增变电站信息") + @PostMapping("/substation/add") + public AjaxResult add(@RequestBody SubstationVo substationVo) { + String username = SecurityUtils.getUsername(); + String userId=SecurityUtils.getUserId()+""; + Map map=new HashMap<>(); + try { + substationVo.setCreateBy(userId); + return toAjax(protectionManageService.insertSubstation(substationVo)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + /** + * 编辑变电站信息 + */ + @ApiOperation(value = "编辑变电站信息") + @SysLog(title = "变电站信息", businessType = OperaType.INSERT, logType = 1,module = "变电站管理->编辑变电站信息") + @PostMapping("/substation/edit") + public AjaxResult edit(@RequestBody SubstationVo substationVo) { + Map map=new HashMap<>(); + try { + return toAjax(protectionManageService.updateSubstation(substationVo)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + @ApiOperation(value = "删除变电站信息") + @SysLog(title = "变电站信息", businessType = OperaType.DELETE, logType = 1,module = "变电站管理->删除变电站信息") + @PostMapping("/substation/del") + public AjaxResult remove(@RequestBody SubstationVo substationVo) { + AjaxResult ar=new AjaxResult(); + System.out.println(substationVo.getSubstationIds().toString()); + Map map=new HashMap<>(); + map=protectionManageService.deleteSubstation(substationVo.getSubstationIds()); + int code=(int)map.get("code"); + if(code==1){ + return AjaxResult.success((String)map.get("msg")); + }else{ + return AjaxResult.error((String)map.get("msg")); + } + } + + /** + * 查询保护定值单信息列表 + */ + @ApiOperation(value = "查询保护定值单信息列表") + @GetMapping("/protectionOrder/list") + public TableDataInfo orderlist(ProtectionVo protectionVo) { + startPage(); + List list = protectionManageService.selectProtectionOrderList(protectionVo); + return getDataTable(list); + } + + /** + * 查询保护定值单信息列表 + */ + @ApiOperation(value = "查询保护定值单信息详情") + @GetMapping("/protectionOrder/detail") + public Map detail(ProtectionVo protectionVo) { + Map map = protectionManageService.getDetail(protectionVo); + return map; + } + + /** + * 新增/编辑保护定值单信息 + */ + @ApiOperation(value = "编辑保护定值单信息") + @SysLog(title = "保护定值单信息", businessType = OperaType.INSERT, logType = 1,module = "保护定值单管理->新增/编辑保护定值单信息") + @PostMapping("/protectionOrder/edit") + public Map editProtection(@RequestBody ProtectionVo protectionVo) { + Map map=new HashMap<>(); + try { + map=protectionManageService.editProtection(protectionVo); + return map; + } catch (Exception e) { + return error(e.getMessage()); + } + } + + + /** + * 删除保护定值单信息 + */ + @ApiOperation(value = "删除保护定值单信息") + @SysLog(title = "保护定值单信息", businessType = OperaType.INSERT, logType = 1,module = "保护定值单管理->删除保护定值单信息") + @PostMapping("/protectionOrder/del") + public AjaxResult delProtection(@RequestBody ProtectionVo protectionVo) { + try { + return toAjax(protectionManageService.delProtection(protectionVo)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + + /** + * 屏幕识别 + */ + @ApiOperation(value = "屏幕识别") + @SysLog(title = "屏幕识别", businessType = OperaType.INSERT, logType = 1,module = "保护定值单管理->屏幕识别") + @PostMapping("/protectionAnalysis/check") + public AjaxResult check(@RequestBody ProtectionVo protectionVo) { + Map map=new HashMap<>(); + try { + return toAjax(protectionManageService.analysisCheck(protectionVo)); + } catch (Exception e) { + return error(e.getMessage()); + } + } + + /** + * 查询保护定值单识别信息列表 + */ + @ApiOperation(value = "查询保护定值单识别信息列表") + @GetMapping("/protectionAnalysis/list") + public TableDataInfo analysislist(ProtectionVo protectionVo) { + startPage(); + List list = protectionManageService.selectProtectionAnalysisList(protectionVo); + return getDataTable(list); + } + +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/mapper/ProtectionManageMapper.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/mapper/ProtectionManageMapper.java new file mode 100644 index 0000000..c72164e --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/mapper/ProtectionManageMapper.java @@ -0,0 +1,72 @@ +package com.bonus.canteen.core.protection.mapper; + +import com.bonus.canteen.core.certificate.vo.CertificateInfo; +import com.bonus.canteen.core.certificate.vo.CertificateRecord; +import com.bonus.canteen.core.certificate.vo.UserInfo; +import com.bonus.canteen.core.protection.vo.ProtectionResultVo; +import com.bonus.canteen.core.protection.vo.ProtectionVo; +import com.bonus.canteen.core.protection.vo.SubstationVo; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 证件信息Mapper接口 + * + * @author xsheng + * @date 2025-05-25 + */ +public interface ProtectionManageMapper { + + /** + * 查询变电站信息列表 + * + * @param substationVo 变电站信息 + * @return 变电站信息集合 + */ + public List selectSubstationList(SubstationVo substationVo); + + public List selectSubstationListByName(SubstationVo substationVo); + + public int insertSubstation(SubstationVo substationVo); + + public int updateSubstation(SubstationVo substationVo); + + public int deleteSubstation(@Param("substationIds") String[] substationIds); + + public List getProtectionBySubstationIds(@Param("substationIds") String[] substationIds); + + public int editProtection(ProtectionVo protectionVo); + + public int deleteProtectionInfo(@Param("protectionId") String protectionId); + public int deleteHeadInfo(@Param("protectionId") String protectionId); + public int deleteDeviceInfo(@Param("protectionId") String protectionId); + public int deleteBhdzInfo(@Param("protectionId") String protectionId); + public int deleteBhdzValueInfo(@Param("protectionId") String protectionId); + public int deleteKzzInfo(@Param("protectionId") String protectionId); + public int deleteKzzValueInfo(@Param("protectionId") String protectionId); + public int deleteImgInfo(@Param("protectionId") String protectionId); + + public List selectProtectionOrderList(ProtectionVo protectionVo); + + public int insertProtectionOrder(ProtectionVo protectionVo); + public int updateProtectionOrder(ProtectionVo protectionVo); + public int insertProtectionImg(ProtectionVo protectionVo); + + public int insertProtectionHead(ProtectionVo protectionVo); + public int insertProtectionSbcs(ProtectionVo protectionVo); + + public int insertProtectionBhdz(ProtectionVo protectionVo); + public int insertProtectionBhdzValue(ProtectionVo protectionVo); + + public int insertProtectionKzz(ProtectionVo protectionVo); + public int insertProtectionKzzValue(ProtectionVo protectionVo); + + public List selectDetailByHead(ProtectionVo protectionVo); + public List selectDetailBySbcs(ProtectionVo protectionVo); + public List selectDetailByBhdz(ProtectionVo protectionVo); + public List selectDetailByKzz(ProtectionVo protectionVo); + + public List selectProtectionAnalysisList(ProtectionVo protectionVo); + +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/service/ProtectionManageService.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/service/ProtectionManageService.java new file mode 100644 index 0000000..ec1aacd --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/service/ProtectionManageService.java @@ -0,0 +1,47 @@ +package com.bonus.canteen.core.protection.service; + +import com.bonus.canteen.core.certificate.vo.CertificateInfo; +import com.bonus.canteen.core.certificate.vo.CertificateRecord; +import com.bonus.canteen.core.protection.vo.ProtectionVo; +import com.bonus.canteen.core.protection.vo.SubstationVo; +import com.bonus.common.core.web.domain.AjaxResult; +import org.springframework.web.multipart.MultipartFile; + +import java.util.List; +import java.util.Map; + +/** + * 证件信息Service接口 + * + * @author xsheng + * @date 2025-05-25 + */ +public interface ProtectionManageService { + + /** + * 查询变电站信息列表 + * + * @param substationVo 证件信息 + * @return 证件信息集合 + */ + public List selectSubstationList(SubstationVo substationVo); + + public int insertSubstation(SubstationVo substationVo); + + public int updateSubstation(SubstationVo substationVo); + + public Map deleteSubstation(String[] substationIds); + + public List selectProtectionOrderList(ProtectionVo protectionVo); + + public Map getDetail(ProtectionVo protectionVo); + + public Map editProtection(ProtectionVo protectionVo); + + public int delProtection(ProtectionVo protectionVo); + + public int analysisCheck(ProtectionVo protectionVo); + + public List selectProtectionAnalysisList(ProtectionVo protectionVo); + +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/service/imp/ProtectionManageServiceImpl.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/service/imp/ProtectionManageServiceImpl.java new file mode 100644 index 0000000..e93c7e5 --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/service/imp/ProtectionManageServiceImpl.java @@ -0,0 +1,417 @@ +package com.bonus.canteen.core.protection.service.imp; + +import com.bonus.canteen.core.certificate.vo.CertificateInfo; +import com.bonus.canteen.core.protection.mapper.ProtectionManageMapper; +import com.bonus.canteen.core.protection.service.ProtectionManageService; +import com.bonus.canteen.core.protection.vo.ProtectionResultVo; +import com.bonus.canteen.core.protection.vo.ProtectionVo; +import com.bonus.canteen.core.protection.vo.SubstationVo; +import com.bonus.canteen.core.utils.BnsUtils; +import com.bonus.canteen.core.utils.ImgAnalysisUtils; +import com.bonus.canteen.core.utils.OcrService; +import com.bonus.common.core.exception.ServiceException; +import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.security.utils.SecurityUtils; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.io.File; +import java.util.*; + +/** + * 证件信息Service业务层处理 + * + * @author xsheng + * @date 2025-05-25 + */ +@Service +public class ProtectionManageServiceImpl implements ProtectionManageService { + @Resource + private ProtectionManageMapper protectionManageMapper; + @Resource + private OcrService ocrService; + + /** + * 查询变电站信息 + * + * @param substationVo + * @return 变电站信息 + */ + @Override + public List selectSubstationList(SubstationVo substationVo) { + return protectionManageMapper.selectSubstationList(substationVo); + } + + @Override + public int insertSubstation(SubstationVo substationVo) { + int num=0; + try{ + substationVo.setCreateTime(DateUtils.getNowDate()); + substationVo.setUpdateTime(DateUtils.getNowDate()); + Long userid = SecurityUtils.getUserId(); + substationVo.setCreateBy(String.valueOf(userid)); + num=protectionManageMapper.insertSubstation(substationVo); + }catch (Exception e){ + e.printStackTrace(); + } + return num; + } + + @Override + public int updateSubstation(SubstationVo substationVo) { + int num=0; + try{ + substationVo.setUpdateTime(DateUtils.getNowDate()); + Long userid = SecurityUtils.getUserId(); + substationVo.setUpdateBy(String.valueOf(userid)); + checkSubstation(substationVo); + num=protectionManageMapper.updateSubstation(substationVo); + }catch (Exception e){ + e.printStackTrace(); + } + return num; + } + void checkSubstation(SubstationVo substationVo) { + List list=protectionManageMapper.selectSubstationListByName(substationVo); + if(list!=null&&list.size()>0){ + throw new ServiceException("变电站已存在"); + } + } + /** + * 批量删除变电站信息 + * + * @param substationIds 需要删除的变电站信息主键 + * @return 结果 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Map deleteSubstation(String[] substationIds) { + Map map=new HashMap<>(); + try{ + List list=protectionManageMapper.getProtectionBySubstationIds(substationIds); + if(list!=null&&list.size()>0){ + map.put("code",0); + String msg=""; + for(SubstationVo vo:list){ + msg=msg+vo.getSubstationName()+"("+vo.getProtectionName()+") "; + } + msg=msg+"。以上变电站已存储无法删除!"; + map.put("msg",msg); + }else{ + int d=protectionManageMapper.deleteSubstation(substationIds); + map.put("code",1); + map.put("msg","删除成功!"); + } + }catch (Exception e){ + e.printStackTrace(); + map.put("code",0); + map.put("msg",e.getMessage()); + } + return map; + } + + /** + * 查询定值单信息 + * + * @param protectionVo + * @return 定值单信息 + */ + @Override + public List selectProtectionOrderList(ProtectionVo protectionVo) { + return protectionManageMapper.selectProtectionOrderList(protectionVo); + } + /** + * 查询定值单详情信息 + * + * @param protectionVo + * @return 定值单详情信息 + */ + @Override + public Map getDetail(ProtectionVo protectionVo) { + Map map=new HashMap<>(); + try{ + List headlist=protectionManageMapper.selectDetailByHead(protectionVo); + List sbcslist=protectionManageMapper.selectDetailBySbcs(protectionVo); + List bhdzlist=protectionManageMapper.selectDetailByBhdz(protectionVo); + List kzzlist=protectionManageMapper.selectDetailByKzz(protectionVo); + map.put("head",headlist); + map.put("sbcs",sbcslist); + map.put("bhdz",bhdzlist); + map.put("kzz",kzzlist); + }catch (Exception e){ + e.printStackTrace(); + } + return map; + } + @Override + public Map editProtection(ProtectionVo protectionVo) { + int num=0; + Map resMap=new HashMap<>(); + resMap.put("code",400); + ObjectMapper objectMapper = new ObjectMapper(); + Long userid = SecurityUtils.getUserId(); + String substationId=""; + ProtectionVo pvo=new ProtectionVo(); + int headflage=0; + int sbcsflage=0; + Map bhdzcheckmap=new HashMap<>(); + Map kzzcheckmap=new HashMap<>(); + int bhdzflage=0; + int kzzflage=0; + try{ + if(protectionVo.getCheckUrlList()!=null&&protectionVo.getCheckUrlList().length>0){ + for(int n=0;n allObject = objectMapper.readValue(restr, new TypeReference>(){}); + Map headmap=(Map)allObject.get("head"); + if (headmap != null && !headmap.isEmpty()) { + if (headmap != null && !headmap.isEmpty()&&headflage==0) { + List headList=new ArrayList<>(); + for (Map.Entry entry : headmap.entrySet()) { + String keyname=entry.getKey(); + String valuename=entry.getValue().toString(); + ProtectionVo headvo=new ProtectionVo(); + headvo.setKeyName(keyname); + headvo.setValueName(valuename); + headList.add(headvo); + if("设备所属".equals(keyname)){ + SubstationVo sub=new SubstationVo(); + sub.setSubstationName(valuename); + List subs=protectionManageMapper.selectSubstationListByName(sub); + if(subs!=null&&subs.size()>0){ + substationId=subs.get(0).getSubstationId(); + }else{ + sub.setCreateTime(DateUtils.getNowDate()); + sub.setUpdateTime(DateUtils.getNowDate()); + sub.setCreateBy(String.valueOf(userid)); + protectionManageMapper.insertSubstation(sub); + substationId=sub.getSubstationId(); + } + } + } + for(ProtectionVo vo:headList){ + if("通知书名称".equals(vo.getKeyName())){ + pvo.setProtectionName(vo.getValueName()); + } + if("定值单编号".equals(vo.getKeyName())){ + pvo.setProtectionCode(vo.getValueName()); + } + if("日期".equals(vo.getKeyName())){ + pvo.setProtectionDate(vo.getValueName()); + } + if("页码".equals(vo.getKeyName())){ + pvo.setProtectionDate(vo.getValueName()); + } + if("设备所属".equals(vo.getKeyName())){ + pvo.setDeviceName(vo.getValueName()); + } + if("一次设备名称".equals(vo.getKeyName())){ + pvo.setOneDevice(vo.getValueName()); + } + if("保护装置名称".equals(vo.getKeyName())){ + pvo.setProtectionDevice(vo.getValueName()); + } + if("保护装置型号".equals(vo.getKeyName())){ + pvo.setProtectionDeviceModel(vo.getValueName()); + } + if("装置版本".equals(vo.getKeyName())){ + pvo.setProtectionDeviceVersion(vo.getValueName()); + } + if("备注".equals(vo.getKeyName())){ + pvo.setRemark(vo.getValueName()); + } + } + //录入订单 + pvo.setCreateTime(DateUtils.getNowDate()); + pvo.setUpdateTime(DateUtils.getNowDate()); + pvo.setCreateBy(String.valueOf(userid)); + pvo.setSubstationId(substationId); + pvo.setImgUrl(protectionVo.getCheckUrlList()[0]); + pvo.setImgName(protectionVo.getCheckUrlNameList()[0]); + pvo.setProtectionId(protectionVo.getProtectionId()); + pvo.setType(protectionVo.getType()); + if(protectionVo.getProtectionId()!=null&&!"".equals(protectionVo.getProtectionId())){ + protectionManageMapper.updateProtectionOrder(pvo); + }else{ + protectionManageMapper.insertProtectionOrder(pvo); + } + protectionManageMapper.deleteHeadInfo(protectionVo.getProtectionId()); + protectionManageMapper.deleteDeviceInfo(protectionVo.getProtectionId()); + protectionManageMapper.deleteBhdzInfo(protectionVo.getProtectionId()); + protectionManageMapper.deleteBhdzValueInfo(protectionVo.getProtectionId()); + protectionManageMapper.deleteKzzInfo(protectionVo.getProtectionId()); + protectionManageMapper.deleteKzzValueInfo(protectionVo.getProtectionId()); + protectionManageMapper.deleteImgInfo(protectionVo.getProtectionId()); + //录入头部 + for(ProtectionVo vo:headList){ + vo.setProtectionId(pvo.getProtectionId()); + vo.setAttributeValue(vo.getValueName()); + vo.setAttributeKey(vo.getKeyName()); + vo.setCreateTime(DateUtils.getNowDate()); + vo.setUpdateTime(DateUtils.getNowDate()); + vo.setCreateBy(String.valueOf(userid)); + headflage=protectionManageMapper.insertProtectionHead(vo); + } + } + if(headflage>0){ + ProtectionVo imgvo=new ProtectionVo(); + imgvo.setProtectionId(pvo.getProtectionId()); + imgvo.setImgUrl(protectionVo.getCheckUrlList()[n]); + imgvo.setCreateTime(DateUtils.getNowDate()); + imgvo.setUpdateTime(DateUtils.getNowDate()); + imgvo.setCreateBy(String.valueOf(userid)); + protectionManageMapper.insertProtectionImg(imgvo); + //录入设备参数 + Map sbcsmap=(Map)allObject.get("sbcs"); + if (sbcsmap != null && !sbcsmap.isEmpty()&&sbcsflage==0){ + for (Map.Entry entry : sbcsmap.entrySet()) { + String keyname=entry.getKey(); + String valuename=entry.getValue().toString(); + ProtectionVo vo=new ProtectionVo(); + vo.setProtectionId(pvo.getProtectionId()); + vo.setAttributeValue(valuename); + vo.setAttributeKey(keyname); + vo.setCreateTime(DateUtils.getNowDate()); + vo.setUpdateTime(DateUtils.getNowDate()); + vo.setCreateBy(String.valueOf(userid)); + sbcsflage=protectionManageMapper.insertProtectionSbcs(vo); + } + } + //录入保护定值 + List> bhdzmaps=(List>)allObject.get("bhdz"); + if (bhdzmaps != null && !bhdzmaps.isEmpty()){ + int k=1; + for(Map bhdzmap:bhdzmaps){ + int kk=1; + for (Map.Entry entry : bhdzmap.entrySet()) { + String keyname=entry.getKey(); + String valuename=entry.getValue().toString(); + ProtectionVo keyvo=new ProtectionVo(); + keyvo.setProtectionId(pvo.getProtectionId()); + keyvo.setAttributeKey(keyname); + keyvo.setOrderNum(kk+""); + keyvo.setCreateBy(String.valueOf(userid)); + keyvo.setType("1"); + if(k==1&&bhdzflage==0){ + protectionManageMapper.insertProtectionBhdz(keyvo); + bhdzcheckmap.put(keyname,keyvo.getAttributeId()); + } + kk++; + ProtectionVo vo=new ProtectionVo(); + vo.setAttributeId((String)bhdzcheckmap.get(keyname)); + vo.setAttributeValue(valuename); + vo.setBelong(k+""); + vo.setProtectionId(pvo.getProtectionId()); + vo.setCreateBy(String.valueOf(userid)); + protectionManageMapper.insertProtectionBhdzValue(vo); + } + bhdzflage=1; + k++; + } + } + //录入控制字 + List> kzzmaps=(List>)allObject.get("kzz"); + if (kzzmaps != null && !kzzmaps.isEmpty()){ + int j=1; + for(Map kzzmap:kzzmaps){ + int jj=1; + for (Map.Entry entry : kzzmap.entrySet()) { + String keyname=entry.getKey(); + String valuename=entry.getValue().toString(); + ProtectionVo keyvo=new ProtectionVo(); + keyvo.setProtectionId(pvo.getProtectionId()); + keyvo.setAttributeKey(keyname); + keyvo.setOrderNum(jj+""); + keyvo.setCreateBy(String.valueOf(userid)); + keyvo.setType("2"); + if(j==1&&kzzflage==0){ + protectionManageMapper.insertProtectionKzz(keyvo); + kzzmap.put(keyname,keyvo.getAttributeId()); + } + jj++; + ProtectionVo vo=new ProtectionVo(); + vo.setAttributeId((String)kzzmap.get(keyname)); + vo.setAttributeValue(valuename); + vo.setBelong(j+""); + vo.setProtectionId(pvo.getProtectionId()); + vo.setCreateBy(String.valueOf(userid)); + protectionManageMapper.insertProtectionKzzValue(vo); + } + kzzflage=1; + j++; + } + } + } + }else{ + resMap.put("msg","模型错误"); + } + } + resMap.put("code",200); + resMap.put("msg","操作成功!"); + }else{ + return resMap; + } + num=1; + }catch (Exception e){ + resMap.put("msg",e.getMessage()); + e.printStackTrace(); + } + return resMap; + } + + @Override + public int delProtection(ProtectionVo protectionVo) { + int num = 0; + try { + String[] protectionIds=protectionVo.getProtectionIds(); + for(int i=0;i0) { + for (int n = 0; n < protectionVo.getCheckUrlList().length; n++) { + protectionVo.setImgUrl(protectionVo.getCheckUrlList()[n]); + File file = BnsUtils.getFile(protectionVo.getImgUrl(), protectionVo.getCheckUrlNameList()[n]); + String restr = ocrService.callOcrServiceApp(file); + System.err.println(restr); + Map allObject = objectMapper.readValue(restr, new TypeReference>() {}); + } + } + num=1; + }catch (Exception e){ + e.printStackTrace(); + } + return num; + } + + @Override + public List selectProtectionAnalysisList(ProtectionVo protectionVo) { + return protectionManageMapper.selectProtectionAnalysisList(protectionVo); + } +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/ProtectionResultVo.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/ProtectionResultVo.java new file mode 100644 index 0000000..b2daf92 --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/ProtectionResultVo.java @@ -0,0 +1,15 @@ +package com.bonus.canteen.core.protection.vo; + +import com.bonus.canteen.core.common.utils.FileUrlUtil; +import com.bonus.common.core.web.domain.BaseEntity; +import lombok.Data; +import lombok.ToString; + +import java.util.List; + +@Data +@ToString +public class ProtectionResultVo { + private String attributeKey; + private String attributeValue; +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/ProtectionVo.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/ProtectionVo.java new file mode 100644 index 0000000..00d1e68 --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/ProtectionVo.java @@ -0,0 +1,65 @@ +package com.bonus.canteen.core.protection.vo; + +import com.bonus.canteen.core.common.utils.FileUrlUtil; +import com.bonus.common.core.web.domain.BaseEntity; +import lombok.Data; +import lombok.ToString; + +import java.util.List; + +@Data +@ToString +public class ProtectionVo extends BaseEntity { + + private String id; + /** 变电站ID */ + private String substationId; + /** 变电站名称 */ + private String substationName; + /** 保护定值单ID */ + private String protectionId; + /** 保护定值单名称 */ + private String protectionName; + /** 保护定值单编号 */ + private String protectionCode; + /** 保护定值单日期 */ + private String protectionDate; + private String deviceName; + /** 一次设备 */ + private String oneDevice; + /** 保护设备 */ + private String protectionDevice; + /** 保护设备型号 */ + private String protectionDeviceModel; + /** 保护设备版本 */ + private String protectionDeviceVersion; + /** 备注 */ + private String remark; + /** 说明 */ + private String description; + private String pageNo; + private String imgUrl; + private String imgName; + private String[] checkUrlList; + private String[] checkUrlNameList; + + private String keyName; + private String valueName; + + private String attributeKey; + private String attributeValue; + private String attributeId; + private List protectionVos; + + private String belong; + private String orderNum; + private String valueId; + private String keyWord; + private String type; + private String analysisDate; + private String[] protectionIds; + + public String getImgUrl() { + return FileUrlUtil.getFileUrl(this.imgUrl); + } +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/SubstationVo.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/SubstationVo.java new file mode 100644 index 0000000..319a303 --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/protection/vo/SubstationVo.java @@ -0,0 +1,20 @@ +package com.bonus.canteen.core.protection.vo; + +import com.bonus.common.core.web.domain.BaseEntity; +import lombok.Data; +import lombok.ToString; + +@Data +@ToString +public class SubstationVo extends BaseEntity { + + private String substationId; + private String substationName; + private String runTime; + private String remark; + private String keyWord; + private String[] substationIds; + private String userId; + private String protectionName; + +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/BnsUtils.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/BnsUtils.java index 275864f..a0206b9 100644 --- a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/BnsUtils.java +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/BnsUtils.java @@ -7,7 +7,10 @@ import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import java.beans.PropertyDescriptor; -import java.io.IOException; +import java.io.*; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.util.Calendar; import java.util.HashSet; import java.util.Set; @@ -166,4 +169,58 @@ public class BnsUtils { } } + public static File getFile(String url, String fileName) throws Exception { + //对本地文件命名 + File file = null; + String prefix=""; + String suffix=""; + prefix = fileName.substring(0,fileName.lastIndexOf(".")); + suffix = fileName.substring(fileName.lastIndexOf("."),fileName.length()); + URL urlfile; + InputStream inStream = null; + OutputStream os = null; + try { + file = File.createTempFile(prefix,suffix); + //下载 + urlfile = new URL(url); + inStream = urlfile.openStream(); + os = new FileOutputStream(file); + + int bytesRead = 0; + byte[] buffer = new byte[8192]; + while ((bytesRead = inStream.read(buffer, 0, 8192)) != -1) { + os.write(buffer, 0, bytesRead); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (null != os) { + os.close(); + } + if (null != inStream) { + inStream.close(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + return file; + } + + + public static File downloadImageToTempFile(String imageUrl) throws IOException { + URL url = new URL(imageUrl); + String suffix=""; + suffix = imageUrl.substring(imageUrl.lastIndexOf("."),imageUrl.length()); + // 创建临时文件 + File tempFile = File.createTempFile("temp-image", suffix); + + try (InputStream in = url.openStream()) { + // 复制URL输入流到临时文件 + Files.copy(in, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } + return tempFile; + } } diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/ImgAnalysisUtils.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/ImgAnalysisUtils.java new file mode 100644 index 0000000..8f65c13 --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/ImgAnalysisUtils.java @@ -0,0 +1,260 @@ +package com.bonus.canteen.core.utils; + +import com.alibaba.fastjson.JSONObject; +import com.bonus.common.core.exception.ServiceException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import okhttp3.*; +import org.json.JSONArray; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.BeanWrapper; +import org.springframework.beans.BeanWrapperImpl; + +import java.beans.PropertyDescriptor; +import java.util.*; + +/** + * @author jsk + * @date 2025/10/25 17:25 + */ +public class ImgAnalysisUtils { + public static Map getImgAnalysis(String imgUrl){ + Map map=new HashMap<>(); + try{ + String headstr=getHeadString(); + // 创建ObjectMapper对象 + ObjectMapper objectMapper = new ObjectMapper(); + // 将json字符串转换成Map + Map headObject = objectMapper.readValue(headstr, new TypeReference>(){}); + map.put("head",headObject); + + String sbcsstr=getSbcsString(); + Map sbcsObject = objectMapper.readValue(sbcsstr, new TypeReference>(){}); + map.put("sbcs",sbcsObject.get("设备参数")); + + String bhdzstr=getBhdzString(); + JSONArray jsonArray = new JSONArray(bhdzstr); + List> bhdzlist = new ArrayList<>(); + for (int i = 0; i < jsonArray.length(); i++) { + org.json.JSONObject jsonObjectd = jsonArray.getJSONObject(i); + Map Objectd = objectMapper.readValue(jsonObjectd.toString(), new TypeReference>(){}); + bhdzlist.add(Objectd); + } + map.put("bhdz",bhdzlist); + + String kzzstr=getKzzString(); + JSONArray jsonArray2 = new JSONArray(kzzstr); + List> kzzlist = new ArrayList<>(); + for (int i = 0; i < jsonArray2.length(); i++) { + org.json.JSONObject jsonObjectd = jsonArray2.getJSONObject(i); + Map Objectd = objectMapper.readValue(jsonObjectd.toString(), new TypeReference>(){}); + kzzlist.add(Objectd); + } + map.put("kzz",kzzlist); + }catch (Exception e){ + e.printStackTrace(); + } + return map; + } + static String getHeadString(){ + return "{\n" + + " \"通知书名称\": \"阜阳电网继电保护装置整定值通知书\",\n" + + " \"定值单编号\": \"FY425143\",\n" + + " \"页码\": \"第1页 共2页\",\n" + + " \"日期\": \"2025年6月8日\",\n" + + " \"设备所属\": \"居士变\",\n" + + " \"一次设备名称\": \"1#电容器\",\n" + + " \"保护装置名称\": \"微机电容器保护\",\n" + + " \"保护装置型号\": \"PAC-8231B-GZK\",\n" + + " \"装置版本\": \"V2.00\",\n" + + " \"备注\": \"新设备投运\"\n" + + "}"; + } + static String getSbcsString(){ + return "{\n" + + " \"设备参数\": {\n" + + " \"不平衡保护CT一次值(安)\": \"1\",\n" + + " \"定值区号\": \"1\",\n" + + " \"被保护设备\": \"1#电容器\",\n" + + " \"不平衡保护CT二次值(安)\": \"5\",\n" + + " \"PT一次值(千伏)\": \"10\",\n" + + " \"零序CT一次值(安)\": \"1\",\n" + + " \"不平衡保护PT一次值(千伏)\": \"10\",\n" + + " \"零序CT二次值(安)\": \"5\",\n" + + " \"不平衡保护PT二次值(伏)\": \"100\",\n" + + " \"保护CT一次值(安)\": \"1000\",\n" + + " \"保护CT二次值(安)\": \"5\"\n" + + " }\n" + + "}"; + } + static String getBhdzString(){ + return "[\n" + + " {\n" + + " \"序号\": \"1\",\n" + + " \"定值名称\": \"过流I段定值(安)\",\n" + + " \"一次值\": \"989.75\",\n" + + " \"二次值\": \"4.95\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"2\",\n" + + " \"定值名称\": \"过流I段时间(秒)\",\n" + + " \"一次值\": \"0.2\",\n" + + " \"二次值\": \"0.2\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"3\",\n" + + " \"定值名称\": \"过流Ⅱ段定值(安)\",\n" + + " \"一次值\": \"395.9\",\n" + + " \"二次值\": \"1.98\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"4\",\n" + + " \"定值名称\": \"过流ⅡI段时间(秒)\",\n" + + " \"一次值\": \"0.5\",\n" + + " \"二次值\": \"0.5\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"5\",\n" + + " \"定值名称\": \"零序过流1段定值(安)\",\n" + + " \"一次值\": \"60\",\n" + + " \"二次值\": \"0.3\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"6\",\n" + + " \"定值名称\": \"零序过流I段时间(秒)\",\n" + + " \"一次值\": \"1.6\",\n" + + " \"二次值\": \"1.6\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"7\",\n" + + " \"定值名称\": \"零序过流Ⅱ段定值(安)\",\n" + + " \"一次值\": \"40\",\n" + + " \"二次值\": \"0.2\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"8\",\n" + + " \"定值名称\": \"零序过流Ⅱ段时间(秒)\",\n" + + " \"一次值\": \"1.8\",\n" + + " \"二次值\": \"1.8\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"9\",\n" + + " \"定值名称\": \"过电压定值(伏)\",\n" + + " \"一次值\": \"\",\n" + + " \"二次值\": \"115.5\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"10\",\n" + + " \"定值名称\": \"过电压时间(秒)\",\n" + + " \"一次值\": \"3\",\n" + + " \"二次值\": \"3\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"11\",\n" + + " \"定值名称\": \"低电压定值(伏)\",\n" + + " \"一次值\": \"\",\n" + + " \"二次值\": \"52.5\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"12\",\n" + + " \"定值名称\": \"低电压时间(秒)\",\n" + + " \"一次值\": \"1\",\n" + + " \"二次值\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"13\",\n" + + " \"定值名称\": \"低电压闭锁电流定值(安)\",\n" + + " \"一次值\": \"118.7\",\n" + + " \"二次值\": \"0.59\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"14\",\n" + + " \"定值名称\": \"不平衡电压定值(伏)\",\n" + + " \"二次值\": \"1.8\",\n" + + " \"一次值\": \"\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"15\",\n" + + " \"定值名称\": \"不平衡电压时间(秒)\",\n" + + " \"一次值\": \"0.2\",\n" + + " \"二次值\": \"0.2\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"16\",\n" + + " \"定值名称\": \"不平衡电流定值(安)\",\n" + + " \"二次值\": \"20\",\n" + + " \"一次值\": \"\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"17\",\n" + + " \"定值名称\": \"不平衡电流时间(秒)\",\n" + + " \"一次值\": \"10\",\n" + + " \"二次值\": \"10\"\n" + + " }\n" + + "]"; + } + static String getKzzString(){ + return "[\n" + + " {\n" + + " \"序号\": \"1\",\n" + + " \"控制字名称\": \"过流1段\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"2\",\n" + + " \"控制字名称\": \"过流1段\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"3\",\n" + + " \"控制字名称\": \"零序电流采用自产零流\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"4\",\n" + + " \"控制字名称\": \"零序过流1段\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"5\",\n" + + " \"控制字名称\": \"零序过流Ⅱ段\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"6\",\n" + + " \"控制字名称\": \"过电压保护\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"7\",\n" + + " \"控制字名称\": \"低电压保护\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"8\",\n" + + " \"控制字名称\": \"不平衡电压保护\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"9\",\n" + + " \"控制字名称\": \"不平衡电流保护\",\n" + + " \"状态\": \"0\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"10\",\n" + + " \"控制字名称\": \"零序过流告警\",\n" + + " \"状态\": \"1\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"11\",\n" + + " \"控制字名称\": \"闭锁简易母线保护\",\n" + + " \"状态\": \"0\"\n" + + " },\n" + + " {\n" + + " \"序号\": \"12\",\n" + + " \"控制字名称\": \"PT断线自检\",\n" + + " \"状态\": \"1\"\n" + + " }\n" + + "]"; + } +} diff --git a/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/OcrService.java b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/OcrService.java new file mode 100644 index 0000000..977756e --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/java/com/bonus/canteen/core/utils/OcrService.java @@ -0,0 +1,180 @@ +package com.bonus.canteen.core.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; +import org.apache.http.HttpEntity; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.apache.http.entity.mime.MultipartEntityBuilder; +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.ContentType; + +import java.io.File; +import java.io.FileInputStream; +import java.nio.charset.StandardCharsets; +import java.io.IOException; +import java.util.Map; + +/** + * @className:OcrService + * @author:cwchen + * @date:2025-10-16-10:35 + * @version:1.0 + * @description: OCR服务实现类 + */ +@Service(value = "OcrService") +@Slf4j +public class OcrService { + + + @Value("${ocr.service.url}") + private String ocrServiceUrl; + + @Value("${ocr.service.urlApp}") + private String ocrAppServiceUrl; + + @Value("${ocr.service.timeout}") + private int timeout; + + private final CloseableHttpClient httpClient; + + private final ObjectMapper objectMapper; + + public OcrService() { + // 配置HTTP客户端 + RequestConfig requestConfig = RequestConfig.custom() + .setConnectTimeout(timeout) + .setSocketTimeout(timeout) + .setConnectionRequestTimeout(timeout) + .build(); + this.httpClient = HttpClients.custom() + .setDefaultRequestConfig(requestConfig) + .build(); + this.objectMapper = new ObjectMapper(); + } + /** + * 调用OCR服务 + */ + public String callOcrService(File file) throws IOException { + HttpPost httpPost = new HttpPost(ocrServiceUrl); + String res="0"; + try { + // 创建 multipart entity builder + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.setCharset(StandardCharsets.UTF_8); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + // 添加文件字段 + builder.addPart("file", + new FileBody(file, ContentType.MULTIPART_FORM_DATA, file.getName())); + // 设置请求实体 - 注意:这里会自动设置正确的 Content-Type 和 boundary + httpPost.setEntity(builder.build()); + // 设置 Accept 头 + httpPost.setHeader("Accept", "application/json"); + log.info("OCR服务开始定值单识别"); + // 执行请求 + try (CloseableHttpResponse response = httpClient.execute(httpPost)) { + HttpEntity entity = response.getEntity(); + String responseBody = EntityUtils.toString(entity, "UTF-8"); + log.info("OCR服务响应状态: {}", response.getStatusLine().getStatusCode()); + log.info("OCR服务响应内容: {}", responseBody); + res=responseBody; + } + } catch (Exception e) { + log.error("调用OCR服务失败", e); + } finally { + // 清理临时文件 +// if (file != null && file.exists()) { +// boolean deleted = file.delete(); +// if (!deleted) { +// log.warn("临时文件删除失败: {}", file.getAbsolutePath()); +// } +// } + httpPost.releaseConnection(); + } + return res; + } + + /** + * 调用OCR服务 + */ + public String callOcrServiceApp(File file) throws IOException { + HttpPost httpPost = new HttpPost(ocrAppServiceUrl); + String res="0"; + try { + // 创建 multipart entity builder + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.setCharset(StandardCharsets.UTF_8); + builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); + // 添加文件字段 + builder.addPart("file", + new FileBody(file, ContentType.MULTIPART_FORM_DATA, file.getName())); + // 设置请求实体 - 注意:这里会自动设置正确的 Content-Type 和 boundary + httpPost.setEntity(builder.build()); + // 设置 Accept 头 + httpPost.setHeader("Accept", "application/json"); + log.info("OCR服务开始屏幕识别"); + // 执行请求 + try (CloseableHttpResponse response = httpClient.execute(httpPost)) { + HttpEntity entity = response.getEntity(); + String responseBody = EntityUtils.toString(entity, "UTF-8"); + log.info("OCR服务响应状态: {}", response.getStatusLine().getStatusCode()); + log.info("OCR服务响应内容: {}", responseBody); + res=responseBody; + } + } catch (Exception e) { + log.error("调用OCR服务失败", e); + } finally { + // 清理临时文件 +// if (file != null && file.exists()) { +// boolean deleted = file.delete(); +// if (!deleted) { +// log.warn("临时文件删除失败: {}", file.getAbsolutePath()); +// } +// } + httpPost.releaseConnection(); + } + return res; + } + + /** + * 关闭HTTP客户端 + */ + public void close() { + try { + httpClient.close(); + } catch (IOException e) { + log.error("关闭HTTP客户端失败", e); + } + } + + public String uploadFileToServer(File file) throws IOException { + String targetUrl=ocrServiceUrl; + try (CloseableHttpClient httpClient = HttpClients.createDefault()) { + HttpPost uploadFile = new HttpPost(targetUrl); + + // 创建multipart请求实体 + MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + // 添加文件参数,这里假设接口需要的参数名为"file",如果不同请修改 + builder.addBinaryBody( + "file", + new FileInputStream(file), + ContentType.APPLICATION_OCTET_STREAM, + file.getName() + ); + HttpEntity multipart = builder.build(); + uploadFile.setEntity(multipart); + // 执行请求并获取响应 + try (CloseableHttpResponse response = httpClient.execute(uploadFile)) { + HttpEntity responseEntity = response.getEntity(); + return EntityUtils.toString(responseEntity, "UTF-8"); + } + } + } +} diff --git a/bonus-modules/bonus-protection/src/main/resources/bootstrap-protection_local.yml b/bonus-modules/bonus-protection/src/main/resources/bootstrap-protection_local.yml index 82b5007..deba19c 100644 --- a/bonus-modules/bonus-protection/src/main/resources/bootstrap-protection_local.yml +++ b/bonus-modules/bonus-protection/src/main/resources/bootstrap-protection_local.yml @@ -1,11 +1,16 @@ # Tomcat server: - port: 48388 + port: 38388 system: sysfile: - prefixOffline: http://localhost:9000/lnyst - prefixOnline: http://localhost:9000/lnyst - bucket: /lnyst + prefixOffline: http://192.168.0.44:9090/jsk + prefixOnline: http://192.168.0.44:9090/jsk + bucket: /jsk +ocr: + service: + url: http://192.168.0.143:8000/ocr/process + timeout: 10000 + urlApp: http://192:168:0:143:8001/ocr/process_screen # Spring spring: cloud: diff --git a/bonus-modules/bonus-protection/src/main/resources/logback.xml b/bonus-modules/bonus-protection/src/main/resources/logback.xml index 983b780..4278c92 100644 --- a/bonus-modules/bonus-protection/src/main/resources/logback.xml +++ b/bonus-modules/bonus-protection/src/main/resources/logback.xml @@ -1,7 +1,7 @@ - + diff --git a/bonus-modules/bonus-protection/src/main/resources/mapper/protection/ProtectionManageMapper.xml b/bonus-modules/bonus-protection/src/main/resources/mapper/protection/ProtectionManageMapper.xml new file mode 100644 index 0000000..4dde4a5 --- /dev/null +++ b/bonus-modules/bonus-protection/src/main/resources/mapper/protection/ProtectionManageMapper.xml @@ -0,0 +1,417 @@ + + + + + + + + insert into bm_substation + + substation_name, + run_time, + remark, + create_by, + create_time, + update_by, + update_time, + + + #{substationName}, + #{runTime}, + #{remark}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + update bm_substation + + substation_name = #{substationName}, + run_time = #{runTime}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where substation_id = #{substationId} + + + + + delete from bm_substation a + where 1=1 + and a.substation_id in + + #{substationId} + + + + + + + insert into bm_protection_order + + substation_id, + protection_name, + protection_code, + img_url, + img_name, + protection_date, + page_no, + device_name, + one_device, + protection_device, + protection_device_model, + protection_device_version, + remark, + description, + type, + create_by, + create_time, + update_by, + update_time, + + + #{substationId}, + #{protectionName}, + #{protectionCode}, + #{imgUrl}, + #{imgName}, + #{protectionDate}, + #{pageNo}, + #{deviceName}, + #{oneDevice}, + #{protectionDevice}, + #{protectionDeviceModel}, + #{protectionDeviceVersion}, + #{remark}, + #{description}, + #{type}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update bm_protection_order + + protection_name = #{protectionName}, + protection_code = #{protectionCode}, + img_url = #{imgUrl}, + img_name = #{imgName}, + protection_date = #{protectionDate}, + device_name = #{deviceName}, + one_device = #{oneDevice}, + protection_device = #{protectionDevice}, + protection_device_model = #{protectionDeviceModel}, + protection_device_version = #{protectionDeviceVersion}, + remark = #{remark}, + description = #{description}, + type = #{type}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where protection_id = #{protectionId} + + + + insert into bm_protection_order_imaga + + protection_id, + img_url, + create_by, + create_time, + update_by, + update_time, + + + #{protectionId}, + #{imgUrl}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + insert into bm_protection_head + + protection_id, + attribute_key, + attribute_value, + create_by, + create_time, + update_by, + update_time, + + + #{protectionId}, + #{attributeKey}, + #{attributeValue}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + insert into bm_protection_device + + protection_id, + attribute_key, + attribute_value, + create_by, + create_time, + update_by, + update_time, + + + #{protectionId}, + #{attributeKey}, + #{attributeValue}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + insert into bm_protection_seting + + protection_id, + attribute_key, + order_num, + type, + create_by, + create_time, + update_by, + update_time, + + + #{protectionId}, + #{attributeKey}, + #{orderNum}, + #{type}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + insert into bm_protection_seting_value + + protection_id, + attribute_id, + attribute_value, + belong, + create_by, + create_time, + update_by, + update_time, + + + #{protectionId}, + #{attributeId}, + #{attributeValue}, + #{belong}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + insert into bm_protection_seting + + protection_id, + attribute_key, + order_num, + type, + create_by, + create_time, + update_by, + update_time, + + + #{protectionId}, + #{attributeKey}, + #{orderNum}, + #{type}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + insert into bm_protection_seting_value + + protection_id, + attribute_id, + attribute_value, + belong, + create_by, + create_time, + update_by, + update_time, + + + #{protectionId}, + #{attributeId}, + #{attributeValue}, + #{belong}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + + + + + update bm_substation + + substation_name = #{substationName}, + run_time = #{runTime}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = #{updateTime}, + + where substation_id = #{substationId} + + + delete from bm_protection_order where protection_id=#{protectionId} + + + delete from bm_protection_head where protection_id=#{protectionId} + + + delete from bm_protection_device where protection_id=#{protectionId} + + + delete from bm_protection_seting where protection_id=#{protectionId} + + + delete from bm_protection_seting_value where protection_id=#{protectionId} + + + delete from bm_protection_seting where protection_id=#{protectionId} + + + delete from bm_protection_seting_value where protection_id=#{protectionId} + + + delete from bm_protection_order_imaga where protection_id=#{protectionId} + + + + + + + + + + \ No newline at end of file diff --git a/bonus-modules/bonus-protection/target/classes/bootstrap-protection_local.yml b/bonus-modules/bonus-protection/target/classes/bootstrap-protection_local.yml index 82b5007..deba19c 100644 --- a/bonus-modules/bonus-protection/target/classes/bootstrap-protection_local.yml +++ b/bonus-modules/bonus-protection/target/classes/bootstrap-protection_local.yml @@ -1,11 +1,16 @@ # Tomcat server: - port: 48388 + port: 38388 system: sysfile: - prefixOffline: http://localhost:9000/lnyst - prefixOnline: http://localhost:9000/lnyst - bucket: /lnyst + prefixOffline: http://192.168.0.44:9090/jsk + prefixOnline: http://192.168.0.44:9090/jsk + bucket: /jsk +ocr: + service: + url: http://192.168.0.143:8000/ocr/process + timeout: 10000 + urlApp: http://192:168:0:143:8001/ocr/process_screen # Spring spring: cloud: diff --git a/bonus-modules/bonus-protection/target/classes/com/bonus/canteen/core/utils/BnsUtils.class b/bonus-modules/bonus-protection/target/classes/com/bonus/canteen/core/utils/BnsUtils.class index e2d9269..6fca2aa 100644 Binary files a/bonus-modules/bonus-protection/target/classes/com/bonus/canteen/core/utils/BnsUtils.class and b/bonus-modules/bonus-protection/target/classes/com/bonus/canteen/core/utils/BnsUtils.class differ diff --git a/bonus-modules/bonus-protection/target/classes/logback.xml b/bonus-modules/bonus-protection/target/classes/logback.xml index 983b780..4278c92 100644 --- a/bonus-modules/bonus-protection/target/classes/logback.xml +++ b/bonus-modules/bonus-protection/target/classes/logback.xml @@ -1,7 +1,7 @@ - + diff --git a/bonus-modules/bonus-shared-station/src/main/java/com/bonus/sharedstation/app/feign/OtherServiceClient.java b/bonus-modules/bonus-shared-station/src/main/java/com/bonus/sharedstation/app/feign/OtherServiceClient.java index 7e7641d..5aeeb38 100644 --- a/bonus-modules/bonus-shared-station/src/main/java/com/bonus/sharedstation/app/feign/OtherServiceClient.java +++ b/bonus-modules/bonus-shared-station/src/main/java/com/bonus/sharedstation/app/feign/OtherServiceClient.java @@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.RequestMethod; * Date: 2025/2/20 下午4:08 * Description: */ -@FeignClient(value="bonus-zjgl") +@FeignClient(value="bonus-protection") @Service @Component public interface OtherServiceClient { diff --git a/bonus-modules/pom.xml b/bonus-modules/pom.xml index 7bf267d..a058f33 100644 --- a/bonus-modules/pom.xml +++ b/bonus-modules/pom.xml @@ -11,7 +11,7 @@ - bonus-zjgl + bonus-protection bonus-shared-station