|
@@ -0,0 +1,110 @@
|
|
|
+package com.fjhx.common.service.coding.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fjhx.common.entity.coding.dto.CodingRuleDto;
|
|
|
+import com.fjhx.common.entity.coding.dto.CodingRuleSelectDto;
|
|
|
+import com.fjhx.common.entity.coding.dto.RuleVo;
|
|
|
+import com.fjhx.common.entity.coding.po.CodingRule;
|
|
|
+import com.fjhx.common.entity.coding.vo.CodingRulePageVo;
|
|
|
+import com.fjhx.common.enums.CodingRuleEnum;
|
|
|
+import com.fjhx.common.mapper.coding.CodingRuleMapper;
|
|
|
+import com.fjhx.common.service.coding.CodingRuleService;
|
|
|
+import com.ruoyi.system.utils.UserUtil;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 编码规则 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2023-04-13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CodingRuleServiceImpl extends ServiceImpl<CodingRuleMapper, CodingRule> implements CodingRuleService {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<CodingRulePageVo> getPage(CodingRuleSelectDto dto) {
|
|
|
+
|
|
|
+ Integer pageNum = dto.getPageNum();
|
|
|
+ Integer pageSize = dto.getPageSize();
|
|
|
+
|
|
|
+ int startIndex = (pageNum - 1) * pageSize;
|
|
|
+ int endIndex = pageNum * pageSize;
|
|
|
+
|
|
|
+ int tempIndex = 0;
|
|
|
+
|
|
|
+ List<CodingRulePageVo> codingRulePageVoList = new ArrayList<>();
|
|
|
+ List<String> keyList = new ArrayList<>();
|
|
|
+
|
|
|
+ for (CodingRuleEnum codingRuleEnum : CodingRuleEnum.values()) {
|
|
|
+ if (StrUtil.isNotBlank(dto.getKeyword())) {
|
|
|
+
|
|
|
+ if (codingRuleEnum.getName().contains(dto.getKeyword())) {
|
|
|
+ tempIndex = getTempIndex(startIndex, endIndex, tempIndex, codingRulePageVoList, keyList, codingRuleEnum);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ tempIndex = getTempIndex(startIndex, endIndex, tempIndex, codingRulePageVoList, keyList, codingRuleEnum);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<CodingRulePageVo> page = dto.getPage();
|
|
|
+ page.setRecords(codingRulePageVoList);
|
|
|
+ page.setTotal(tempIndex);
|
|
|
+
|
|
|
+ if (keyList.size() == 0) {
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, CodingRule> kEntity = mapKEntity(CodingRule::getCodingKey, q -> q.in(CodingRule::getCodingKey, keyList));
|
|
|
+
|
|
|
+ for (CodingRulePageVo codingRulePageVo : codingRulePageVoList) {
|
|
|
+ CodingRule codingRule = kEntity.get(codingRulePageVo.getCodingKey());
|
|
|
+ if (codingRule == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ codingRulePageVo.setId(codingRule.getId());
|
|
|
+ codingRulePageVo.setRuleVoList(JSON.parseArray(codingRule.getRuleJson(), RuleVo.class));
|
|
|
+ codingRulePageVo.setUpdateTime(codingRule.getUpdateTime());
|
|
|
+ codingRulePageVo.setUpdateUser(codingRule.getUpdateUser());
|
|
|
+ }
|
|
|
+
|
|
|
+ UserUtil.assignmentNickName(codingRulePageVoList, CodingRulePageVo::getUpdateUser, CodingRulePageVo::setUpdateUserName);
|
|
|
+
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void edit(CodingRuleDto codingRuleDto) {
|
|
|
+ codingRuleDto.setRuleJson(JSON.toJSONString(codingRuleDto.getRuleVoList()));
|
|
|
+ this.saveOrUpdate(codingRuleDto);
|
|
|
+ }
|
|
|
+
|
|
|
+ private int getTempIndex(int startIndex, int endIndex, int tempIndex,
|
|
|
+ List<CodingRulePageVo> codingRulePageVoList,
|
|
|
+ List<String> keyList,
|
|
|
+ CodingRuleEnum codingRuleEnum) {
|
|
|
+
|
|
|
+ if (tempIndex >= startIndex && tempIndex < endIndex) {
|
|
|
+ CodingRulePageVo codingRulePageVo = new CodingRulePageVo();
|
|
|
+ codingRulePageVo.setCodingKey(codingRuleEnum.getKey());
|
|
|
+ codingRulePageVo.setCodingName(codingRuleEnum.getName());
|
|
|
+ codingRulePageVo.setRuleVoList(codingRuleEnum.getDefaultRuleVoList());
|
|
|
+ codingRulePageVoList.add(codingRulePageVo);
|
|
|
+ keyList.add(codingRuleEnum.getKey());
|
|
|
+ }
|
|
|
+
|
|
|
+ return ++tempIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|