package com.miniframe.bisiness.system; import java.util.Map; import com.miniframe.core.ExecProcessFlow; import com.miniframe.core.exception.BusinessException; import com.miniframe.core.ext.UtilTools; import com.miniframe.generate.business.system.model.D10011BaseModel; import com.miniframe.model.system.DPipe; import com.miniframe.model.system.DSensor; import com.miniframe.model.system.DSensorSQLBuilder; import com.miniframe.model.system.dao.DPipeMapper; import com.miniframe.model.system.dao.DSensorMapper; /** * 基础系统,“传感器数据添加修改”逻辑处理(重新生成不覆盖)。 */ public class D10011Service extends D10011BaseModel implements ExecProcessFlow { private static final long serialVersionUID = -7051358269847459502L; /** * 基础系统,“传感器数据添加修改”业务核心处理 */ public void transExecute() throws Exception { Integer seid =this.getA_d10011().getSeid(); Integer pid =this.getA_d10011().getPid(); double site =this.getA_d10011().getSite(); String type =this.getA_d10011().getType(); DPipeMapper pipeMapper =UtilTools.getBean(DPipeMapper.class); DPipe pipe = pipeMapper.selectByPrimaryKey(pid); if(pipe==null){ throw new BusinessException("EB3100015"); } String pname =pipe.getName(); DSensorMapper sensorMapper = UtilTools.getBean(DSensorMapper.class); if(seid==null||seid<=0){//添加 pdPidSiteType(pid, (float) site, type, sensorMapper); DSensor s =new DSensor(); s.setPid(pid); s.setSite((float)site); s.setType(type); s.setPname(pname); sensorMapper.insertSelective(s); }else{ DSensor s = sensorMapper.selectByPrimaryKey(seid); if (s == null) { throw new BusinessException("EB3100008"); } pdPidSiteTypeBySeid(pid, (float) site, type,seid, sensorMapper); s.setPid(pid); s.setSite((float)site); s.setType(type); s.setPname(pname); sensorMapper.updateByPrimaryKey(s); } } private void pdPidSiteTypeBySeid(Integer pid, float site, String type,Integer seid, DSensorMapper sensorMapper) throws BusinessException { DSensorSQLBuilder sb =new DSensorSQLBuilder(); DSensorSQLBuilder.Criteria sc =sb.createCriteria(); sc.andPidEqualTo(pid); sc.andSiteEqualTo(site); sc.andTypeEqualTo(type); sc.andIdNotEqualTo(seid); int count = sensorMapper.selectCountByExample(sb); if(count>0){ throw new BusinessException("EB3100007"); } } private void pdPidSiteType(Integer pid, float site, String type, DSensorMapper sensorMapper) throws BusinessException { DSensorSQLBuilder sb =new DSensorSQLBuilder(); DSensorSQLBuilder.Criteria sc =sb.createCriteria(); sc.andPidEqualTo(pid); sc.andSiteEqualTo(site); sc.andTypeEqualTo(type); int count = sensorMapper.selectCountByExample(sb); if(count>0){ throw new BusinessException("EB3100007"); } } /** * 基础系统,“传感器数据添加修改”业务前处理 */ 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(); } }