5 changed files with 144 additions and 25 deletions
-
13src/controller/die.controller.js
-
5src/router/die.route.js
-
10src/service/chicken.service.js
-
58src/service/die.service.js
-
83src/test/someFunc.js
@ -1,24 +1,65 @@ |
|||||
function generateSerialNumber() { |
|
||||
const now = new Date(); |
|
||||
const year = now.getFullYear(); //得到年份
|
|
||||
const month = now.getMonth() + 1; //得到月份
|
|
||||
const date = now.getDate(); //得到日期
|
|
||||
const hour = now.getHours(); //得到小时数
|
|
||||
const minute = now.getMinutes(); //得到分钟数
|
|
||||
const second = now.getSeconds(); //得到秒数
|
|
||||
const time = now.getTime(); |
|
||||
return `${year}${month}${date}${hour}${minute}${second}${time}`; |
|
||||
} |
|
||||
|
// function generateSerialNumber() {
|
||||
|
// const now = new Date();
|
||||
|
// const year = now.getFullYear(); //得到年份
|
||||
|
// const month = now.getMonth() + 1; //得到月份
|
||||
|
// const date = now.getDate(); //得到日期
|
||||
|
// const hour = now.getHours(); //得到小时数
|
||||
|
// const minute = now.getMinutes(); //得到分钟数
|
||||
|
// const second = now.getSeconds(); //得到秒数
|
||||
|
// const time = now.getTime();
|
||||
|
// return `${year}${month}${date}${hour}${minute}${second}${time}`;
|
||||
|
// }
|
||||
|
|
||||
const res = generateSerialNumber(); |
|
||||
console.log(res); |
|
||||
|
// const res = generateSerialNumber();
|
||||
|
// console.log(res);
|
||||
|
|
||||
function haveSame(arr, otherArr) { |
|
||||
// 合并数组
|
|
||||
const normalArr = [...arr, ...otherArr]; |
|
||||
// 合并数组并去重
|
|
||||
const setArr = [...new Set(normalArr)]; |
|
||||
return normalArr.length !== setArr.length; |
|
||||
} |
|
||||
|
// function haveSame(arr, otherArr) {
|
||||
|
// // 合并数组
|
||||
|
// const normalArr = [...arr, ...otherArr];
|
||||
|
// // 合并数组并去重
|
||||
|
// const setArr = [...new Set(normalArr)];
|
||||
|
// return normalArr.length !== setArr.length;
|
||||
|
// }
|
||||
|
|
||||
|
// console.log(haveSame("2,5".split(","), ["1"]));
|
||||
|
|
||||
console.log(haveSame("2,5".split(","), ["1"])); |
|
||||
|
const arr = [ |
||||
|
{ |
||||
|
id: 1, |
||||
|
house_id: 4, |
||||
|
coop_id: 2, |
||||
|
reason_id: 1, |
||||
|
die_number: 222, |
||||
|
}, |
||||
|
{ |
||||
|
id: 2, |
||||
|
house_id: 4, |
||||
|
coop_id: 2, |
||||
|
reason_id: 1, |
||||
|
die_number: 222, |
||||
|
}, |
||||
|
{ |
||||
|
id: 3, |
||||
|
house_id: 4, |
||||
|
coop_id: 7, |
||||
|
reason_id: 1, |
||||
|
die_number: 222, |
||||
|
}, |
||||
|
]; |
||||
|
let temp = []; |
||||
|
arr.map((item, index) => { |
||||
|
if ( |
||||
|
temp.every( |
||||
|
(it) => it.house_id != item.house_id || it.coop_id != item.coop_id |
||||
|
) |
||||
|
) { |
||||
|
temp.push(item); |
||||
|
} else { |
||||
|
const real = temp.filter( |
||||
|
(it) => it.house_id == item.house_id && it.coop_id == item.coop_id |
||||
|
); |
||||
|
if (real && real.length > 0) { |
||||
|
real[0].die_number = item.die_number + real[0].die_number; |
||||
|
} |
||||
|
} |
||||
|
}); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue