|  | @@ -1,16 +1,25 @@
 | 
	
		
			
				|  |  |  package com.miniframe.bisiness.system;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.io.BufferedReader;
 | 
	
		
			
				|  |  | +import java.io.File;
 | 
	
		
			
				|  |  | +import java.io.FileReader;
 | 
	
		
			
				|  |  | +import java.util.ArrayList;
 | 
	
		
			
				|  |  | +import java.util.List;
 | 
	
		
			
				|  |  |  import java.util.Map;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +import com.miniframe.constant.MFConstant;
 | 
	
		
			
				|  |  |  import com.miniframe.core.ExecProcessFlow;
 | 
	
		
			
				|  |  |  import com.miniframe.core.exception.BusinessException;
 | 
	
		
			
				|  |  |  import com.miniframe.core.ext.UtilTools;
 | 
	
		
			
				|  |  |  import com.miniframe.generate.business.system.model.D10021BaseModel;
 | 
	
		
			
				|  |  | -import com.miniframe.model.system.DAccident;
 | 
	
		
			
				|  |  | -import com.miniframe.model.system.DGas;
 | 
	
		
			
				|  |  | -import com.miniframe.model.system.SysFile;
 | 
	
		
			
				|  |  | +import com.miniframe.generate.comm.system.D_D10016_CHVALS_RECODE;
 | 
	
		
			
				|  |  | +import com.miniframe.generate.comm.system.D_D10016_COCODES_RECODE;
 | 
	
		
			
				|  |  | +import com.miniframe.model.system.*;
 | 
	
		
			
				|  |  |  import com.miniframe.model.system.dao.DAccidentMapper;
 | 
	
		
			
				|  |  | +import com.miniframe.model.system.dao.DGasGatherAreaMapper;
 | 
	
		
			
				|  |  |  import com.miniframe.model.system.dao.DGasMapper;
 | 
	
		
			
				|  |  |  import com.miniframe.model.system.dao.SysFileMapper;
 | 
	
		
			
				|  |  | +import com.miniframe.tools.XIFileUtils;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.rmi.CORBA.Util;
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -18,91 +27,179 @@ import javax.rmi.CORBA.Util;
 | 
	
		
			
				|  |  |   * 基础系统,“瓦斯灾源添加修改”逻辑处理(重新生成不覆盖)。
 | 
	
		
			
				|  |  |   */
 | 
	
		
			
				|  |  |  public class D10021Service extends D10021BaseModel implements ExecProcessFlow {
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	private static final long serialVersionUID = -7051358269847459502L;
 | 
	
		
			
				|  |  | -		
 | 
	
		
			
				|  |  | -	/**
 | 
	
		
			
				|  |  | -	 * 基础系统,“瓦斯灾源添加修改”业务核心处理
 | 
	
		
			
				|  |  | - 	 */
 | 
	
		
			
				|  |  | -	public void transExecute() throws Exception {
 | 
	
		
			
				|  |  | -		Integer gid = this.getA_d10021().getGid();
 | 
	
		
			
				|  |  | -		String gfid =this.getA_d10021().getGfid();
 | 
	
		
			
				|  |  | -		String bfid =this.getA_d10021().getBfid();
 | 
	
		
			
				|  |  | -		Integer aid =this.getA_d10021().getAid();
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		SysFileMapper sysFileMapper = UtilTools.getBean(SysFileMapper.class);
 | 
	
		
			
				|  |  | -		SysFile gf = sysFileMapper.selectByPrimaryKey(gfid);
 | 
	
		
			
				|  |  | -		if(gf ==null){
 | 
	
		
			
				|  |  | -			throw  new BusinessException("EB3100020");
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -		SysFile bf =sysFileMapper.selectByPrimaryKey(bfid);
 | 
	
		
			
				|  |  | -		if(bf==null){
 | 
	
		
			
				|  |  | -			throw  new BusinessException("EB3100021");
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		//TODO 解析 边界文件 生成瓦斯积聚区数据
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		DAccidentMapper accidentMapper = UtilTools.getBean(DAccidentMapper.class);
 | 
	
		
			
				|  |  | -		DAccident accident =accidentMapper.selectByPrimaryKey(aid);
 | 
	
		
			
				|  |  | -		if(accident ==null) {
 | 
	
		
			
				|  |  | -			throw  new BusinessException("EB3000002");
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -		DGasMapper gasMapper =UtilTools.getBean(DGasMapper.class);
 | 
	
		
			
				|  |  | -		if(gid==null||gid<=0){//添加
 | 
	
		
			
				|  |  | -			DGas gas =new DGas();
 | 
	
		
			
				|  |  | -			gas.setAid(aid);
 | 
	
		
			
				|  |  | -			gas.setBfid(bfid);
 | 
	
		
			
				|  |  | -			gas.setBfname(bf.getFilename());
 | 
	
		
			
				|  |  | -			gas.setGfid(gfid);
 | 
	
		
			
				|  |  | -			gas.setGfname(gf.getFilename());
 | 
	
		
			
				|  |  | -			gasMapper.insertSelective(gas);
 | 
	
		
			
				|  |  | -		}else{//修改
 | 
	
		
			
				|  |  | -			DGas gas =gasMapper.selectByPrimaryKey(gid);
 | 
	
		
			
				|  |  | -			if(gas ==null){
 | 
	
		
			
				|  |  | -				throw new BusinessException("EB3100022");
 | 
	
		
			
				|  |  | -			}
 | 
	
		
			
				|  |  | -			gas.setAid(aid);
 | 
	
		
			
				|  |  | -			gas.setBfid(bfid);
 | 
	
		
			
				|  |  | -			gas.setBfname(bf.getFilename());
 | 
	
		
			
				|  |  | -			gas.setGfid(gfid);
 | 
	
		
			
				|  |  | -			gas.setGfname(gf.getFilename());
 | 
	
		
			
				|  |  | -			gasMapper.updateByPrimaryKey(gas);
 | 
	
		
			
				|  |  | -		}
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	/**
 | 
	
		
			
				|  |  | -	 * 基础系统,“瓦斯灾源添加修改”业务前处理
 | 
	
		
			
				|  |  | - 	 */
 | 
	
		
			
				|  |  | -	public void preTransFlow() throws Exception {
 | 
	
		
			
				|  |  | -		this.validater();
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	/**
 | 
	
		
			
				|  |  | -	 * 基础系统,“瓦斯灾源添加修改”业务后处理
 | 
	
		
			
				|  |  | - 	 */
 | 
	
		
			
				|  |  | -	public void afterTransFlow() throws Exception {
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | -	
 | 
	
		
			
				|  |  | -	/**
 | 
	
		
			
				|  |  | -	 * 基础系统,“瓦斯灾源添加修改”逻辑入口处理方法
 | 
	
		
			
				|  |  | - 	 */
 | 
	
		
			
				|  |  | - 	@SuppressWarnings("rawtypes")
 | 
	
		
			
				|  |  | -	@Override
 | 
	
		
			
				|  |  | -	public Map execute(Map vars) throws Exception {
 | 
	
		
			
				|  |  | -		this.setTransMap(vars);
 | 
	
		
			
				|  |  | -		preTransFlow();// 执行业务开始的规则检查和校验
 | 
	
		
			
				|  |  | -		transExecute();// 执行核心业务段
 | 
	
		
			
				|  |  | -		afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
 | 
	
		
			
				|  |  | -		return this.getTransMap();
 | 
	
		
			
				|  |  | -	}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private static final long serialVersionUID = -7051358269847459502L;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 基础系统,“瓦斯灾源添加修改”业务核心处理
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public void transExecute() throws Exception {
 | 
	
		
			
				|  |  | +        Integer gid = this.getA_d10021().getGid();
 | 
	
		
			
				|  |  | +        String gfid = this.getA_d10021().getGfid();
 | 
	
		
			
				|  |  | +        String bfid = this.getA_d10021().getBfid();
 | 
	
		
			
				|  |  | +        Integer aid = this.getA_d10021().getAid();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        SysFileMapper sysFileMapper = UtilTools.getBean(SysFileMapper.class);
 | 
	
		
			
				|  |  | +        SysFile gf = sysFileMapper.selectByPrimaryKey(gfid);
 | 
	
		
			
				|  |  | +        if (gf == null) {
 | 
	
		
			
				|  |  | +            throw new BusinessException("EB3100020");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        SysFile bf = sysFileMapper.selectByPrimaryKey(bfid);
 | 
	
		
			
				|  |  | +        if (bf == null) {
 | 
	
		
			
				|  |  | +            throw new BusinessException("EB3100021");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<String> blockNames = readBFile(bf);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        DAccidentMapper accidentMapper = UtilTools.getBean(DAccidentMapper.class);
 | 
	
		
			
				|  |  | +        DAccident accident = accidentMapper.selectByPrimaryKey(aid);
 | 
	
		
			
				|  |  | +        if (accident == null) {
 | 
	
		
			
				|  |  | +            throw new BusinessException("EB3000002");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        DGasGatherAreaMapper areaMapper = UtilTools.getBean(DGasGatherAreaMapper.class);
 | 
	
		
			
				|  |  | +        DGasMapper gasMapper = UtilTools.getBean(DGasMapper.class);
 | 
	
		
			
				|  |  | +        if (gid == null || gid <= 0) {//添加
 | 
	
		
			
				|  |  | +            DGas gas = new DGas();
 | 
	
		
			
				|  |  | +            gas.setAid(aid);
 | 
	
		
			
				|  |  | +            gas.setBfid(bfid);
 | 
	
		
			
				|  |  | +            gas.setBfname(bf.getFilename());
 | 
	
		
			
				|  |  | +            gas.setGfid(gfid);
 | 
	
		
			
				|  |  | +            gas.setGfname(gf.getFilename());
 | 
	
		
			
				|  |  | +            gasMapper.insertSelective(gas);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            DGasSQLBuilder sb = new DGasSQLBuilder();
 | 
	
		
			
				|  |  | +            DGasSQLBuilder.Criteria sc = sb.createCriteria();
 | 
	
		
			
				|  |  | +            sc.andAidEqualTo(aid);
 | 
	
		
			
				|  |  | +            sc.andBfidEqualTo(bfid);
 | 
	
		
			
				|  |  | +            sc.andGfidEqualTo(gfid);
 | 
	
		
			
				|  |  | +            sb.setOrderByClause("id DESC");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            gas = gasMapper.selectOneByExample(sb);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            for (String blockName : blockNames) {
 | 
	
		
			
				|  |  | +                DGasGatherArea area =new DGasGatherArea();
 | 
	
		
			
				|  |  | +                area.setGasdensity(0f);
 | 
	
		
			
				|  |  | +                area.setType("0");
 | 
	
		
			
				|  |  | +                area.setAid(aid);
 | 
	
		
			
				|  |  | +                area.setGid(gid);
 | 
	
		
			
				|  |  | +                area.setName(blockName);
 | 
	
		
			
				|  |  | +                areaMapper.insertSelective(area);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        } else {//修改
 | 
	
		
			
				|  |  | +            DGas gas = gasMapper.selectByPrimaryKey(gid);
 | 
	
		
			
				|  |  | +            if (gas == null) {
 | 
	
		
			
				|  |  | +                throw new BusinessException("EB3100022");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(gas.getBfid()!=bfid){
 | 
	
		
			
				|  |  | +                DGasGatherAreaSQLBuilder ggsb = new DGasGatherAreaSQLBuilder();
 | 
	
		
			
				|  |  | +                DGasGatherAreaSQLBuilder.Criteria ggsc = ggsb.createCriteria();
 | 
	
		
			
				|  |  | +                ggsc.andGidEqualTo(gid);
 | 
	
		
			
				|  |  | +                areaMapper.deleteByExample(ggsb);
 | 
	
		
			
				|  |  | +                for (String blockName : blockNames) {
 | 
	
		
			
				|  |  | +                    DGasGatherArea area =new DGasGatherArea();
 | 
	
		
			
				|  |  | +                    area.setGasdensity(0f);
 | 
	
		
			
				|  |  | +                    area.setType("0");
 | 
	
		
			
				|  |  | +                    area.setAid(aid);
 | 
	
		
			
				|  |  | +                    area.setGid(gid);
 | 
	
		
			
				|  |  | +                    area.setName(blockName);
 | 
	
		
			
				|  |  | +                    areaMapper.insertSelective(area);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            gas.setAid(aid);
 | 
	
		
			
				|  |  | +            gas.setBfid(bfid);
 | 
	
		
			
				|  |  | +            gas.setBfname(bf.getFilename());
 | 
	
		
			
				|  |  | +            gas.setGfid(gfid);
 | 
	
		
			
				|  |  | +            gas.setGfname(gf.getFilename());
 | 
	
		
			
				|  |  | +            gasMapper.updateByPrimaryKey(gas);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    private List<String> readBFile(SysFile bf) throws BusinessException {
 | 
	
		
			
				|  |  | +        //TODO 解析 边界文件 生成瓦斯积聚区数据
 | 
	
		
			
				|  |  | +        File bfFile = new File(XIFileUtils.getRootPathStr() + MFConstant.separator + bf.getFilepath());
 | 
	
		
			
				|  |  | +        List<String> fileStrs = new ArrayList<>();
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            FileReader fileReader = new FileReader(bfFile);
 | 
	
		
			
				|  |  | +            BufferedReader reader = new BufferedReader(fileReader);
 | 
	
		
			
				|  |  | +            String line;
 | 
	
		
			
				|  |  | +            int linNum = 1;
 | 
	
		
			
				|  |  | +            while ((line = reader.readLine()) != null) {
 | 
	
		
			
				|  |  | +                fileStrs.add(line);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            fileReader.close();
 | 
	
		
			
				|  |  | +            reader.close();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (fileStrs.size() <= 3) {
 | 
	
		
			
				|  |  | +                throw new BusinessException("EB3100025");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            boolean isBlockStart = false;
 | 
	
		
			
				|  |  | +            boolean isBlockNumStart = false;
 | 
	
		
			
				|  |  | +            int blockNum = 0;
 | 
	
		
			
				|  |  | +            List<String> blockNames = new ArrayList<>();
 | 
	
		
			
				|  |  | +            for (int i = 3; i < fileStrs.size(); i++) {
 | 
	
		
			
				|  |  | +                if (!isBlockStart) {
 | 
	
		
			
				|  |  | +                    isBlockStart = true;
 | 
	
		
			
				|  |  | +                    blockNames.add(fileStrs.get(i));
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (!isBlockNumStart) {
 | 
	
		
			
				|  |  | +                    blockNum = Integer.valueOf(fileStrs.get(i));
 | 
	
		
			
				|  |  | +                    isBlockNumStart = true;
 | 
	
		
			
				|  |  | +                    continue;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                int dyhang = 0;
 | 
	
		
			
				|  |  | +                for (int j = 0; j < blockNum; j++) {
 | 
	
		
			
				|  |  | +                    String linet = fileStrs.get(i + dyhang + j);
 | 
	
		
			
				|  |  | +                    String[] t = linet.trim().split(" ");
 | 
	
		
			
				|  |  | +                    int last = Integer.valueOf(t[t.length - 1]);
 | 
	
		
			
				|  |  | +                    if (last == -1) {
 | 
	
		
			
				|  |  | +                        ++dyhang;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                i = i + dyhang + blockNum;
 | 
	
		
			
				|  |  | +                isBlockStart = false;
 | 
	
		
			
				|  |  | +                isBlockNumStart = false;
 | 
	
		
			
				|  |  | +                return blockNames;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } catch (Exception e) {
 | 
	
		
			
				|  |  | +            System.out.println(e);
 | 
	
		
			
				|  |  | +            throw new BusinessException("EB3100025");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return null;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 基础系统,“瓦斯灾源添加修改”业务前处理
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public void preTransFlow() throws Exception {
 | 
	
		
			
				|  |  | +        this.validater();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 基础系统,“瓦斯灾源添加修改”业务后处理
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    public void afterTransFlow() throws Exception {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 基础系统,“瓦斯灾源添加修改”逻辑入口处理方法
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    @SuppressWarnings("rawtypes")
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Map execute(Map vars) throws Exception {
 | 
	
		
			
				|  |  | +        this.setTransMap(vars);
 | 
	
		
			
				|  |  | +        preTransFlow();// 执行业务开始的规则检查和校验
 | 
	
		
			
				|  |  | +        transExecute();// 执行核心业务段
 | 
	
		
			
				|  |  | +        afterTransFlow();// 执行核心逻辑完成后的收尾逻辑
 | 
	
		
			
				|  |  | +        return this.getTransMap();
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  }
 |