//我是督查表扬数据输入,替换 = 后面的就行
var biaoyangStr =[{"id":1,"company":"邢庄乡","duChaCompany":"县委县政府督查局"},{"id":2,"company":"邢庄乡","duChaCompany":"县委县政府督查局"},{"id":3,"company":"庄头镇","duChaCompany":"县委县政府督查局"},{"id":4,"company":"庄头镇","duChaCompany":"县委县政府督查局"},{"id":5,"company":"庄头镇","duChaCompany":"县委县政府督查局"},{"id":6,"company":"门楼任乡","duChaCompany":"县委县政府督查局"},{"id":7,"company":"先进制造业开发区","duChaCompany":"县委县政府督查局"},{"id":8,"company":"县委办","duChaCompany":"县委县政府督查局"},{"id":9,"company":"县委办","duChaCompany":"县委县政府督查局"},{"id":10,"company":"政府办","duChaCompany":"县委县政府督查局"},{"id":11,"company":"政府办","duChaCompany":"县委县政府督查局"},{"id":12,"company":"政府办","duChaCompany":"县委县政府督查局"},{"id":13,"company":"组织部","duChaCompany":"县委县政府督查局"},{"id":14,"company":"政法委","duChaCompany":"县委县政府督查局"},{"id":15,"company":"总工会","duChaCompany":"县委县政府督查局"},{"id":16,"company":"信访局","duChaCompany":"县委县政府督查局"},{"id":17,"company":"科协","duChaCompany":"县委县政府督查局"},{"id":18,"company":"乡村振兴局","duChaCompany":"县委县政府督查局"},{"id":19,"company":"农业农村局","duChaCompany":"县委县政府督查局"},{"id":20,"company":"科工信局","duChaCompany":"县委县政府督查局"},{"id":21,"company":"科工信局","duChaCompany":"县委县政府督查局"},{"id":22,"company":"商务局","duChaCompany":"县委县政府督查局"},{"id":23,"company":"商务局","duChaCompany":"县委县政府督查局"},{"id":24,"company":"发改委","duChaCompany":"县委县政府督查局"},{"id":25,"company":"发改委","duChaCompany":"县委县政府督查局"},{"id":26,"company":"重点项目办","duChaCompany":"县委县政府督查局"},{"id":27,"company":"重点项目办","duChaCompany":"县委县政府督查局"},{"id":28,"company":"住建局","duChaCompany":"县委县政府督查局"},{"id":29,"company":"住建局","duChaCompany":"县委县政府督查局"},{"id":30,"company":"住建局","duChaCompany":"县委县政府督查局"},{"id":31,"company":"生态环境局","duChaCompany":"县委县政府督查局"},{"id":32,"company":"统计局","duChaCompany":"县委县政府督查局"},{"id":33,"company":"统计局","duChaCompany":"县委县政府督查局"},{"id":34,"company":"统计局","duChaCompany":"县委县政府督查局"},{"id":35,"company":"财政局","duChaCompany":"县委县政府督查局"},{"id":36,"company":"财政局","duChaCompany":"县委县政府督查局"},{"id":37,"company":"公安局","duChaCompany":"县委县政府督查局"},{"id":38,"company":"公安局","duChaCompany":"县委县政府督查局"},{"id":39,"company":"民政局","duChaCompany":"县委县政府督查局"},{"id":40,"company":"督查局","duChaCompany":"县委县政府督查局"},{"id":41,"company":"卫建委","duChaCompany":"县委县政府督查局"},{"id":42,"company":"疫情指挥部(卫建委)","duChaCompany":"县委县政府督查局"},{"id":43,"company":"疫情指挥部(卫建委)","duChaCompany":"县委县政府督查局"},{"id":44,"company":"疫情指挥部(卫建委)","duChaCompany":"县委县政府督查局"}]
//我是督查批评数据输入,替换 = 后面的就行
var pipingStr =[{"id":1,"company":"两湖街道办","duChaCompany":"县委县政府督查局"},{"id":2,"company":"朱曲镇","duChaCompany":"县委县政府督查局"},{"id":3,"company":"蔡庄镇","duChaCompany":"县委县政府督查局"},{"id":4,"company":"蔡庄镇","duChaCompany":"县委县政府督查局"},{"id":5,"company":"永兴镇","duChaCompany":"县委县政府督查局"},{"id":6,"company":"张市镇","duChaCompany":"县委县政府督查局"},{"id":7,"company":"十八里镇","duChaCompany":"县委县政府督查局"},{"id":8,"company":"邢庄乡","duChaCompany":"县委县政府督查局"},{"id":9,"company":"庄头镇","duChaCompany":"县委县政府督查局"},{"id":10,"company":"大营镇","duChaCompany":"县委县政府督查局"},{"id":11,"company":"岗李乡","duChaCompany":"县委县政府督查局"},{"id":12,"company":"大桥乡","duChaCompany":"县委县政府督查局"},{"id":13,"company":"政法委","duChaCompany":"县委县政府督查局"},{"id":14,"company":"科协","duChaCompany":"县委县政府督查局"},{"id":15,"company":"应急管理局","duChaCompany":"县委县政府督查局"},{"id":16,"company":"科工信局","duChaCompany":"县委县政府督查局"},{"id":17,"company":"交通局","duChaCompany":"县委县政府督查局"},{"id":18,"company":"住建局","duChaCompany":"县委县政府督查局"},{"id":19,"company":"税务局","duChaCompany":"县委县政府督查局"},{"id":20,"company":"人行","duChaCompany":"县委县政府督查局"},{"id":21,"company":"民政局","duChaCompany":"县委县政府督查局"},{"id":22,"company":"爱卫办","duChaCompany":"县委县政府督查局"},{"id":23,"company":"红十字会","duChaCompany":"县委县政府督查局"},{"id":24,"company":"长线局","duChaCompany":"县委县政府督查局"},{"id":25,"company":"工商行","duChaCompany":"县委县政府督查局"},{"id":26,"company":"合益村镇银行","duChaCompany":"县委县政府督查局"},{"id":27,"company":"交通局等","duChaCompany":"县委县政府督查局"},{"id":28,"company":"棉麻公司","duChaCompany":"县委县政府督查局"},{"id":29,"company":"农发行","duChaCompany":"县委县政府督查局"},{"id":30,"company":"人保公司","duChaCompany":"县委县政府督查局"},{"id":31,"company":"石化公司","duChaCompany":"县委县政府督查局"},{"id":32,"company":"武警中队","duChaCompany":"县委县政府督查局"},{"id":33,"company":"县二院","duChaCompany":"县委县政府督查局"},{"id":34,"company":"疫情指挥部(卫建委)","duChaCompany":"县委县政府督查局"},{"id":35,"company":"疫情指挥部(卫建委)","duChaCompany":"县委县政府督查局"},{"id":36,"company":"疫情指挥部(卫建委)","duChaCompany":"县委县政府督查局"},{"id":37,"company":"疫情指挥部(卫建委)","duChaCompany":"县委县政府督查局"},{"id":38,"company":"邮政银行","duChaCompany":"县委县政府督查局"},{"id":39,"company":"中华财险","duChaCompany":"县委县政府督查局"},{"id":40,"company":"中行","duChaCompany":"县委县政府督查局"},{"id":41,"company":"中原银行","duChaCompany":"县委县政府督查局"},{"id":42,"company":"住房公积金","duChaCompany":"县委县政府督查局"}]
ResultData = function (id, company, cityAdmirTimes, areaAdmirTimes, admirMoney,
cityPipingTimes, areaPipingTimes, pipingMoney) {
this.id = id;
this.company = company;
this.cityAdmirTimes = cityAdmirTimes;
this.areaAdmirTimes = areaAdmirTimes;
this.admirMoney = admirMoney;
this.cityPipingTimes = cityPipingTimes;
this.areaPipingTimes = cityPipingTimes;
this.pipingMoney = pipingMoney;
}
var resultDatas = new Array;
//这里开始是处理表彰的
var admirDatas = biaoyangStr;
var cityTimes = 0, areaTimes = 0, itemId = 1, cityMultiple = 1.0, areaMultiple = 0.5;
for (var i = 0; i < admirDatas.length; i++) {
//这里是确定到底是市局还是县局
if (admirDatas[i].duChaCompany == "县委县政府督查局"
|| "县委督查局委员会" == admirDatas[i].duChaCompany ) {
areaTimes++;
} else {
cityTimes++;
}
var resultdata = {
id: itemId,
company: admirDatas[i].company,
cityAdmirTimes: cityTimes,
areaAdmirTimes: areaTimes,
admirMoney: 0,
cityPipingTimes: 0,
areaPipingTimes: 0,
pipingMoney: 0
};
//将第一个item添加到结果数组中
if (i == 0) {
resultDatas.push(resultdata);
} else if (i > 0) {
if (admirDatas[i].company == admirDatas[i - 1].company) {
resultDatas[resultDatas.length - 1] = resultdata;
} else {
//将奖励次数置空
if (admirDatas[i].duChaCompany == "县委县政府督查局"
|| "县委督查局委员会" == admirDatas[i].duChaCompany ) {
areaTimes = 1;
cityTimes = 0;
} else {
areaTimes = 0;
cityTimes = 1;
}
resultdata.cityAdmirTimes = cityTimes;
resultdata.areaAdmirTimes = areaTimes;
//这里是将新的item加上去
itemId++;
resultdata.id = itemId;
resultDatas.push(resultdata);
//这里计算前一个奖惩了多少钱
var cityTime = resultDatas[resultDatas.length - 2].cityAdmirTimes;
var areaTime = resultDatas[resultDatas.length - 2].areaAdmirTimes;
var admirMoney = cityTime * cityMultiple + areaMultiple * areaTime;
resultDatas[resultDatas.length - 2].admirMoney = admirMoney;
}
}
}
//这里计算最后一个奖惩了多少钱
var cityTime = resultDatas[resultDatas.length - 1].cityAdmirTimes;
var areaTime = resultDatas[resultDatas.length - 1].areaAdmirTimes;
var admirMoney = cityTime * cityMultiple + areaMultiple * areaTime;
resultDatas[resultDatas.length - 1].admirMoney = admirMoney;
///////////////////////////我是华丽的分割线/////////////////////////////////
var criticismDatas = pipingStr;
for (var i = 0; i < resultDatas.length; i++) {
var itemData = resultDatas[i];
var cityTimes = 0, areaTimes = 0;
var currentName = "";
var haveItem = false;
for (var j = 0; j < criticismDatas.length; j++) {
var companyName = criticismDatas[j].company;
if (criticismDatas[j].company == resultDatas[i].company) {
haveItem = true;
if (criticismDatas[j].duChaCompany == "县委县政府督查局"
|| "县委督查局委员会" == admirDatas[i].duChaCompany ) {
areaTimes++;
} else {
cityTimes++;
}
}
if (j == criticismDatas.length - 1) {
if (haveItem) {
resultDatas[i].cityPipingTimes = cityTimes;
resultDatas[i].areaPipingTimes = areaTimes;
resultDatas[i].pipingMoney = cityTimes * -1.0 + areaTimes * -0.5;
haveItem = false;
} else {
// itemId++;
// var resultdata = {
// id: itemId,
// company: companyName,
// cityAdmirTimes: 0,
// areaAdmirTimes: 0,
// admirMoney: 0,
// cityPipingTimes: cityTimes,
// areaPipingTimes: areaTimes,
// pipingMoney: 0
// };
// resultDatas.push(resultdata);
}
cityTimes = 0, areaTimes = 0;
}
}
}
//定义一个pipingDatas,让它获取到resultdata里面没有的项
var pipingDatas = new Array;
for (var i = 0; i < criticismDatas.length; i++) {
for (var j = 0; j < resultDatas.length; j++) {
var isExist = false;
if (criticismDatas[i].company == resultDatas[j].company) {
isExist = true;
break;
}
if (j == resultDatas.length - 1 && !isExist) {
pipingDatas.push(criticismDatas[i]);
}
}
}
for (var i = 0; i < pipingDatas.length; i++) {
for (var j = i; j < resultDatas.length; j++) {
if (pipingDatas[i].company == resultDatas[j].company) {
if (pipingDatas[i].duChaCompany == "县委县政府督查局"
|| "县委督查局委员会" == admirDatas[i].duChaCompany ) {
resultDatas[j].areaPipingTimes = resultDatas[j].areaPipingTimes + 1;
} else {
resultDatas[j].cityPipingTimes = resultDatas[j].cityPipingTimes + 1;
}
break;
}
if (j == resultDatas.length - 1) {
var cityTimes = 0, areaTimes = 0;
if (pipingDatas[i].duChaCompany == "县委县政府督查局"
|| "县委督查局委员会" == admirDatas[i].duChaCompany ) {
areaTimes++;
} else {
cityTimes++;
}
itemId++;
//这里我也不知道为什么,反正就是要剪一个数
if(cityTimes>0){
cityTimes --
}
if(areaTimes >0){
areaTimes --
}
var resultdata = {
id: itemId,
company: pipingDatas[i].company,
cityAdmirTimes: 0,
areaAdmirTimes: 0,
admirMoney: 0,
cityPipingTimes: cityTimes,
areaPipingTimes: areaTimes,
pipingMoney: 0
};
resultDatas.push(resultdata);
areaTimes = 0, citytimes = 0;
}
}
}
// for (var i = 0; i < resultDatas.length; i++) {
// document.write(
// resultDatas[i].id + " " + resultDatas[i].company + " " +
// resultDatas[i].cityAdmirTimes + " " + resultDatas[i].areaAdmirTimes + " " +
// resultDatas[i].admirMoney + " " +
// resultDatas[i].cityPipingTimes + " " + resultDatas[i].areaPipingTimes + " " +
// resultDatas[i].pipingMoney + "</br>");
// }
document.write(
JSON.stringify( resultDatas ))
console