|
|
@@ -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;
|
|
|
-};
|