addDo: function (req, res) {
var body = req.body;
var parentId = parseInt(body.parentId);
Sys_unit.findOne({id: parentId}).exec(function (err, unit) {
var path = '';
if (unit)path = unit.path || '';
Sys_unit.find().where({parentId: parentId}).sort({path: 'desc'}).limit(1).exec(function (ferr, objs) {
if (objs.length > 0) {
var num = parseInt(objs[0].path) + 1;
path = StringUtil.getPath(num, objs[0].path.length);
}else{
path=path+'0001';
}
body.path = path;
body.location = 0;
body.createdBy = req.session.user.id;
Sys_unit.create(body).exec(function (cerr, obj) {
if (cerr || !obj)return res.json({code: 1, msg: sails.__('add.fail')});
if (parentId > 0) {
Sys_unit.update({id: parentId}, {hasChildren: true}).exec(function(e,o){});
}
return res.json({code: 0, msg: sails.__('add.ok')});
});
});
});
},