123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /**
- * Created by Zhong on 2018/1/24.
- */
- const mongoose = require('mongoose');
- const rationItemModel = mongoose.model('std_ration_lib_ration_items');
- const installFeeItemModel = mongoose.model('std_ration_lib_installation');
- const installSectionModel = mongoose.model('std_ration_lib_installationSection');
- class InstallationDao{
- async getInstallation(rationRepId, callback){
- try {
- let feeItems = await installFeeItemModel.find({rationRepId: rationRepId, $or: [{deleted: false}, {deleted: null}]});
- for(let feeItem of feeItems){
- let sids = [];
- for(let sec of feeItem.section){
- sids.push(sec.ID);
- }
- if(sids.length > 0){
- let sections = await installSectionModel.find({ID: {$in: sids}, $or: [{deleted: false}, {deleted: null}]});
- feeItem._doc.section = sections;
- }
- }
- callback(0, feeItems);
- }
- catch(err){
- callback(err, null);
- }
- }
- async updateSection(updateData, callback){
- try{
- for(let data of updateData){
- if(data.updateType === 'new'){
- await installSectionModel.create(data.updateData);
- }
- else if(data.updateType === 'update' && !data.updateData.deleted){
- await installSectionModel.update({ID: data.updateData.ID}, data.updateData);
- }
- else {
- await installSectionModel.remove({ID: data.updateData.ID});
- }
- }
- callback(0, null);
- }
- catch(err){
- callback(err, null);
- }
- }
- async updateFeeItem(updateData, callback){
- try{
- for(let data of updateData){
- if(data.updateType === 'new'){
- await installFeeItemModel.create(data.updateData);
- }
- else if(data.updateType === 'update' && !data.updateData.deleted){
- await installFeeItemModel.update({ID: data.updateData.ID}, data.updateData);
- }
- else{
- await installFeeItemModel.remove({ID: data.updateData.ID});
- }
- }
- callback(0, null);
- }
- catch(err){
- callback(err, null);
- }
- }
- async batchUpdateInst(rationSection, inst, callback){
- try{
- for(let sectionId of rationSection){
- await rationItemModel.update({sectionId: sectionId, $or: [{isDeleted: null}, {isDeleted: false}]},
- {$addToSet: {rationInstList: {feeItemId: inst.feeItemId, sectionId: inst.sectionId}}}, {multi: true});
- }
- callback(0, null);
- }
- catch(err){
- callback(err, null);
- }
- }
- }
- export default InstallationDao;
|