pipIrr-platform/.gitignore
@@ -1,3 +1,4 @@ target/ /pipIrr-platform.iml /pipIrr-parent.iml /文档/~$pIrr接口.docx pipIrr-platform/pipIrr-common/src/main/java/com/dy/common/mw/protocol/p206V1_0_0/parse/Cd_66_Up.java
@@ -69,7 +69,7 @@ cdData.ip = ip1 + "." + ip2 + "." + ip3 + "." + ip4 ; String port = "" +ByteUtilUnsigned.bytes2Short_LE(bs, index++) ; String port = "" +ByteUtilUnsigned.bytes2Short_BE(bs, index++) ; cdData.port = Integer.parseInt(port) ; } pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/resource/ResourceUnit.java
@@ -123,7 +123,7 @@ /** * 得到一个日志文件 * @param fileName 文件名称 * @param fileName 文件名称([rtuAddr].log) */ @SuppressWarnings("unused") public File getLogFile(String fileName){ pipIrr-platform/pipIrr-mw/pipIrr-mw-rtu/src/main/java/com/dy/rtuMw/web/com/CommandCtrl.java
@@ -1,5 +1,6 @@ package com.dy.rtuMw.web.com; import com.dy.rtuMw.resource.ResourceUnit; import com.dy.rtuMw.server.ServerProperties; import com.dy.rtuMw.server.forTcp.TcpSessionCache; import com.dy.rtuMw.server.local.CommandInnerDeaLer; @@ -10,9 +11,16 @@ import com.dy.common.mw.protocol.CommandType; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import java.io.*; import java.util.ArrayList; import java.util.List; /** @@ -32,6 +40,100 @@ return BaseResponseUtils.buildSuccess("ok"); } /** * 下载控制器(RTU)上下行数据的log日志文件 * @param rtuAddr * @param req * @param rep */ @GetMapping("/rtuLogFile") public void rtuLogFile(String rtuAddr, HttpServletRequest req, HttpServletResponse rep){ File logFile = ResourceUnit.getInstance().getLogFile(rtuAddr + ".log") ; if(logFile != null && logFile.exists()){ //在Spring Boot中,application/octet-stream;charset=UTF-8通常表示响应的内容是字节流, //并且字符集是UTF-8。对于这种类型的响应,Spring Boot默认使用ByteArrayHttpMessageConverter来处理, //因为它可以处理所有application/octet-stream类型的响应。 //然而,ByteArrayHttpMessageConverter并不直接处理字符集(charset)。 //字符集通常用于文本内容,而application/octet-stream通常用于二进制内容,因此在这种情况下指定字符集可能是不合适的。 //不过,如果你确实需要处理带有特定字符集的application/octet-stream响应,你可能需要自定义HttpMessageConverter。 rep.addHeader("content-type", "application/octet-stream;charset=UTF-8"); rep.addHeader("Content-Disposition", "attachment;fileName=" + (rtuAddr + ".log")) ; ServletOutputStream out = null; FileInputStream in = null ; try { out = rep.getOutputStream() ; } catch (Exception ee) { out = null ; }finally{ if(out != null){ byte[] bs = new byte[1024] ; int len = -1 ; try { in = new FileInputStream(logFile); len = in.read(bs) ; while(len != -1){ out.write(bs, 0, len); len = in.read(bs) ; } } catch (Exception eee) { } finally { if(out != null){ try{ out.flush(); out.close(); }catch(Exception e){ }finally{ if(in != null){ try{ in.close(); }catch(Exception e){ } } } } } } } } } /** * 下载控制器(RTU)上下行数据的log日志文件 * @param rtuAddr */ @GetMapping("/rtuLogText") public BaseResponse<List<String>> rtuLogText(String rtuAddr){ List<String> list = new ArrayList() ; File logFile = ResourceUnit.getInstance().getLogFile(rtuAddr + ".log") ; if(logFile != null && logFile.exists()){ BufferedReader reader = null ; try { reader = new BufferedReader(new FileReader(logFile)) ; String line ; while((line = reader.readLine()) != null){ list.add(line) ; } return BaseResponseUtils.buildSuccess(list); } catch (Exception e) { list.add("读取控制器(" + rtuAddr + ")的日志文件异常:" + (e.getMessage() == null?"":("," + e.getMessage()))) ; return BaseResponseUtils.buildSuccess(list); }finally{ if(reader != null){ try{ reader.close(); }catch(Exception e){ } } } }else{ list.add("未得到控制器(" + rtuAddr + ")的日志文件") ; return BaseResponseUtils.buildSuccess(list); } } /** * 接收web系统发来的命令 * @param com * @return */ @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) public BaseResponse<Command> send(@RequestBody Command com) { log.info("收到web系统发来的命令:\n" + com.toString()) ; pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/p206V1_0_0/ComSupportP206V1_0_0.java
@@ -20,6 +20,8 @@ public class ComSupportP206V1_0_0 { protected static String mwUrlTest = "http://127.0.0.1:8070/rtuMw/com/test" ; protected static String mwUrlSendCom = "http://127.0.0.1:8070/rtuMw/com/send" ; protected static String mwUrlRtuLogFile = "http://127.0.0.1:8070/rtuMw/com/rtuLogFile" ; protected static String mwUrlRtuLogText = "http://127.0.0.1:8070/rtuMw/com/rtuLogText" ; protected static String rtuAddr = "532328059995" ; // protected static String mwUrlTest = "http://8.140.179.55:8071/rtuMw/com/test" ; pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/rtuLog/ByteArrayConverterConfig.java
New file @@ -0,0 +1,18 @@ package com.dy.pipIrrMwTestWeb.rtuLog; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; /** * @Author: liurunyu * @Date: 2024/8/28 16:02 * @Description */ @Configuration public class ByteArrayConverterConfig { @Bean public HttpMessageConverter<byte[]> logFileByteArrayHttpMessageConverter() { return new ByteArrayHttpMessageConverter(); } } pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/rtuLog/ByteArrayHttpMessageConverter.java
New file @@ -0,0 +1,40 @@ package com.dy.pipIrrMwTestWeb.rtuLog; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.converter.AbstractHttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; import java.io.IOException; import java.nio.charset.StandardCharsets; /** * @Author: liurunyu * @Date: 2024/8/28 15:58 * @Description */ public class ByteArrayHttpMessageConverter extends AbstractHttpMessageConverter<byte[]> { public ByteArrayHttpMessageConverter() { super(MediaType.APPLICATION_OCTET_STREAM, new MediaType("application", "octet-stream", StandardCharsets.UTF_8)); } @Override protected boolean supports(Class<?> clazz) { return byte[].class == clazz; } @Override protected byte[] readInternal(Class<? extends byte[]> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { // Read the byte array from the input message return org.springframework.util.StreamUtils.copyToByteArray(inputMessage.getBody()); } @Override protected void writeInternal(byte[] bytes, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { // Write the byte array to the output message outputMessage.getBody().write(bytes); } } pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/rtuLog/RtuLogCtrl.java
New file @@ -0,0 +1,60 @@ package com.dy.pipIrrMwTestWeb.rtuLog; import com.dy.common.webUtil.BaseResponse; import com.dy.common.webUtil.BaseResponseUtils; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.net.URLEncoder; import java.util.List; /** * @Author: liurunyu * @Date: 2024/8/28 14:55 * @Description */ @Slf4j @RestController @RequestMapping(path="rtuLog") public class RtuLogCtrl extends RtuLogSupport { @GetMapping(path = "logFile") public BaseResponse<List<String>> rtuLogFile(String rtuAddr, HttpServletRequest req, HttpServletResponse rep){ ServletOutputStream out = null ; try{ byte[] bs = this.requestMw4File(rtuAddr, mwUrlRtuLogFile) ; if(bs != null && bs.length > 0){ String fileReName = rtuAddr + ".log" ; //URLEncoder.encode可以防止中文乱码 fileReName = URLEncoder.encode(fileReName, "UTF-8").replaceAll("\\+", "%20"); rep.addHeader("content-type", "application/octet-stream;charset=UTF-8"); rep.addHeader("Content-Disposition", "attachment;fileName=" + fileReName); out = rep.getOutputStream() ; out.write(bs, 0, (bs==null?0:bs.length)); out.flush(); }else{ return BaseResponseUtils.buildError("获取文件失败") ; } }catch (Exception e){ }finally { if(out != null){ try{ out.close(); }catch(Exception e){ } } } return null ; } @GetMapping(path="logText") public BaseResponse<List<String>> rtuLogText(String rtuAddr){ BaseResponse<List<String>> response = this.requestMw4Text(rtuAddr, mwUrlRtuLogText) ; return response ; } } pipIrr-platform/pipIrr-web/pipIrr-mwTest-web/src/main/java/com/dy/pipIrrMwTestWeb/rtuLog/RtuLogSupport.java
New file @@ -0,0 +1,68 @@ package com.dy.pipIrrMwTestWeb.rtuLog; import com.dy.common.webUtil.BaseResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.http.HttpRequest; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; import java.util.List; /** * @Author: liurunyu * @Date: 2024/8/28 14:58 * @Description */ public class RtuLogSupport { protected static String mwUrlRtuLogFile = "http://127.0.0.1:8070/rtuMw/com/rtuLogFile" ; protected static String mwUrlRtuLogText = "http://127.0.0.1:8070/rtuMw/com/rtuLogText" ; @Autowired private RestTemplate restTemplate; /** * 发送命令 * @return */ protected byte[] requestMw4File(String rtuAddr, String mwUrl) throws Exception{ String url = UriComponentsBuilder.fromUriString(mwUrl) .build() .toUriString(); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) //.queryParam("paramTest", "test") .queryParam("rtuAddr", rtuAddr); String fullUrl = builder.toUriString(); byte[] bs = restTemplate.getForObject(fullUrl, byte[].class); return bs ; } /** * 发送命令 * @return */ protected BaseResponse<List<String>> requestMw4Text(String rtuAddr, String mwUrl){ String url = UriComponentsBuilder.fromUriString(mwUrl) .build() .toUriString(); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url) //.queryParam("paramTest", "test") .queryParam("rtuAddr", rtuAddr); String fullUrl = builder.toUriString(); HttpHeaders headers = new HttpHeaders(); HttpEntity<?> httpEntity = new HttpEntity<>(headers); ResponseEntity<BaseResponse> response = null; try { // 通过Get方式调用接口 response = restTemplate.exchange(fullUrl, HttpMethod.GET, httpEntity, BaseResponse.class); } catch (Exception e) { e.printStackTrace(); } return response.getBody(); } } pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/controller/ControllerCtrl.java
@@ -102,7 +102,7 @@ try { List<Map<String, Object>> list = Optional.ofNullable(controllerSv.getControllersByAddr(rtuAddr)).orElse(new ArrayList<>()); if (list.size() <= 0) { return BaseResponseUtils.buildFail(ProjectResultCode.NO_RECORDS.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.NO_RECORDS.getMessage()); } return BaseResponseUtils.buildSuccess(list); } catch (Exception e) { @@ -133,7 +133,7 @@ //public BaseResponse<Boolean> add(@RequestBody @Valid DtoController po, BindingResult bindingResult){ public BaseResponse<Boolean> add(@RequestBody @Valid PrController po, BindingResult bindingResult) { if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } //PrController prController = DtoToPojo.INSTANCT.po2vo(po); @@ -151,7 +151,7 @@ } Integer rec = Optional.ofNullable(controllerSv.addController(po)).orElse(0); if (rec == 0) { return BaseResponseUtils.buildFail(ProjectResultCode.CONTROLLER_FAIL.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.CONTROLLER_FAIL.getMessage()); } return BaseResponseUtils.buildSuccess(true); } @@ -175,13 +175,13 @@ @SsoAop() public BaseResponse<Boolean> delete(@RequestBody Map map) { if (map == null || map.size() <= 0) { return BaseResponseUtils.buildFail(ProjectResultCode.PLEASE_INPUT_CONTROLLER_ID.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.PLEASE_INPUT_CONTROLLER_ID.getMessage()); } Long controllerId = Long.parseLong(map.get("controllerId").toString()); Integer recordCount = Optional.ofNullable(controllerSv.deleteControllerById(controllerId)).orElse(0); if (recordCount == 0) { return BaseResponseUtils.buildFail(ProjectResultCode.DELETE_CONTROLLER_FAIL.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.DELETE_CONTROLLER_FAIL.getMessage()); } return BaseResponseUtils.buildSuccess(true); } pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/divide/DivideCtrl.java
@@ -101,7 +101,7 @@ if(res != null) { return BaseResponseUtils.buildSuccess(res); }else { return BaseResponseUtils.buildFail(ProjectResultCode.NO_DIVIDES.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.NO_DIVIDES.getMessage()); } } catch (Exception e) { log.error("查询农户异常", e); @@ -129,7 +129,7 @@ @SsoAop() public BaseResponse<Boolean> add(@RequestBody @Valid DtoDivide po, BindingResult bindingResult){ if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } // 接收村编号(主键) Long villageId = po.getVillageId(); @@ -142,7 +142,7 @@ */ Map map_districts = Optional.ofNullable(divideSv.getDistrictsByVillageId(villageId)).orElse(new HashMap()); if(map_districts.size() <= 0) { return BaseResponseUtils.buildFail("区划信息有误"); return BaseResponseUtils.buildErrorMsg("区划信息有误"); } Long countryId = Long.parseLong(map_districts.get("countryId").toString()); Long townId = Long.parseLong(map_districts.get("townId").toString()); @@ -155,7 +155,7 @@ prDivide.setDeleted((byte)0); Integer rec = Optional.ofNullable(divideSv.addDivide(prDivide)).orElse(0); if(rec == 0) { return BaseResponseUtils.buildFail(ProjectResultCode.DIVIDE_FAIL.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.DIVIDE_FAIL.getMessage()); } return BaseResponseUtils.buildSuccess(true) ; } @@ -186,7 +186,7 @@ try { Integer res = Optional.ofNullable(divideSv.deleteDivideById(id)).orElse(0); if(res == 0) return BaseResponseUtils.buildFail(ProjectResultCode.DELETE_DIVIDE_FAIL.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.DELETE_DIVIDE_FAIL.getMessage()); return BaseResponseUtils.buildSuccess(true); } catch (Exception e) { @@ -215,7 +215,7 @@ @SsoAop() public BaseResponse<Boolean> update(@RequestBody @Valid DtoDivide po, BindingResult bindingResult){ if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } // 接收村编号(主键) @@ -229,7 +229,7 @@ */ Map map_districts = Optional.ofNullable(divideSv.getDistrictsByVillageId(villageId)).orElse(new HashMap()); if(map_districts.size() <= 0) { return BaseResponseUtils.buildFail("区划信息有误"); return BaseResponseUtils.buildErrorMsg("区划信息有误"); } Long countryId = Long.parseLong(map_districts.get("countryId").toString()); Long townId = Long.parseLong(map_districts.get("townId").toString()); @@ -242,7 +242,7 @@ Integer rec = Optional.ofNullable(divideSv.updateByPrimaryKey(prDivide)).orElse(0); if(rec == 0) { return BaseResponseUtils.buildFail("分水房修改失败"); return BaseResponseUtils.buildErrorMsg("分水房修改失败"); } return BaseResponseUtils.buildSuccess(true) ; } pipIrr-platform/pipIrr-web/pipIrr-web-project/src/main/java/com/dy/pipIrrProject/intake/IntakeCtrl.java
@@ -78,7 +78,7 @@ try { QueryResultVo<List<PrIntake>> res = this.intakeSv.selectAll(); if (res == null) { return BaseResponseUtils.buildFail(ProjectResultCode.NO_INTAKES.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.NO_INTAKES.getMessage()); } else { return BaseResponseUtils.buildSuccess(res); } @@ -106,7 +106,7 @@ @SsoAop() public BaseResponse<PrIntake> one(@PathVariable("id") Long id) { if (this.intakeSv.selectById(id) == null) { return BaseResponseUtils.buildFail(ProjectResultCode.NO_INTAKES.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.NO_INTAKES.getMessage()); } else { return BaseResponseUtils.buildSuccess(this.intakeSv.selectById(id)); } @@ -127,7 +127,7 @@ try { QueryResultVo<List<VoIntake>> res = intakeSv.getIntakes(vo); if (res == null) { return BaseResponseUtils.buildFail(ProjectResultCode.NO_INTAKES.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.NO_INTAKES.getMessage()); } return BaseResponseUtils.buildSuccess(res); } catch (Exception e) { @@ -151,17 +151,17 @@ public BaseResponse<Boolean> add(@RequestBody @Valid PrIntake po, @Parameter(hidden = true) BindingResult bindingResult) { DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } List<Long> ids = intakeSv.getIntakeIdsByName(po.getName()); if (ids.size() > 0) { return BaseResponseUtils.buildFail(ProjectResultCode.INTAKE_NAME_EXIST.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.INTAKE_NAME_EXIST.getMessage()); } po.setOperateDt(new Date()); po.setDeleted((byte) 0); Integer rec = Optional.ofNullable(intakeSv.addIntake(po)).orElse(0); if (rec == 0) { return BaseResponseUtils.buildFail(ProjectResultCode.ADD_INTAKE_FAIL.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.ADD_INTAKE_FAIL.getMessage()); } return BaseResponseUtils.buildSuccess(true); } @@ -185,11 +185,11 @@ @SsoAop() public BaseResponse<Boolean> update(@RequestBody @Parameter(description = "form表单json数据", required = true) @Valid PrIntake po, @Parameter(hidden = true) BindingResult bindingResult) { if (bindingResult != null && bindingResult.hasErrors()) { return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } List<Long> ids = intakeSv.getIntakeIdByNameExcludeId(po.getId(), po.getName()); if (ids.size() > 0) { return BaseResponseUtils.buildFail(ProjectResultCode.INTAKE_NAME_EXIST.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.INTAKE_NAME_EXIST.getMessage()); } int count; po.setOperateDt(new Date()); @@ -200,7 +200,7 @@ return BaseResponseUtils.buildException(e.getMessage()); } if (count <= 0) { return BaseResponseUtils.buildFail(ProjectResultCode.UPDATE_INTAKE.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.UPDATE_INTAKE.getMessage()); } else { return BaseResponseUtils.buildSuccess(true); } @@ -225,14 +225,14 @@ @SsoAop() public BaseResponse<Boolean> delete(@RequestBody Map map) { if (map == null || map.size() <= 0) { return BaseResponseUtils.buildFail(ProjectResultCode.PLEASE_INPUT_INTAKE_ID.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.PLEASE_INPUT_INTAKE_ID.getMessage()); } Long id = Long.parseLong(map.get("id").toString()); try { //取水口ID Integer recordCount = Optional.ofNullable(intakeSv.delete(id)).orElse(0); if (recordCount == 0) { return BaseResponseUtils.buildFail(ProjectResultCode.DELETE_INTAKE_FAIL.getMessage()); return BaseResponseUtils.buildErrorMsg(ProjectResultCode.DELETE_INTAKE_FAIL.getMessage()); } else { return BaseResponseUtils.buildSuccess(true); } pipIrr-platform/pipIrr-web/pipIrr-web-sso/src/main/java/com/dy/sso/busi/SsoCtrl.java
@@ -100,18 +100,15 @@ @PostMapping(path = "loginJson", consumes = MediaType.APPLICATION_JSON_VALUE) public BaseResponse<UserVo> loginJson(@RequestBody @Parameter(description = "登录json数据", required = true) @Valid LoginVo vo, @Parameter(hidden = true) BindingResult bindingResult) { if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } if(vo.phone == null || vo.phone.trim().length() == 0){ return BaseResponseUtils.buildFail("手机号不能为空"); return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } if(!vo.phone.equals("admin")){ if(vo.phone.length() != 11){ return BaseResponseUtils.buildFail("手机号(长度不是11位)不正确"); return BaseResponseUtils.buildErrorMsg("手机号(长度不是11位)不正确"); } } if(vo.orgTag == null || vo.orgTag.trim().length() == 0){ return BaseResponseUtils.buildFail("未选择组织单位"); return BaseResponseUtils.buildErrorMsg("未选择组织单位"); } //把组织单位标签作为数据源名称 DataSourceContext.set(vo.orgTag); @@ -119,7 +116,7 @@ //得到所有用户账号 List<String> phones = sv.getPhones(); if(!phones.contains(vo.phone)){ return BaseResponseUtils.buildFail("账号不存在"); return BaseResponseUtils.buildErrorMsg("账号不存在"); } String uuid ; @@ -145,7 +142,7 @@ uVo.token = uuid ; return BaseResponseUtils.buildSuccess(uVo); }else{ return BaseResponseUtils.buildFail("密码错误"); return BaseResponseUtils.buildErrorMsg("密码错误"); } } @@ -166,10 +163,10 @@ @PostMapping(path = "loginForm", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public BaseResponse<UserVo> loginForm(@Parameter(description = "form表单数据", required = true) @Valid LoginVo vo, @Parameter(hidden = true) BindingResult bindingResult){ if(bindingResult != null && bindingResult.hasErrors()){ return BaseResponseUtils.buildFail(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); return BaseResponseUtils.buildErrorMsg(Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage()); } if(vo.orgTag == null || vo.orgTag.trim().length() == 0){ return BaseResponseUtils.buildFail("未选择组织单位"); return BaseResponseUtils.buildErrorMsg("未选择组织单位"); } //把组织单位标签作为数据源名称 DataSourceContext.set(vo.orgTag); @@ -197,7 +194,7 @@ uVo.token = uuid ; return BaseResponseUtils.buildSuccess(uVo); }else{ return BaseResponseUtils.buildFail("登录失败"); return BaseResponseUtils.buildErrorMsg("登录失败"); } } @@ -222,7 +219,7 @@ this.sv.logout(token) ; return BaseResponseUtils.buildSuccess(true); }else{ return BaseResponseUtils.buildFail("未从header中得到token"); return BaseResponseUtils.buildErrorMsg("未从header中得到token"); } }