rationAss.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import { IRationAss, IThirdRation } from '@sc/types';
  2. import { ceil, floor, round, sortBy } from 'lodash';
  3. import { roundForObj } from '@sc/util';
  4. export interface IAssTime {
  5. times: number;
  6. ass: IRationAss | IThirdRation;
  7. }
  8. export interface IStateList {
  9. index: number;
  10. content: string;
  11. addCode?: string; // 添加工料机的编号,用来标记,如果是子目换算中的单个人材机生成的,改成 调:...
  12. }
  13. export const stateSeq = {
  14. ass: 1,
  15. proportion: 2,
  16. replace: 3,
  17. coe: 4,
  18. add: 5,
  19. cusQuantity: 6,
  20. cusCoe: 7,
  21. area: 8,
  22. adjMak: 9,
  23. };
  24. // 处理多个辅助定额的情况
  25. export const handleMulAss = (rationAssList: IRationAss[]) => {
  26. const assList = [];
  27. for (const ass of rationAssList) {
  28. // 处理多个辅助定额的情况
  29. if (ass.groupList && ass.groupList.length > 0) {
  30. const newAss = { ...ass };
  31. const newList = sortBy(ass.groupList, item => parseFloat(item.param || '0')); // 按参数排序
  32. let pre = 0;
  33. for (const tem of newList) {
  34. if (ass.actualValue) {
  35. if (ass.actualValue > pre && ass.actualValue <= parseFloat(tem.param || '0')) {
  36. // 落在中间,则用组里的这条定额
  37. newAss.param = tem.param;
  38. newAss.paramName = tem.paramName;
  39. newAss.assistCode = tem.assistCode;
  40. break;
  41. }
  42. pre = parseFloat(tem.param || '0');
  43. }
  44. }
  45. assList.push(newAss);
  46. } else {
  47. assList.push(ass);
  48. }
  49. }
  50. return assList;
  51. };
  52. export const calcAssTime = (ass: IRationAss) => {
  53. if (ass.isAdjust === false) return undefined;
  54. const actualValue = ass.actualValue ? ass.actualValue : 0;
  55. const stdValue = ass.stdValue ? parseFloat(ass.stdValue) : 0;
  56. const stepValue = ass.stepValue ? parseFloat(ass.stepValue) : 1;
  57. let times = (actualValue - stdValue) / stepValue;
  58. let r = false; // 是否负数
  59. if (times < 0) {
  60. r = true;
  61. times *= -1;
  62. }
  63. if (ass.carryBit === '四舍五入') {
  64. times = round(times, ass.decimal);
  65. } else if (ass.carryBit === '进一') {
  66. times = ceil(times, ass.decimal);
  67. } else if (ass.carryBit === '舍一') {
  68. times = floor(times, ass.decimal);
  69. }
  70. if (r) {
  71. times *= -1;
  72. }
  73. return roundForObj(times, 6);
  74. };
  75. export const calcRationAssTimes = (
  76. rationAssList?: IRationAss[],
  77. thirdRation?: IThirdRation,
  78. stateList?: IStateList[]
  79. ) => {
  80. const timeList: IAssTime[] = [];
  81. if (rationAssList) {
  82. const assList = handleMulAss(rationAssList);
  83. const temTimes = [];
  84. const thirdRationCodes = [];
  85. for (const rationAss of assList) {
  86. const times = calcAssTime(rationAss);
  87. if (times) {
  88. const { thirdRationCode } = rationAss;
  89. if (thirdRationCode) {
  90. temTimes.push(times);
  91. thirdRationCodes.push(thirdRationCode);
  92. }
  93. timeList.push({ times, ass: rationAss });
  94. if (stateList)
  95. stateList.push({
  96. index: stateSeq.ass,
  97. content: `${rationAss.name} ${rationAss.actualValue} : ${rationAss.assistCode}x${times}`,
  98. });
  99. }
  100. }
  101. if (thirdRation && temTimes.length === 2 && thirdRationCodes[0] === thirdRationCodes[1]) {
  102. // 说明有第三定额
  103. const timesT = temTimes[0] * temTimes[1];
  104. timeList.push({ times: timesT, ass: thirdRation });
  105. if (stateList) stateList.push({ index: stateSeq.ass, content: `+${thirdRationCodes[0]}x${timesT}` });
  106. }
  107. }
  108. return timeList;
  109. };