package com.shlanbao.tzsc.pms.equ.lubricate.service.impl; import java.util.ArrayList; import java.util.Date; import java.util.List; import com.shlanbao.tzsc.utils.tools.LogAnno; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.shlanbao.tzsc.base.dao.BaseDaoI; import com.shlanbao.tzsc.base.dao.EqmLubricantDaoI; import com.shlanbao.tzsc.base.mapping.EqmLubricant; import com.shlanbao.tzsc.base.mapping.EqmLubricantPlan; import com.shlanbao.tzsc.base.mapping.EqpLubricantRecord; import com.shlanbao.tzsc.base.mapping.MdEqpCategory; import com.shlanbao.tzsc.base.mapping.MdEqpType; import com.shlanbao.tzsc.base.mapping.MdEquipment; import com.shlanbao.tzsc.base.mapping.SchStatInput; import com.shlanbao.tzsc.base.mapping.SysEqpCategory; import com.shlanbao.tzsc.base.mapping.SysEqpType; import com.shlanbao.tzsc.base.mapping.SysRole; import com.shlanbao.tzsc.base.mapping.SysUser; import com.shlanbao.tzsc.base.model.DataGrid; import com.shlanbao.tzsc.base.model.PageParams; import com.shlanbao.tzsc.base.service.BaseService; import com.shlanbao.tzsc.pms.equ.fix.beans.EqmFixRecBean; import com.shlanbao.tzsc.pms.equ.lubricate.beans.EqmLubricantBean; import com.shlanbao.tzsc.pms.equ.lubricate.service.EqmLubricantServiceI; import com.shlanbao.tzsc.pms.sch.stat.beans.InputBean; import com.shlanbao.tzsc.pms.sys.datadict.beans.SysEqpTypeBean; import com.shlanbao.tzsc.utils.tools.BeanConvertor; import com.shlanbao.tzsc.utils.tools.DateUtil; import com.shlanbao.tzsc.utils.tools.StringUtil; @Service public class EqmLubricantServiceImpl extends BaseService implements EqmLubricantServiceI { @Autowired private EqmLubricantDaoI lubricantDao; @Autowired private BaseDaoI baseDao; //新增 @LogAnno(operateType = "新增设备润滑数据明细") @Override public boolean addBean(EqmLubricant bean) { lubricantDao.save(bean); return true; } //根据Id获取对象 @Override public EqmLubricant getBeanById(String id){ return lubricantDao.findById(EqmLubricant.class, id); } //根据Id获取对象 @Override public EqmLubricantBean getBeanByIds(String id) throws Exception{ EqmLubricant qmLubricant=lubricantDao.findById(EqmLubricant.class, id); EqmLubricantBean bean=BeanConvertor.copyProperties(qmLubricant, EqmLubricantBean.class); bean.setCategoryId(qmLubricant.getSysEqpCategory().getId()); bean.setCategoryName(qmLubricant.getSysEqpCategory().getName()); return bean; } //修改 @LogAnno(operateType = "修改设备润滑数据明细") @Override public boolean updateBean(EqmLubricantBean bean) { EqmLubricant o = lubricantDao.findById(EqmLubricant.class, bean.getId()); o.setNum(bean.getNum()); o.setEquLocation(bean.getEquLocation()); o.setEnable(bean.getEnable()); o.setLubPosition(bean.getLubPosition()); o.setFixedPoints(bean.getFixedPoints()); o.setLubOil(bean.getLubOil()); o.setLubMethod(bean.getLubMethod()); o.setChangeOilDosage(bean.getChangeOilDosage()); o.setChangeOilCycle(bean.getChangeOilCycle()); o.setSpePerson(bean.getSpePerson()); o.setRoleId(bean.getRoleId()); o.setQuaQuantity(bean.getQuaQuantity()); o.setQuaUnit(bean.getQuaUnit()); o.setDes(bean.getDes()); o.setRoleId(bean.getRoleId()); o.setLastUpdateName(bean.getLastUpdateName()); o.setLastUpdateTime(bean.getLastUpdateTime()); o.setShiftId(bean.getShiftId()); return lubricantDao.saveOrUpdate(o); } //查询 @Override public DataGrid searchBean(EqmLubricantBean seachBean,PageParams pageParams) { StringBuffer hql=new StringBuffer(); hql.append("select o.id,o.name,"); hql.append("o.eqp_type.id,"); hql.append("o.eqp_type.name,"); hql.append("o.create_usr.id ,"); hql.append("o.create_usr.name ,"); hql.append("o.cycle,");//周期 hql.append("o.last_time,"); hql.append("o.next_time,"); hql.append("o.create_time,"); hql.append("o.rule_id,"); hql.append("o.rule_name,"); hql.append("o.status, "); hql.append("o.eqp_category.id "); hql.append("from EqmLubricant o where 1=1 "); if(StringUtil.notNull(seachBean.getId())){ hql.append("and o.id='"+seachBean.getId()+"' "); } /*if(StringUtil.notNull(seachBean.getEqp_typeId())){ hql.append("and o.eqp_type.id='"+seachBean.getEqp_typeId()+"' "); } if(seachBean.getStatus()>-1){ hql.append("and o.status='"+seachBean.getStatus()+"' "); }*/ long total=baseDao.query(hql.toString()).size(); //hql.append("order by o.date_p,o.shift.code "); List list=baseDao.queryByPage(hql.toString(), pageParams); List returnList=new ArrayList(); for(Object o:list){ Object[] temp=(Object[]) o; EqmLubricantBean b=new EqmLubricantBean(); b.setId(temp[0].toString()); /*b.setName(temp[1].toString()); b.setEqp_typeId(temp[2].toString()); b.setEqp_typeName(temp[3].toString()); b.setCreate_uId(temp[4].toString()); b.setCreate_uName(temp[5].toString()); b.setCycle(Integer.parseInt(temp[6].toString())); if(temp[7]!=null)b.setLast_time(temp[7].toString()); if(temp[8]!=null)b.setNext_time(temp[8].toString()); if(temp[9]!=null)b.setCreate_time(temp[9].toString()); b.setRuleId(temp[10].toString()); if(temp[11]!=null) b.setRuleName(temp[11].toString()); b.setStatus(Integer.parseInt(temp[12].toString())); b.setEqp_category(temp[13].toString()); returnList.add(b);*/ } return new DataGrid(returnList,total); } //生产润滑计划 public void createLubricantPlan(String lubriId,String eqpId){ EqmLubricant lubri=getBeanById(lubriId); EqmLubricantPlan plan=new EqmLubricantPlan(); plan.setDate_p(new Date()); plan.setEqp(new MdEquipment(eqpId)); /*plan.setLub_id(lubri.getRule_id());*/ plan.setStatus(0); } @Override public List getListBySql(String sql){ return baseDao.queryBySql(sql); } /** * [功能说明]:通过ID,查询润滑详细 * @date 2017年8月30日11:28:42 * @author wanchanghuang * */ @Override public DataGrid queryEqmLubricationById(SysEqpCategory bean, PageParams pageParams) { List beans = new ArrayList(); StringBuffer sb=new StringBuffer(); long total=0; sb.append(" select a.ID,a.NUM,a.EQU_LOCATION,a.LUB_POSITION,a.FIXED_POINTS,a.LUB_OIL,a.LUB_METHOD,a.CHANGE_OILDOSAGE,a.CHANGE_OILCYCLE, "); sb.append(" a.SPE_PERSON,a.QUA_QUANTITY,a.QUA_UNIT,a.DES,a.CREATE_TIME,a.LAST_UPDATE_NAME,b.id as SYS_EC,a.role_id,a.ENABLE,a.SHIFT_ID,a.LAST_UPDATE_TIME from EQM_LUBRICATION a,SYS_EQP_CATEGORY b "); sb.append(" where b.maintainace_type='"+bean.getMaintainaceType()+"' and b.id='"+bean.getId()+"' and a.SYS_EC=b.id "); if(StringUtil.notEmpty(bean.getCode())&&!"4".equals(bean.getCode())){ sb.append(" and a.SHIFT_ID ="+StringUtil.convert2Integer(bean.getCode())+""); } if (StringUtil.notEmpty(bean.getLubPosition())) { sb.append(" and a.lub_position like '%"+bean.getLubPosition()+"%'"); } if (StringUtil.notEmpty(bean.getEquLocation())) { sb.append(" and a.equ_location like '%"+bean.getEquLocation()+"%'"); } if(StringUtil.notNull(bean.getEqpType())){ sb.append(" and b.name like '%"+bean.getEqpType()+"%'"); } if(StringUtil.notNull(bean.getCycleType())){ sb.append(" and b.cycle_type='"+bean.getCycleType()+"' "); } sb.append(" order by a.num asc "); List list= lubricantDao.queryBySql(sb.toString()); if(list!=null && list.size()>0){ EqmLubricantBean eb=null; for(Object o:list){ Object[] temp=(Object[]) o; eb=new EqmLubricantBean(); eb.setId(StringUtil.convertObjToString(temp[0])); eb.setNum(StringUtil.convertObjToString(temp[1])); eb.setEquLocation(StringUtil.convertObjToString(temp[2])); eb.setLubPosition(StringUtil.convertObjToString(temp[3])); eb.setFixedPoints(StringUtil.convertObjToString(temp[4])); eb.setLubOil(StringUtil.convertObjToString(temp[5])); eb.setLubMethod(StringUtil.convertObjToString(temp[6])); eb.setChangeOilDosage(StringUtil.convertObjToString(temp[7])); eb.setChangeOilCycle(StringUtil.convertObjToString(temp[8])); eb.setSpePerson(StringUtil.convertObjToString(temp[9])); eb.setQuaQuantity(StringUtil.convertObjToString(temp[10])); eb.setQuaUnit(StringUtil.convertObjToString(temp[11])); eb.setDes(StringUtil.convertObjToString(temp[12])); eb.setCreateTime(DateUtil.formatStringToDate(temp[13].toString(), "yyyy-MM-dd HH:mm:ss")); eb.setLastUpdateName(StringUtil.convertObjToString(temp[14])); eb.setCategoryId(StringUtil.convertObjToString(temp[15])); eb.setRoleId(StringUtil.convertObjToString(temp[16])); eb.setEnable(StringUtil.convertObjToString(temp[17])); eb.setShiftId(StringUtil.convert2Integer(temp[18])); eb.setLastUpdateTime(temp[19]==null?null:DateUtil.formatStringToDate(temp[19].toString(), "yyyy-MM-dd HH:mm:ss")); beans.add(eb); } } return new DataGrid(beans, total); } @Override public List getRoleAll() { try { String sql="select id,name from SYS_ROLE where del=0"; List list=baseDao.queryBySql(sql); List srlist=new ArrayList(); if(list!=null && list.size()>0){ SysRole sr=null; for(Object o:list){ Object[] temp=(Object[]) o; sr=new SysRole(); sr.setId(StringUtil.convertObjToString(temp[0])); sr.setName(StringUtil.convertObjToString(temp[1])); srlist.add(sr); } } return srlist; } catch (Exception e) { e.printStackTrace(); } return null; } @LogAnno(operateType = "删除设备润滑数据明细") @Override public void deleteLubrCycle(String id) { // sysEqpTypeDao.findById(SysEqpType.class, id).setDel("1"); lubricantDao.deleteById(id, EqmLubricant.class); //.deleteById(id, SysEqpType.class); // comboboxServiceI.initCombobox(ComboboxType.EQPTYPE); } @Override public DataGrid queryLubricantRec(EqpLubricantRecord eqmFixRecBean, PageParams pageParams) { int page=pageParams.getPage(); int row=pageParams.getRows(); Integer leng=0; StringBuffer count=this.getSql(eqmFixRecBean, 0); List l=lubricantDao.queryBySql(count.toString()); if(l!=null && l.size()>0){ leng=Integer.parseInt( l.get(0).toString()) ; } StringBuffer sb=this.getSql(eqmFixRecBean, 1); sb.append(" and t.rownumberf > " +(page-1)*row); sb.append(" and t.rownumberf <= " +page*row); List ls=(List) lubricantDao.queryBySql(sb.toString()); List beans=new ArrayList(); EqpLubricantRecord bean =null; for (Object[] o : ls) { try { bean=new EqpLubricantRecord(); if(o[1]!=null){ bean.setId(o[1].toString()); } if(o[2]!=null){ bean.setGreaser(o[2].toString()); } if(o[3]!=null){ bean.setLubricantName(o[3].toString()); } if(o[4]!=null){ bean.setLubricantCode(o[4].toString()); } if(o[5]!=null){ bean.setLubricantCount(o[5].toString()); } if(o[6]!=null){ bean.setCreateTime_(o[6].toString()); } if(o[7]!=null){ bean.setLubricantTime_(o[7].toString()); } if(o[8]!=null){ bean.setEqp(o[8].toString()); } if(o[9]!=null){ bean.setShift(o[9].toString()); } beans.add(bean); } catch (Exception e) { e.printStackTrace(); } } return new DataGrid(beans, (long)leng); } @Override public void batchDeleteLubrCycle(String ids) { String[] split = ids.split(","); try { for (int i = 0; i < split.length; i++) { lubricantDao.deleteById(split[i], EqmLubricant.class); } }catch (Exception e){ e.printStackTrace(); } } private StringBuffer getSql(EqpLubricantRecord eqmFixRecBean,int type){ StringBuffer sb=null; if(type==1){ sb=new StringBuffer(" SELECT * from "); }else{ sb=new StringBuffer(" select count(0) from "); } sb.append("(select rownum as rownumberf,a.id,a.greaser,a.LUBRICANT_NAME,a.LUBRICANT_CODE," +" a.LUBRICANT_COUNT,a.CREATE_TIME,a.LUBRICANT_TIME,b.EQP_NAME," +" b.SHIFT_NAME from EQP_LUBRICANT_RECORD a join EQM_WHEEL_COVEL_PLAN b" +" on a.EWCP_ID = b.id where 1=1"); if(StringUtil.notNull(eqmFixRecBean.getLubricantTime_())){ sb.append(" and to_char(a.LUBRICANT_TIME,'yyyy-MM-dd') >='" +eqmFixRecBean.getLubricantTime_()+ "'"); } //完成时间2 if(StringUtil.notNull(eqmFixRecBean.getCreateTime_())){ sb.append(" and to_char(a.LUBRICANT_TIME,'yyyy-MM-dd') <= '" +eqmFixRecBean.getCreateTime_()+ "'"); } //设备id if(StringUtil.notNull(eqmFixRecBean.getEqp())){ sb.append( " and b.EQP_ID= '" +eqmFixRecBean.getEqp()+ "'"); } //班次 if(StringUtil.notNull(eqmFixRecBean.getShift())){ sb.append(" and b.SHIFT_ID='" +eqmFixRecBean.getShift()+ "'"); } /*//维修类型 0 电器和 机械 1 if(eqmFixRecBean.getFixtype()!=null){ sb.append( " and b.TYPE=" +eqmFixRecBean.getFixtype()); }*/ sb.append(" order by a.LUBRICANT_TIME ) t where 1=1 "); return sb; } }