|
@@ -1,8 +1,35 @@
|
|
|
package com.diagbot.facade;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.diagbot.dto.KlRuleByIdDTO;
|
|
|
+import com.diagbot.dto.KlRuleByIdParDTO;
|
|
|
+import com.diagbot.dto.KlRuleByIdSubDTO;
|
|
|
+import com.diagbot.dto.KlRuleInfoDTO;
|
|
|
+import com.diagbot.entity.KlRule;
|
|
|
+import com.diagbot.entity.KlRuleBase;
|
|
|
+import com.diagbot.entity.KlRuleCondition;
|
|
|
+import com.diagbot.enums.IsDeleteEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
import com.diagbot.service.impl.KlRuleServiceImpl;
|
|
|
+import com.diagbot.util.BeanUtil;
|
|
|
+import com.diagbot.util.DateUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.StringUtil;
|
|
|
+import com.diagbot.vo.KlRuleByIdVO;
|
|
|
+import com.diagbot.vo.KlRuleInfoClearVO;
|
|
|
+import com.diagbot.vo.KlRuleInfoSaveSubVO;
|
|
|
+import com.diagbot.vo.KlRuleInfoSaveVO;
|
|
|
+import com.diagbot.vo.KlRuleInfoVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* @Description:
|
|
|
* @author: gaodm
|
|
@@ -10,4 +37,177 @@ import org.springframework.stereotype.Component;
|
|
|
*/
|
|
|
@Component
|
|
|
public class KlRuleFacade extends KlRuleServiceImpl {
|
|
|
+ @Autowired
|
|
|
+ KlRuleConditionFacade klRuleConditionFacade;
|
|
|
+ @Autowired
|
|
|
+ KlRuleBaseFacade klRuleBaseFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param klRuleInfoVO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public IPage<KlRuleInfoDTO> getKlRuleInfoPage(KlRuleInfoVO klRuleInfoVO) {
|
|
|
+ return this.getKlRuleInfoPages(klRuleInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ public KlRuleByIdParDTO getByIdRuleInfos(KlRuleByIdVO klRuleByIdVO) {
|
|
|
+ KlRuleByIdParDTO klRuleByIdPar = new KlRuleByIdParDTO();
|
|
|
+ List<KlRuleByIdSubDTO> klRuleByIdSubLsit = new ArrayList<>();
|
|
|
+ List<KlRuleByIdDTO> byIdRuleInfo = this.getByIdRuleInfo(klRuleByIdVO);
|
|
|
+ if (ListUtil.isNotEmpty(byIdRuleInfo)) {
|
|
|
+ klRuleByIdPar.setParId(byIdRuleInfo.get(0).getParId());
|
|
|
+ klRuleByIdPar.setParDescription(byIdRuleInfo.get(0).getParDescription());
|
|
|
+ klRuleByIdPar.setParRuleType(byIdRuleInfo.get(0).getParRuleType());
|
|
|
+ klRuleByIdPar.setParConceptId(byIdRuleInfo.get(0).getParConceptId());
|
|
|
+ klRuleByIdPar.setParlibName(byIdRuleInfo.get(0).getParlibName());
|
|
|
+ klRuleByIdPar.setParHasSub(byIdRuleInfo.get(0).getParHasSub());//是否有子条件(0:无,1:有)
|
|
|
+ klRuleByIdPar.setParMsg(byIdRuleInfo.get(0).getParMsg());//附加信息
|
|
|
+ klRuleByIdPar.setParStatus(byIdRuleInfo.get(0).getParStatus());//启用状态(0:禁用,1:启用)
|
|
|
+ klRuleByIdPar.setParLenName(byIdRuleInfo.get(0).getParLenName());
|
|
|
+ klRuleByIdPar.setParLenCode(byIdRuleInfo.get(0).getParLenCode());
|
|
|
+ for (KlRuleByIdDTO data : byIdRuleInfo) {
|
|
|
+ if (null != data.getSubDescription()) {
|
|
|
+ KlRuleByIdSubDTO klRuleByIdSub = new KlRuleByIdSubDTO();
|
|
|
+ BeanUtil.copyProperties(data, klRuleByIdSub);
|
|
|
+ klRuleByIdSubLsit.add(klRuleByIdSub);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ klRuleByIdPar.setKlRuleByIdSub(klRuleByIdSubLsit);
|
|
|
+ return klRuleByIdPar;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Boolean saveRuleInfos(KlRuleInfoSaveVO klRuleInfoSaveVO) {
|
|
|
+ Date now = DateUtil.now();
|
|
|
+ boolean res = false;
|
|
|
+ // 校验名称是否相同
|
|
|
+ int count = this.count(new QueryWrapper<KlRule>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("description", klRuleInfoSaveVO.getParDescription())
|
|
|
+ .ne("id", klRuleInfoSaveVO.getId() == null ? -1 : klRuleInfoSaveVO.getId()));
|
|
|
+ if (count > 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该规则名称已存在");
|
|
|
+ }
|
|
|
+ //校验数据是否还在
|
|
|
+ if (null != klRuleInfoSaveVO.getId()) {
|
|
|
+ int sum = this.count(new QueryWrapper<KlRule>().eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", klRuleInfoSaveVO.getId()));
|
|
|
+ if (sum == 0) {
|
|
|
+ throw new CommonException(CommonErrorCode.SERVER_IS_ERROR, "该数据已不存在!");
|
|
|
+ }
|
|
|
+ UpdateWrapper<KlRule> klRuleUpdate = new UpdateWrapper<>();
|
|
|
+ klRuleUpdate.eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("id", klRuleInfoSaveVO.getId())
|
|
|
+ .set(StringUtil.isNotBlank(klRuleInfoSaveVO.getParDescription()), "description", klRuleInfoSaveVO.getParDescription())
|
|
|
+ .set(StringUtil.isNotBlank(klRuleInfoSaveVO.getParConceptId().toString()), "concept_id", klRuleInfoSaveVO.getParConceptId())
|
|
|
+ .set(StringUtil.isNotBlank(klRuleInfoSaveVO.getParRuleType().toString()), "rule_type", klRuleInfoSaveVO.getParRuleType())
|
|
|
+ .set(StringUtil.isNotBlank(klRuleInfoSaveVO.getParHasSub().toString()), "has_sub_cond", klRuleInfoSaveVO.getParHasSub())
|
|
|
+ .set(StringUtil.isNotBlank(klRuleInfoSaveVO.getParStatus().toString()), "status", klRuleInfoSaveVO.getParStatus())
|
|
|
+ .set(StringUtil.isNotBlank(klRuleInfoSaveVO.getParMsg()), "msg", klRuleInfoSaveVO.getParMsg())
|
|
|
+ .set("gmt_modified", now);
|
|
|
+ res = this.update(klRuleUpdate);
|
|
|
+
|
|
|
+ //先删除原有的详情;
|
|
|
+ res = clearSub(klRuleInfoSaveVO.getId());
|
|
|
+ if (ListUtil.isNotEmpty(klRuleInfoSaveVO.getKlRuleInfoSaveSub())) {
|
|
|
+ //再重新传入的详情保存
|
|
|
+ res = saveCommon(klRuleInfoSaveVO);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //先保存主表rule
|
|
|
+ KlRule klRule = new KlRule();
|
|
|
+ klRule.setConceptId(klRuleInfoSaveVO.getParConceptId());
|
|
|
+ klRule.setDescription(klRuleInfoSaveVO.getParDescription());
|
|
|
+ klRule.setHasSubCond(klRuleInfoSaveVO.getParHasSub());
|
|
|
+ klRule.setRuleType(klRuleInfoSaveVO.getParRuleType());
|
|
|
+ klRule.setMsg(klRuleInfoSaveVO.getParMsg());
|
|
|
+ klRule.setStatus(klRuleInfoSaveVO.getParStatus());
|
|
|
+ klRule.setGmtCreate(now);
|
|
|
+ res = this.save(klRule);
|
|
|
+ if (res) {
|
|
|
+ //再保存附表
|
|
|
+ klRuleInfoSaveVO.setId(klRule.getId());
|
|
|
+ res = saveCommon(klRuleInfoSaveVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Boolean clearRuleInfos(KlRuleInfoClearVO klRuleInfoClearVO) {
|
|
|
+ boolean res = false;
|
|
|
+ res = clearSub(klRuleInfoClearVO.getId());
|
|
|
+ //最后删除主表rule
|
|
|
+ res = this.removeById(klRuleInfoClearVO.getId());
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除明细表
|
|
|
+ */
|
|
|
+ public boolean clearSub(Long id) {
|
|
|
+ boolean res = false;
|
|
|
+ QueryWrapper<KlRuleCondition> klRuleConditionQuery = new QueryWrapper<>();
|
|
|
+ klRuleConditionQuery.eq("is_deleted", IsDeleteEnum.N.getKey()).eq("rule_id", id);
|
|
|
+ List<KlRuleCondition> ruleConditionList = klRuleConditionFacade.list(klRuleConditionQuery);
|
|
|
+ List<Long> ruleBaseId = new ArrayList<>();
|
|
|
+ if (ListUtil.isNotEmpty(ruleConditionList)) {
|
|
|
+ for (KlRuleCondition data : ruleConditionList) {
|
|
|
+ ruleBaseId.add(data.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(ruleBaseId)) {
|
|
|
+ QueryWrapper<KlRuleBase> klRuleBaseQuery = new QueryWrapper<>();
|
|
|
+ klRuleBaseQuery.eq("is_deleted", IsDeleteEnum.N.getKey()).in("id", ruleBaseId);
|
|
|
+ //删除kl_rule_base表数据
|
|
|
+ res = klRuleBaseFacade.remove(klRuleBaseQuery);
|
|
|
+
|
|
|
+ }
|
|
|
+ //删除kl_rule_condition表的数据
|
|
|
+ res = klRuleConditionFacade.remove(klRuleConditionQuery);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存数据
|
|
|
+ */
|
|
|
+ public boolean saveCommon(KlRuleInfoSaveVO klRuleInfoSaveVO) {
|
|
|
+ boolean res = false;
|
|
|
+ List<KlRuleInfoSaveSubVO> klRuleInfoSaveSub = klRuleInfoSaveVO.getKlRuleInfoSaveSub();
|
|
|
+ //先保存数据到kl_rule_base表里
|
|
|
+ List<KlRuleBase> klRuleBaseList = new ArrayList<>();
|
|
|
+ for (KlRuleInfoSaveSubVO list : klRuleInfoSaveSub) {
|
|
|
+ KlRuleBase klRuleBase = new KlRuleBase();
|
|
|
+ klRuleBase.setConceptId(list.getSubConceptId());
|
|
|
+ klRuleBase.setType(list.getSubType());
|
|
|
+ klRuleBase.setDescription(list.getSubDescription());
|
|
|
+ klRuleBase.setMaxOperator(list.getSubMaxOperator());
|
|
|
+ klRuleBase.setMaxValue(list.getSubMaxValue());
|
|
|
+ klRuleBase.setMaxUnit(list.getSubMaxUnit());
|
|
|
+ klRuleBase.setMinOperator(list.getSubMinOperator());
|
|
|
+ klRuleBase.setMinValue(list.getSubMinValue());
|
|
|
+ klRuleBase.setMinUnit(list.getSubMinUnit());
|
|
|
+ klRuleBase.setStatus(1);
|
|
|
+ klRuleBase.setEqValue(list.getSubEqValue());
|
|
|
+ klRuleBase.setEqOperator(list.getSubEqOperator());
|
|
|
+ klRuleBase.setEqUnit(list.getSubEqUnit());
|
|
|
+ klRuleBaseList.add(klRuleBase);
|
|
|
+ }
|
|
|
+ res = klRuleBaseFacade.saveBatchAll(klRuleBaseList);
|
|
|
+ List<KlRuleCondition> klRuleConditionList = new ArrayList<>();
|
|
|
+ for (KlRuleBase data1 : klRuleBaseList) {
|
|
|
+ for (KlRuleInfoSaveSubVO data2 : klRuleInfoSaveSub) {
|
|
|
+ KlRuleCondition klRuleCondition = new KlRuleCondition();
|
|
|
+ if (data1.getDescription().equals(data2.getSubDescription())) {
|
|
|
+ klRuleCondition.setGroupType(data2.getGroupType());
|
|
|
+ klRuleCondition.setRuleBaseId(data1.getId());
|
|
|
+ klRuleCondition.setRuleId(klRuleInfoSaveVO.getId());
|
|
|
+ klRuleConditionList.add(klRuleCondition);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res = klRuleConditionFacade.saveBatchAll(klRuleConditionList);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|