Преглед изворни кода

refactor(util): 将业务相关的工具移出util,util只包含业务不相关的通用工具

vian пре 4 година
родитељ
комит
8816f0d44c
6 измењених фајлова са 7 додато и 229 уклоњено
  1. 5 0
      util/README.md
  2. 2 2
      util/package.json
  3. 0 82
      util/src/bill.ts
  4. 0 27
      util/src/glj.ts
  5. 0 3
      util/src/index.ts
  6. 0 115
      util/src/rationAss.ts

+ 5 - 0
util/README.md

@@ -1,7 +1,12 @@
 ### 开始
+所有项目通用的工具包
 
+## math
 统一 4 舍 5 入算法,防止浮点数计算不精确问题。
 
+## reg
+常用的正则表达式
+
 ### 初始化
 
 npm install

+ 2 - 2
util/package.json

@@ -1,7 +1,7 @@
 {
   "name": "@sc/util",
-  "version": "1.0.6",
-  "description": "用的工具包",
+  "version": "1.0.7",
+  "description": "用的工具包",
   "main": "./dist/index.cjs.js",
   "module": "./dist/index.esm.js",
   "browser": "./dist/index.min.js",

+ 0 - 82
util/src/bill.ts

@@ -1,82 +0,0 @@
-import { IJobContent, IItemCharacter, IStdBill, IStdJobContent, IStdItemCharacter } from '@sc/types';
-
-interface IJobsAndCharacterText {
-  jobContentText: string;
-  itemCharacterText: string;
-}
-
-interface IJobContentMap {
-  [id: string]: IStdJobContent;
-}
-interface IItemCharacterMap {
-  [id: string]: IStdItemCharacter;
-}
-
-export interface IJobAndCharacter extends IJobsAndCharacterText {
-  jobContents: IJobContent[];
-  itemCharacters: IItemCharacter[];
-}
-
-export const getJobsAndCharacterText = (
-  jobContents: IJobContent[],
-  itemCharacters: IItemCharacter[]
-): IJobsAndCharacterText => {
-  const jobContentText = '';
-  let itemCharacterText = '';
-  jobContents.sort((a, b) => a.seq - b.seq);
-  itemCharacters.sort((a, b) => a.seq - b.seq);
-  const textArray: string[] = ['[项目特征]'];
-  let i = 1;
-  for (const item of itemCharacters) {
-    if (item.isChecked) textArray.push(`${i}. ${item.character || ''}: ${item.eigenvalue || ''}`);
-    i += 1;
-  }
-
-  textArray.push('[工作内容]');
-  i = 1;
-  for (const job of jobContents) {
-    if (job.isChecked) textArray.push(`${i}. ${job.content || ''}`);
-    i += 1;
-  }
-  itemCharacterText = textArray.join('\n');
-  return { jobContentText, itemCharacterText };
-};
-
-export const getJobContents = (stdBill: IStdBill, stdJobContentMap: IJobContentMap): IJobContent[] => {
-  const jobs: IJobContent[] = [];
-  let i = 1;
-  for (const j of stdBill.jobs) {
-    const job = stdJobContentMap[j.id];
-    if (job) {
-      jobs.push({ seq: i + 1, content: job.content, isChecked: true });
-      i += 1;
-    }
-  }
-
-  return jobs;
-};
-
-export const getItemCharacters = (stdBill: IStdBill, itemCharacterMap: IItemCharacterMap): IItemCharacter[] => {
-  const characters: IItemCharacter[] = [];
-  let i = 1;
-  for (const item of stdBill.items) {
-    const character = itemCharacterMap[item.id];
-    if (character) {
-      const newItem: IItemCharacter = {
-        seq: i + 1,
-        character: character.content,
-        eigenvalueList: [],
-        eigenvalue: '',
-        isChecked: false,
-      };
-      const eigenvalues = character.itemValue;
-      for (let j = 0; j < eigenvalues.length; j += 1) {
-        newItem.eigenvalueList.push(eigenvalues[j].value);
-      }
-      characters.push(newItem);
-      i += 1;
-    }
-  }
-
-  return characters;
-};

+ 0 - 27
util/src/glj.ts

@@ -1,27 +0,0 @@
-import { IBaseGlj, IInfoPriceItem, TaxType } from '@sc/types';
-
-export const getInfoMarketPrice = (info: IInfoPriceItem, taxType: TaxType) => {
-  // 1: 一般计税 2: 简易计税
-  const fieldArray = ['noTaxPrice']; // 一般计税 - 不含税价 || 简易计税 - 含税价
-  if (taxType === TaxType.GENERAL) {
-    fieldArray.push('taxPrice');
-  } else {
-    fieldArray.unshift('taxPrice');
-  }
-  // 一个放后面,一个放前面
-  let infoPrice = (info as any)[fieldArray[0]];
-  if (infoPrice === null || infoPrice === undefined) infoPrice = (info as any)[fieldArray[1]]; // 信息价只有一个价格(含税价/不含税价),则不分计税方式,套用仅有的价格。
-  return parseFloat(infoPrice);
-};
-
-// 返回五大项组成的索引
-export const getIndex = (obj: IBaseGlj, pops = ['code', 'name', 'specs', 'unit', 'type']): string => {
-  let index = '';
-  const arr = [];
-  for (const p of pops) {
-    const tmpK = obj[p] === undefined || obj[p] === null || obj[p] === '' ? 'null' : obj[p];
-    arr.push(tmpK);
-  }
-  index = arr.join('|-|');
-  return index;
-};

+ 0 - 3
util/src/index.ts

@@ -1,5 +1,2 @@
 export * from './math';
-export * from './bill';
-export * from './rationAss';
 export * from './reg';
-export * from './glj';

+ 0 - 115
util/src/rationAss.ts

@@ -1,115 +0,0 @@
-import { IRationAss, IThirdRation } from '@sc/types';
-import { ceil, floor, round, sortBy } from 'lodash';
-import { roundForObj } from './math';
-
-export interface IAssTime {
-  times: number;
-  ass: IRationAss | IThirdRation;
-}
-
-export interface IStateList {
-  index: number;
-  content: string;
-  addCode?: string; // 添加工料机的编号,用来标记,如果是子目换算中的单个人材机生成的,改成 调:...
-}
-
-export const stateSeq = {
-  ass: 1,
-  replace: 2,
-  coe: 3,
-  add: 4,
-  cusQuantity: 5,
-  cusCoe: 6,
-  area: 7,
-  adjMak: 8,
-};
-// 处理多个辅助定额的情况
-export const handleMulAss = (rationAssList: IRationAss[]) => {
-  const assList = [];
-  for (const ass of rationAssList) {
-    // 处理多个辅助定额的情况
-    if (ass.groupList && ass.groupList.length > 0) {
-      const newAss = { ...ass };
-      const newList = sortBy(ass.groupList, item => parseFloat(item.param)); // 按参数排序
-      let pre = 0;
-      for (const tem of newList) {
-        if (ass.actualValue) {
-          if (ass.actualValue > pre && ass.actualValue <= parseFloat(tem.param)) {
-            // 落在中间,则用组里的这条定额
-            newAss.param = tem.param;
-            newAss.paramName = tem.paramName;
-            newAss.assistCode = tem.assistCode;
-            break;
-          }
-          pre = parseFloat(tem.param);
-        }
-      }
-      assList.push(newAss);
-    } else {
-      assList.push(ass);
-    }
-  }
-  return assList;
-};
-
-export const calcAssTime = (ass: IRationAss) => {
-  if (ass.isAdjust === false) return undefined;
-  const actualValue = ass.actualValue ? ass.actualValue : 0;
-  const stdValue = ass.stdValue ? parseInt(ass.stdValue, 10) : 0;
-  const stepValue = ass.stepValue ? parseInt(ass.stepValue, 10) : 1;
-  let times = (actualValue - stdValue) / stepValue;
-  let r = false; // 是否负数
-  if (times < 0) {
-    r = true;
-    times *= -1;
-  }
-
-  if (ass.carryBit === '四舍五入') {
-    times = round(times, ass.decimal);
-  } else if (ass.carryBit === '进一') {
-    times = ceil(times, ass.decimal);
-  } else if (ass.carryBit === '舍一') {
-    times = floor(times, ass.decimal);
-  }
-  if (r) {
-    times *= -1;
-  }
-  return roundForObj(times, 6);
-};
-
-export const calcRationAssTimes = (
-  rationAssList?: IRationAss[],
-  thirdRation?: IThirdRation,
-  stateList?: IStateList[]
-) => {
-  const timeList: IAssTime[] = [];
-  if (rationAssList) {
-    const assList = handleMulAss(rationAssList);
-    const temTimes = [];
-    const thirdRationCodes = [];
-    for (const rationAss of assList) {
-      const times = calcAssTime(rationAss);
-      if (times) {
-        const { thirdRationCode } = rationAss;
-        if (thirdRationCode) {
-          temTimes.push(times);
-          thirdRationCodes.push(thirdRationCode);
-        }
-        timeList.push({ times, ass: rationAss });
-        if (stateList)
-          stateList.push({
-            index: stateSeq.ass,
-            content: `${rationAss.name} ${rationAss.actualValue} : ${rationAss.assistCode}x${times}`,
-          });
-      }
-    }
-    if (thirdRation && temTimes.length === 2 && thirdRationCodes[0] === thirdRationCodes[1]) {
-      // 说明有第三定额
-      const timesT = temTimes[0] * temTimes[1];
-      timeList.push({ times: timesT, ass: thirdRation });
-      if (stateList) stateList.push({ index: stateSeq.ass, content: `+${thirdRationCodes[0]}x${timesT}` });
-    }
-  }
-
-  return timeList;
-};