package com.sys.bus.jx.service;

import com.jfinal.plugin.activerecord.SqlPara;
import com.sys.bus.model.UpdateRatingPermission;
import com.sys.core.utils.Conditions;
import com.sys.core.utils.Tool;

import java.util.List;

public class UpdateRatingPermissionService {
   public int  addPermission(String cycleId,String orgId,String isSubOrg){


       UpdateRatingPermission updateRatingPermission = new UpdateRatingPermission();

        updateRatingPermission.setCycleId(cycleId);
        updateRatingPermission.setOrgId(orgId);
        updateRatingPermission.setIsSubordinate(isSubOrg);
       Conditions condi = new Conditions();
       condi.modelToCondition(updateRatingPermission);
       SqlPara sp = condi.getSqlPara();
       sp.setSql(sp.getSql());
       List<UpdateRatingPermission> updateRatingPermissions = UpdateRatingPermission.dao.find(sp);
        if(updateRatingPermissions.size()>0){
            return 1;
        }
       updateRatingPermission.setPermissionId(Tool.uuid());
        updateRatingPermission.setIsEnable("1");
       boolean save = updateRatingPermission.save();
       return 0;
    }
}
