package com.jeesite.modules.mes.web; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.alibaba.fastjson.JSON; import com.jeesite.common.lang.DateUtils; import com.jeesite.common.lang.ObjectUtils; import com.jeesite.common.lang.StringUtils; import com.jeesite.common.utils.excel.ExcelExport; import com.jeesite.modules.mes.entity.*; import com.jeesite.modules.mes.req.MesSearchDateReq; import com.jeesite.modules.mes.service.MesDeviceService; import com.jeesite.modules.mes.service.MesPlanService; import com.jeesite.modules.mes.util.CommonUitl; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.checkerframework.checker.units.qual.A; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.jeesite.common.config.Global; import com.jeesite.common.entity.Page; import com.jeesite.common.web.BaseController; import com.jeesite.modules.mes.service.MesDeviceTimeService; /** * 工位生产时间Controller * @author hzd * @version 2023-08-22 */ @Controller @RequestMapping(value = "${adminPath}/mes/mesDeviceTime") public class MesDeviceTimeController extends BaseController { @Autowired private MesDeviceTimeService mesDeviceTimeService; @Autowired private MesDeviceService mesDeviceService; @Autowired private MesPlanService mesPlanService; /** * 获取数据 */ @ModelAttribute public MesDeviceTime get(String id, boolean isNewRecord) { return mesDeviceTimeService.get(id, isNewRecord); } /** * 查询列表 */ @RequiresPermissions("mes:mesDeviceTime:view") @RequestMapping(value = {"list", ""}) public String list(MesDeviceTime mesDeviceTime, Model model) { MesSearchDateReq dateMap = CommonUitl.getSearchDate(); mesDeviceTime.setStartDate_gte(dateMap.getStartDate()); mesDeviceTime.setStartDate_lte(dateMap.getEndtDate()); model.addAttribute("mesDeviceTime", mesDeviceTime); return "modules/mes/mesDeviceTimeList"; } /** * 查询列表数据 */ @RequiresPermissions("mes:mesDeviceTime:view") @RequestMapping(value = "listData") @ResponseBody public Page listData(MesDeviceTime mesDeviceTime, HttpServletRequest request, HttpServletResponse response) { mesDeviceTime.setPage(new Page<>(request, response)); Page page = mesDeviceTimeService.findPage(mesDeviceTime); return page; } /** * 查看编辑表单 */ @RequiresPermissions("mes:mesDeviceTime:view") @RequestMapping(value = "form") public String form(MesDeviceTime mesDeviceTime, Model model) { model.addAttribute("mesDeviceTime", mesDeviceTime); return "modules/mes/mesDeviceTimeForm"; } /** * 导出数据 */ @RequiresPermissions("mes:mesDeviceTime:view") @RequestMapping(value = "exportData") public void exportData(MesDeviceTime mesDeviceTime, HttpServletResponse response) { List list = mesDeviceTimeService.findList(mesDeviceTime); String fileName = "工位生产时间" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx"; try(ExcelExport ee = new ExcelExport("工位生产时间", MesDeviceTime.class)){ ee.setDataList(list).write(response, fileName); } } /** * 保存数据 */ // @RequiresPermissions("mes:mesDeviceTime:edit") @PostMapping(value = "save") @ResponseBody public String save(@Validated MesDeviceTime mesDeviceTime) { if(StringUtils.isEmpty(mesDeviceTime.getOprno())){ return renderResult(Global.FALSE, text("工位号不能为空!")); } if(StringUtils.isEmpty(mesDeviceTime.getSn())){ return renderResult(Global.FALSE, text("二维码编号不能为空!")); } if(mesDeviceTime.getStartDate() == null){ return renderResult(Global.FALSE, text("开始时间不能为空!")); } MesDeviceTime mesDeviceTime2 = mesDeviceTimeService.getInfoByOprnoAndSn(mesDeviceTime.getOprno(),mesDeviceTime.getSn()); if(mesDeviceTime.getIsNewRecord() && !ObjectUtils.isEmpty(mesDeviceTime2)){ return renderResult(Global.FALSE, text("记录已存在")); } if(mesDeviceTime.getStartDate() != null && mesDeviceTime.getEndDate() != null){ if(mesDeviceTime.getStartDate().getTime() >= mesDeviceTime.getEndDate().getTime()){ return renderResult(Global.FALSE, text("结束时间必须大于开始时间!")); } Integer interval = Math.round((mesDeviceTime.getEndDate().getTime() - mesDeviceTime.getStartDate().getTime())/1000); mesDeviceTime.setInterval(interval); }else{ mesDeviceTime.setInterval(0); } // 获取预计完成时间 MesDevice mesDevice = mesDeviceService.findInfoBySn(mesDeviceTime.getOprno()); if(!ObjectUtils.isEmpty(mesDevice)){ Long time = mesDeviceTime.getStartDate().getTime() + mesDevice.getInterval() * 1000; // 未设置默认为0 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String format = sdf.format(time);// 格式化时间 Date date = null; try { date = sdf.parse(format); } catch (ParseException e) { e.printStackTrace(); } mesDeviceTime.setScheduledDate(date); } mesDeviceTimeService.save(mesDeviceTime); return renderResult(Global.TRUE, text("保存工位生产时间成功!")); } @PostMapping(value = "update") @ResponseBody public String update(MesDeviceTime mesDeviceTime1) { MesDeviceTime mesDeviceTime = mesDeviceTimeService.getInfoByOprnoAndSn(mesDeviceTime1.getOprno(),mesDeviceTime1.getSn()); mesDeviceTime.setEndDate(mesDeviceTime1.getEndDate()); if(mesDeviceTime.getStartDate() != null && mesDeviceTime.getEndDate() != null){ if(mesDeviceTime.getStartDate().getTime() >= mesDeviceTime.getEndDate().getTime()){ return renderResult(Global.FALSE, text("结束时间必须大于开始时间!")); } Integer interval = Math.round((mesDeviceTime.getEndDate().getTime() - mesDeviceTime.getStartDate().getTime())/1000); mesDeviceTime.setInterval(interval); }else{ mesDeviceTime.setInterval(0); } mesDeviceTimeService.save(mesDeviceTime); return renderResult(Global.TRUE, text("保存工位生产时间成功!")); } @RequestMapping(value = {"list2", ""}) public String olist(MesDeviceTime mesDeviceTime, Model model) { model.addAttribute("mesDeviceTime", mesDeviceTime); Map map = mesPlanService.getCurShiftPlan(mesDeviceTime.getOprno(),mesDeviceTime.getProductCate(),""); logger.info("map:"+ JSON.toJSONString(map)); model.addAttribute("map", map); return "modules/mes/mesDeviceTimeList2"; } /** * 查询列表数据 */ @RequestMapping(value = "listData2") @ResponseBody public Page listData2(MesDeviceTime mesDeviceTime, HttpServletRequest request, HttpServletResponse response) { mesDeviceTime.setPage(new Page<>(request, response)); Date edate = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR, -48); // 减去48小时 Date sdate = calendar.getTime(); mesDeviceTime.setStartDate_gte(sdate); mesDeviceTime.setStartDate_lte(edate); Page page = mesDeviceTimeService.findPage(mesDeviceTime); Date curDate = new Date(); for (int i=0;i 0){ }else{ Integer interval = Math.round((curDate.getTime() - page.getList().get(i).getStartDate().getTime())/1000); page.getList().get(i).setInterval(interval); } } return page; } }