package com.engine.organization.service.impl;

import com.engine.core.impl.Service;
import com.engine.organization.service.NonStandardOptService;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;

import java.util.Arrays;

/**
 * @author:dxfeng
 * @createTime: 2022/09/01
 * @version: 1.0
 */
public class NonStandardOptServiceImpl extends Service implements NonStandardOptService {
    private static final String NON_STANDARD_NUM = "151";
    private static final String START = "start";
    private static final String STOP = "stop";

    @Override
    public void NonStandardOpt(String method, String ids) {
        if (StringUtils.isAnyBlank(ids, method)) {
            return;
        }
        // 判断是否包含151非标号
        boolean contains = Arrays.asList(ids.split(",")).contains(NON_STANDARD_NUM);
        if (contains) {
            switch (method.toLowerCase()) {
                case START:
                    Start();
                    break;
                case STOP:
                    Stop();
                    break;
                default:
                    break;
            }
        }
    }

    private void Start() {
        RecordSet rs = new RecordSet();
        // 更新人员表系统字段
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=1,allowhide=-1 where fieldname='sex'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=-1 where fieldname='departmentid'");
        // 非标启用，停用EC岗位字段
        rs.executeUpdate("update hrm_formfield set isuse=0,ismand=0,allowhide=-1 where fieldname='jobtitle'");
        rs.executeUpdate("update hrm_formfield set isuse=0,ismand=0,allowhide=-1 where fieldname='jobactivity'");
        rs.executeUpdate("update hrm_formfield set isuse=0,ismand=0,allowhide=-1 where fieldname='joblevel'");
        rs.executeUpdate("update hrm_formfield set isuse=0,ismand=0,allowhide=-1 where fieldname='jobcall'");
        rs.executeUpdate("update hrm_formfield set isuse=0,ismand=0,allowhide=-1 where fieldname='jobGroupId'");
        rs.executeUpdate("update hrm_formfield set isuse=0,ismand=0,allowhide=-1 where fieldname='jobactivitydesc'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1,groupid=1,fieldorder=18 where fieldname='managerid'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1,groupid=1,fieldorder=99 where fieldname='systemlanguage'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1,groupid=1,fieldorder=21 where fieldname='assistantid'");

        // 更新聚才林自定义字段
        rs.executeUpdate("update cus_formfield set ISMAND = 1, ISUSE = 1 where SCOPE = 'HrmCustomFieldByInfoType' and SCOPEID = -1 and FIELDID in(100001,100002,100003)");
        rs.executeUpdate("update cus_formfield set ISMAND = 0, ISUSE = 1 where scope = 'HrmCustomFieldByInfoType' and SCOPEID = 3 and FIELDID in(100005, 100006, 100007, 100008, 100009, 100010, 100004)");


    }

    private void Stop() {
        RecordSet rs = new RecordSet();
        // 更新人员表系统字段
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1 where fieldname='sex'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=1,allowhide=-1 where fieldname='departmentid'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=1,allowhide=-1 where fieldname='jobtitle'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=1,allowhide=1 where fieldname='jobactivity'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1 where fieldname='joblevel'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1 where fieldname='jobcall'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1 where fieldname='jobGroupId'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1 where fieldname='jobactivitydesc'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=1,allowhide=-1,groupid=3,fieldorder=21 where fieldname='managerid'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1,groupid=1,fieldorder=12 where fieldname='systemlanguage'");
        rs.executeUpdate("update hrm_formfield set isuse=1,ismand=0,allowhide=1,groupid=3,fieldorder=22 where fieldname='assistantid'");

        // 更新聚才林自定义字段
        rs.executeUpdate("update cus_formfield set ISMAND = 0, ISUSE = 0 where SCOPE = 'HrmCustomFieldByInfoType' and SCOPEID = -1 and FIELDID in(100001,100002,100003)");
        rs.executeUpdate("update cus_formfield set ISMAND = 0, ISUSE = 0 where scope = 'HrmCustomFieldByInfoType' and SCOPEID = 3 and FIELDID in(100005, 100006, 100007, 100008, 100009, 100010, 100004)");

    }
}
