package weaver.interfaces.htsc.tgpt;

import com.engine.integration.util.StringUtils;
import weaver.conn.RecordSet;
import weaver.formmode.customjavacode.AbstractModeExpandJavaCodeNew;
import weaver.general.BaseBean;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.soa.workflow.request.RequestInfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9
 * @Company: 泛微软件
 * @author: K1810039
 * @version: 1.0
 * @CreateDate: 2022-08-19
 * @Description: 同步外部投资者今年来沟通数量
 * @ModifyLog:
 **/
public class UpdateWbtzzConnectNum extends AbstractModeExpandJavaCodeNew {
    /**
     * 执行模块扩展动作
     * @param param
     *  param包含(但不限于)以下数据
     *  user 当前用户
     *  importtype 导入方式(仅在批量导入的接口动作会传输) 1 追加，2覆盖,3更新，获取方式(int)param.get("importtype")
     *  导入链接中拼接的特殊参数(仅在批量导入的接口动作会传输)，比如a=1，可通过param.get("a")获取参数值
     *  页面链接拼接的参数，比如b=2,可以通过param.get("b")来获取参数
     * @return
     */
    public Map<String, String> doModeExpand(Map<String, Object> param) {
        Map<String, String> result = new HashMap<String, String>();
        BaseBean bb = new BaseBean();
        bb.writeLog("投关平台修改沟通次数开始");
        RecordSet rs = new RecordSet();
        RecordSet rs1 = new RecordSet();
        RecordSet wbfxsUpdateRs = new RecordSet();
        try {
            User user = (User)param.get("user");
            int billid = -1;//数据id
            int modeid = -1;//模块id
            RequestInfo requestInfo = (RequestInfo)param.get("RequestInfo");
            if(requestInfo!=null){
                billid = Util.getIntValue(requestInfo.getRequestid());
                modeid = Util.getIntValue(requestInfo.getWorkflowid());
                if(billid>0&&modeid>0){
                    //------请在下面编写业务逻辑代码------
                    bb.writeLog("投关平台billid"+billid);
                    bb.writeLog("投关平台modeid"+modeid);
                    String  dt1Sql = "select *  from uf_jdhd_dt1 where mainid =  " + billid;
                    rs1.execute(dt1Sql);
                    while(rs1.next()){
                        String xm = rs1.getString("xm");
                        String wbfxsSql = "select * from uf_jgtzzxxgl where modeuuid= '" +xm+"'" ;
                        JAVATools.writelog("机构投资者wbfxsSql"+wbfxsSql);
                        wbfxsUpdateRs.execute(wbfxsSql);
                        if(wbfxsUpdateRs.next()){
                            String sql = "select count(xm) count,xm as uuid from uf_jdhd_dt1 where  nf = (select extract(year from sysdate)　from dual) and  xm = '"+xm+"' and isdelete = 0  GROUP BY xm ";
                            JAVATools.writelog("机构投资者sql"+sql);
                            rs.execute(sql);
                            String count = "0";
                            if(rs.next()){
                                count = StringUtils.isEmpty(rs.getString("count"))?"0":rs.getString("count");
                            }
                            String csz1 = wbfxsUpdateRs.getString("csz");
                            String csz = StringUtils.isEmpty(wbfxsUpdateRs.getString("csz"))?"0":wbfxsUpdateRs.getString("csz");
                            String updateSql= "update uf_jgtzzxxgl set jnylygsgtsl =  '"+String.valueOf(Integer.parseInt(csz)+Integer.parseInt(count))+"' where modeuuid = '"+xm+"'" ;
                            JAVATools.writelog("机构投资者updateSql"+updateSql);
                            wbfxsUpdateRs.execute(updateSql);
                        }
                    }

                }
            }
            result.put("flag", "true");
        } catch (Exception e) {
            JAVATools.writelog("机构投资者"+e.getMessage());
            JAVATools.writelog("机构投资者"+e.getMessage());
            result.put("errmsg","自定义出错信息");
            result.put("flag", "false");
        }
        return result;
    }

}

