| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { IJobContent, IItemCharacter, IStdBill, IStdJobContent, IStdItemCharacter } from '@sc/types';
- interface IJobsAndCharacterText {
- jobContentText: string;
- itemCharacterText: string;
- onlyItemCharacterText: string;
- onlyJobContentText: 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[],
- divided = false // 分别对应
- ): IJobsAndCharacterText => {
- let jobContentText = '';
- let itemCharacterText = '';
- let onlyJobContentText = '';
- let onlyItemCharacterText = '';
- jobContents.sort((a, b) => a.seq - b.seq);
- itemCharacters.sort((a, b) => a.seq - b.seq);
- const characterTextArray: string[] = divided ? [] : ['[项目特征]'];
- let i = 1;
- for (const item of itemCharacters) {
- if (item.isChecked) characterTextArray.push(`${i}. ${item.character || ''}: ${item.eigenvalue || ''}`);
- i += 1;
- }
- onlyItemCharacterText = characterTextArray.join('\n');
- const jobTextArray = divided ? [] : ['[工作内容]'];
- i = 1;
- for (const job of jobContents) {
- if (job.isChecked) jobTextArray.push(`${i}. ${job.content || ''}`);
- i += 1;
- }
- onlyJobContentText = jobTextArray.join('\n');
- jobContentText = divided ? onlyJobContentText : '';
- itemCharacterText = divided ? onlyItemCharacterText : `${onlyItemCharacterText}\n${onlyJobContentText}`;
- return { jobContentText, itemCharacterText, onlyItemCharacterText, onlyJobContentText };
- };
- 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;
- };
|