package com.shlanbao.tzsc.pms.equ.trouble.service.impl; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.shlanbao.tzsc.base.dao.EqmFixRecDaoI; import com.shlanbao.tzsc.base.dao.EqmTroubleDaoI; import com.shlanbao.tzsc.base.dao.EqmTroubleReDaoI; import com.shlanbao.tzsc.base.interceptor.WorkOrderStatChangeInterceptor; import com.shlanbao.tzsc.base.mapping.EqmFixRec; import com.shlanbao.tzsc.base.mapping.EqmTrouble; 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.trouble.beans.EqmTroubleBean; import com.shlanbao.tzsc.pms.equ.trouble.beans.EqmTroubleInfoBean; import com.shlanbao.tzsc.pms.equ.trouble.beans.TroubleBean; import com.shlanbao.tzsc.pms.equ.trouble.service.TroubleServiceI; import com.shlanbao.tzsc.utils.tools.StringUtil; @Service public class TroubleServiceImpl extends BaseService implements TroubleServiceI { @Autowired private EqmTroubleDaoI troubleDao; @Autowired private EqmTroubleReDaoI eqmtroubleDaoI; @Autowired private EqmFixRecDaoI eqmFixRecDao; @Override public DataGrid queryTrouble(TroubleBean bean, PageParams pageParams) throws Exception { StringBuffer sqlBuffer=new StringBuffer(); sqlBuffer.append("from EqmTrouble t where 1=1 "); if(StringUtil.notNull(bean.getStartDate())){ sqlBuffer.append("and to_char(t.create_time,'yyyy-MM-dd')>='"+bean.getStartDate()+"' "); } if(StringUtil.notNull(bean.getEndDate())){ sqlBuffer.append("and to_char(t.create_time,'yyyy-MM-dd')<='"+bean.getEndDate()+"' "); } if(StringUtil.notNull(bean.getEqu_id())){ sqlBuffer.append("and t.EQU_ID='"+bean.getEqu_id()+"' "); } if(StringUtil.notNull(bean.getShift_id())){ sqlBuffer.append("and t.SHIFT_ID='"+bean.getShift_id()+"' "); } sqlBuffer.append("order by t.create_time desc "); List lists=troubleDao.query(sqlBuffer.toString()); long total=troubleDao.queryTotal("select count(*) "+sqlBuffer.toString()); return new DataGrid(lists,total); } @Override public DataGrid queryTrouble(EqmTroubleBean eqmtroubleBean, PageParams pageParams) throws Exception { /*StringBuilder hql=new StringBuilder(); hql.append(" from EqmTrouble t where 1=1 and t.del='0' "); if(StringUtil.notNull(eqmtroubleBean.getMdWorkshopId()) ) hql.append(" and t.mdEquipment.mdWorkshop.id='"+eqmtroubleBean.getMdWorkshopId()+"' "); if(StringUtil.notNull(eqmtroubleBean.getMdEqpCategoryId())) hql.append(" and t.mdEquipment.mdEqpType.mdEqpCategory.id='"+eqmtroubleBean.getMdEqpCategoryId()+"' "); if(StringUtil.notNull(eqmtroubleBean.getMdEqpTypeId())) hql.append(" and t.mdEquipment.mdEqpType.id='"+eqmtroubleBean.getMdEqpTypeId()+"' "); if(StringUtil.notNull(eqmtroubleBean.getMdEquipmentId())) hql.append(" and t.mdEquipment.id='"+eqmtroubleBean.getMdEquipmentId()+"' "); if(StringUtil.notNull(eqmtroubleBean.getMdShiftId())) hql.append(" and t.mdShift.id='"+eqmtroubleBean.getMdShiftId()+"' "); hql.append(StringUtil.fmtDateBetweenParams("t.fault_date", eqmtroubleBean.getRuntime(), eqmtroubleBean.getEndtime())); List troubles=eqmtroubleDaoI.queryByPage(hql.toString(), pageParams); List eqmTroubleBeans=new ArrayList(); for (EqmTrouble eqmTrouble : troubles) { EqmTroubleBean bean=BeanConvertor.copyProperties(eqmTrouble, EqmTroubleBean.class); if(eqmTrouble.getMdShift()!=null){ bean.setMdShiftId(eqmTrouble.getMdShift().getId()); bean.setMdShiftName(eqmTrouble.getMdShift().getName()); } if(eqmTrouble.getMdEquipment()!=null){ bean.setMdEquipmentId(eqmTrouble.getMdEquipment().getId()); bean.setMdEquipmentName(eqmTrouble.getMdEquipment().getEquipmentName()); } bean.setFaultDate(DateUtil.formatDateToString(eqmTrouble.getFault_date(),"yyyy-MM-dd")); eqmTroubleBeans.add(bean); } long total=eqmtroubleDaoI.queryTotal("select count(*) "+hql.toString()); return new DataGrid(eqmTroubleBeans, total);*/ return null; } /** * 张璐 * 设备信息表查询--测试用 * @return */ @Override public List queryTroubleInfo(EqmTroubleInfoBean troubleBean){ /*StringBuffer sb=new StringBuffer(); sb.append("SELECT et.id,et.md_eqp_type_id,et.trouble_part_description,et.part_code_description,et.trouble_phenomenon_description,et.trouble_reason_description,et.trouble_code,et.trouble_phenomenon,et.trouble_reason from EQM_TROUBLE_INFO et where 1=1 "); if(StringUtil.notNull(troubleBean.getTroubleName())){ sb.append(" and et.trouble_reason_description='"+troubleBean.getTroubleName()+"'"); } List list = eqmtroubleDaoI.queryBySql(sb.toString()); List listBean = new ArrayList(); if(list.size()>0){ for(Object b:list){ Object[]temp = (Object[]) b; EqmTroubleInfoBean bean = new EqmTroubleInfoBean(); bean.setId(temp[0].toString()); if(null!=temp[1]){ bean.setEqp_DES(temp[1].toString()); } bean.setTrouble_part_description(temp[2].toString()); bean.setPart_code_description(temp[3].toString()); bean.setTrouble_phenomenon_description(temp[4].toString()); bean.setTrouble_reason_description(temp[5].toString()); bean.setTrouble_code(temp[6].toString()); bean.setTrouble_phenomenon((int) temp[7]); bean.setTrouble_reason(temp[8].toString()); listBean.add(bean); } } return listBean;*/ StringBuffer sb=new StringBuffer(1000); sb.append("SELECT id,code,description,type,parent_id from EQM_TROUBLE_INFO where 1=1 "); if(StringUtil.notNull(troubleBean.getParent_id())){ sb.append(" and parent_id='"+troubleBean.getParent_id()+"'"); } sb.append(" ORDER BY type"); List list = eqmtroubleDaoI.queryBySql(sb.toString()); List listBean = new ArrayList(); if(list.size()>0){ for(Object b:list){ Object[]temp = (Object[]) b; EqmTroubleInfoBean bean = new EqmTroubleInfoBean(); bean.setId(temp[0].toString()); bean.setCode(temp[1].toString()); bean.setDescription(temp[2].toString()); bean.setType(temp[3].toString()); if(temp[4]!=null){ bean.setParent_id(temp[4].toString()); } listBean.add(bean); } } return listBean; } /**张璐2015-10-30 * 用于添加新的故障信息 * @param des--故障描述 * @param fiveCode--本级代码 * @param pid--父节点 */ @Override public void addNewTrouble(String des,String fiveCode,String pid,String id){ StringBuffer sb=new StringBuffer(1000); sb.append("INSERT into EQM_TROUBLE_INFO VALUES('"+id+"','"+fiveCode+"','"+des+"',5,'"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"','"+pid+"')"); eqmtroubleDaoI.updateBySql(sb.toString(), null); } /** * 删除新添加的故障 * 张璐 */ @Override public void deleteNewTrouble(String id){ StringBuffer sb=new StringBuffer(1000); sb.append("DELETE from EQM_TROUBLE_INFO where id='"+id+"' "); eqmtroubleDaoI.updateBySql(sb.toString(), null); } @Override public void dasSendTrouble(String ids) { ids=ids.replaceAll(",", "','"); StringBuffer hqlbuffer=new StringBuffer(1000); hqlbuffer.append("from EqmTrouble where 1=1 and status=1 and id in ('"+ids+"')"); List eqmtlist=troubleDao.query(hqlbuffer.toString());//通过ids查询维修记录表 hqlbuffer.setLength(0); hqlbuffer.append("from EqmFixRec where 1=1 and eqmtrouble_id in ('"+ids+"') ");//通过ids查询备品备件更换记录表 List eqmfrlist=eqmFixRecDao.query(hqlbuffer.toString()); //调用封装XML方法 try { WorkOrderStatChangeInterceptor.getInstance().dasSendEquipmentRepairRecord(eqmtlist,eqmfrlist); } catch (Exception e) { log.info("设备维修记录反馈异常!"); e.printStackTrace(); } } }