package com.shlanbao.tzsc.pms.equ.fix.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
|
import com.shlanbao.tzsc.utils.tools.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.shlanbao.tzsc.base.dao.EqmFixRecDaoI;
|
import com.shlanbao.tzsc.base.mapping.EqmFixRec;
|
import com.shlanbao.tzsc.base.mapping.MdEquipment;
|
import com.shlanbao.tzsc.base.mapping.MdShift;
|
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.model.SessionInfo;
|
import com.shlanbao.tzsc.base.service.BaseService;
|
import com.shlanbao.tzsc.pms.equ.fix.beans.EqmFixRecBean;
|
import com.shlanbao.tzsc.pms.equ.fix.service.EqmFixRecServiceI;
|
|
@Service
|
public class EqmFixRecServiceImpl extends BaseService implements EqmFixRecServiceI{
|
@Autowired
|
protected EqmFixRecDaoI eqmFixDao;
|
|
@Override
|
public void addFixRec(EqmFixRecBean eqmFixRecBean) throws Exception {
|
if(StringUtil.notNull(eqmFixRecBean.getId())){
|
String hql = "from EqmFixRec where id = ? ";
|
List<Object> params = new ArrayList<Object>();
|
params.add(eqmFixRecBean.getId());
|
EqmFixRec fixRec = eqmFixDao.unique(EqmFixRec.class, hql, params);
|
if(null!=fixRec){
|
fixRec.setEqp_id(new MdEquipment(eqmFixRecBean.getEquipId()));//设备
|
fixRec.setShift_id(new MdShift(eqmFixRecBean.getShiftId()));//班次
|
//fixRec.setFixtype(eqmFixRecBean.getFixtype());//维修类型
|
fixRec.setMaintaiin_type(new Long(eqmFixRecBean.getFixtype()).intValue());
|
fixRec.setRemark(eqmFixRecBean.getRemark());//备注
|
if(null!=eqmFixRecBean.getAppointUsrId()&&!"".equals(eqmFixRecBean.getAppointUsrId())){
|
fixRec.setMaintaiin_id(eqmFixRecBean.getAppointUsrId());//维修人
|
fixRec.setStatus(2);//状态 新增是 0 或 空 , 运行是 1 ,完成 2
|
fixRec.setCreate_user_time(new Date());//创建时间
|
}
|
}
|
}else{
|
//新增
|
EqmFixRec fixRec = BeanConvertor.copyProperties(eqmFixRecBean, EqmFixRec.class ) ;
|
fixRec.setAsk_date(new Date());//请求时间
|
fixRec.setEqp_id(new MdEquipment(eqmFixRecBean.getEquipId()));//设备
|
SessionInfo sessionInfo = (SessionInfo) WebContextUtil.getObjectFromSession();//设置请求用户
|
fixRec.setAsk_userId(sessionInfo.getUser().getId());
|
|
fixRec.setShift_id(new MdShift(eqmFixRecBean.getShiftId()));//班次
|
//fixRec.setShift_id(eqmFixRecBean.getShiftId());
|
//fixRec.setId(null);
|
fixRec.setStatus(0);//状态 新增是 0 或 空 , 运行是 1 ,完成 2
|
if(null!=eqmFixRecBean.getAppointUsrId()&&!"".equals(eqmFixRecBean.getAppointUsrId())){
|
fixRec.setMaintaiin_id(eqmFixRecBean.getAppointUsrId());
|
fixRec.setMaintaiin_time(new Date());
|
}
|
eqmFixDao.save(fixRec);
|
}
|
//eqmFixDao.saveOrUpdate(fixRec);
|
}
|
|
@Override
|
|
public EqmFixRecBean getFixRecById(String id) throws Exception {
|
EqmFixRec fixRec= eqmFixDao.findById(EqmFixRec.class,id);
|
EqmFixRecBean recBean=BeanConvertor.copyProperties(fixRec, EqmFixRecBean.class);
|
MdEquipment mdEquipment=fixRec.getEqp_id();
|
recBean.setEquipId(mdEquipment.getId());
|
recBean.setEquipName(mdEquipment.getEquipmentName());
|
MdShift shift=fixRec.getShift_id();
|
recBean.setShiftId(shift.getId());
|
recBean.setShiftName(shift.getName());
|
if(null!=fixRec.getMaintaiin_id()){
|
// recBean.setAppointUsrId(fixRec.getAppointUsr().getId());
|
// recBean.setAppointUsrName(fixRec.getAppointUsr().getName());
|
recBean.setAppointUsrId(fixRec.getMaintaiin_id());
|
recBean.setAppointUsrName(fixRec.getMaintaiin_name());
|
}
|
return recBean;
|
}
|
/**
|
* 备件跟换记录查询
|
* 2015-09-30
|
* shisihai
|
*/
|
@Override
|
public DataGrid queryFixRec(EqmFixRecBean eqmFixRecBean, PageParams pageParams)throws Exception {
|
int page=pageParams.getPage();
|
int row=pageParams.getRows();
|
Integer leng=0;
|
StringBuffer count=this.getSql(eqmFixRecBean, 0);
|
List<?> l=eqmFixDao.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<Object[]> ls=(List<Object[]>) eqmFixDao.queryBySql(sb.toString());
|
List<EqmFixRecBean> beans=new ArrayList<EqmFixRecBean>();
|
EqmFixRecBean bean =null;
|
for (Object[] o : ls) {
|
try {
|
bean=new EqmFixRecBean();
|
if(o[1]!=null){
|
bean.setId(o[1].toString());
|
}
|
if(o[2]!=null||o[10]!=null){
|
bean.setEquipName(o[2]==null?o[10].toString():o[2].toString());
|
}
|
if(o[3]!=null||o[11]!=null){
|
bean.setShiftName(o[3]==null?o[11].toString():o[3].toString());
|
}
|
if(o[4]!=null){
|
bean.setBjName(o[4].toString());
|
}
|
if(o[5]!=null){
|
bean.setBjCode(o[5].toString());
|
}
|
if(o[6]!=null){
|
bean.setBjNum(o[6].toString());
|
}
|
if(o[7]!=null){
|
bean.setFixtim(o[7].toString());
|
}
|
if(o[8]!=null){
|
bean.setGhName(o[8].toString());
|
}
|
if(o[9]!=null){
|
bean.setFixtype(Long.parseLong(o[9].toString()));//更换备件的来源 1-点检 2-维修呼叫 3-轮保 4-备品备件 5、检修
|
}
|
beans.add(bean);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
return new DataGrid(beans, (long)leng);
|
}
|
|
@LogAnno(operateType = "删除备品备件更换记录")
|
@Override
|
public void deleteFixRec(String id) throws Exception {
|
List list = new ArrayList<>();
|
list.add(id);
|
eqmFixDao.updateBySql("delete from EQP_SPARE_PARTS where id = ?",list);
|
}
|
@LogAnno(operateType = "批量删除备品备件更换记录")
|
@Override
|
public void batchDeleteFixRec(String ids) {
|
String[] split = ids.split(",");
|
try {
|
for (int i = 0; i < split.length; i++) {
|
List list = new ArrayList<>();
|
list.add(split[i]);
|
eqmFixDao.updateBySql("delete from EQP_SPARE_PARTS where id = ?",list);
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
*
|
* @param eqmFixRecBean
|
* @param type 1 查信息 其余查条数
|
* @return
|
*/
|
private StringBuffer getSql(EqmFixRecBean 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,d.equipment_name,e.name,"
|
+" a.SPARE_PARTS_NAME,a.SPARE_PARTS_CODE,a.SPARE_PARTS_NUM,"
|
+" a.REPAIR_DATE,a.MAINTAIIN_NAME,b.type,b.eqp_name,b.shift_name"
|
+" from EQP_SPARE_PARTS a "
|
+" LEFT JOIN EQM_WHEEL_COVEL_PLAN b ON A .EWCP_ID = b.ID"
|
+" left join EQP_REQUEST_RECORD f on a.eqp_rr_id = f.id "
|
+" LEFT JOIN MD_EQUIPMENT D ON f.eqp_id = D.ID"
|
+" LEFT JOIN MD_SHIFT E ON f.shift = E.ID where 1=1 ");
|
|
|
|
if(StringUtil.notNull(eqmFixRecBean.getReqtim())){
|
sb.append(" and to_char(a.REPAIR_DATE,'yyyy-MM-dd') >='" +eqmFixRecBean.getReqtim()+ "'");
|
}
|
//完成时间2
|
if(StringUtil.notNull(eqmFixRecBean.getRestim())){
|
sb.append(" and to_char(a.REPAIR_DATE,'yyyy-MM-dd') <= '" +eqmFixRecBean.getRestim()+ "'");
|
}
|
|
//设备id
|
if(StringUtil.notNull(eqmFixRecBean.getEquipId())){
|
sb.append( " and d.id= '" +eqmFixRecBean.getEquipId()+ "'");
|
}
|
//班次
|
if(StringUtil.notNull(eqmFixRecBean.getShiftId())){
|
sb.append(" and e.id='" +eqmFixRecBean.getShiftId()+ "'");
|
}
|
/*//维修类型 0 电器和 机械 1
|
if(eqmFixRecBean.getFixtype()!=null){
|
sb.append( " and b.TYPE=" +eqmFixRecBean.getFixtype());
|
}*/
|
sb.append(" order by a.REPAIR_DATE ) t where 1=1 ");
|
return sb;
|
}
|
|
}
|