|
|
@@ -0,0 +1,133 @@
|
|
|
+package com.xunmei.core.notice.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.xunmei.common.core.domain.notice.CoreNoticeRule;
|
|
|
+import com.xunmei.common.core.domain.notice.CoreNoticeRuleItem;
|
|
|
+import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
+import com.xunmei.core.notice.dto.CoreNoticeRuleDto;
|
|
|
+import com.xunmei.core.notice.mapper.CoreNoticeRuleMapper;
|
|
|
+import com.xunmei.core.notice.service.ICoreNoticeRuleItemService;
|
|
|
+import com.xunmei.core.notice.service.ICoreNoticeRuleService;
|
|
|
+import com.xunmei.core.notice.vo.CoreNoticeRuleVo;
|
|
|
+import com.xunmei.core.notice.vo.SelectProductVo;
|
|
|
+import com.xunmei.core.notice.vo.SelectUserVo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 通知规则表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author xujie
|
|
|
+ * @since 2024-09-19
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CoreNoticeRuleServiceImpl extends ServiceImpl<CoreNoticeRuleMapper, CoreNoticeRule> implements ICoreNoticeRuleService {
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ICoreNoticeRuleItemService itemService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public TableDataInfo selectPage(CoreNoticeRuleDto dto) {
|
|
|
+ Page<CoreNoticeRuleVo> page = baseMapper.selectPageData(dto.getPageRequest(), dto);
|
|
|
+ return TableDataInfo.build(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SelectUserVo> selectUserList(CoreNoticeRuleDto dto) {
|
|
|
+ if (dto != null && dto.getOrgIds() != null && dto.getOrgIds().size() > 0) {
|
|
|
+ return baseMapper.selectUserList(dto.getOrgIds());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<SelectProductVo> selectProductTypeList() {
|
|
|
+ return baseMapper.selectProductTypeList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void saveOrUpdate(CoreNoticeRuleDto dto) {
|
|
|
+ CoreNoticeRule noticeRule = new CoreNoticeRule();
|
|
|
+ noticeRule.setName(dto.getName());
|
|
|
+ noticeRule.setRemark(dto.getRemark());
|
|
|
+ noticeRule.setEnable(dto.getEnable() ? 1 : 0);
|
|
|
+ noticeRule.setSendSms(dto.getSendSms() ? 1 : 0);
|
|
|
+
|
|
|
+ if (dto.getId() != null){
|
|
|
+ noticeRule.setId(dto.getId());
|
|
|
+ noticeRule.setUpdateTime(new Date());
|
|
|
+ super.updateById(noticeRule);
|
|
|
+
|
|
|
+ QueryWrapper<CoreNoticeRuleItem> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.lambda().eq(CoreNoticeRuleItem::getRuleId, dto.getId());
|
|
|
+ itemService.remove(wrapper);
|
|
|
+ //处理关联表数据
|
|
|
+ saveOrUpdateItem(dto, noticeRule.getId());
|
|
|
+ }else {
|
|
|
+ noticeRule.setId(IdWorker.getId());
|
|
|
+ noticeRule.setCreateTime(new Date());
|
|
|
+ super.save(noticeRule);
|
|
|
+ //处理关联表数据
|
|
|
+ saveOrUpdateItem(dto, noticeRule.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public void deleteNoticeRule(Serializable id) {
|
|
|
+ super.removeById(id);
|
|
|
+
|
|
|
+ QueryWrapper<CoreNoticeRuleItem> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.lambda().eq(CoreNoticeRuleItem::getRuleId, id);
|
|
|
+ itemService.remove(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveOrUpdateItem(CoreNoticeRuleDto dto, Long ruleId) {
|
|
|
+ ArrayList<CoreNoticeRuleItem> items = new ArrayList<>();
|
|
|
+ String userId = handStr(dto.getUserIds());
|
|
|
+ String roleId = handStr(dto.getRoleIds());
|
|
|
+ //String productType = handStr(dto.getProductTypes());
|
|
|
+
|
|
|
+ for (Long orgId : dto.getOrgIds()) {
|
|
|
+ for (String productType : dto.getProductTypes()) {
|
|
|
+ CoreNoticeRuleItem item = new CoreNoticeRuleItem();
|
|
|
+ item.setRuleId(ruleId);
|
|
|
+ item.setOrgId(orgId);
|
|
|
+ item.setUserIds(userId);
|
|
|
+ item.setRoleIds(roleId);
|
|
|
+ item.setAllRoleUser(0);
|
|
|
+ if (ObjectUtil.isEmpty(userId)){
|
|
|
+ item.setAllRoleUser(1);
|
|
|
+ }
|
|
|
+ item.setProductType(productType);
|
|
|
+ items.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ itemService.saveBatch(items);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String handStr(List<String> list){
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ sb.append(list.get(i));
|
|
|
+ if (i < list.size() - 1) {
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+}
|