|
@@ -0,0 +1,109 @@
|
|
|
|
+package com.diagbot.facade;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
+import com.diagbot.client.UserServiceClient;
|
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
|
+import com.diagbot.dto.RuleAppDTO;
|
|
|
|
+import com.diagbot.entity.RuleApp;
|
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
|
+import com.diagbot.enums.RuleAppTypeEnum;
|
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
|
+import com.diagbot.service.impl.RuleAppServiceImpl;
|
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
|
+import com.diagbot.util.IntegerUtil;
|
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
|
+import com.diagbot.util.UserUtils;
|
|
|
|
+import com.diagbot.vo.RuleAppIdVO;
|
|
|
|
+import com.diagbot.vo.RuleAppPageVO;
|
|
|
|
+import com.diagbot.vo.RuleAppSaveVO;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @Description:
|
|
|
|
+ * @author: gaodm
|
|
|
|
+ * @time: 2020/1/30 15:44
|
|
|
|
+ */
|
|
|
|
+@Component
|
|
|
|
+public class RuleAppFacade extends RuleAppServiceImpl {
|
|
|
|
+ @Autowired
|
|
|
|
+ private UserServiceClient userServiceClient;
|
|
|
|
+
|
|
|
|
+ public IPage<RuleAppDTO> pageRuleApp(RuleAppPageVO ruleAppPageVO) {
|
|
|
|
+ IPage<RuleAppDTO> res = new Page<>(ruleAppPageVO.getCurrent(), ruleAppPageVO.getSize());
|
|
|
|
+ QueryWrapper<RuleApp> ruleAppQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ ruleAppQueryWrapper.like(StringUtil.isNotBlank(ruleAppPageVO.getRuleId()), "rule_id", ruleAppPageVO.getRuleId())
|
|
|
|
+ .like(StringUtil.isNotBlank(ruleAppPageVO.getRemind()), "remind", ruleAppPageVO.getRemind())
|
|
|
|
+ .eq(StringUtil.isNotBlank(ruleAppPageVO.getTypeId()), "type_id", ruleAppPageVO.getTypeId())
|
|
|
|
+ .orderByDesc("gmt_modified", "id");
|
|
|
|
+ IPage<RuleApp> page = this.page(ruleAppPageVO, ruleAppQueryWrapper);
|
|
|
|
+ BeanUtil.copyProperties(page, res);
|
|
|
|
+ if (ListUtil.isNotEmpty(page.getRecords())) {
|
|
|
|
+ List<String> userIds = page.getRecords().stream()
|
|
|
|
+ .map(i -> i.getModifier()).distinct().collect(Collectors.toList());
|
|
|
|
+ RespDTO<Map<String, String>> respDTO = userServiceClient.getUserInfoByIds(userIds);
|
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "获取用户信息失败");
|
|
|
|
+ List<RuleAppDTO> ruleAppDTOList = ListUtil.newArrayList();
|
|
|
|
+ for (RuleApp ruleApp : page.getRecords()) {
|
|
|
|
+ RuleAppDTO ruleAppDTO = new RuleAppDTO();
|
|
|
|
+ BeanUtil.copyProperties(ruleApp, ruleAppDTO);
|
|
|
|
+ ruleAppDTO.setOperName(respDTO.data.get(ruleApp.getModifier()));
|
|
|
|
+ ruleAppDTO.setTypeIdName(RuleAppTypeEnum.getName(Integer.valueOf(ruleApp.getTypeId())));
|
|
|
|
+ ruleAppDTOList.add(ruleAppDTO);
|
|
|
|
+ }
|
|
|
|
+ res.setRecords(ruleAppDTOList);
|
|
|
|
+ }
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Boolean removeRuleApp(RuleAppIdVO ruleAppIdVO) {
|
|
|
|
+ return this.removeById(ruleAppIdVO.getId());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public RuleAppDTO getRuleApp(RuleAppIdVO ruleAppIdVO) {
|
|
|
|
+ RuleApp ruleApp = this.getById(ruleAppIdVO.getId());
|
|
|
|
+ RuleAppDTO ruleAppDTO = new RuleAppDTO();
|
|
|
|
+ BeanUtil.copyProperties(ruleApp, ruleAppDTO);
|
|
|
|
+ return ruleAppDTO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Boolean saveRuleApp(@Valid @RequestBody RuleAppSaveVO ruleAppSaveVO) {
|
|
|
|
+ if (null == ruleAppSaveVO) {
|
|
|
|
+ throw new CommonException(CommonErrorCode.PARAM_IS_NULL);
|
|
|
|
+ }
|
|
|
|
+ RuleApp ruleApp = new RuleApp();
|
|
|
|
+ BeanUtil.copyProperties(ruleAppSaveVO, ruleApp);
|
|
|
|
+ String userId = UserUtils.getCurrentPrincipleID();
|
|
|
|
+ Date date = DateUtil.now();
|
|
|
|
+ ruleApp.setModifier(userId);
|
|
|
|
+ ruleApp.setGmtModified(date);
|
|
|
|
+ //查询id 是否存在
|
|
|
|
+ if (!IntegerUtil.isNull(ruleAppSaveVO.getId())) {
|
|
|
|
+ QueryWrapper<RuleApp> ruleAppQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ ruleAppQueryWrapper.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
|
+ .eq("id", ruleAppSaveVO.getId());
|
|
|
|
+ if (this.count(ruleAppQueryWrapper) < 1) {
|
|
|
|
+ ruleApp.setCreator(userId);
|
|
|
|
+ ruleApp.setGmtCreate(date);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ ruleApp.setCreator(userId);
|
|
|
|
+ ruleApp.setGmtCreate(date);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return this.saveOrUpdate(ruleApp);
|
|
|
|
+ }
|
|
|
|
+}
|