java110-db/src/main/resources/mapper/common/MachineRecordServiceDaoImplMapper.xml
@@ -279,5 +279,18 @@ limit 0,7 </select> <!-- 保存设备上报信息 add by wuxw 2018-07-03 --> <insert id="saveMachineRecords" parameterType="Map"> insert into machine_record( file_time,machine_code,open_type_cd,id_card,machine_record_id,machine_id,`name`,tel,community_id,b_id,file_id,record_type_cd ) values <foreach collection="machineRecords" item="item" separator=","> ( #{item.fileTime},#{item.machineCode},#{item.openTypeCd},#{item.idCard},#{item.machineRecordId},#{item.machineId},#{item.name},#{item.tel},#{item.communityId},'-1',#{item.fileId} ,#{item.recordTypeCd} ) </foreach> </insert> </mapper> java110-interface/src/main/java/com/java110/intf/common/IMachineRecordInnerServiceSMO.java
@@ -3,11 +3,11 @@ import com.alibaba.fastjson.JSONArray; import com.java110.config.feign.FeignConfiguration; import com.java110.dto.machine.MachineRecordDto; import com.java110.po.machine.MachineRecordPo; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -43,4 +43,14 @@ @RequestMapping(value = "/getAssetsMachineRecords", method = RequestMethod.POST) JSONArray getAssetsMachineRecords(@RequestBody String communityId); /** * 查询<p>小区楼</p>总记录数 * * @param machineRecordPos 数据对象分享 * @return 小区下的小区楼记录数 */ @RequestMapping(value = "/saveMachineRecords", method = RequestMethod.POST) int saveMachineRecords(@RequestBody List<MachineRecordPo> machineRecordPos); } java110-utils/src/main/java/com/java110/utils/util/ImageUtils.java
New file @@ -0,0 +1,86 @@ /* * Copyright 2017-2020 吴学文 and java110 team. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.java110.utils.util; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.net.URL; /** * @desc add by 吴学文 16:41 */ public class ImageUtils { public static String getBase64ByImgUrl(String url) { String suffix = url.substring(url.lastIndexOf(".") + 1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { URL urls = new URL(url); Image image = Toolkit.getDefaultToolkit().getImage(urls); BufferedImage biOut = toBufferedImage(image); ImageIO.write(biOut, suffix, baos); String base64Str = Base64Convert.byteToBase64(baos.toByteArray()); return base64Str; } catch (Exception e) { return ""; }finally { try { baos.close(); } catch (IOException e) { e.printStackTrace(); } } } public static BufferedImage toBufferedImage(Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; } // This code ensures that all the pixels in the image are loaded image = new ImageIcon(image).getImage(); BufferedImage bimage = null; GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment(); try { int transparency = Transparency.OPAQUE; GraphicsDevice gs = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gs.getDefaultConfiguration(); bimage = gc.createCompatibleImage(image.getWidth(null), image.getHeight(null), transparency); } catch (HeadlessException e) { // The system does not have a screen } if (bimage == null) { // Create a buffered image using the default color model int type = BufferedImage.TYPE_INT_RGB; bimage = new BufferedImage(image.getWidth(null), image.getHeight(null), type); } // Copy image to buffered image Graphics g = bimage.createGraphics(); // Paint the image onto the buffered image g.drawImage(image, 0, 0, null); g.dispose(); return bimage; } } service-api/src/main/java/com/java110/api/listener/owner/QueryOwnersListener.java
@@ -13,6 +13,7 @@ import com.java110.utils.constant.ServiceCodeConstant; import com.java110.utils.util.Assert; import com.java110.utils.util.BeanConvertUtil; import com.java110.utils.util.StringUtil; import com.java110.vo.api.ApiOwnerDataVo; import com.java110.vo.api.ApiOwnerVo; import org.springframework.beans.factory.annotation.Autowired; @@ -126,13 +127,13 @@ for (OwnerDto ownerDto : ownerDtoList) { //对业主身份证号隐藏处理 String idCard = ownerDto.getIdCard(); if (mark.size() == 0 && idCard != null && !idCard.equals("") && idCard.length() > 16) { if (mark.size() == 0 && !StringUtil.isEmpty(idCard) && idCard.length() > 16) { idCard = idCard.substring(0, 6) + "**********" + idCard.substring(16); ownerDto.setIdCard(idCard); } //对业主手机号隐藏处理 String link = ownerDto.getLink(); if (mark.size() == 0 && link != null && !link.equals("") && link.length() == 11) { if (mark.size() == 0 && !StringUtil.isEmpty(link) && link.length() == 11) { link = link.substring(0, 3) + "****" + link.substring(7); ownerDto.setLink(link); } service-common/src/main/java/com/java110/common/dao/IMachineRecordServiceDao.java
@@ -75,4 +75,5 @@ List<Map> getAssetsMachineRecords(Map info); int saveMachineRecords(Map info); } service-common/src/main/java/com/java110/common/dao/impl/MachineRecordServiceDaoImpl.java
@@ -136,5 +136,16 @@ return machineRecordInfos; } @Override public int saveMachineRecords(Map info) { int saveFlag = sqlSessionTemplate.update("machineRecordServiceDaoImpl.saveMachineRecords", info); if (saveFlag < 1) { throw new DAOException(ResponseConstant.RESULT_PARAM_ERROR, "添加数据失败:" + JSONObject.toJSONString(info)); } return saveFlag; } } service-common/src/main/java/com/java110/common/smo/impl/MachineRecordInnerServiceSMOImpl.java
@@ -8,11 +8,13 @@ import com.java110.dto.machine.MachineRecordDto; import com.java110.intf.common.IMachineRecordInnerServiceSMO; import com.java110.intf.user.IUserInnerServiceSMO; import com.java110.po.machine.MachineRecordPo; import com.java110.utils.util.BeanConvertUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -68,6 +70,18 @@ return JSONArray.parseArray(JSONArray.toJSONString(records)); } @Override public int saveMachineRecords(@RequestBody List<MachineRecordPo> machineRecordPos) { List<Map> machineRecords = new ArrayList<>(); for (MachineRecordPo payFeePo : machineRecordPos) { machineRecords.add(BeanConvertUtil.beanCovertMap(payFeePo)); } Map info = new HashMap(); info.put("machineRecords", machineRecords); return machineRecordServiceDaoImpl.saveMachineRecords(info); } public IMachineRecordServiceDao getMachineRecordServiceDaoImpl() { return machineRecordServiceDaoImpl; } service-job/src/main/java/com/java110/job/JobServiceApplication.java
@@ -55,6 +55,14 @@ return restTemplate; } @Bean //@LoadBalanced public RestTemplate formRestTemplate() { RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter(Charset.forName("UTF-8"))); return restTemplate; } /** * 实例化RestTemplate,通过@LoadBalanced注解开启均衡负载能力. * service-job/src/main/java/com/java110/job/adapt/ximoIot/GetToken.java
@@ -21,10 +21,7 @@ import com.java110.utils.cache.CommonCache; import com.java110.utils.util.StringUtil; import com.java110.vo.ResultVo; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.http.*; /** * 获取token @@ -45,7 +42,7 @@ HttpEntity httpEntity = new HttpEntity(headers); ResponseEntity<String> tokenRes = restTemplate.exchange(XimoIotConstant.GET_TOKEN_URL, HttpMethod.GET, httpEntity, String.class); if (tokenRes.getStatusCode() != null) { if (tokenRes.getStatusCode() != HttpStatus.OK) { throw new IllegalArgumentException("获取token失败" + tokenRes.getBody()); } JSONObject tokenObj = JSONObject.parseObject(tokenRes.getBody()); @@ -55,7 +52,7 @@ } token = tokenObj.getJSONObject("data").getString("accessToken"); int expiresIn = tokenObj.getJSONObject("data").getInteger("accessToken"); int expiresIn = tokenObj.getJSONObject("data").getInteger("expiresIn"); CommonCache.setValue(XimoIotConstant.XI_MO_TOKEN, token, expiresIn - 200); service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoAddMachineTransactionIotAdapt.java
@@ -21,7 +21,6 @@ import com.java110.entity.order.Business; import com.java110.intf.common.IMachineInnerServiceSMO; import com.java110.job.adapt.DatabusAdaptImpl; import com.java110.job.adapt.IDatabusAdapt; import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn; import com.java110.po.machine.MachinePo; import com.java110.utils.util.Assert; @@ -67,6 +66,8 @@ if (bObj instanceof JSONObject) { businessMachines = new JSONArray(); businessMachines.add(bObj); } else if (bObj instanceof List) { businessMachines = JSONArray.parseArray(JSONObject.toJSONString(bObj)); } else { businessMachines = (JSONArray) bObj; } service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoDeleteMachineTransactionIotAdapt.java
@@ -68,6 +68,8 @@ if (bObj instanceof JSONObject) { businessMachines = new JSONArray(); businessMachines.add(bObj); } else if (bObj instanceof List) { businessMachines = JSONArray.parseArray(JSONObject.toJSONString(bObj)); } else { businessMachines = (JSONArray) bObj; } service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoGetOpenDoorLogAdapt.java
New file @@ -0,0 +1,201 @@ /* * Copyright 2017-2020 吴学文 and java110 team. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.java110.job.adapt.ximoIot; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.java110.core.client.RestTemplate; import com.java110.core.factory.GenerateCodeFactory; import com.java110.dto.community.CommunityDto; import com.java110.dto.file.FileDto; import com.java110.dto.machine.MachineDto; import com.java110.dto.owner.OwnerDto; import com.java110.dto.task.TaskDto; import com.java110.intf.common.IFileInnerServiceSMO; import com.java110.intf.common.IFileRelInnerServiceSMO; import com.java110.intf.common.IMachineInnerServiceSMO; import com.java110.intf.common.IMachineRecordInnerServiceSMO; import com.java110.intf.user.IOwnerInnerServiceSMO; import com.java110.job.quartz.TaskSystemQuartz; import com.java110.po.file.FileRelPo; import com.java110.po.machine.MachineRecordPo; import com.java110.utils.util.BeanConvertUtil; import com.java110.utils.util.DateUtil; import com.java110.utils.util.ImageUtils; import com.java110.vo.ResultVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; /** * @desc add by 吴学文 12:28 */ @Service("ximoGetOpenDoorLogAdapt") public class XimoGetOpenDoorLogAdapt extends TaskSystemQuartz { private static Date preDate = null; @Autowired private IMachineInnerServiceSMO machineInnerServiceSMOImpl; @Autowired private RestTemplate outRestTemplate; @Autowired private IMachineRecordInnerServiceSMO machineRecordInnerServiceSMOImpl; @Autowired private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl; @Autowired private IFileInnerServiceSMO fileInnerServiceSMOImpl; @Autowired private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl; @Override protected void process(TaskDto taskDto) throws Exception { // 获取小区 List<CommunityDto> communityDtos = getAllCommunity(); for (CommunityDto communityDto : communityDtos) { queryOpenDoorLog(taskDto, communityDto); } } private void queryOpenDoorLog(TaskDto taskDto, CommunityDto communityDto) { if (preDate == null) { preDate = new Date(); } MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); postParameters.add("extCommunityUuid", communityDto.getCommunityId()); postParameters.add("startDateTime", DateUtil.getFormatTimeString(preDate, DateUtil.DATE_FORMATE_STRING_A)); Calendar calendar = Calendar.getInstance(); calendar.setTime(preDate); calendar.add(Calendar.SECOND, XimoIotConstant.DEFAULT_LOG_TIME); postParameters.add("endDateTime", DateUtil.getFormatTimeString(calendar.getTime(), DateUtil.DATE_FORMATE_STRING_A)); postParameters.add("currPage", 1); postParameters.add("pageSize", 200); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders); ResponseEntity<String> responseEntity = outRestTemplate.exchange(XimoIotConstant.UPDATE_MACHINE_URL, HttpMethod.GET, httpEntity, String.class); if (responseEntity.getStatusCode() != null) { throw new IllegalArgumentException("获取token失败" + responseEntity.getBody()); } JSONObject tokenObj = JSONObject.parseObject(responseEntity.getBody()); if (!tokenObj.containsKey("code") || ResultVo.CODE_OK != tokenObj.getInteger("code")) { throw new IllegalArgumentException("获取token失败" + responseEntity.getBody()); } preDate = calendar.getTime(); JSONArray list = tokenObj.getJSONObject("data").getJSONArray("list"); MachineDto tMachineDto = null; List<MachineRecordPo> machineRecordPos = new ArrayList<>(); for (int dataIndex = 0; dataIndex < list.size(); dataIndex++) { saveMachineOpenDoor(list.getJSONObject(dataIndex), communityDto, machineRecordPos); } machineRecordInnerServiceSMOImpl.saveMachineRecords(machineRecordPos); logger.debug("调用吸墨信息:" + responseEntity); } private void saveMachineOpenDoor(JSONObject jsonObject, CommunityDto communityDto, List<MachineRecordPo> machineRecordPos) { String machineCode = jsonObject.getString("devSn"); MachineDto machineDto = new MachineDto(); machineDto.setCommunityId(communityDto.getCommunityId()); machineDto.setMachineCode(machineCode); List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto); //设备不存在 if (machineDtos == null || machineDtos.size() < 1) { return; } String ownerId = ""; String tel = ""; String idCard = ""; if (jsonObject.containsKey("empUuid")) { OwnerDto ownerDto = new OwnerDto(); ownerDto.setOwnerId(jsonObject.getString("empUuid")); ownerDto.setCommunityId(communityDto.getCommunityId()); List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto); if (ownerDtos != null && ownerDtos.size() > 0) { ownerId = ownerDtos.get(0).getOwnerId(); tel = ownerDtos.get(0).getLink(); idCard = ownerDtos.get(0).getIdCard(); } } machineDto = machineDtos.get(0); MachineRecordPo machineRecordPo = new MachineRecordPo(); machineRecordPo.setCommunityId(communityDto.getCommunityId()); machineRecordPo.setMachineCode(machineDto.getMachineCode()); machineRecordPo.setMachineId(machineDto.getMachineId()); machineRecordPo.setMachineRecordId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_machineRecordId)); machineRecordPo.setOpenTypeCd("21".equals(jsonObject.getString("eventType")) ? "1000" : "2000"); machineRecordPo.setName(jsonObject.getString("empName")); machineRecordPo.setTel(tel); machineRecordPo.setIdCard(idCard); machineRecordPo.setRecordTypeCd("8888"); machineRecordPo.setFileTime(jsonObject.getString("eventTime")); if (!jsonObject.containsKey("captureImage") || !jsonObject.getString("captureImage").startsWith("http")) { return; } String img = ImageUtils.getBase64ByImgUrl(jsonObject.getString("captureImage")); String fileId = GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_file_id); FileDto fileDto = new FileDto(); fileDto.setCommunityId(communityDto.getCommunityId()); fileDto.setFileId(fileId); fileDto.setFileName(fileId); fileDto.setContext(img); fileDto.setSuffix("jpeg"); String fileName = fileInnerServiceSMOImpl.saveFile(fileDto); JSONObject businessUnit = new JSONObject(); businessUnit.put("fileRelId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_fileRelId)); businessUnit.put("relTypeCd", "60000"); businessUnit.put("saveWay", "ftp"); businessUnit.put("objId", machineRecordPo.getMachineRecordId()); businessUnit.put("fileRealName", fileId); businessUnit.put("fileSaveName", fileName); fileRelInnerServiceSMOImpl.saveFileRel(BeanConvertUtil.covertBean(businessUnit, FileRelPo.class)); machineRecordPo.setFileId(fileId); } } service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoIotConstant.java
@@ -37,4 +37,7 @@ public static final String XI_MO_TOKEN = "XI_MO_TOKEN"; //单位为秒 public static final int DEFAULT_LOG_TIME = 5 * 60; } service-job/src/main/java/com/java110/job/adapt/ximoIot/XimoModifyMachineTransactionIotAdapt.java
@@ -67,6 +67,8 @@ if (bObj instanceof JSONObject) { businessMachines = new JSONArray(); businessMachines.add(bObj); } else if (bObj instanceof List) { businessMachines = JSONArray.parseArray(JSONObject.toJSONString(bObj)); } else { businessMachines = (JSONArray) bObj; } service-job/src/main/java/com/java110/job/adapt/ximoIot/asyn/impl/XimoMachineAsynImpl.java
@@ -39,17 +39,17 @@ @Autowired private RestTemplate outRestTemplate; private RestTemplate formRestTemplate; @Override @Async public void send(MultiValueMap<String, Object> postParameters) { postParameters.add("accessToken", GetToken.get(outRestTemplate)); postParameters.add("accessToken", GetToken.get(formRestTemplate)); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders); ResponseEntity<String> responseEntity = outRestTemplate.exchange(XimoIotConstant.ADD_MACHINE_URL, HttpMethod.POST, httpEntity, String.class); ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.ADD_MACHINE_URL, HttpMethod.POST, httpEntity, String.class); logger.debug("调用吸墨信息:" + responseEntity); } @@ -57,24 +57,24 @@ @Override @Async public void updateSend(MultiValueMap<String, Object> postParameters) { postParameters.add("accessToken", GetToken.get(outRestTemplate)); postParameters.add("accessToken", GetToken.get(formRestTemplate)); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders); ResponseEntity<String> responseEntity = outRestTemplate.exchange(XimoIotConstant.UPDATE_MACHINE_URL, HttpMethod.POST, httpEntity, String.class); ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.UPDATE_MACHINE_URL, HttpMethod.POST, httpEntity, String.class); logger.debug("调用吸墨信息:" + responseEntity); } @Override public void deleteSend(MultiValueMap<String, Object> postParameters) { postParameters.add("accessToken", GetToken.get(outRestTemplate)); postParameters.add("accessToken", GetToken.get(formRestTemplate)); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.add("Content-Type", "application/x-www-form-urlencoded"); HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity(postParameters, httpHeaders); ResponseEntity<String> responseEntity = outRestTemplate.exchange(XimoIotConstant.DELETE_MACHINE_URL, HttpMethod.POST, httpEntity, String.class); ResponseEntity<String> responseEntity = formRestTemplate.exchange(XimoIotConstant.DELETE_MACHINE_URL, HttpMethod.POST, httpEntity, String.class); logger.debug("调用吸墨信息:" + responseEntity); } service-order/src/main/java/com/java110/order/listener/TransactionOrderInfoToDataBusListener.java
@@ -56,7 +56,7 @@ return; } String databusSwitch = MappingCache.getRemark(DomainContant.COMMON_DOMAIN, DATABUS_SWITCH); String databusSwitch = MappingCache.getValue(DomainContant.COMMON_DOMAIN, DATABUS_SWITCH); if (!DATABUS_SWITCH_ON.equals(databusSwitch)) { return;