package cn.com.capcloud.api.action.myself.system;

import cn.com.capcloud.ccui.core.common.json.JackJSONArray;
import cn.com.capcloud.ccui.core.common.json.JackJSONObject;
import cn.com.capcloud.core.util.ReadProperty;
import cn.com.capcloud.api.action.service.ApiService;
import cn.com.capcloud.core.noentitydb.BaseService;
import cn.com.capcloud.core.noentitydb.DefaultAction;
import cn.com.capcloud.core.system.user.UserService;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Component
public class OrgAction extends DefaultAction {
    @Resource
    private BaseService baseService;
    @Resource
    private UserService userService;
    @Resource
    private ApiService apiService;
    @Resource
    private ReadProperty readProperty;
    private static OrgAction action;
    @PostConstruct
    public void init(){
        action=this;
        action.baseService=this.baseService;
        action.userService=this.userService;
        action.apiService =this.apiService;
        action.readProperty =this.readProperty;
    }

    @Override
    public JackJSONArray saveAfter(String jsonStr, JackJSONObject retJson, HttpServletRequest request, JackJSONArray array) {
        JackJSONObject orgInfo=array.getJackJSONObject(0);
        String orgId=String.valueOf(orgInfo.get("id"));
        if(!orgId.equals("null")&&orgId.length()>0){//更新部门时将用户表的部门名称同步最新
            String updateSql="update tbl_system_user set org_name='"+orgInfo.get("org_name")+"' where org_id='"+orgId+"'";
            this.getJdbcTemplate().execute(updateSql);
        }
        return super.saveAfter(jsonStr, retJson, request, array);
    }
}
