| | |
| | | public class MachineDto extends PageDto implements Serializable { |
| | | |
| | | public static final String MACHINE_TYPE_CAR = "9996"; |
| | | public static final String MACHINE_STATE_ON = "1200"; |
| | | public static final String MACHINE_STATE_OFF = "1300"; |
| | | |
| | | private String machineMac; |
| | | private String machineId; |
| New file |
| | |
| | | package com.java110.core.annotation; |
| | | |
| | | |
| | | import org.springframework.core.annotation.AliasFor; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.annotation.*; |
| | | |
| | | @Target(ElementType.METHOD) |
| | | @Retention(RetentionPolicy.RUNTIME) |
| | | @Documented |
| | | @Component |
| | | public @interface Java110Synchronized { |
| | | |
| | | @AliasFor("key") |
| | | String value() default ""; |
| | | |
| | | @AliasFor("value") |
| | | String key() default ""; |
| | | } |
| | |
| | | * add by wuxw 2020/7/5 |
| | | **/ |
| | | @Configuration |
| | | public class FeignRequestInterceptor implements RequestInterceptor { |
| | | public class FeignRequestInterceptor implements RequestInterceptor { |
| | | |
| | | |
| | | /** |
| New file |
| | |
| | | package com.java110.core.aop; |
| | | |
| | | import com.java110.core.annotation.Java110Synchronized; |
| | | import com.java110.utils.lock.DistributedLock; |
| | | import org.aspectj.lang.JoinPoint; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.Signature; |
| | | import org.aspectj.lang.annotation.*; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.core.LocalVariableTableParameterNameDiscoverer; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * @ClassName Java110TransactionalAop |
| | | * @Description TODO |
| | | * @Author wuxw |
| | | * @Date 2020/7/3 22:13 |
| | | * @Version 1.0 |
| | | * add by wuxw 2020/7/3 |
| | | **/ |
| | | @Component |
| | | @Aspect |
| | | public class Java110SynchronizedAop { |
| | | |
| | | private static Logger logger = LoggerFactory.getLogger(Java110SynchronizedAop.class); |
| | | |
| | | @Pointcut("@annotation(com.java110.core.annotation.Java110Synchronized)") |
| | | public void dataProcess() { |
| | | } |
| | | |
| | | /** |
| | | * 初始化数据 |
| | | * |
| | | * @param joinPoint |
| | | * @throws Throwable |
| | | */ |
| | | @Before("dataProcess()") |
| | | public void deBefore(JoinPoint joinPoint) throws Throwable { |
| | | |
| | | |
| | | // 接收到请求,记录请求内容 |
| | | ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
| | | HttpServletRequest request = attributes.getRequest(); |
| | | |
| | | } |
| | | |
| | | private String getKey(JoinPoint joinPoint) { |
| | | Signature signature = joinPoint.getSignature();//此处joinPoint的实现类是MethodInvocationProceedingJoinPoint |
| | | MethodSignature methodSignature = (MethodSignature) signature;//获取参数名 |
| | | Java110Synchronized java110Synchronized = methodSignature.getMethod().getAnnotation(Java110Synchronized.class); |
| | | String value = java110Synchronized.value(); |
| | | Object[] args = joinPoint.getArgs(); |
| | | LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer(); |
| | | String[] paramNames = u.getParameterNames(methodSignature.getMethod()); |
| | | for (Object param : args) { |
| | | for (String paramName : paramNames) { |
| | | if (paramName.equals(value)) { |
| | | value = String.valueOf(param); |
| | | } |
| | | } |
| | | } |
| | | return value; |
| | | } |
| | | |
| | | @AfterReturning(returning = "ret", pointcut = "dataProcess()") |
| | | public void doAfterReturning(Object ret) throws Throwable { |
| | | // 处理完请求,返回内容 |
| | | logger.debug("方法调用前执行doAfterReturning()"); |
| | | } |
| | | |
| | | //后置异常通知 |
| | | @AfterThrowing("dataProcess()") |
| | | public void throwException(JoinPoint jp) { |
| | | logger.debug("方法调用异常执行throwException()"); |
| | | |
| | | |
| | | } |
| | | |
| | | //后置最终通知,final增强,不管是抛出异常或者正常退出都会执行 |
| | | @After("dataProcess()") |
| | | public void after(JoinPoint jp) throws IOException { |
| | | // 接收到请求,记录请求内容 |
| | | logger.debug("方法调用后执行after()"); |
| | | } |
| | | |
| | | //环绕通知,环绕增强,相当于MethodInterceptor |
| | | @Around("dataProcess()") |
| | | public Object around(ProceedingJoinPoint pjp) throws Throwable { |
| | | Object o = null; |
| | | String value = getKey(pjp); |
| | | String requestId = DistributedLock.getLockUUID(); |
| | | String key = this.getClass().getSimpleName() + value; |
| | | try { |
| | | //开启事务 |
| | | DistributedLock.waitGetDistributedLock(key, requestId); |
| | | o = pjp.proceed(); |
| | | return o; |
| | | } catch (Throwable e) { |
| | | logger.error("执行方法异常", e); |
| | | throw e; |
| | | } finally { |
| | | //清理事务信息 |
| | | DistributedLock.releaseDistributedLock(requestId, key); |
| | | } |
| | | } |
| | | } |
| | |
| | | */ |
| | | @RequestMapping(value = "/queryMachinesCount", method = RequestMethod.POST) |
| | | int queryMachinesCount(@RequestBody MachineDto machineDto); |
| | | |
| | | |
| | | /** |
| | | * <p>查询小区楼信息</p> |
| | | * |
| | | * @param machineDto 数据对象分享 |
| | | * @return MachineDto 对象数据 |
| | | */ |
| | | @RequestMapping(value = "/updateMachineState", method = RequestMethod.POST) |
| | | int updateMachineState(@RequestBody MachineDto machineDto); |
| | | } |
| | |
| | | package com.java110.intf.job; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.config.feign.FeignConfiguration; |
| | | import com.java110.dto.task.TaskDto; |
| | | import com.java110.entity.order.Business; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | @RequestMapping(value = "/exchange", method = RequestMethod.POST) |
| | | boolean exchange(@RequestBody List<Business> businesses); |
| | | |
| | | |
| | | /** |
| | | * <p>开门</p> |
| | | * |
| | | * @param reqJson 请求信息 |
| | | * @return TaskDto 对象数据 |
| | | */ |
| | | @RequestMapping(value = "/openDoor", method = RequestMethod.POST) |
| | | boolean openDoor(@RequestBody JSONObject reqJson); |
| | | |
| | | } |
| | |
| | | */ |
| | | public final static String CACHE_PRIVILEGE = "PRIVILEGE"; |
| | | |
| | | /** |
| | | * 映射 databus |
| | | */ |
| | | public final static String CACHE_DATABUS = "DATABUS"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 映射 缓存常量 |
| New file |
| | |
| | | package com.java110.common.api; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.bmo.attrValue.IDeleteAttrValueBMO; |
| | | import com.java110.common.bmo.attrValue.IGetAttrValueBMO; |
| | | import com.java110.common.bmo.attrValue.ISaveAttrValueBMO; |
| | | import com.java110.common.bmo.attrValue.IUpdateAttrValueBMO; |
| | | import com.java110.common.bmo.machine.IMachineOpenDoorBMO; |
| | | import com.java110.po.attrValue.AttrValuePo; |
| | | import com.java110.utils.util.Assert; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | 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.RestController; |
| | | |
| | | |
| | | @RestController |
| | | @RequestMapping(value = "/machine") |
| | | public class MachineApi { |
| | | |
| | | @Autowired |
| | | private IMachineOpenDoorBMO machineOpenDoorBMOImpl; |
| | | |
| | | /** |
| | | * 微信保存消息模板 |
| | | * |
| | | * @param reqJson |
| | | * @return |
| | | * @serviceCode /machine/openDoor |
| | | * @path /app/machine/openDoor |
| | | */ |
| | | @RequestMapping(value = "/openDoor", method = RequestMethod.POST) |
| | | public ResponseEntity<String> saveAttrValue(@RequestBody JSONObject reqJson) { |
| | | |
| | | Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含小区信息"); |
| | | Assert.hasKeyAndValue(reqJson, "machineCode", "请求报文中未包含设备信息"); |
| | | Assert.hasKeyAndValue(reqJson, "userType", "请求报文中未包含用户类型"); |
| | | Assert.hasKeyAndValue(reqJson, "userId", "请求报文中未包含用户信息"); |
| | | |
| | | return machineOpenDoorBMOImpl.openDoor(reqJson); |
| | | } |
| | | |
| | | |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.common.bmo.machine; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.dto.attrValue.AttrValueDto; |
| | | import org.springframework.http.ResponseEntity; |
| | | |
| | | public interface IMachineOpenDoorBMO { |
| | | |
| | | /** |
| | | * 开门接口类 |
| | | * |
| | | * @param reqJson 请求报文信息 |
| | | * @return |
| | | */ |
| | | ResponseEntity<String> openDoor(JSONObject reqJson); |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.common.bmo.machine.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.java110.common.bmo.machine.IMachineOpenDoorBMO; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * 设备开门功能 |
| | | * @desc add by 吴学文 14:15 |
| | | */ |
| | | @Service |
| | | public class MachineOpenDoorBMOImpl implements IMachineOpenDoorBMO { |
| | | |
| | | /** |
| | | * 开门功能 |
| | | * @param reqJson 请求报文信息 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public ResponseEntity<String> openDoor(JSONObject reqJson) { |
| | | return null; |
| | | } |
| | | } |
| | |
| | | |
| | | import com.java110.common.dao.IMachineServiceDao; |
| | | import com.java110.core.base.smo.BaseServiceSMO; |
| | | import com.java110.intf.common.IMachineInnerServiceSMO; |
| | | import com.java110.intf.user.IUserInnerServiceSMO; |
| | | import com.java110.dto.PageDto; |
| | | import com.java110.dto.demo.DemoDto; |
| | | import com.java110.dto.machine.MachineDto; |
| | | import com.java110.dto.user.UserDto; |
| | | import com.java110.intf.common.IMachineInnerServiceSMO; |
| | | import com.java110.intf.user.IUserInnerServiceSMO; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | return machineServiceDaoImpl.queryMachinesCount(BeanConvertUtil.beanCovertMap(machineDto)); |
| | | } |
| | | |
| | | @Override |
| | | public int updateMachineState(@RequestBody MachineDto machineDto) { |
| | | machineServiceDaoImpl.updateMachineInfoInstance(BeanConvertUtil.beanCovertMap(machineDto)); |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | public IMachineServiceDao getMachineServiceDaoImpl() { |
| | | return machineServiceDaoImpl; |
| | | } |
| | |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.http.converter.StringHttpMessageConverter; |
| | | import org.springframework.scheduling.annotation.EnableAsync; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | |
| | | import java.nio.charset.Charset; |
| | |
| | | "com.java110.intf.goods" |
| | | }) |
| | | @EnableScheduling |
| | | @EnableAsync |
| | | public class JobServiceApplication { |
| | | private static Logger logger = LoggerFactory.getLogger(JobServiceApplication.class); |
| | | |
| | |
| | | |
| | | import com.java110.entity.order.Business; |
| | | import com.java110.job.adapt.IDatabusAdapt; |
| | | import com.java110.job.adapt.hcIot.asyn.ITransactionMachineAsyn; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | * |
| | | * @desc add by 吴学文 18:58 |
| | | */ |
| | | @Component(value = "machineTransactionIotAdapt") |
| | | public class MachineTransactionIotAdapt implements IDatabusAdapt { |
| | | |
| | | @Autowired |
| | | private ITransactionMachineAsyn transactionMachineAsynImpl; |
| | | |
| | | @Override |
| | | public void execute(Business business, List<Business> businesses) { |
| | | |
| New file |
| | |
| | | /* |
| | | * 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.hcIot.asyn; |
| | | |
| | | /** |
| | | * 设备同步 异步处理 |
| | | */ |
| | | public interface ITransactionMachineAsyn { |
| | | |
| | | void doSend(); |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.hcIot.asyn.impl; |
| | | |
| | | import com.java110.job.adapt.hcIot.asyn.ITransactionMachineAsyn; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * @desc add by 吴学文 9:23 |
| | | */ |
| | | |
| | | @Service |
| | | public class TransactionMachineAsynImpl implements ITransactionMachineAsyn { |
| | | @Override |
| | | @Async |
| | | public void doSend() { |
| | | |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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; |
| | | |
| | | /** |
| | | * 该包 下抒写databus 适配器信息,抒写时为了不影响主业务的受理,建议 同步其他平台 一律采用异步方式传输, |
| | | * 例如再hcIot 包下新建 asyn ,在MachineTransactionIotAdapt 中同步准备要求的报文,但是同步外围系统时 采用 |
| | | * TransactionMachineAsynImpl 异步方式 |
| | | * |
| | | * add by wuxw 2020-12-08 |
| | | * |
| | | **/ |
| New file |
| | |
| | | /* |
| | | * 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.JSONObject; |
| | | import com.java110.core.annotation.Java110Synchronized; |
| | | import com.java110.core.client.RestTemplate; |
| | | 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; |
| | | |
| | | /** |
| | | * 获取token |
| | | * |
| | | * @desc add by 吴学文 9:46 |
| | | */ |
| | | |
| | | public class GetToken { |
| | | |
| | | |
| | | @Java110Synchronized(value = "ximo_get_token") |
| | | public static String get(RestTemplate restTemplate) { |
| | | String token = CommonCache.getValue(XimoIotConstant.XI_MO_TOKEN); |
| | | if (!StringUtil.isEmpty(token)) { |
| | | return token; |
| | | } |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | HttpEntity httpEntity = new HttpEntity(headers); |
| | | ResponseEntity<String> tokenRes = restTemplate.exchange(XimoIotConstant.GET_TOKEN_URL, HttpMethod.GET, httpEntity, String.class); |
| | | |
| | | if (tokenRes.getStatusCode() != null) { |
| | | throw new IllegalArgumentException("获取token失败" + tokenRes.getBody()); |
| | | } |
| | | JSONObject tokenObj = JSONObject.parseObject(tokenRes.getBody()); |
| | | |
| | | if (!tokenObj.containsKey("code") || ResultVo.CODE_OK != tokenObj.getInteger("code")) { |
| | | throw new IllegalArgumentException("获取token失败" + tokenRes.getBody()); |
| | | } |
| | | |
| | | token = tokenObj.getJSONObject("data").getString("accessToken"); |
| | | int expiresIn = tokenObj.getJSONObject("data").getInteger("accessToken"); |
| | | |
| | | CommonCache.setValue(XimoIotConstant.XI_MO_TOKEN, token, expiresIn - 200); |
| | | |
| | | return token; |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.dto.machine.MachineDto; |
| | | import com.java110.entity.order.Business; |
| | | import com.java110.intf.common.IMachineInnerServiceSMO; |
| | | 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; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * HC iot 设备同步适配器 |
| | | * |
| | | * @desc add by 吴学文 18:58 |
| | | */ |
| | | @Component(value = "ximoAddMachineTransactionIotAdapt") |
| | | public class XimoAddMachineTransactionIotAdapt implements IDatabusAdapt { |
| | | |
| | | @Autowired |
| | | private IXimoMachineAsyn ximoMachineAsynImpl; |
| | | @Autowired |
| | | IMachineInnerServiceSMO machineInnerServiceSMOImpl; |
| | | |
| | | /** |
| | | * accessToken={access_token} |
| | | * &extCommunityUuid=01000 |
| | | * &extCommunityId=1 |
| | | * &devSn=111111111 |
| | | * &name=设备名称 |
| | | * &positionType=0 |
| | | * &positionUuid=1 |
| | | * |
| | | * @param business 当前处理业务 |
| | | * @param businesses 所有业务信息 |
| | | */ |
| | | @Override |
| | | public void execute(Business business, List<Business> businesses) { |
| | | JSONObject data = business.getData(); |
| | | if (data.containsKey(MachinePo.class.getSimpleName())) { |
| | | Object bObj = data.get(MachinePo.class.getSimpleName()); |
| | | JSONArray businessMachines = null; |
| | | if (bObj instanceof JSONObject) { |
| | | businessMachines = new JSONArray(); |
| | | businessMachines.add(bObj); |
| | | } else { |
| | | businessMachines = (JSONArray) bObj; |
| | | } |
| | | //JSONObject businessMachine = data.getJSONObject("businessMachine"); |
| | | for (int bMachineIndex = 0; bMachineIndex < businessMachines.size(); bMachineIndex++) { |
| | | JSONObject businessMachine = businessMachines.getJSONObject(bMachineIndex); |
| | | doSendMachine(business, businessMachine); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void doSendMachine(Business business, JSONObject businessMachine) { |
| | | |
| | | MachinePo machinePo = BeanConvertUtil.covertBean(businessMachine, MachinePo.class); |
| | | |
| | | MachineDto machineDto = new MachineDto(); |
| | | machineDto.setMachineCode(machinePo.getMachineCode()); |
| | | machineDto.setCommunityId(machinePo.getCommunityId()); |
| | | List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto); |
| | | |
| | | Assert.listOnlyOne(machineDtos, "未找到设备"); |
| | | |
| | | MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); |
| | | |
| | | postParameters.add("extCommunityUuid", machinePo.getCommunityId()); |
| | | postParameters.add("devSn", machinePo.getMachineCode()); |
| | | postParameters.add("uuid", machineDtos.get(0).getMachineId()); |
| | | postParameters.add("name", machinePo.getMachineName()); |
| | | postParameters.add("positionType", "0"); |
| | | postParameters.add("positionUuid", machinePo.getCommunityId()); |
| | | ximoMachineAsynImpl.send(postParameters); |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.dto.machine.MachineDto; |
| | | import com.java110.entity.order.Business; |
| | | import com.java110.intf.common.IMachineInnerServiceSMO; |
| | | 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; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * HC iot 设备同步适配器 |
| | | * |
| | | * @desc add by 吴学文 18:58 |
| | | */ |
| | | @Component(value = "ximoDeleteMachineTransactionIotAdapt") |
| | | public class XimoDeleteMachineTransactionIotAdapt implements IDatabusAdapt { |
| | | |
| | | @Autowired |
| | | private IXimoMachineAsyn ximoMachineAsynImpl; |
| | | |
| | | @Autowired |
| | | IMachineInnerServiceSMO machineInnerServiceSMOImpl; |
| | | |
| | | /** |
| | | * accessToken={access_token} |
| | | * &extCommunityUuid=01000 |
| | | * &extCommunityId=1 |
| | | * &devSn=111111111 |
| | | * &name=设备名称 |
| | | * &positionType=0 |
| | | * &positionUuid=1 |
| | | * |
| | | * @param business 当前处理业务 |
| | | * @param businesses 所有业务信息 |
| | | */ |
| | | @Override |
| | | public void execute(Business business, List<Business> businesses) { |
| | | JSONObject data = business.getData(); |
| | | if (data.containsKey(MachinePo.class.getSimpleName())) { |
| | | Object bObj = data.get(MachinePo.class.getSimpleName()); |
| | | JSONArray businessMachines = null; |
| | | if (bObj instanceof JSONObject) { |
| | | businessMachines = new JSONArray(); |
| | | businessMachines.add(bObj); |
| | | } else { |
| | | businessMachines = (JSONArray) bObj; |
| | | } |
| | | //JSONObject businessMachine = data.getJSONObject("businessMachine"); |
| | | for (int bMachineIndex = 0; bMachineIndex < businessMachines.size(); bMachineIndex++) { |
| | | JSONObject businessMachine = businessMachines.getJSONObject(bMachineIndex); |
| | | doSendMachine(business, businessMachine); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void doSendMachine(Business business, JSONObject businessMachine) { |
| | | |
| | | MachinePo machinePo = BeanConvertUtil.covertBean(businessMachine, MachinePo.class); |
| | | MachineDto machineDto = new MachineDto(); |
| | | machineDto.setMachineId(machinePo.getMachineId()); |
| | | List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto); |
| | | |
| | | Assert.listOnlyOne(machineDtos, "未找到设备"); |
| | | |
| | | MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); |
| | | |
| | | postParameters.add("extCommunityUuid", machineDtos.get(0)); |
| | | //postParameters.add("devSn", machinePo.getMachineCode()); |
| | | postParameters.add("uuids", machinePo.getMachineId()); |
| | | ximoMachineAsynImpl.deleteSend(postParameters); |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.dto.community.CommunityDto; |
| | | import com.java110.dto.machine.MachineDto; |
| | | import com.java110.dto.task.TaskDto; |
| | | import com.java110.intf.common.IMachineInnerServiceSMO; |
| | | import com.java110.job.quartz.TaskSystemQuartz; |
| | | 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.List; |
| | | |
| | | /** |
| | | * @desc add by 吴学文 12:28 |
| | | */ |
| | | @Service("ximoGetMachineStateAdapt") |
| | | public class XimoGetMachineStateAdapt extends TaskSystemQuartz { |
| | | |
| | | @Autowired |
| | | private IMachineInnerServiceSMO machineInnerServiceSMOImpl; |
| | | @Autowired |
| | | private RestTemplate outRestTemplate; |
| | | |
| | | @Override |
| | | protected void process(TaskDto taskDto) throws Exception { |
| | | // 获取小区 |
| | | List<CommunityDto> communityDtos = getAllCommunity(); |
| | | |
| | | for (CommunityDto communityDto : communityDtos) { |
| | | queryMachineStatue(taskDto, communityDto); |
| | | } |
| | | } |
| | | |
| | | private void queryMachineStatue(TaskDto taskDto, CommunityDto communityDto) { |
| | | |
| | | MachineDto machineDto = new MachineDto(); |
| | | machineDto.setCommunityId(communityDto.getCommunityId()); |
| | | List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto); |
| | | |
| | | StringBuilder devSns = new StringBuilder(); |
| | | |
| | | for (MachineDto tmpMachineDto : machineDtos) { |
| | | devSns.append(tmpMachineDto.getMachineCode()); |
| | | devSns.append(","); |
| | | } |
| | | |
| | | String devSnsString = devSns.toString().endsWith(",") |
| | | ? devSns.toString().substring(0, devSns.length() - 2) : devSns.toString(); |
| | | MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); |
| | | postParameters.add("devSns", devSnsString); |
| | | postParameters.add("accessToken", GetToken.get(outRestTemplate)); |
| | | 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); |
| | | |
| | | 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()); |
| | | } |
| | | |
| | | JSONArray data = tokenObj.getJSONArray("data"); |
| | | MachineDto tMachineDto = null; |
| | | for (int dataIndex = 0; dataIndex < data.size(); dataIndex++) { |
| | | for (MachineDto tmpMachineDto : machineDtos) { |
| | | if (!data.getJSONObject(dataIndex).getString("devSn").equals(tmpMachineDto.getMachineCode())) { |
| | | continue; |
| | | } |
| | | tMachineDto = new MachineDto(); |
| | | tMachineDto.setMachineId(tmpMachineDto.getMachineId()); |
| | | tMachineDto.setState("1".equals(data.getJSONObject(dataIndex).getString("connectionStatus")) |
| | | ? MachineDto.MACHINE_STATE_ON : MachineDto.MACHINE_STATE_OFF); |
| | | machineInnerServiceSMOImpl.updateMachineState(tMachineDto); |
| | | } |
| | | } |
| | | |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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; |
| | | |
| | | /** |
| | | * 吸墨常量类 |
| | | * |
| | | * @desc add by 吴学文 9:49 |
| | | */ |
| | | public class XimoIotConstant { |
| | | |
| | | public static final String IOT_URL = "https://cloud-api.test.thinmoo.com/"; |
| | | |
| | | public static final String APP_ID = "e86a6a373c354927bea5fd21a0bec617"; |
| | | public static final String APP_SECRET = "ead9a2f67f96e2b8ed2fe38cc9709463"; |
| | | |
| | | public static final String GET_TOKEN_URL = IOT_URL + "/platCompany/extapi/getAccessToken?appId=" + APP_ID + "&appSecret=" + APP_SECRET; |
| | | |
| | | //添加设备 |
| | | public static final String ADD_MACHINE_URL = IOT_URL + "/devDevice/extapi/add"; |
| | | public static final String UPDATE_MACHINE_URL = IOT_URL + "/devDevice/extapi/update"; |
| | | public static final String DELETE_MACHINE_URL = IOT_URL + "/devDevice/extapi/delete"; |
| | | |
| | | public static final String XI_MO_TOKEN = "XI_MO_TOKEN"; |
| | | |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.dto.machine.MachineDto; |
| | | import com.java110.entity.order.Business; |
| | | import com.java110.intf.common.IMachineInnerServiceSMO; |
| | | 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; |
| | | import com.java110.utils.util.BeanConvertUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * HC iot 设备同步适配器 |
| | | * |
| | | * @desc add by 吴学文 18:58 |
| | | */ |
| | | @Component(value = "ximoModifyMachineTransactionIotAdapt") |
| | | public class XimoModifyMachineTransactionIotAdapt implements IDatabusAdapt { |
| | | |
| | | @Autowired |
| | | private IXimoMachineAsyn ximoMachineAsynImpl; |
| | | |
| | | @Autowired |
| | | IMachineInnerServiceSMO machineInnerServiceSMOImpl; |
| | | |
| | | /** |
| | | * accessToken={access_token} |
| | | * &extCommunityUuid=01000 |
| | | * &extCommunityId=1 |
| | | * &devSn=111111111 |
| | | * &name=设备名称 |
| | | * &positionType=0 |
| | | * &positionUuid=1 |
| | | * |
| | | * @param business 当前处理业务 |
| | | * @param businesses 所有业务信息 |
| | | */ |
| | | @Override |
| | | public void execute(Business business, List<Business> businesses) { |
| | | JSONObject data = business.getData(); |
| | | if (data.containsKey(MachinePo.class.getSimpleName())) { |
| | | Object bObj = data.get(MachinePo.class.getSimpleName()); |
| | | JSONArray businessMachines = null; |
| | | if (bObj instanceof JSONObject) { |
| | | businessMachines = new JSONArray(); |
| | | businessMachines.add(bObj); |
| | | } else { |
| | | businessMachines = (JSONArray) bObj; |
| | | } |
| | | //JSONObject businessMachine = data.getJSONObject("businessMachine"); |
| | | for (int bMachineIndex = 0; bMachineIndex < businessMachines.size(); bMachineIndex++) { |
| | | JSONObject businessMachine = businessMachines.getJSONObject(bMachineIndex); |
| | | doSendMachine(business, businessMachine); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void doSendMachine(Business business, JSONObject businessMachine) { |
| | | |
| | | MachinePo machinePo = BeanConvertUtil.covertBean(businessMachine, MachinePo.class); |
| | | MachineDto machineDto = new MachineDto(); |
| | | machineDto.setMachineId(machinePo.getMachineId()); |
| | | List<MachineDto> machineDtos = machineInnerServiceSMOImpl.queryMachines(machineDto); |
| | | |
| | | Assert.listOnlyOne(machineDtos, "未找到设备"); |
| | | |
| | | MultiValueMap<String, Object> postParameters = new LinkedMultiValueMap<>(); |
| | | |
| | | postParameters.add("extCommunityUuid", machineDtos.get(0)); |
| | | //postParameters.add("devSn", machinePo.getMachineCode()); |
| | | postParameters.add("uuid", machinePo.getMachineId()); |
| | | postParameters.add("name", machinePo.getMachineName()); |
| | | postParameters.add("positionType", "0"); |
| | | postParameters.add("positionUuid", machinePo.getCommunityId()); |
| | | ximoMachineAsynImpl.updateSend(postParameters); |
| | | } |
| | | } |
| New file |
| | |
| | | package com.java110.job.adapt.ximoIot.asyn;/* |
| | | * 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. |
| | | */ |
| | | |
| | | import org.springframework.util.MultiValueMap; |
| | | |
| | | public interface IXimoMachineAsyn { |
| | | |
| | | public void send(MultiValueMap<String, Object> postParameters); |
| | | |
| | | void updateSend(MultiValueMap<String, Object> postParameters); |
| | | |
| | | void deleteSend(MultiValueMap<String, Object> postParameters); |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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.asyn.impl; |
| | | |
| | | import com.java110.core.client.RestTemplate; |
| | | import com.java110.job.adapt.ximoIot.GetToken; |
| | | import com.java110.job.adapt.ximoIot.XimoIotConstant; |
| | | import com.java110.job.adapt.ximoIot.asyn.IXimoMachineAsyn; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | 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.scheduling.annotation.Async; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.MultiValueMap; |
| | | |
| | | /** |
| | | * @desc add by 吴学文 11:55 |
| | | */ |
| | | @Service |
| | | public class XimoMachineAsynImpl implements IXimoMachineAsyn { |
| | | private static final Logger logger = LoggerFactory.getLogger(XimoMachineAsynImpl.class); |
| | | |
| | | |
| | | @Autowired |
| | | private RestTemplate outRestTemplate; |
| | | |
| | | @Override |
| | | @Async |
| | | public void send(MultiValueMap<String, Object> postParameters) { |
| | | postParameters.add("accessToken", GetToken.get(outRestTemplate)); |
| | | 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); |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | |
| | | @Override |
| | | @Async |
| | | public void updateSend(MultiValueMap<String, Object> postParameters) { |
| | | postParameters.add("accessToken", GetToken.get(outRestTemplate)); |
| | | 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); |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | |
| | | @Override |
| | | public void deleteSend(MultiValueMap<String, Object> postParameters) { |
| | | postParameters.add("accessToken", GetToken.get(outRestTemplate)); |
| | | 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); |
| | | |
| | | logger.debug("调用吸墨信息:" + responseEntity); |
| | | } |
| | | } |
| | |
| | | |
| | | |
| | | import com.java110.core.base.smo.BaseServiceSMO; |
| | | import com.java110.dto.businessDatabus.BusinessDatabusDto; |
| | | import com.java110.entity.order.Business; |
| | | import com.java110.intf.job.IDataBusInnerServiceSMO; |
| | | import com.java110.job.adapt.IDatabusAdapt; |
| | | import com.java110.utils.cache.DatabusCache; |
| | | import com.java110.utils.factory.ApplicationContextFactory; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | |
| | | **/ |
| | | @RestController |
| | | public class DataBusInnerServiceSMOImpl extends BaseServiceSMO implements IDataBusInnerServiceSMO { |
| | | private static final Logger logger = LoggerFactory.getLogger(DataBusInnerServiceSMOImpl.class); |
| | | |
| | | @Autowired |
| | | IDatabusAdapt databusAdaptImpl; |
| | | |
| | | @Override |
| | | public boolean exchange(@RequestBody List<Business> businesses) { |
| | | List<BusinessDatabusDto> databusDtos = DatabusCache.getDatabuss(); |
| | | for (Business business : businesses) { |
| | | doExchange(business, businesses, databusDtos); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 处理业务类 |
| | | * |
| | | * @param business 当前业务 |
| | | * @param businesses 全部业务 |
| | | * @param databusDtos databus |
| | | */ |
| | | private void doExchange(Business business, List<Business> businesses, List<BusinessDatabusDto> databusDtos) { |
| | | for (BusinessDatabusDto databusDto : databusDtos) { |
| | | try { |
| | | if (business.getBusinessTypeCd().equals(databusDto.getBusinessTypeCd())) { |
| | | databusAdaptImpl = ApplicationContextFactory.getBean(databusDto.getBeanName(), IDatabusAdapt.class); |
| | | databusAdaptImpl.execute(business, businesses); |
| | | } |
| | | } catch (Exception e) { |
| | | logger.error("执行databus失败", e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.java110.core.event.app.order.Ordered; |
| | | import com.java110.core.event.center.event.InvokeFinishBusinessSystemEvent; |
| | | import com.java110.core.event.center.listener.DataFlowListener; |
| | | import com.java110.dto.businessDatabus.BusinessDatabusDto; |
| | | import com.java110.entity.order.Business; |
| | | import com.java110.intf.job.IDataBusInnerServiceSMO; |
| | | import com.java110.utils.cache.DatabusCache; |
| | | import com.java110.utils.cache.MappingCache; |
| | | import com.java110.utils.constant.DomainContant; |
| | | import com.java110.utils.util.StringUtil; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | public class TransactionOrderInfoToDataBusListener implements DataFlowListener<InvokeFinishBusinessSystemEvent>, Ordered { |
| | | |
| | | //databus 业务类型 |
| | | private static final String DATABUS_KEY = "DATABUS_BUSINESS_TYPE_CD"; |
| | | private static final String DATABUS_SWITCH = "DATABUS_SWITCH"; |
| | | private static final String DATABUS_SWITCH_ON = "ON"; // 开关打开 |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(TransactionOrderInfoToDataBusListener.class); |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | String businessTypeCds = MappingCache.getRemark(DomainContant.COMMON_DOMAIN, DATABUS_KEY); |
| | | String databusSwitch = MappingCache.getRemark(DomainContant.COMMON_DOMAIN, DATABUS_SWITCH); |
| | | |
| | | if (StringUtil.isEmpty(businessTypeCds)) { |
| | | if (!DATABUS_SWITCH_ON.equals(databusSwitch)) { |
| | | return; |
| | | } |
| | | List<BusinessDatabusDto> databusDtos = DatabusCache.getDatabuss(); |
| | | |
| | | String[] typeCds = businessTypeCds.split("\\|"); |
| | | List<Business> businesses = dataFlow.getBusinessList(); |
| | | |
| | | if (!hasTypeCd(typeCds, businesses)) { |
| | | if (!hasTypeCd(databusDtos, dataFlow.getBusinessList())) { |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | //同步databus |
| | | dataBusInnerServiceSMOImpl.exchange(businesses); |
| | | dataBusInnerServiceSMOImpl.exchange(dataFlow.getBusinessList()); |
| | | } catch (Exception e) { |
| | | logger.error("传输databus 失败", e); |
| | | } |
| | | } |
| | | |
| | | private boolean hasTypeCd(String[] typeCds, List<Business> businesses) { |
| | | for (String typeCd : typeCds) { |
| | | private boolean hasTypeCd(List<BusinessDatabusDto> databusDtos, List<Business> businesses) { |
| | | |
| | | for (BusinessDatabusDto databusDto : databusDtos) { |
| | | for (Business business : businesses) { |
| | | if (typeCd.equals(business.getBusinessTypeCd())) { |
| | | if (databusDto.getBusinessTypeCd().equals(business.getBusinessTypeCd())) { |
| | | return true; |
| | | } |
| | | } |
| | |
| | | //5.0 刷新基础权限 |
| | | flushPrivilege(dataQuery); |
| | | |
| | | //刷新databus |
| | | doFlushDatabus(dataQuery); |
| | | |
| | | dataQuery.setResponseInfo(DataTransactionFactory.createBusinessResponseJson(ResponseConstant.RESULT_CODE_SUCCESS, "刷新成功")); |
| | | } |
| | | |
| | |
| | | |
| | | //5.0 刷新基础权限 |
| | | flushPrivilege(headers); |
| | | |
| | | flushDatabus(headers); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | doFlushPrivilege(); |
| | | |
| | | //刷新databus |
| | | doFlushDatabus(); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 刷新 Mapping 数据 |
| | | */ |
| | | private void doFlushDatabus(DataQuery dataQuery) { |
| | | |
| | | JSONObject params = dataQuery.getRequestParams(); |
| | | |
| | | if (!CommonConstant.CACHE_DATABUS.equals(params.getString(CommonConstant.CACHE_PARAM_NAME))) { |
| | | return; |
| | | } |
| | | |
| | | doFlushDatabus(); |
| | | } |
| | | |
| | | /** |
| | | * 刷新 Mapping 数据 |
| | | */ |
| | | private void flushPrivilege(Map<String, String> headers) { |
| | | |
| | | Assert.hasKey(headers, CommonConstant.CACHE_PARAM, "未包含cache参数" + headers.toString()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 刷新 databus 数据 |
| | | */ |
| | | private void flushDatabus(Map<String, String> headers) { |
| | | |
| | | Assert.hasKey(headers, CommonConstant.CACHE_PARAM, "未包含cache参数" + headers.toString()); |
| | | |
| | | if (!CommonConstant.CACHE_DATABUS.equals(headers.get(CommonConstant.CACHE_PARAM)) |
| | | && !CommonConstant.CACHE_ALL.equals(headers.get(CommonConstant.CACHE_PARAM))) { |
| | | return; |
| | | } |
| | | |
| | | doFlushDatabus(); |
| | | } |
| | | |
| | | /** |
| | | * 刷新 Mapping 数据 |
| | | */ |
| | | private void flushMapping(Map<String, String> headers) { |