rationAss.ts 3.4 KB

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