const system = require("../../system");
const ServiceBase = require("../sve.base");
const moment = require("moment");
class EcompanybpoService extends ServiceBase {
   constructor() {
      super(ServiceBase.getDaoName(EcompanybpoService));
   }

   async saveCompanybpo(ecompanyId, bpos) {
      if(!ecompanyId) {
         return;
      }
      // 删除 by ecompanyId
      await this.delByECompanyId(ecompanyId);
      if(!bpos || bpos.length == 0) {
         return;
      }
      for(var bpo of bpos) {
         bpo.ecompany_id = ecompanyId;
      }
      // 插入
      await this.dao.model.bulkCreate(bpos);
   }

   async delByECompanyId(ecompanyId) {
      var sql = "DELETE FROM `c_ecompany_bpo` WHERE ecompany_id = " + ecompanyId;
      return await this.dao.customExecAddOrPutSql(sql);
   }

   async findByECompanyId(ecompanyId) {
      return this.dao.findByECompanyId(ecompanyId);
   }
}
module.exports = EcompanybpoService;