package com.shlanbao.tzsc.pms.md.eqpStopMaintain.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import com.shlanbao.tzsc.base.mapping.*;
|
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.EqpStopMaintainDaoI;
|
import com.shlanbao.tzsc.base.model.DataGrid;
|
import com.shlanbao.tzsc.base.service.BaseService;
|
import com.shlanbao.tzsc.pms.md.eqpStopMaintain.EqpStopMaintainBean;
|
import com.shlanbao.tzsc.pms.md.eqpStopMaintain.service.EqpStopMaintainServiceI;
|
import com.shlanbao.tzsc.utils.tools.BeanConvertor;
|
import com.shlanbao.tzsc.utils.tools.DateUtil;
|
import com.shlanbao.tzsc.utils.tools.StringUtil;
|
|
@Service
|
public class EqpStopMaintainServiceImpl extends BaseService implements
|
EqpStopMaintainServiceI {
|
|
@Autowired
|
private EqpStopMaintainDaoI eqpStopMaintainDaoI;
|
|
@Autowired
|
private BaseDaoI<Object> baseDao;
|
|
@Override
|
public DataGrid getAllStopMaintain(EqpStopMaintainBean eqpStopMaintainBean) throws Exception {
|
String hql="from EqpStopMaintain o left join fetch o.mdteam t left join fetch o.mdeqp e join fetch o.mdca s where 1=1";//1 deleted data is not visible
|
String params="";
|
if(StringUtil.notEmpty(eqpStopMaintainBean.getsDate())){
|
params = params.concat(" and to_char(o.actualDate,'yyyy-MM') = '" + eqpStopMaintainBean.getsDate() + "'");
|
}
|
if(StringUtil.notEmpty(eqpStopMaintainBean.getTeamId())){
|
params = params.concat(" and t.code = '" + eqpStopMaintainBean.getTeamId() + "'");
|
}
|
if(StringUtil.notEmpty(eqpStopMaintainBean.getEqptype())){
|
params = params.concat(" and s.id = '" + eqpStopMaintainBean.getEqptype() + "'");
|
}
|
if(StringUtil.notEmpty(eqpStopMaintainBean.getEqpId())){
|
params = params.concat(" and e.id = '" + eqpStopMaintainBean.getEqpId() + "'");
|
}
|
if(StringUtil.notEmpty(eqpStopMaintainBean.getContent())){
|
params = params.concat(" and o.content = '" + eqpStopMaintainBean.getContent() + "'");
|
}
|
|
params = params.concat(" order by to_char(o.actualDate,'yyyy-MM-dd')");
|
|
List<EqpStopMaintain> rows=eqpStopMaintainDaoI.query(hql.concat(params));
|
List<EqpStopMaintainBean> orderBeans = new ArrayList<EqpStopMaintainBean>();
|
|
EqpStopMaintainBean bean = null;
|
try {
|
|
for (EqpStopMaintain eqpStopMaintain : rows) {
|
|
bean = BeanConvertor.copyProperties(eqpStopMaintain, EqpStopMaintainBean.class);
|
String realStim = DateUtil.datetoStr(eqpStopMaintain.getActualDate(), "yyyy-MM-dd");
|
bean.setActualDate(realStim);
|
if (eqpStopMaintain.getMdteam()!=null) {
|
bean.setTeamname(eqpStopMaintain.getMdteam().getName());
|
bean.setTeamId(eqpStopMaintain.getMdteam().getId());
|
}
|
if (eqpStopMaintain.getMdShift()!=null) {
|
bean.setShiftName(eqpStopMaintain.getMdShift().getName());
|
bean.setShiftId(eqpStopMaintain.getMdShift().getId());
|
}
|
if (eqpStopMaintain.getMdeqp()!=null) {
|
bean.setEqpId(eqpStopMaintain.getMdeqp().getId());
|
bean.setEqptype(eqpStopMaintain.getMdeqp().getMdEqpType().getMdEqpCategory().getCode());
|
bean.setEquipment(eqpStopMaintain.getMdeqp().getEquipmentName());
|
}
|
bean.setContent(eqpStopMaintain.getContent());
|
bean.setNum(eqpStopMaintain.getNum());
|
bean.setFree(eqpStopMaintain.getFree());
|
bean.setFree2(eqpStopMaintain.getFree2());
|
bean.setFree1(eqpStopMaintain.getFree1());
|
orderBeans.add(bean);
|
|
bean = null;
|
}
|
return new DataGrid(orderBeans, 0L);
|
|
} catch (Exception e) {
|
|
log.error("POVO转换异常", e);
|
|
}
|
|
return null;
|
|
}
|
|
@Override
|
public void addStopMaintain(EqpStopMaintainBean eqpStopMaintainBean) throws Exception {
|
EqpStopMaintain o = BeanConvertor.copyProperties(eqpStopMaintainBean, EqpStopMaintain.class);
|
|
List<?> shiftId = eqpStopMaintainDaoI.queryBySql("select shift from sch_calendar where to_char(date_,'yyyy-mm-dd') = '"+eqpStopMaintainBean.getActualDate()+"' and team = "+eqpStopMaintainBean.getTeamId()+" and workshop = 1 ");
|
|
|
if (shiftId!=null && shiftId.size()>0) {
|
o.setMdShift(new MdShift(shiftId.get(0).toString()));
|
}
|
|
/*Date abc=DateUtil.strToDate(eqpStopMaintainBean.getActualDate()+" 00:00:00","yyyy-MM-dd HH:mm:ss");
|
o.setActualDate(abc);*/
|
|
o.setMdteam(new MdTeam(eqpStopMaintainBean.getTeamId()));
|
o.setMdeqp(new MdEquipment(eqpStopMaintainBean.getEqpId()));
|
/* String ceh=eqpStopMaintainDaoI.queryBySql("select EQP_TYPE_ID from MD_EQUIPMENT where code = ?", eqpStopMaintainBean.getEqptype()).get(0).toString();
|
o.setMdca(new MdEqpCategory(ceh));*/
|
o.setMdca(new MdEqpCategory(eqpStopMaintainBean.getEqptype()));
|
eqpStopMaintainDaoI.save(o);
|
|
}
|
|
|
|
@Override
|
public void editStopMaintain(EqpStopMaintainBean eqpStopMaintainBean) throws Exception {
|
EqpStopMaintain o = BeanConvertor.copyProperties(eqpStopMaintainBean, EqpStopMaintain.class);
|
List<?> shiftId = eqpStopMaintainDaoI.queryBySql("select shift from sch_calendar where to_char(date_,'yyyy-mm-dd') = '"+eqpStopMaintainBean.getActualDate()+"' and team = "+eqpStopMaintainBean.getTeamId()+" and workshop = 1 ");
|
|
|
if (shiftId!=null && shiftId.size()>0) {
|
o.setMdShift(new MdShift(shiftId.get(0).toString()));
|
}
|
o.setMdteam(new MdTeam(eqpStopMaintainBean.getTeamId()));
|
o.setMdeqp(new MdEquipment(eqpStopMaintainBean.getEqpId()));
|
o.setMdca(new MdEqpCategory(eqpStopMaintainBean.getEqptype()));
|
EqpStopMaintain s;
|
s=o;
|
eqpStopMaintainDaoI.update(s);
|
|
}
|
|
|
@Override
|
public EqpStopMaintainBean getStopMaintainById(String id) throws Exception {
|
/* return BeanConvertor.copyProperties(eqpStopMaintainDaoI.findById(EqpStopMaintain.class, id),EqpStopMaintainBean.class);
|
*/
|
EqpStopMaintain eqpStopMaintain = eqpStopMaintainDaoI.findById(EqpStopMaintain.class, id);
|
|
EqpStopMaintainBean bean = BeanConvertor.copyProperties(eqpStopMaintain, EqpStopMaintainBean.class);
|
bean.setEqptype(eqpStopMaintain.getMdca().getId());
|
bean.setTeamname(eqpStopMaintain.getMdteam().getName());
|
bean.setTeamId(eqpStopMaintain.getMdteam().getId());
|
bean.setEquipment(eqpStopMaintain.getMdeqp().getEquipmentName());
|
bean.setEqpId(eqpStopMaintain.getMdeqp().getId());
|
bean.setFree2(eqpStopMaintain.getMdca().getName());
|
|
return bean;
|
|
}
|
|
@Override
|
public void deleteStopMaintain(String id) throws Exception {
|
eqpStopMaintainDaoI.deleteById(id, EqpStopMaintain.class);
|
|
}
|
|
@Override
|
public void enableStopMaintain(String id,int enable) {
|
List<Object> list = new ArrayList<>();
|
list.add(enable);
|
list.add(id);
|
eqpStopMaintainDaoI.updateBySql("update EQP_STOP_MAINTAIN set free1 = ? where id = ?", list);
|
|
}
|
|
|
|
}
|