MerchantServiceImpl.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package cn.hhj.rabbitmq.service.impl;
  2. import cn.hhj.rabbitmq.entity.Merchant;
  3. import cn.hhj.rabbitmq.mapper.MerchantMapper;
  4. import cn.hhj.rabbitmq.service.MerchantService;
  5. import com.alibaba.fastjson.JSONObject;
  6. import org.springframework.amqp.core.AmqpTemplate;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.stereotype.Service;
  10. import java.util.List;
  11. @Service
  12. public class MerchantServiceImpl implements MerchantService {
  13. @Value("${cn.hhj.rabbitmq.topicexchange}")
  14. private String topicExchange;
  15. @Value("${cn.hhj.rabbitmq.topicroutingkey1}")
  16. private String topicRoutingKey;
  17. @Autowired
  18. private MerchantMapper merchantMapper;
  19. @Autowired
  20. AmqpTemplate rabbitTemplate;
  21. @Override
  22. public List<Merchant> getMerchantList(String name, int page, int limit) {
  23. return merchantMapper.getMerchantList(name,page,limit);
  24. }
  25. @Override
  26. public Merchant getMerchantById(Integer id) {
  27. return merchantMapper.getMerchantById(id);
  28. }
  29. @Override
  30. public int add(Merchant merchant) {
  31. int k = merchantMapper.add(merchant);
  32. System.out.println("aaa : "+merchant.getId());
  33. JSONObject title = new JSONObject();
  34. String jsonBody = JSONObject.toJSONString(merchant);
  35. title.put("type","add");
  36. title.put("desc","新增商户");
  37. title.put("content",jsonBody);
  38. rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
  39. return k;
  40. }
  41. @Override
  42. public int updateState(Merchant merchant) {
  43. int k = merchantMapper.updateState(merchant);
  44. JSONObject title = new JSONObject();
  45. String jsonBody = JSONObject.toJSONString(merchant);
  46. title.put("type","state");
  47. title.put("desc","更新商户状态");
  48. title.put("content",jsonBody);
  49. rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
  50. return k;
  51. }
  52. @Override
  53. public int update(Merchant merchant) {
  54. int k = merchantMapper.update(merchant);
  55. JSONObject title = new JSONObject();
  56. String jsonBody = JSONObject.toJSONString(merchant);
  57. title.put("type","update");
  58. title.put("desc","更新商户信息");
  59. title.put("content",jsonBody);
  60. rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
  61. return k;
  62. }
  63. @Override
  64. public int delete(Integer id) {
  65. int k = merchantMapper.delete(id);
  66. JSONObject title = new JSONObject();
  67. Merchant merchant = new Merchant();
  68. merchant.setId(id);
  69. String jsonBody = JSONObject.toJSONString(merchant);
  70. title.put("type","delete");
  71. title.put("desc","删除商户");
  72. title.put("content",jsonBody);
  73. rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
  74. return k;
  75. }
  76. @Override
  77. public int getMerchantCount() {
  78. return merchantMapper.getMerchantCount();
  79. }
  80. }