package weaver.interfaces.htsc.jgzxzysx;

import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.htsc.jgzxzysx.service.impl.JgzxzysxServiceImp;
import com.engine.integration.util.StringUtils;
import weaver.general.Util;
import weaver.hrm.User;
import weaver.interfaces.htsc.GlobatTools.JAVATools;
import weaver.interfaces.htsc.comInfo.PropBean;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

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

/**
 * @author K1810015
 * @version 1.0.0
 * @ClassName CreateNumberAction.java
 * @createTime 2022年05月23日 13:28:00
 */
public class CreateNumberAction  implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = Util.null2String(requestInfo.getRequestid());
        String tablename = Util.null2String(requestInfo.getRequestManager().getBillTableName());
        User user = requestInfo.getRequestManager().getUser();
        if (StringUtils.isBlank(requestid) || StringUtils.isBlank(tablename)) {
            return Action.SUCCESS;
        }
        try {
            //不影响流程提交
            String sql = "select szbm,lcbh from " + tablename + " where 1=1 ";
            Map<String, String> wheremap = new HashMap<>();
            wheremap.put("requestid", requestid);
            Map<String, Object> mainmap = JAVATools.GetTableToMap(sql, wheremap);
            if (mainmap == null || mainmap.size() <= 0) {
                return Action.SUCCESS;
            }
            String lcbhvalue = Util.null2String(mainmap.get("lcbh"));
            String deptid = Util.null2String(mainmap.get("szbm"));
            if (StringUtils.isBlank(lcbhvalue) ) {
                Map<String, Object> unnumbermap = new HashMap<>();
                unnumbermap.put("unnumber", new PropBean().getPropName("jgzxzysx.unnumber"));
                unnumbermap.put("deptid",deptid);
                lcbhvalue = ServiceUtil.getService(JgzxzysxServiceImp.class).getnumber(user, unnumbermap);
                if (StringUtils.isBlank(lcbhvalue) ) {
                    return Action.SUCCESS;
                }
                Map<String, String> lcbhsetmap = new HashMap<>();
                lcbhsetmap.put("lcbh", lcbhvalue);
                JAVATools.Updatesql(lcbhsetmap, tablename, wheremap);

            }
            Map<String, String> setmap = new HashMap<>();
            setmap.put("requestmark", lcbhvalue);
            JAVATools.Updatesql(setmap, "workflow_requestbase", wheremap);
            return Action.SUCCESS;
        }catch (Exception e){
            return Action.SUCCESS;
        }
    }
}
