package com.unis.crk.common.service.impl;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unis.crk.common.entity.Billnonewgjj;
import com.unis.crk.common.mapper.BillnonewgjjMapper;
import com.unis.crk.common.service.IBillnonewgjjService;
import com.unis.crk.utils.FunUtils;
import com.unis.crk.utils.SqpMapUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import sun.misc.UUDecoder;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 专用于生成国家局业务单据号 服务实现类
 * </p>
 *
 * @author TangSong
 * @since 2023-08-03
 */
@Service
public class BillnonewgjjServiceImpl extends ServiceImpl<BillnonewgjjMapper, Billnonewgjj> implements IBillnonewgjjService {

    @Resource
    private BillnonewgjjMapper billnonewgjjMapper;



    @SuppressWarnings("unchecked")
    public String createNewNo(String prefix, String tableName, String unitId,String BillNo,
                              int NoLen,String... cpzRq) {
        String newvalue = "";
        String sql = "";
        try {

            synchronized(this){
                //先查询是BillNo是否已经生成，如果已经生成则返回为空
                sql = "select ywdh as \"m\" from billnonewGjj b where  tableName='" + tableName+"' and BillNo = '"+BillNo+"' and unitid = '"+unitId+"' " ;
                List<Map<String, Object>> ls1 = billnonewgjjMapper.findBySql(sql);
                if (ls1.size() == 1) { //表示此数据已经存在，不再生成防止重复
                    return ls1.get(0).get("m").toString();
                }
                String  expression = "";
                sql = "select IFNULL( max(ywdh),'') \"m\" from billnonewGjj b where  tableName='" + tableName+"' " ;
                //表示是粮食入库记录
                if (StringUtils.equals("data_crkyw_rmdj_default", tableName)) {
                    //入库有特殊之处，汽车可能在库里面过夜倒导第一车入库时间与入仓时间不是同一天，引起库存查询有差异
                    //得到公式中的年月日 2023-01-12，如是这种，prefix：14表入库
                    expression = cpzRq[0].substring(2);
                    expression = expression.replaceAll("-", "");
                    //使用前缀+年月日
                    sql += " and ywdh like '" + prefix +expression + "%' ";
                }
                //表示是粮食出库记录
                if ( StringUtils.equals("data_crkyw_ckrmdj_default", tableName)) {
                    //得到公式中的年月日 230112，如是这种，prefix：14表入库
                    expression = BillNo.substring(0,BillNo.length()-3);
                    expression = expression.substring(expression.length()-6);
                    //使用前缀+年月日
                    sql += " and ywdh like '" + prefix +expression + "%' ";
                }
                //表示是库存变动
                if (StringUtils.equals("data_kcgl_kcbd_default", tableName) ) {
                    //得到公式中的年月日 20230112，如是这种，prefix：货位代码
                    expression = BillNo.substring(0,BillNo.length()-3);
                    expression = expression.substring(expression.length()-8);
                    //使用前缀+年月日
                    sql += " and ywdh like '" + prefix +expression + "%' ";
                }
                //表示是粮食入库结算记录
                if (StringUtils.equals("data_crkyw_jsxx_default", tableName)) {
                    //得到公式中的年月日 20230112，如是这种，prefix：使用库区编码
                    expression = BillNo.substring(0,BillNo.length()-3);
//                    expression = expression.substring(expression.length()-8);
                    //使用前缀+年月日
                    sql +=   "  and ywdh like '" + prefix +expression + "%' ";
                }
                //表示是粮食倒仓记录
                if (StringUtils.equals("data_crkyw_cpz_default", tableName)) {
                    //得到公式中的年月日 20230112，如是这种，prefix：使用库区编码
                    expression = BillNo.substring(0,BillNo.length()-4);
                    expression = expression.substring(expression.length()-8);
                    //使用前缀+年月日
                    sql +=   " and ywdh like '" + prefix +expression + "%' ";
                }
                //表示是粮食入库检验记录，其单号要与入库记录单号一致
                if (StringUtils.equals("data_crkyw_jyxx_default", tableName)) {
                    String[] strings = BillNo.split(",");
                    BillNo = strings[0]; //存放检验单号
                    String string = strings[1]; //存放单据号
                    sql = "select IFNULL( max(ywdh),'') \"m\" from billnonewGjj b where  tableName='data_crkyw_rmdj_default' and BillNo = '"+BillNo+"' " ;
                }
                List<Map<String, Object>> ls = billnonewgjjMapper.findBySql(sql);
                if (ls.size() == 1) {
                    Map<String, Object> map = (Map) ls.get(0);
                    newvalue =  StringUtils.isBlank(map.get("m").toString())? prefix+expression + getNo("", NoLen) : getNo(map.get("m")
                            .toString(), NoLen);
                    String uuid = IdUtil.fastSimpleUUID();
//                    String ins_sql = "insert into billnonewgjj (newId,unitId,BillNo,tableName,ywdh,buildDate) values ("+uuid+",'"
//                            + unitId + "', '" + BillNo + "', '" + tableName + "', '" + newvalue + "',"+FunUtils.get_sysdate()+") ";
//                     billnonewgjjMapper.executeUpdate(ins_sql);
                    Billnonewgjj  billnonewgjj  = new Billnonewgjj();
                    billnonewgjj.setNewId(uuid);
                    billnonewgjj.setUnitId(unitId);
                    billnonewgjj.setBillNo(BillNo);
                    billnonewgjj.setTableName(tableName);
                    billnonewgjj.setYwdh(newvalue);
                    billnonewgjj.setBuildDate(new Date());
                    if (!this.save(billnonewgjj)) {
                        newvalue = "";
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return newvalue;
    }

    private String getNo(String expr, int len) {
        if (StringUtils.isBlank(expr)) {
            return String.format("%0" + len + "d", 1);
        }
        String temp = expr.substring(expr.length() - len);
        int no = 1;
        try {
            no = Integer.parseInt(temp);
        } catch (Exception localException) {
        }
        return expr.substring(0, expr.length() - len) + String.format("%0" + len + "d",no + 1);
    }

    @Override
    public String createRkyw(String unitId, String bizNo, String rkywdh) {
        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\",rkjsdh as \"rkjsdh\" FROM ods_up_lsrkxxjk_final where rkywdh = '"+rkywdh+"' ");
        String czbz ="i"; //操作标志
        String rkjsdh = ""; //入库结算单号
        String sql_del = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_lsrkxxjk_final where rkywdh = '"+rkywdh+"';";
            czbz = "u";
            rkjsdh = list.get(0).get("rkjsdh").toString();
        }else {
            //通过生成
            //得到结算表结算单号
            list = billnonewgjjMapper.findBySql("SELECT jsdh as \"jsdh\",b.kqbm as \"kqbm\" FROM data_crkyw_jsxx_default a inner JOIN depot_qh"+FunUtils.DataBaseSplitChar+"org_info b on a.UnitID = b.org_id where a.bizno = '"+bizNo+"' ");
            if (!list.isEmpty()) {
                String jsdh =list.get(0).get("jsdh").toString();
                String kqbm =list.get(0).get("kqbm").toString();
                rkjsdh = createNewNo(kqbm, "data_crkyw_jsxx_default".toLowerCase(), unitId, jsdh, 4);
            }
        }
        String sql_ins =SqpMapUtil.getSql("GJJ_RKYW");
        sql_ins = sql_ins.replace("'rkywdh'", "'"+rkywdh+"'");
        sql_ins = sql_ins.replace("'BizNo'", "'"+bizNo+"'");
        sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        sql_ins = sql_ins.replace("'rkjsdh'", "'"+rkjsdh+"'");
        //合同号，货位编码
        //合同号使用单位表中的kqbm+htbm拼成
        //货位编码直接使用货位表中的hwbm
        billnonewgjjMapper.executeUpdate(sql_del+sql_ins);
        //，化验相关明细扣量
        //先查询对应的化验扣量之后，防止因小数据问题，之和不对
        list = billnonewgjjMapper.findBySql("SELECT  id as \"id\",zjklxj as \"zjklxj\" FROM ods_up_lsrkxxjk_final where rkywdh = '"+rkywdh+"' ");
        if (!list.isEmpty()) {
            Double zjklxj = Double.parseDouble(list.get(0).get("zjklxj").toString());
            String id = list.get(0).get("id").toString();

            if (zjklxj != 0.0) { //表示有化验扣量，无扣量不执行
                String sql_jykl =SqpMapUtil.getSql("GJJ_JYKL");
                sql_jykl = String.format(sql_jykl, bizNo);
                list = billnonewgjjMapper.findBySql(sql_jykl);
                Double zl = 0.0;
                if (!list.isEmpty()) {
                    String sql_update = " update ods_up_lsrkxxjk_final set ";
                    for (int i = 0; i < list.size(); i++) {
                        Map<String, Object> map = list.get(i);
                        Double zklsl = Double.parseDouble(map.get("zklsl").toString());
                        if (i == list.size()-1) { //保证数据的一致性，防止计算出来不一致扣量，使用了round方法zjklxj
                            zklsl = zjklxj-zl;
                        }else {
                            zl +=zklsl;
                        }
                        String zbxmc = map.get("EnumItemName").toString();
                        if (StringUtils.startsWith(zbxmc, "水分")) { //水分(%)
                            sql_update += "qzsfzkl="+zklsl+",";
                            continue;
                        }
                        if (StringUtils.startsWith(zbxmc, "杂质")) { //杂质
                            sql_update += "qzzzzkl="+zklsl+",";
                            continue;
                        }
                        if (StringUtils.startsWith(zbxmc, "不完善粒")) { //不完善粒
                            sql_update += "qzbwslkl="+zklsl+",";
                            continue;
                        }
                        if (StringUtils.startsWith(zbxmc, "互混率粒")) { //互混率
                            sql_update += "qzhhkl="+zklsl+",";
                            continue;
                        }
                        if (StringUtils.startsWith(zbxmc, "生霉粒") || StringUtils.startsWith(zbxmc, "霉变粒")) { //互混率
                            sql_update += "qzsmlkl="+zklsl+",";
                            continue;
                        }
                        if (StringUtils.startsWith(zbxmc, "整精米率") ) { //整精米粒扣量
                            sql_update += "qzzjmlkl="+zklsl+",";
                            continue;
                        }
                        if (StringUtils.startsWith(zbxmc, "谷外糙米") ) { //谷外糙米
                            sql_update += "qzgwcmkl="+zklsl+",";
                            continue;
                        }
                        if (StringUtils.startsWith(zbxmc, "黄粒米") ) { //黄粒米
                            sql_update += "qzhlmkl="+zklsl+",";
                            continue;
                        }
                        //不满足所有的扣量，放在其它扣量里面
                        sql_update += "qzqtkl="+zklsl+",";
                    }
                    sql_update +="czbz='u' where id='"+id+"'";
                    if (StringUtils.isNotBlank(sql_update)) {
                         billnonewgjjMapper.executeUpdate(sql_update);
                    }
                }
            }
        }
        return null;
    }

    @Override
    public String deleteYw(String dataId, String tableName) {
        String sql = "";
        if (StringUtils.equals("DATA_CRKYW_RKCM_DEFAULT", tableName.toUpperCase()) ) {
            sql = "update ods_up_lsrkxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where id='"+dataId+"'";
        }
        if (StringUtils.equals("DATA_CRKYW_JSXX_DEFAULT", tableName.toUpperCase()) ) {
            sql = "update ods_up_lsrkjsxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where id='"+dataId+"'";
        }
        if (StringUtils.equals("DATA_CRKYW_JYXX_DEFAULT", tableName.toUpperCase()) ) {
            sql = "update ods_up_lsrkjyxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where id='"+dataId+"'";
        }
        if (StringUtils.equals("DATA_CRKYW_CKCM_DEFAULT", tableName.toUpperCase()) ) {
            sql = "update ods_up_lsckxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where id='"+dataId+"'";
        }
        if(StringUtils.isNotBlank(sql))
            billnonewgjjMapper.executeUpdate(sql);

        return null;
    }
    @Override
    public String deleteYwByBizNo(String bizNo, String tableName) {
        String sql = "";
        if (StringUtils.equals("DATA_CRKYW_RKCM_DEFAULT", tableName.toUpperCase()) ) {
            sql = "update ods_up_lsrkxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where bizNo='"+bizNo+"';";
            billnonewgjjMapper.executeUpdate(sql);
            sql = "update ods_up_lsrkjsxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where bizNo='"+bizNo+"';";
            billnonewgjjMapper.executeUpdate(sql);
            sql = "update ods_up_lsrkjyxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where bizNo='"+bizNo+"';";
            billnonewgjjMapper.executeUpdate(sql);
        }
        if (StringUtils.equals("DATA_CRKYW_CKCM_DEFAULT", tableName.toUpperCase()) ) {
            sql = "update ods_up_lsckxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where bizNo='"+bizNo+"'";
        }
        if (StringUtils.equals("ODS_UP_SYDXXJK_FINAL", tableName.toUpperCase()) ) {
            sql = "update ODS_UP_SYDXXJK_FINAL set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where bddh='"+bizNo+"'";
        }
        if (StringUtils.equals("ODS_UP_SYDXXJK_FINAL", tableName.toUpperCase()) ) {
            sql = "update ods_up_lsxzzbdxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where bddh='"+bizNo+"'";
        }
        if (StringUtils.equals("ods_up_dcxxjk_final", tableName.toUpperCase()) ) {
            sql = "update ods_up_dcxxjk_final set czbz = 'd',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where zycx='"+bizNo+"'";
        }
        billnonewgjjMapper.executeUpdate(sql);
        return null;
    }

    @Override
    public String createRkJyyw(String unitId, String bizNo, String rkywdh) {

        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\" FROM ods_up_lsrkjyxxjk_final where rkywdh = '"+rkywdh+"' ");
        String czbz ="i"; //操作标志
        String sql_del = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_lsrkjyxxjk_final where rkywdh = '"+rkywdh+"';";
            czbz = "u";
        }
        String sql_ins =SqpMapUtil.getSql("GJJ_RKJYYW");
        sql_ins = sql_ins.replace("'rkywdh'", "'"+rkywdh+"'");
        sql_ins = sql_ins.replace("'BizNo'", "'"+bizNo+"'");
        sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        //位编码
        //货位编码直接使用货位表中的hwbm
         billnonewgjjMapper.executeUpdate(sql_del+sql_ins);
        //，化验相关明细
        cerateRjjymx(bizNo, "");

        return null;

    }

    public String cerateRjjymx(String bizNo,String dataId) {
        List<Map<String, Object>> list;
        boolean flag;
        String sql_jymx =SqpMapUtil.getSql("GJJ_RKJYMX");
        if (StringUtils.isNotBlank(dataId)) { //表示传入的是从表主键id，上传时使用
            list = billnonewgjjMapper.findBySql("SELECT DISTINCT  b.bizno as \"bizno\" FROM data_crkyw_jyxx_flt_001 a  JOINleft data_crkyw_jyxx_default b ON B.DATAID = A.MAINDATAID where a.dataid = '"+dataId+"' ");
            if (!list.isEmpty()) {
                bizNo = list.get(0).get("bizno").toString();
            }
        }
        sql_jymx = String.format(sql_jymx, bizNo);
        list = billnonewgjjMapper.findBySql(sql_jymx);
        Double zl = 0.0;
        if (!list.isEmpty()) {
            String sql_update = " update ods_up_lsrkjyxxjk_final set ";
            String jyxm = "";
            String jyz = "";
            String zkj = "";
            String zkl = "";
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = list.get(i);
                String jyxm_ = map.get("jyxm").toString();
                String jyz_ = map.get("jyz").toString();
                String zkj_ = map.get("zkj").toString();
                String zkl_ = map.get("zkl").toString();
                jyxm +=jyxm_+",";
                jyz +=jyz_+",";
                zkj +=zkj_+",";
                zkl +=zkl_+",";
            }
            sql_update +=" jyxm='"+jyxm.substring(0,jyxm.length()-1)+"',jyz='"+jyz.substring(0,jyz.length()-1)+"',zkj='"+zkj.substring(0,zkj.length()-1)+"',zkl='"+zkl.substring(0,zkl.length()-1)+"',";
            sql_update +="czbz='u' where bizno='"+bizNo+"'";
             billnonewgjjMapper.executeUpdate(sql_update);
        }
        return null;
    }

    @Override
    public String createRkJsyw(String unitId, String bizNo, String rkjsdh) {
        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\" FROM ods_up_lsrkjsxxjk_final where bizNo = '"+bizNo+"' ");
        String czbz ="i"; //操作标志
        String sql_del = "";
        String sql_Update = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_lsrkjsxxjk_final where bizNo = '"+bizNo+"';";
            czbz = "u";
        }
        String sql_ins =SqpMapUtil.getSql("GJJ_RKJSYW");
        sql_ins = sql_ins.replace("'rkjsdh'", "'"+rkjsdh+"'");
        sql_ins = sql_ins.replace("'BizNo'", "'"+bizNo+"'");
        sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        //如果状态为i则表示新生成的，可能和入库中的rkjsdh不一致，需要更新入库的rkjsdh
        if ( StringUtils.equals("i", czbz)) {
            sql_Update = "update ods_up_lsrkxxjk_final set rkjsdh='"+rkjsdh+"',czbz = 'u',zhgxsj=DATE_FORMAT("+FunUtils.get_sysdate()+",'%Y-%m-%d %T') where bizNo='"+bizNo+"';";

        }
        //货位编码直接使用货位表中的hwbm
         billnonewgjjMapper.executeUpdate(sql_del+sql_ins+";"+sql_Update);
        return null;

    }

    @Override
    public String createCkyw(String unitId, String bizNo, String ckywdh) {

        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\",ckjsdh as \"ckjsdh\" FROM ods_up_lsckxxjk_final where ckywdh = '"+ckywdh+"' ");
        String czbz ="i"; //操作标志
        String sql_del = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_lsckxxjk_final where ckywdh = '"+ckywdh+"';";
            czbz = "u";
        }else {}
        String sql_ins =SqpMapUtil.getSql("GJJ_CKYW");
        sql_ins = sql_ins.replace("'ckywdh'", "'"+ckywdh+"'");
        sql_ins = sql_ins.replace("'BizNo'", "'"+bizNo+"'");
        sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        //合同号，货位编码
        //合同号使用单位表中的kqbm+htbm拼成
        //货位编码直接使用货位表中的hwbm
         billnonewgjjMapper.executeUpdate(sql_del+sql_ins);
        return null;

    }

    @Override
    public String createDcyw(String unitId, String zycx, String dcdh,boolean isKcdbYc) {

        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\" FROM ods_up_dcxxjk_final where dcdh = '"+dcdh+"' ");
        String czbz ="i"; //操作标志
        String sql_del = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_dcxxjk_final where dcdh = '"+dcdh+"';";
            czbz = "u";
        }
        String sql_ins = "";
        if (!isKcdbYc) {
            sql_ins =SqpMapUtil.getSql("GJJ_DCYW");
            sql_ins = sql_ins.replace("'dcdh'", "'"+dcdh+"'");
            sql_ins = sql_ins.replace("'unitId'", "'"+unitId+"'");
            sql_ins = sql_ins.replace("'zycx'", "'"+zycx+"'");
            sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        }else {
            sql_ins =SqpMapUtil.getSql("GJJ_DCYW_BY_YC");
            sql_ins = sql_ins.replace("'dcdh'", "'"+dcdh+"'");
            sql_ins = sql_ins.replace("'unitId'", "'"+unitId+"'");
            sql_ins = sql_ins.replace("'bddh'", "'"+zycx+"'");
            sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        }
        //位编码
        //货位编码直接使用货位表中的hwbm
         billnonewgjjMapper.executeUpdate(sql_del+sql_ins);

        return null;


    }

    @Override
    public String createXzbdyw(String unitId, String bddh, String lsxzzbdh) {


        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\" FROM ods_up_lsxzzbdxxjk_final where lsxzzbdh = '"+lsxzzbdh+"' ");
        String czbz ="i"; //操作标志
        String sql_del = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_lsxzzbdxxjk_final where lsxzzbdh = '"+lsxzzbdh+"';";
            czbz = "u";
        }
        String sql_ins =SqpMapUtil.getSql("GJJ_XZBDYW");
        sql_ins = sql_ins.replace("'lsxzzbdh'", "'"+lsxzzbdh+"'");
        sql_ins = sql_ins.replace("'bddh'", "'"+bddh+"'");
        sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        //位编码
        //货位编码直接使用货位表中的hwbm
         billnonewgjjMapper.executeUpdate(sql_del+sql_ins);

        return null;
    }

    @Override
    public String createSydyw(String unitId, String bddh, String sydh) {
        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\" FROM ods_up_sydxxjk_final where sydh = '"+sydh+"' ");
        String czbz ="i"; //操作标志
        String sql_del = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_sydxxjk_final where sydh = '"+sydh+"';";
            czbz = "u";
        }
        int number = RandomUtil.randomInt(50000, 100000);
        System.out.println(number);
        String sql_ins =SqpMapUtil.getSql("GJJ_SYDYW");
        sql_ins = sql_ins.replace("'sydh'", "'"+sydh+"'");
        sql_ins = sql_ins.replace("'bddh'", "'"+bddh+"'");
        //针对入库或出库净重为0数，加一个随机数
        sql_ins = sql_ins.replace("syslNumber", ""+number);
        sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        //位编码
        //货位编码直接使用货位表中的hwbm
         billnonewgjjMapper.executeUpdate(sql_del+sql_ins);
        return null;




    }

    @Override
    public String createZmkcyw(String unitId,String zmkcId,String bizno) {
        //查询数据是否存在
        List<Map<String, Object>> list = billnonewgjjMapper.findBySql("SELECT id as \"id\" FROM ods_up_zmkcxxjk_final where bizno = '"+bizno+"' ");
        String czbz ="i"; //操作标志
        String sql_del = "";
        if (!list.isEmpty()) {
            //进行删除操作
            sql_del = "delete from ods_up_zmkcxxjk_final where bizno = '"+bizno+"';";
            czbz = "u";
        }
        String sql_ins =SqpMapUtil.getSql("GJJ_ZMKCYW");
        sql_ins = sql_ins.replace("'zmkcId'", "'"+zmkcId+"'");
        sql_ins = sql_ins.replace("'bizno'", "'"+bizno+"'");
        sql_ins = sql_ins.replace("'czbz'", "'"+czbz+"'");
        //位编码
        //货位编码直接使用货位表中的hwbm
         billnonewgjjMapper.executeUpdate(sql_del+sql_ins);
        return null;
    }


}
