AddAccountReceiver.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. package com.zcxk.meterreadingsystemv2.kafka;
  2. import com.zcxk.meterreadingsystemv2.common.JacksonUtil;
  3. import com.zcxk.meterreadingsystemv2.dao.TRemoteCustomerMapper;
  4. import com.zcxk.meterreadingsystemv2.dao.YcblhbMapper;
  5. import com.zcxk.meterreadingsystemv2.dbs.DynamicDataSourceContextHolder;
  6. import com.zcxk.meterreadingsystemv2.entity.AcceptData;
  7. import com.zcxk.meterreadingsystemv2.entity.AcceptListData;
  8. import com.zcxk.meterreadingsystemv2.entity.TRemoteCustomer;
  9. import com.zcxk.meterreadingsystemv2.entity.Ycblhb;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.kafka.annotation.KafkaListener;
  13. import org.springframework.stereotype.Component;
  14. import javax.annotation.Resource;
  15. import java.math.BigDecimal;
  16. /**
  17. * 接收验收立户消息类
  18. */
  19. @Slf4j
  20. @Component
  21. public class AddAccountReceiver {
  22. @Autowired
  23. YcblhbMapper ycblhbMapper;
  24. @Resource
  25. private TRemoteCustomerMapper tRemoteCustomerMapper;
  26. @KafkaListener(topics = {"${com.zcxk.kafka.add-account.topic}"})
  27. public void receiveMessage(String message) {
  28. log.info("Kafka consumer Received :{}",message);
  29. try {
  30. AcceptData acceptData = JacksonUtil.string2Obj(message, AcceptData.class);
  31. String commOrgLevel = null;
  32. String commOrgIdenty = null;
  33. if (acceptData != null) {
  34. //萝北自来水公司立户
  35. if("prd".equals(acceptData.getActive()) && acceptData.getCustomerId() == 25){
  36. DynamicDataSourceContextHolder.setDataSourceKey("lb");
  37. log.info("=====service当前连接的数据库是:" + DynamicDataSourceContextHolder.getDataSourceKey());
  38. if (acceptData.getAcceptListData() != null && acceptData.getAcceptListData().size() > 0) {
  39. for (AcceptListData acceptListData : acceptData.getAcceptListData()) {
  40. Ycblhb ycblhb = new Ycblhb();
  41. ycblhb.setYhdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  42. ycblhb.setSbdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  43. ycblhb.setBc("001");
  44. ycblhb.setBsm(acceptListData.getWaterMeterNo());
  45. ycblhb.setZdsj("010101");
  46. ycblhb.setYys("020101");
  47. ycblhb.setBw(acceptListData.getBuildingName() + acceptListData.getLocation());
  48. ycblhb.setBxh("4");
  49. ycblhb.setBcj("37");
  50. //ycblhb.setBqds(acceptListData.getReadData());
  51. ycblhb.setBqds(BigDecimal.ZERO);
  52. ycblhb.setNhrq(acceptListData.getInstallTime());
  53. //log.info(JacksonUtil.obj2String(ycblhb));
  54. ycblhbMapper.insertSelective(ycblhb);
  55. }
  56. }
  57. }
  58. //绥滨自来水公司立户
  59. else if("prd".equals(acceptData.getActive()) && acceptData.getCustomerId() == 33){
  60. DynamicDataSourceContextHolder.setDataSourceKey("suibin");
  61. log.info("=====service当前连接的数据库是:" + DynamicDataSourceContextHolder.getDataSourceKey());
  62. if (acceptData.getAcceptListData() != null && acceptData.getAcceptListData().size() > 0) {
  63. for (AcceptListData acceptListData : acceptData.getAcceptListData()) {
  64. Ycblhb ycblhb = new Ycblhb();
  65. ycblhb.setYhdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  66. ycblhb.setSbdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  67. ycblhb.setBc("001");
  68. ycblhb.setBsm(acceptListData.getWaterMeterNo());
  69. ycblhb.setZdsj("010101");
  70. ycblhb.setYys("020101");
  71. ycblhb.setBw(acceptListData.getBuildingName() + acceptListData.getLocation());
  72. ycblhb.setBxh("4");
  73. ycblhb.setBcj("37");
  74. //ycblhb.setBqds(acceptListData.getReadData());
  75. ycblhb.setBqds(BigDecimal.ZERO);
  76. ycblhb.setNhrq(acceptListData.getInstallTime());
  77. //log.info(JacksonUtil.obj2String(ycblhb));
  78. ycblhbMapper.insertSelective(ycblhb);
  79. }
  80. }
  81. }
  82. //同江供水有限公司立户
  83. else if("prd".equals(acceptData.getActive()) && acceptData.getCustomerId() == 57){
  84. DynamicDataSourceContextHolder.setDataSourceKey("tongjiang");
  85. log.info("=====service当前连接的数据库是:" + DynamicDataSourceContextHolder.getDataSourceKey());
  86. commOrgLevel = "10001014";
  87. commOrgIdenty = "10001014";
  88. if (acceptData.getAcceptListData() != null && acceptData.getAcceptListData().size() > 0) {
  89. for (AcceptListData acceptListData : acceptData.getAcceptListData()) {
  90. Ycblhb ycblhb = new Ycblhb();
  91. ycblhb.setYhdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  92. ycblhb.setSbdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  93. ycblhb.setBc("001");
  94. ycblhb.setBsm(acceptListData.getWaterMeterNo());
  95. ycblhb.setZdsj("010101");
  96. ycblhb.setYys("020101");
  97. ycblhb.setBw(acceptListData.getBuildingName() + acceptListData.getLocation());
  98. ycblhb.setBxh("4");
  99. //ycblhb.setBqds(acceptListData.getReadData());
  100. ycblhb.setBqds(BigDecimal.ZERO);
  101. ycblhb.setNhrq(acceptListData.getInstallTime());
  102. ycblhb.setLdh(acceptListData.getBuildingName());
  103. ycblhb.setDyh(acceptListData.getCommunityName());
  104. ycblhb.setMph(acceptListData.getLocation());
  105. ycblhb.setBcj("37");
  106. ycblhb.setCommOrgLevel(commOrgLevel);
  107. ycblhb.setCommOrgIdenty(commOrgIdenty);
  108. //log.info(JacksonUtil.obj2String(ycblhb));
  109. ycblhbMapper.insertSelective(ycblhb);
  110. }
  111. }
  112. }
  113. //泾阳立户
  114. else if("prd".equals(acceptData.getActive()) && acceptData.getCustomerId() == 22){
  115. DynamicDataSourceContextHolder.setDataSourceKey("jingyang");
  116. log.info("=====service当前连接的数据库是:" + DynamicDataSourceContextHolder.getDataSourceKey());
  117. commOrgLevel = "10001017";
  118. commOrgIdenty = "10001017";
  119. if (acceptData.getAcceptListData() != null && acceptData.getAcceptListData().size() > 0) {
  120. for (AcceptListData acceptListData : acceptData.getAcceptListData()) {
  121. Ycblhb ycblhb = new Ycblhb();
  122. ycblhb.setYhdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  123. ycblhb.setSbdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  124. ycblhb.setBc("001");
  125. ycblhb.setBsm(acceptListData.getWaterMeterNo());
  126. ycblhb.setZdsj("010101");
  127. ycblhb.setYys("020101");
  128. ycblhb.setBw(acceptListData.getBuildingName() + acceptListData.getLocation());
  129. ycblhb.setBxh("4");
  130. //ycblhb.setBqds(acceptListData.getReadData());
  131. ycblhb.setBqds(BigDecimal.ZERO);
  132. ycblhb.setNhrq(acceptListData.getInstallTime());
  133. ycblhb.setLdh(acceptListData.getBuildingName());
  134. ycblhb.setDyh(acceptListData.getCommunityName());
  135. ycblhb.setMph(acceptListData.getLocation());
  136. ycblhb.setBcj("05");
  137. ycblhb.setCommOrgLevel(commOrgLevel);
  138. ycblhb.setCommOrgIdenty(commOrgIdenty);
  139. //log.info(JacksonUtil.obj2String(ycblhb));
  140. ycblhbMapper.insertSelective(ycblhb);
  141. }
  142. }
  143. }
  144. //汇川立户
  145. else if("prd".equals(acceptData.getActive()) && acceptData.getCustomerId() == 38){
  146. DynamicDataSourceContextHolder.setDataSourceKey("huichuan");
  147. log.info("=====service当前连接的数据库是:" + DynamicDataSourceContextHolder.getDataSourceKey());
  148. commOrgLevel = "10001002";
  149. commOrgIdenty = "10001002";
  150. if (acceptData.getAcceptListData() != null && acceptData.getAcceptListData().size() > 0) {
  151. for (AcceptListData acceptListData : acceptData.getAcceptListData()) {
  152. Ycblhb ycblhb = new Ycblhb();
  153. ycblhb.setYhdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  154. ycblhb.setSbdz(acceptListData.getBuildingName() + acceptListData.getLocation());
  155. ycblhb.setBc("001");
  156. ycblhb.setBsm(acceptListData.getWaterMeterNo());
  157. ycblhb.setZdsj("010101");
  158. ycblhb.setYys("020101");
  159. ycblhb.setBw(acceptListData.getBuildingName() + acceptListData.getLocation());
  160. ycblhb.setBxh("4");
  161. //ycblhb.setBqds(acceptListData.getReadData());
  162. ycblhb.setBqds(BigDecimal.ZERO);
  163. ycblhb.setNhrq(acceptListData.getInstallTime());
  164. ycblhb.setLdh(acceptListData.getBuildingName());
  165. ycblhb.setDyh(acceptListData.getCommunityName());
  166. ycblhb.setMph(acceptListData.getLocation());
  167. ycblhb.setBcj("31");
  168. ycblhb.setCommOrgLevel(commOrgLevel);
  169. ycblhb.setCommOrgIdenty(commOrgIdenty);
  170. //log.info(JacksonUtil.obj2String(ycblhb));
  171. ycblhbMapper.insertSelective(ycblhb);
  172. }
  173. }
  174. }
  175. //监利
  176. else if("prd".equals(acceptData.getActive()) && acceptData.getCustomerId() == 19){
  177. DynamicDataSourceContextHolder.setDataSourceKey("jl");
  178. log.info("=====service当前连接的数据库是:" + DynamicDataSourceContextHolder.getDataSourceKey());
  179. if (acceptData.getAcceptListData() != null && acceptData.getAcceptListData().size() > 0) {
  180. for (AcceptListData acceptListData : acceptData.getAcceptListData()) {
  181. TRemoteCustomer tRemoteCustomerOld = tRemoteCustomerMapper.findByMeteraddr(acceptListData.getWaterMeterNo());
  182. if (tRemoteCustomerOld != null) {
  183. log.info(acceptListData.getWaterMeterNo()+"已经存在");
  184. continue;
  185. }
  186. TRemoteCustomer tRemoteCustomer = new TRemoteCustomer();
  187. tRemoteCustomer.setFactoryid(5);
  188. tRemoteCustomer.setMeteraddr(acceptListData.getWaterMeterNo());
  189. tRemoteCustomer.setUsername(acceptListData.getUsername());
  190. tRemoteCustomer.setLinkman(acceptListData.getUsername());
  191. tRemoteCustomer.setPhone(acceptListData.getUserPhone());
  192. tRemoteCustomer.setPaperno(acceptListData.getIdCard());
  193. tRemoteCustomer.setAddress(acceptListData.getLocation());
  194. //tRemoteCustomer.setCaliber(); 口径
  195. tRemoteCustomer.setInstalldate(acceptListData.getInstallTime());
  196. tRemoteCustomer.setIfctrlvalve(0);//是否阀控表
  197. tRemoteCustomer.setImported(0);
  198. //log.info(JSON.toJSONString(tRemoteCustomer));
  199. //tRemoteCustomer.setOldmeterid();
  200. tRemoteCustomer.setUsercode(acceptListData.getFileNo());//客户编码
  201. //tRemoteCustomer.setExtenddata1();
  202. //tRemoteCustomer.setExtenddata2();
  203. //tRemoteCustomer.setExtenddata3();
  204. //tRemoteCustomer.setOldmeteraddr();
  205. //tRemoteCustomer.setValveflag();
  206. //tRemoteCustomer.setId();
  207. tRemoteCustomerMapper.insertSelective(tRemoteCustomer);
  208. }
  209. }
  210. }else {
  211. return;
  212. }
  213. }
  214. }catch (Exception e){
  215. log.info("Kafka consumer Received error={},{}",e.getMessage(),e);
  216. e.printStackTrace();
  217. }
  218. }
  219. }