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.ccui.core.common.utils.StringUtil;
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 org.springframework.beans.factory.annotation.Autowired;
import javax.servlet.http.HttpServletRequest;

@Component
public class OrgAction extends DefaultAction {
    @Autowired
    private BaseService baseService;
    @Autowired
    private UserService userService;
    @Autowired
    private ApiService apiService;
    @Autowired
    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(StringUtil.isNotEmpty(orgId)){//更新部门时将用户表的部门名称同步最新
            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);
    }
}

