123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- package cn.hhj.rabbitmq.service.impl;
- import cn.hhj.rabbitmq.entity.Merchant;
- import cn.hhj.rabbitmq.mapper.MerchantMapper;
- import cn.hhj.rabbitmq.service.MerchantService;
- import com.alibaba.fastjson.JSONObject;
- import org.springframework.amqp.core.AmqpTemplate;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import java.util.List;
- @Service
- public class MerchantServiceImpl implements MerchantService {
- @Value("${cn.hhj.rabbitmq.topicexchange}")
- private String topicExchange;
- @Value("${cn.hhj.rabbitmq.topicroutingkey1}")
- private String topicRoutingKey;
- @Autowired
- private MerchantMapper merchantMapper;
- @Autowired
- AmqpTemplate rabbitTemplate;
- @Override
- public List<Merchant> getMerchantList(String name, int page, int limit) {
- return merchantMapper.getMerchantList(name,page,limit);
- }
- @Override
- public Merchant getMerchantById(Integer id) {
- return merchantMapper.getMerchantById(id);
- }
- @Override
- public int add(Merchant merchant) {
- int k = merchantMapper.add(merchant);
- System.out.println("aaa : "+merchant.getId());
- JSONObject title = new JSONObject();
- String jsonBody = JSONObject.toJSONString(merchant);
- title.put("type","add");
- title.put("desc","新增商户");
- title.put("content",jsonBody);
- rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
- return k;
- }
- @Override
- public int updateState(Merchant merchant) {
- int k = merchantMapper.updateState(merchant);
- JSONObject title = new JSONObject();
- String jsonBody = JSONObject.toJSONString(merchant);
- title.put("type","state");
- title.put("desc","更新商户状态");
- title.put("content",jsonBody);
- rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
- return k;
- }
- @Override
- public int update(Merchant merchant) {
- int k = merchantMapper.update(merchant);
- JSONObject title = new JSONObject();
- String jsonBody = JSONObject.toJSONString(merchant);
- title.put("type","update");
- title.put("desc","更新商户信息");
- title.put("content",jsonBody);
- rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
- return k;
- }
- @Override
- public int delete(Integer id) {
- int k = merchantMapper.delete(id);
- JSONObject title = new JSONObject();
- Merchant merchant = new Merchant();
- merchant.setId(id);
- String jsonBody = JSONObject.toJSONString(merchant);
- title.put("type","delete");
- title.put("desc","删除商户");
- title.put("content",jsonBody);
- rabbitTemplate.convertAndSend(topicExchange,topicRoutingKey, title.toJSONString());
- return k;
- }
- @Override
- public int getMerchantCount() {
- return merchantMapper.getMerchantCount();
- }
- }
|