package com.shlanbao.tzsc.pms.md.eqpStopMaintain.controller; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import com.shlanbao.tzsc.base.mapping.*; import com.shlanbao.tzsc.base.model.Combobox; import com.shlanbao.tzsc.init.BaseParams; import com.shlanbao.tzsc.pms.sch.workorder.service.WorkOrderServiceI; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.google.gson.Gson; import com.shlanbao.tzsc.base.controller.BaseController; import com.shlanbao.tzsc.base.model.DataGrid; import com.shlanbao.tzsc.base.model.Json; import com.shlanbao.tzsc.pms.md.FilterCount.SchFilterCountBean; import com.shlanbao.tzsc.pms.md.eqpStopMaintain.EqpStopMaintainBean; import com.shlanbao.tzsc.pms.md.eqpStopMaintain.service.EqpStopMaintainServiceI; @Controller @RequestMapping("/pms/stopmaintain") public class StopMaintainController extends BaseController{ @Autowired public EqpStopMaintainServiceI eqpStopMaintainServiceI; @Autowired private WorkOrderServiceI workOrderService; @ResponseBody @RequestMapping("/getStopMaintain") public DataGrid getStopMaintain(EqpStopMaintainBean eqpStopMaintainBean){ try { return eqpStopMaintainServiceI.getAllStopMaintain(eqpStopMaintainBean); } catch (Exception e) { log.error("查询异常", e); } return null; } @RequestMapping("/goToStopMaintainAddJsp") public String goToStopMaintainAddJsp(){ return "/pms/md/stopMaintain/eqpStopMaintainAdd"; } @RequestMapping("/goToStopMaintainBatchAddJsp") public String goToStopMaintainBatchAddJsp(){ return "/pms/md/stopMaintain/eqpStopMaintainBatchAdd"; } @ResponseBody @RequestMapping("/addStopMaintain") public Json addStopMaintain(EqpStopMaintainBean eqpStopMaintainBean){ Json json=new Json(); try { eqpStopMaintainServiceI.addStopMaintain(eqpStopMaintainBean); json.setMsg("新增成功!"); json.setSuccess(true); } catch (Exception e) { log.error(message, e); json.setMsg("新增失败!"); json.setSuccess(false); } return json; } @ResponseBody @RequestMapping("/addStopMaintainBatch") public Json addStopMaintainBatch(EqpStopMaintainBean eqpStopMaintainBean){ Json json=new Json(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); String [] eqps = eqpStopMaintainBean.getEqpId().split(","); String [] shifts = eqpStopMaintainBean.getShiftId().split(","); String [] contents = eqpStopMaintainBean.getContent().split(","); Date sDate = null; Date eDate = null; try { sDate = simpleDateFormat.parse(eqpStopMaintainBean.getActualDate()); eDate = simpleDateFormat.parse(eqpStopMaintainBean.getActualDateEnd()); } catch (ParseException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } Calendar c = Calendar.getInstance(); while(sDate.getTime()<=eDate.getTime()) { eqpStopMaintainBean.setActualDate(simpleDateFormat.format(sDate)); for (String eqp : eqps) { eqpStopMaintainBean.setEqpId(eqp); for(String shift : shifts) { eqpStopMaintainBean.setShiftId(shift); SchCalendar schCalendar = workOrderService.queryTeamByDateShift(eqpStopMaintainBean.getActualDate(),shift); // SchWorkorder workOrder = workOrderService.findWorkOrderByDateShiftEqp(eqpStopMaintainBean.getActualDate(),shift,eqpStopMaintainBean.getEqpId()); if (schCalendar != null){ eqpStopMaintainBean.setTeamId(schCalendar.getMdTeam().getId()); for (String content : contents) { eqpStopMaintainBean.setContent(content); try { eqpStopMaintainServiceI.addStopMaintain(eqpStopMaintainBean); json.setMsg("新增成功!"); json.setSuccess(true); } catch (Exception e) { log.error(message, e); json.setMsg("新增失败!"); json.setSuccess(false); } } } } } c.setTime(sDate); c.add(Calendar.DAY_OF_MONTH, 1); //利用Calendar 实现 Date日期+1天 sDate = c.getTime(); } return json; } @RequestMapping("/goToStopMaintainEditJsp") public String goToStopMaintainEditJsp(HttpServletRequest request,String id){ try { request.setAttribute("eqpStopMaintainBean", eqpStopMaintainServiceI.getStopMaintainById(id)); } catch (Exception e) { log.error("获取ID:"+id+"的数据失败", e); } return "pms/md/stopMaintain/eqpStopMaintainEdit"; } @ResponseBody @RequestMapping("/editStopMaintain") public Json editStopMaintain(EqpStopMaintainBean eqpStopMaintainBean){ Json json=new Json(); try { eqpStopMaintainServiceI.editStopMaintain(eqpStopMaintainBean); json.setMsg("编辑成功!"); json.setSuccess(true); } catch (Exception e) { log.error(message, e); json.setMsg("编辑失败!"); } return json; } @ResponseBody @RequestMapping("/deleteStopMaintain") public Json deleteStopMaintain(String id){ Json json=new Json(); try { eqpStopMaintainServiceI.deleteStopMaintain(id); json.setMsg("删除成功!"); json.setSuccess(true); } catch (Exception e) { log.error(message, e); json.setMsg("删除失败!"); } return json; } @ResponseBody @RequestMapping("/deleteStopMaintainBatch") public Json deleteStopMaintainBatch(String ids){ Json json=new Json(); String [] idStrings = ids.split(","); try { for (String id : idStrings) { eqpStopMaintainServiceI.deleteStopMaintain(id); } json.setMsg("删除成功!"); json.setSuccess(true); } catch (Exception e) { log.error(message, e); json.setMsg("删除失败!"); } return json; } @ResponseBody @RequestMapping("/enableStopMaintainBatch") public Json enableStopMaintainBatch(String ids,int enable){ Json json=new Json(); String [] idStrings = ids.split(","); try { for (String id : idStrings) { eqpStopMaintainServiceI.enableStopMaintain(id,enable); } json.setMsg("修改成功!"); json.setSuccess(true); } catch (Exception e) { log.error(message, e); json.setMsg("修改失败!"); } return json; } @ResponseBody @RequestMapping("/getEqp") public String getEqpl(HttpServletRequest request,HttpSession session,String type)throws Exception{ String typeName = ""; List typeBeans = BaseParams.getEqpCategoryCombobox(false); for (Combobox bean : typeBeans){ if (bean.getId().equals(type)){ typeName = bean.getName(); } } List list= null; if (typeName.equals("包装机组")){ list = BaseParams.getAllPackersCombobox(false); } else if(typeName.equals("卷接机组")){ list = BaseParams.getAllRollersCombobox(false); } else if(typeName.equals("封箱机组")){ list = BaseParams.getAllBoxersCombobox(false); } else if(typeName.equals("成型机组")){ list = BaseParams.getAllFiltersCombobox(false); } else if(typeName.equals("发射机组")){ list = BaseParams.getAllTransmCombobox(false); } Gson gson=new Gson(); String json = gson.toJson(list); //返回到前台 return json; } @ResponseBody @RequestMapping("/getEqpty") public String getEqpty(HttpServletRequest request,HttpSession session)throws Exception{ List list = BaseParams.getTeamCombobox(false); Gson gson=new Gson(); String json = gson.toJson(list); //返回到前台 return json; } }