| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- package com.jeesite.modules.mes.web;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.jeesite.common.lang.StringUtils;
- import com.jeesite.modules.mes.entity.*;
- import com.jeesite.modules.mes.resp.BindMaterialResp;
- import com.jeesite.modules.mes.resp.ParamsResp;
- import com.jeesite.modules.mes.service.*;
- import com.jeesite.modules.mes.util.CommonUitl;
- import com.jeesite.modules.utils.DateLocalUtils;
- import org.apache.shiro.authz.annotation.RequiresPermissions;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.ui.Model;
- import org.springframework.util.ObjectUtils;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import com.jeesite.common.config.Global;
- import com.jeesite.common.collect.ListUtils;
- import com.jeesite.common.entity.Page;
- import com.jeesite.common.lang.DateUtils;
- import com.jeesite.common.utils.excel.ExcelExport;
- import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
- import org.springframework.web.multipart.MultipartFile;
- import com.jeesite.common.web.BaseController;
- /**
- * 电批过程参数Controller
- * @author mes
- * @version 2024-05-12
- */
- @Controller
- @RequestMapping(value = "${adminPath}/mes/mesElectricTorque")
- public class MesElectricTorqueController extends BaseController {
- @Autowired
- private MesElectricTorqueService mesElectricTorqueService;
- @Autowired
- private MesElectricTorqueInfoService mesElectricTorqueInfoService;
- @Autowired
- private MesProductRecordService mesProductRecordService;
- @Autowired
- private MesLineProcessMaterialService mesLineProcessMaterialService;
- @Autowired
- private MesMaterialPrebindService mesMaterialPrebindService;
- @Autowired
- private MesToolLifeService mesToolLifeService;
- @Autowired
- private MesProductOprnoService mesProductOprnoService;
- /**
- * 获取数据
- */
- @ModelAttribute
- public MesElectricTorque get(String id, boolean isNewRecord) {
- return mesElectricTorqueService.get(id, isNewRecord);
- }
- /**
- * 查询列表
- */
- @RequestMapping(value = {"list", ""})
- public String list(MesElectricTorque mesElectricTorque, Model model) {
- model.addAttribute("mesElectricTorque", mesElectricTorque);
- // MesElectricTorque mesElectricTorque1 = new MesElectricTorque();
- // mesElectricTorque.setBatchId(mesElectricTorque.getBatchId());
- // MesElectricTorque mlInfo = mesElectricTorqueService.get(mesElectricTorque);
- // model.addAttribute("mlInfo", mlInfo);
- return "modules/mes/mesElectricTorqueList";
- }
- /**
- * 查询列表数据
- */
- @RequestMapping(value = "listData")
- @ResponseBody
- public Page<MesElectricTorque> listData(MesElectricTorque mesElectricTorque, HttpServletRequest request, HttpServletResponse response) {
- mesElectricTorque.setPage(new Page<>(request, response));
- Page<MesElectricTorque> page = mesElectricTorqueService.findPage(mesElectricTorque);
- return page;
- }
- /**
- * 查看编辑表单
- */
- @RequestMapping(value = "form")
- public String form(MesElectricTorque mesElectricTorque, Model model) {
- model.addAttribute("mesElectricTorque", mesElectricTorque);
- return "modules/mes/mesElectricTorqueForm";
- }
- /**
- * 保存数据
- */
- @PostMapping(value = "save")
- @ResponseBody
- public String save(@Validated MesElectricTorque mesElectricTorque) {
- mesElectricTorqueService.save(mesElectricTorque);
- return renderResult(Global.TRUE, text("保存电批过程参数成功!"));
- }
- /**
- * 导出数据
- */
- @RequestMapping(value = "exportData")
- public void exportData(MesElectricTorque mesElectricTorque, HttpServletResponse response) {
- List<MesElectricTorque> list = mesElectricTorqueService.findList(mesElectricTorque);
- String fileName = "电批过程参数" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
- try(ExcelExport ee = new ExcelExport("电批过程参数", MesElectricTorque.class)){
- ee.setDataList(list).write(response, fileName);
- }
- }
- /**
- * 下载模板
- */
- @RequestMapping(value = "importTemplate")
- public void importTemplate(HttpServletResponse response) {
- MesElectricTorque mesElectricTorque = new MesElectricTorque();
- List<MesElectricTorque> list = ListUtils.newArrayList(mesElectricTorque);
- String fileName = "电批过程参数模板.xlsx";
- try(ExcelExport ee = new ExcelExport("电批过程参数", MesElectricTorque.class, Type.IMPORT)){
- ee.setDataList(list).write(response, fileName);
- }
- }
- /**
- * 导入数据
- */
- @ResponseBody
- @PostMapping(value = "importData")
- public String importData(MultipartFile file) {
- try {
- String message = mesElectricTorqueService.importData(file);
- return renderResult(Global.TRUE, "posfull:"+message);
- } catch (Exception ex) {
- return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
- }
- }
- /**
- * 删除数据
- */
- @RequestMapping(value = "delete")
- @ResponseBody
- public String delete(MesElectricTorque mesElectricTorque) {
- mesElectricTorqueService.delete(mesElectricTorque);
- return renderResult(Global.TRUE, text("删除电批过程参数成功!"));
- }
- /**
- * 电批扭力参数批量上传
- */
- @RequestMapping(value = "batchSave")
- @ResponseBody
- @Transactional
- public String batchSave(@RequestBody MesElectricTorque mesElectricTorque) {
- if (mesElectricTorque == null
- || ("").equals(mesElectricTorque.getOprno())
- || ("").equals(mesElectricTorque.getLineSn())){
- return renderResult(Global.FALSE, text("操作失败!缺少参数值!"));
- }
- //创建时间
- Date createDate = DateLocalUtils.getCurrentTimeReturnDate();
- List<MesElectricTorque> list = mesElectricTorque.getData();
- //一级表扭力过程参数批次表生成
- MesElectricTorqueInfo mesElectricTorqueInfo = new MesElectricTorqueInfo();
- mesElectricTorqueInfo.setSn(mesElectricTorque.getSn());
- mesElectricTorqueInfo.setOprno(mesElectricTorque.getOprno());
- mesElectricTorqueInfo.setLineSn(mesElectricTorque.getLineSn());
- mesElectricTorqueInfo.setCreateDate(createDate);
- mesElectricTorqueInfo.setCount(list == null || list.isEmpty() ? 0 : list.size());
- mesElectricTorqueInfo.setBatch(DateLocalUtils.generateBatch());
- mesElectricTorqueInfoService.save(mesElectricTorqueInfo);
- if (list!= null && list.size() > 0){
- for (MesElectricTorque dtl : list) {
- MesElectricTorque extend = new MesElectricTorque();
- extend.setSn(mesElectricTorque.getSn());
- extend.setOprno(mesElectricTorque.getOprno());
- extend.setLineSn(mesElectricTorque.getLineSn());
- extend.setNumber(dtl.getNumber());
- extend.setTask(dtl.getTask());
- extend.setElapsedTime(dtl.getElapsedTime());
- extend.setTorsion(dtl.getTorsion());
- extend.setResult(dtl.getResult());
- extend.setCreateDate(createDate);
- extend.setBatchId(mesElectricTorqueInfo.getId());
- mesElectricTorqueService.save(extend);
- }
- }
- if(mesElectricTorque.getOprno().equals("OP060")){
- List<String> crafts = new ArrayList<>();
- crafts.add("400008");
- List<BindMaterialResp> bmlists = mesLineProcessMaterialService.getBindMaterial(mesElectricTorque.getOprno(), mesElectricTorque.getLineSn());
- // 更新绑定的物料
- if(!ListUtils.isEmpty(bmlists)){
- for (BindMaterialResp bindMaterialResp:bmlists){
- if(!StringUtils.isEmpty(bindMaterialResp.getBatchSn())){
- Integer lastTimes = Integer.valueOf(bindMaterialResp.getLastTimes());
- if(lastTimes >= 1){ // 更新数量
- if(crafts.contains(bindMaterialResp.getCraft())){
- MesMaterialPrebind mesMaterialPrebind = bindMaterialResp.getMesMaterialPrebind();
- mesMaterialPrebind.setLastTimes(lastTimes - 1);
- mesMaterialPrebindService.update(mesMaterialPrebind);
- }
- }
- }
- }
- }
- // 更新批头寿命
- List<MesToolLife> tools = mesToolLifeService.getToolLifeList(mesElectricTorque.getOprno(),mesElectricTorque.getLineSn());
- if(!ListUtils.isEmpty(tools)){
- for (MesToolLife mesToolLife:tools){
- Integer curLife = mesToolLife.getCurLife() - mesToolLife.getConsumeLife();
- curLife = curLife > 0?curLife:0;
- mesToolLife.setCurLife(curLife);
- mesToolLifeService.update(mesToolLife);
- }
- }
- }
- String newOprno = CommonUitl.formatOprno(mesElectricTorque.getOprno());
- // 如果其他电批枪的结果都不为UDF,则更新总结果
- if("OP310".equals(newOprno)) {
- List<ParamsResp> params = new ArrayList<>();
- ParamsResp paramsResp1 = new ParamsResp();
- paramsResp1.setCraft("400001");
- paramsResp1.setResult("OK");
- paramsResp1.setVal("");
- params.add(paramsResp1);
- MesProductOprno mesProductOprno = new MesProductOprno();
- mesProductOprno.setSn(mesElectricTorque.getSn());
- mesProductOprno.setOprno(newOprno);
- mesProductOprno.setLineSn("XT");
- MesProductOprno mesProductOprno1 = mesProductOprnoService.findInfo(mesProductOprno);
- System.out.println(mesProductOprno1);
- if(ObjectUtils.isEmpty(mesProductOprno1)){
- //添加子工位表
- mesProductOprnoService.save(mesProductOprno);
- mesProductOprno1 = mesProductOprnoService.findInfo(mesProductOprno);
- }
- mesProductOprno1.setResult2("OK");
- mesProductOprnoService.save(mesProductOprno1);
- // 全有结果
- if(mesProductOprno1.getResult1()!=null && !StringUtils.isEmpty(mesProductOprno1.getResult1()) && mesProductOprno1.getResult2()!=null && !StringUtils.isEmpty(mesProductOprno1.getResult2())) {
- String lastRet = "NG";
- if (mesProductOprno1.getResult1().equals("OK") && mesProductOprno1.getResult2().equals("OK")) {
- lastRet = "OK";
- }
- // 2.判断物料批次是否符合绑定
- List<BindMaterialResp> bmlists = mesLineProcessMaterialService.getBindMaterial(mesElectricTorque.getOprno(), "XT");
- // 总结果产线要求写死“OK”
- mesProductRecordService.updateRecordResult(mesElectricTorque.getSn(), "OP310", "100000", "", lastRet, "System", params, "XT", true, bmlists);
- }
- }
- return renderResult(Global.TRUE, text("操作成功!"));
- }
- /**
- * 检验是否合格
- */
- @RequestMapping(value = "check")
- @ResponseBody
- public String check(@RequestBody MesElectricTorque mesElectricTorque) {
- String oprno = mesElectricTorque.getOprno();
- String lineSn = mesElectricTorque.getLineSn();
- String sn = mesElectricTorque.getSn();
- if ("".equals(oprno) || "".equals(lineSn) || "".equals(sn)){
- return renderResult(Global.FALSE, text("操作失败,缺少参数值!"));
- }
- return renderResult(Global.TRUE, text("删除电批过程参数成功!"));
- }
- }
|