From 62a447d89331aee1feae7724c7616aa1bb2cfe79 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期三, 16 十月 2024 14:28:37 +0800 Subject: [PATCH] 将CMQ替换为rabbitmq --- fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialLabelImpl.java | 244 ++++++++++++++++++++++++++---------------------- 1 files changed, 134 insertions(+), 110 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialLabelImpl.java b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialLabelImpl.java index fcbffed..3a25b79 100644 --- a/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialLabelImpl.java +++ b/fanli/src/main/java/com/yeshi/fanli/service/impl/homemodule/SpecialLabelImpl.java @@ -1,110 +1,134 @@ -package com.yeshi.fanli.service.impl.homemodule; - -import java.util.Date; -import java.util.List; - -import javax.annotation.Resource; - -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import com.yeshi.fanli.dao.mybatis.homemodule.SpecialLabelMapMapper; -import com.yeshi.fanli.dao.mybatis.homemodule.SpecialLabelMapper; -import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel; -import com.yeshi.fanli.entity.bus.homemodule.SpecialLabelMap; -import com.yeshi.fanli.exception.homemodule.SpecialLabelException; -import com.yeshi.fanli.service.inter.homemodule.SpecialLabelService; -import com.yeshi.fanli.util.StringUtil; - -@Service -public class SpecialLabelImpl implements SpecialLabelService { - - @Resource - private SpecialLabelMapper specialLabelMapper; - - @Resource - private SpecialLabelMapMapper specialLabelMapMapper; - - - @Override - public void save(SpecialLabel record) throws SpecialLabelException{ - String name = record.getName(); - if (StringUtil.isNullOrEmpty(name)) - throw new SpecialLabelException(1, "鍚嶇О涓嶈兘涓虹┖"); - - String bgColor = record.getBgColor(); - if (StringUtil.isNullOrEmpty(bgColor)) - throw new SpecialLabelException(1, "鑳屾櫙鑹蹭笉鑳戒负绌�"); - - if (record.getState() == null) - record.setState(0); - - record.setUpdateTime(new Date()); - - Long id = record.getId(); - if (id == null) { - record.setCreateTime(new Date()); - specialLabelMapper.insert(record); - } else { - SpecialLabel resultObj = specialLabelMapper.selectByPrimaryKey(id); - if (resultObj == null) - throw new SpecialLabelException(1, "鎿嶄綔鍐呭宸蹭笉瀛樺湪"); - - record.setCreateTime(resultObj.getCreateTime()); - specialLabelMapper.updateByPrimaryKey(record); - } - } - - - @Override - public int deleteByPrimaryKeyBatch(List<Long> list){ - return specialLabelMapper.deleteByPrimaryKeyBatch(list); - } - - - - @Override - public List<SpecialLabel> listQuery(long start, int count, String key, Integer state) { - return specialLabelMapper.listQuery(start, count, key, state); - } - - - @Override - public long countQuery(String key, Integer state) { - return specialLabelMapper.countQuery(key, state); - } - - @Override - public List<SpecialLabel> getLabelsBySpecialId(Long specialId) { - return specialLabelMapper.getLabelsBySpecialId(specialId); - } - - - @Override - @Transactional(rollbackFor= Exception.class) - public void stickLabelOnSpecial(List<Long> idList, List<Long> labIdList) { - if (idList == null || idList.isEmpty()) - return; - - // 娓呯┖鏍囩 - specialLabelMapMapper.deleteBySpecialIds(idList); - - if (labIdList == null || labIdList.isEmpty()) { - return; - } - - // 鏂板鏍囩 - Date date = new Date(); - for (Long id:idList) { - for (Long labid:labIdList) { - SpecialLabelMap objectMap = new SpecialLabelMap(); - objectMap.setLabId(labid); - objectMap.setSpid(id); - objectMap.setCreateTime(date); - specialLabelMapMapper.insertSelective(objectMap); - } - } - } - -} - +package com.yeshi.fanli.service.impl.homemodule; + +import java.util.Date; +import java.util.List; + +import javax.annotation.Resource; + +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.yeshi.fanli.dao.mybatis.homemodule.SpecialLabelMapMapper; +import com.yeshi.fanli.dao.mybatis.homemodule.SpecialLabelMapper; +import com.yeshi.fanli.entity.bus.homemodule.SpecialLabel; +import com.yeshi.fanli.entity.bus.homemodule.SpecialLabelMap; +import com.yeshi.fanli.exception.homemodule.SpecialLabelException; +import com.yeshi.fanli.service.inter.homemodule.SpecialLabelService; +import com.yeshi.fanli.util.StringUtil; + +@Service +public class SpecialLabelImpl implements SpecialLabelService { + + @Resource + private SpecialLabelMapper specialLabelMapper; + + @Resource + private SpecialLabelMapMapper specialLabelMapMapper; + + + @Override + public void save(SpecialLabel record) throws SpecialLabelException{ + String name = record.getName(); + if (StringUtil.isNullOrEmpty(name)) + throw new SpecialLabelException(1, "鍚嶇О涓嶈兘涓虹┖"); + + String bgColor = record.getBgColor(); + if (StringUtil.isNullOrEmpty(bgColor)) + throw new SpecialLabelException(1, "鑳屾櫙鑹蹭笉鑳戒负绌�"); + + if (record.getState() == null) + record.setState(0); + + record.setUpdateTime(new Date()); + + Long id = record.getId(); + if (id == null) { + record.setCreateTime(new Date()); + specialLabelMapper.insert(record); + } else { + SpecialLabel resultObj = specialLabelMapper.selectByPrimaryKey(id); + if (resultObj == null) + throw new SpecialLabelException(1, "鎿嶄綔鍐呭宸蹭笉瀛樺湪"); + + record.setCreateTime(resultObj.getCreateTime()); + specialLabelMapper.updateByPrimaryKey(record); + } + } + + @Override + public void switchState(Long id) throws SpecialLabelException { + if (id == null) { + throw new SpecialLabelException(1, "璇蜂紶閫掓纭弬鏁�"); + } + + SpecialLabel resultObj = specialLabelMapper.selectByPrimaryKey(id); + if (resultObj == null) { + throw new SpecialLabelException(1, "姝ゅ唴瀹瑰凡涓嶅瓨鍦�"); + } + + Integer state = resultObj.getState(); + if (state == null || state == 0) { + state = 1; + } else { + state = 0; + } + + SpecialLabel updateObj = new SpecialLabel(); + updateObj.setId(id); + updateObj.setState(state); + specialLabelMapper.updateByPrimaryKeySelective(updateObj); + } + + + @Override + public int deleteByPrimaryKeyBatch(List<Long> list){ + return specialLabelMapper.deleteByPrimaryKeyBatch(list); + } + + + + @Override + public List<SpecialLabel> listQuery(long start, int count, String key, Integer state) { + return specialLabelMapper.listQuery(start, count, key, state); + } + + + @Override + public long countQuery(String key, Integer state) { + return specialLabelMapper.countQuery(key, state); + } + + @Override + public List<SpecialLabel> getLabelsBySpecialId(Long specialId) { + return specialLabelMapper.getLabelsBySpecialId(specialId); + } + + + @Override + @Transactional(rollbackFor= Exception.class) + public void stickLabelOnSpecial(List<Long> idList, List<Long> labIdList) { + if (idList == null || idList.isEmpty()) + return; + + // 娓呯┖鏍囩 + specialLabelMapMapper.deleteBySpecialIds(idList); + + if (labIdList == null || labIdList.isEmpty()) { + return; + } + + // 鏂板鏍囩 + Date date = new Date(); + for (Long id:idList) { + for (Long labid:labIdList) { + SpecialLabelMap objectMap = new SpecialLabelMap(); + objectMap.setLabId(labid); + objectMap.setSpid(id); + objectMap.setCreateTime(date); + specialLabelMapMapper.insertSelective(objectMap); + } + } + } + +} + -- Gitblit v1.8.0