package com.steerinfo.ems.emsgmpcjh.controller; import com.alibaba.fastjson.JSON; import com.steerinfo.auth.utils.JwtUtil; import com.steerinfo.ems.Utils.DateUtils; import com.steerinfo.ems.Utils.ExcelToolUtils; import com.steerinfo.ems.Utils.WebSocket; import com.steerinfo.ems.emsgmpcjh.mapper.EmsGmPcJhMapper; import com.steerinfo.ems.emsgmpcjh.model.EmsGmPcJh; import com.steerinfo.ems.emsgmpcjh.service.IEmsGmPcJhService; import com.steerinfo.ems.emsprodplanweightadjustment.mapper.EmsProdplanWeightAdjustmentMapper; import com.steerinfo.ems.emsprodplanweightadjustment.model.EmsProdplanWeightAdjustment; import com.steerinfo.framework.controller.BaseRESTfulController; import com.steerinfo.framework.controller.RESTfulResult; import com.steerinfo.framework.service.pagehelper.PageList; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.math.BigDecimal; import java.util.Date; import java.util.HashMap; import java.util.Map; /** * EmsGmPcJh RESTful接口: * @author generator * @version 1.0-SNAPSHORT 2021-09-10 07:00 * 类描述 * 修订历史: * 日期:2021-09-10 * 作者:generator * 参考: * 描述:EmsGmPcJh RESTful接口 * @see null * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved. */ @RestController @RequestMapping("/${api.version}/emsgmpcjhs") public class EmsGmPcJhController extends BaseRESTfulController { private static final String AT2005 = "G-G1-"; private static final String AT2006 = "G-G2-"; private static final String AT2004 = "G-L1-"; private static final String AT2007 = "G-X1-"; @Autowired IEmsGmPcJhService emsGmPcJhService; @Autowired EmsGmPcJhMapper emsGmPcJhMapper; @Autowired private WebSocket webSocket; @Autowired EmsProdplanWeightAdjustmentMapper emsProdplanWeightAdjustmentMapper; @ApiOperation(value="获取列表", notes="分页查询") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer") }) //@RequiresPermissions("emsgmpcjh:view") @GetMapping(value = "/") public RESTfulResult list(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){ if(parmas.get("grades") != null && !parmas.get("grades").toString().isEmpty()){ String grades = parmas.get("grades").toString(); if(!grades.startsWith("'")){ grades = "'" + grades.replaceAll(",", "','").replaceAll(",", "','") + "'"; } parmas.put("grades", grades); } if(parmas.get("specifications") != null && !parmas.get("specifications").toString().isEmpty()){ String grades = parmas.get("specifications").toString(); if(!grades.startsWith("'")){ grades = "'" + grades.replaceAll(",", "','").replaceAll(",", "','") + "'"; } parmas.put("specifications", grades); } if(parmas.get("lengthTimesWidth") != null && !parmas.get("lengthTimesWidth").toString().isEmpty()){ String grades = parmas.get("lengthTimesWidth").toString(); if(!grades.startsWith("'")){ grades = "'" + grades.replaceAll(",", "','").replaceAll(",", "','") + "'"; } parmas.put("lengthTimesWidth", grades); } PageList list = emsGmPcJhService.queryForPage(parmas, pageNum, pageSize); return success(list); } @ApiOperation(value="获取列表", notes="分页模糊查询") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer") }) //@RequiresPermissions("emsgmpcjh:view") @GetMapping(value = "/like/") public RESTfulResult listLike(@RequestParam HashMap parmas,Integer pageNum, Integer pageSize){ PageList list = emsGmPcJhService.queryLikeForPage(parmas, pageNum, pageSize); return success(list); } @ApiOperation(value="创建", notes="根据EmsGmPcJh对象创建GM计划") @ApiImplicitParam(name = "emsGmPcJh", value = "详细实体emsGmPcJh", required = true, dataType = "EmsGmPcJh") //@RequiresPermissions("emsgmpcjh:create") @PostMapping(value = "/") public RESTfulResult add(@RequestBody EmsGmPcJh model){ String userId = JwtUtil.getUseridByToken(); String yyyymmdd = DateUtils.dateStr(model.getJhTime(), "yyyyMMdd"); model.setStartTime(yyyymmdd); model.setType(this.getType(model)); String maxid = emsGmPcJhService.getMaxid(model); model.setId(maxid); model.setKxfWeight(model.getPlanWeight()); model.setYxfWeight(new BigDecimal("0")); model.setCreateTime(new Date()); model.setCreateMan(userId); EmsGmPcJh emsGmPcJh = emsGmPcJhService.add(model); EmsProdplanWeightAdjustment emsProdplanWeightAdjustment = new EmsProdplanWeightAdjustment(); emsProdplanWeightAdjustment.setId(model.getId()); emsProdplanWeightAdjustment.setAuditStatus("0"); emsProdplanWeightAdjustment.setPlanWeight(model.getPlanWeight()); emsProdplanWeightAdjustment.setPlanWeightOld(model.getPlanWeight()); emsProdplanWeightAdjustmentMapper.insert(emsProdplanWeightAdjustment); return success(emsGmPcJh); } @ApiOperation(value="创建", notes="根据EmsGmPcJh对象创建GM计划") @ApiImplicitParam(name = "emsGmPcJh", value = "详细实体emsGmPcJh", required = true, dataType = "EmsGmPcJh") //@RequiresPermissions("emsgmpcjh:create") @PostMapping(value = "/addNbJH") public RESTfulResult addNbJH(@RequestBody EmsGmPcJh model){ String userId = JwtUtil.getUseridByToken(); String yyyymmdd = DateUtils.dateStr(model.getJhTime(), "yyyyMMdd"); model.setStartTime(yyyymmdd); model.setType(this.getNbJH(model)); String maxid = emsGmPcJhService.getMaxid(model); model.setId(maxid); model.setPlanWeight(model.getPlanWeight() == null ? new BigDecimal("0"): model.getPlanWeight()); model.setKxfWeight(model.getPlanWeight() == null ? new BigDecimal("0"): model.getPlanWeight()); model.setYxfWeight(new BigDecimal("0")); model.setCreateTime(new Date()); model.setState("2"); model.setCreateMan(userId); EmsGmPcJh emsGmPcJh = emsGmPcJhService.add(model); return success(emsGmPcJh); } @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息") @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String") //@RequiresPermissions("emsgmpcjh:view") @GetMapping(value = "/{id}") public RESTfulResult get(@PathVariable String id){ EmsGmPcJh emsGmPcJh = emsGmPcJhService.getById(id); return success(emsGmPcJh); } @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsGmPcJh信息来更新详细信息") @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"), @ApiImplicitParam(name = "emsGmPcJh", value = "详细实体emsGmPcJh", required = true, dataType = "EmsGmPcJh") }) //@RequiresPermissions("emsgmpcjh:update") @PutMapping(value = "/batchupdate", produces = "application/json;charset=UTF-8") public RESTfulResult update(@RequestBody EmsGmPcJh[] models){ String userId = JwtUtil.getUseridByToken(); for (EmsGmPcJh model : models) { EmsGmPcJh emsGmPcJh = this.emsGmPcJhMapper.selectByPrimaryKey(model.getId()); if(emsGmPcJh.getState().equals("2")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经下发"); } if (emsGmPcJh.getState().equals("1")) { return failed(model, "操作失败,计划号为:" + model.getId() + "正在审核"); } if (emsGmPcJh.getState().equals("3")) { return failed(model, "操作失败,计划号为:" + model.getId() + "已接收"); } model.setYxfWeight(new BigDecimal("0")); model.setKxfWeight(model.getPlanWeight()); model.setUpdateMan(userId); model.setUpdateTime(new Date()); EmsProdplanWeightAdjustment emsProdplanWeightAdjustment = emsProdplanWeightAdjustmentMapper.selectByPrimaryKey(model.getId()); emsProdplanWeightAdjustment.setPlanWeight(model.getPlanWeight()); emsProdplanWeightAdjustment.setPlanWeightOld(model.getPlanWeight()); emsGmPcJhMapper.updateByPrimaryKey(model); emsProdplanWeightAdjustmentMapper.updateByPrimaryKey(emsProdplanWeightAdjustment); } return success(); } @ApiOperation(value="删除", notes="根据url的id来指定删除对象") @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String") //@RequiresPermissions("emsgmpcjh:delete") @DeleteMapping(value = "/delete",produces = "application/json;charset=UTF-8")//String public RESTfulResult delete(@RequestBody EmsGmPcJh[] models){ for (EmsGmPcJh model : models) { EmsGmPcJh emsGmPcJh = this.emsGmPcJhMapper.selectByPrimaryKey(model.getId()); if(emsGmPcJh.getState().equals("2")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经下发"); } if (model.getState().equals("1")) { return failed(null,"计划号为:"+model.getId()+"正在审核"); } if (model.getState().equals("3")) { return failed(null,"计划号为:"+model.getId()+"已经接收"); } emsGmPcJhMapper.deleteByPrimaryKey(model.getId()); } return success(); } @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsGmPcJh信息来更新详细信息") @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"), @ApiImplicitParam(name = "emsGmPcJh", value = "详细实体emsGmPcJh", required = true, dataType = "EmsGmPcJh") }) //@RequiresPermissions("emsgmpcjh:update") @PutMapping(value = "/updatestate", produces = "application/json;charset=UTF-8") public RESTfulResult updatestate(@RequestBody EmsGmPcJh[] models){ String userId = JwtUtil.getUseridByToken(); String soketMessage="国贸订单编号"; boolean result = false; for (EmsGmPcJh model : models) { EmsGmPcJh emsGmPcJh = this.emsGmPcJhMapper.selectByPrimaryKey(model.getId()); if(emsGmPcJh.getState().equals("2")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经下发"); } if (emsGmPcJh.getState().equals("3")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经接收"); } if (emsGmPcJh.getState().equals("1")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"正在审核"); } if(emsGmPcJh.getState().equals("0")) { result = true; soketMessage+=emsGmPcJh.getId()+","; } model.setYxfWeight(new BigDecimal("0")); model.setKxfWeight(model.getPlanWeight()); model.setUpdateTime(new Date()); model.setUpdateMan(userId); emsGmPcJhService.updateState(model); } if(result){ soketMessage += "已下发,请注意接收"; String[] roles = {"生产部-生产处"}; Map map = new HashMap(); map.put("role",roles); map.put("title","国贸订单下发"); map.put("message",soketMessage); map.put("tips","您好,有新的国贸计划已下发,请注意接收。"); soketMessage= JSON.toJSONString(map); webSocket.sendAllMessage(soketMessage); } return success(); } @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsGmPcJh信息来更新详细信息") @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"), @ApiImplicitParam(name = "emsGmPcJh", value = "详细实体emsGmPcJh", required = true, dataType = "EmsGmPcJh") }) //@RequiresPermissions("emsgmpcjh:update") @PutMapping(value = "/submitaudit", produces = "application/json;charset=UTF-8") public RESTfulResult submitaudit(@RequestBody EmsGmPcJh[] models){ String soketMessage="国贸订单编号"; boolean result = false; String userId = JwtUtil.getUseridByToken(); for (EmsGmPcJh model : models) { EmsGmPcJh emsGmPcJh = this.emsGmPcJhMapper.selectByPrimaryKey(model.getId()); if(emsGmPcJh.getState().equals("2")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经下发"); } if (emsGmPcJh.getState().equals("3")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经接收"); } if (emsGmPcJh.getState().equals("1")) { return failed(null, "操作失败,编号为" + emsGmPcJh.getId() + "正在审核"); } model.setYxfWeight(new BigDecimal("0")); model.setKxfWeight(model.getPlanWeight()); model.setUpdateTime(new Date()); model.setUpdateMan(userId); emsGmPcJhService.updateState(model); result = true; soketMessage+=emsGmPcJh.getId()+","; } if(result){ soketMessage += "已提交审核,请注意接收"; String[] roles = {"国贸-部门领导"}; Map map = new HashMap(); map.put("role",roles); map.put("title","国贸订单审核"); map.put("message",soketMessage); map.put("tips","您好,有新的国贸计划已提交审核,请注意接收。"); soketMessage= JSON.toJSONString(map); webSocket.sendAllMessage(soketMessage); } return success(); } //@RequiresPermissions("emsgmpcjh:update") @PutMapping(value = "/passaudits", produces = "application/json;charset=UTF-8") public RESTfulResult passaudits(@RequestBody EmsGmPcJh[] models){ String soketMessage="国贸订单编号"; boolean result = false; String userId = JwtUtil.getUseridByToken(); for (EmsGmPcJh model : models) { EmsGmPcJh emsGmPcJh = this.emsGmPcJhMapper.selectByPrimaryKey(model.getId()); if(emsGmPcJh.getState().equals("2")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经下发"); } if (emsGmPcJh.getState().equals("3")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经接收"); } model.setUpdateMan(userId); emsGmPcJhService.updateState(model); result = true; soketMessage+=emsGmPcJh.getId()+","; if(result){ soketMessage += "下发,请注意接收"; String[] roles = {"生产部-生产处"}; Map map = new HashMap(); map.put("role",roles); map.put("title","国贸订单下发"); map.put("message",soketMessage); map.put("tips","您好,有新的国贸计划已经下发,请注意接收。"); soketMessage= JSON.toJSONString(map); webSocket.sendAllMessage(soketMessage); } } return success(); } //@RequiresPermissions("emsgmpcjh:update") @PutMapping(value = "/turndown", produces = "application/json;charset=UTF-8") public RESTfulResult turndown(@RequestBody EmsGmPcJh[] models){ String userId = JwtUtil.getUseridByToken(); String soketMessage="国贸订单编号"; boolean result = false; for (EmsGmPcJh model : models) { EmsGmPcJh emsGmPcJh = this.emsGmPcJhMapper.selectByPrimaryKey(model.getId()); if (emsGmPcJh.getState().equals("3")) { return failed(null,"操作失败,编号为"+emsGmPcJh.getId()+"已经接收"); } emsGmPcJhService.updateState(model); result = true; soketMessage+=emsGmPcJh.getId()+","; if(result){ soketMessage += "已被撤回,请注意查看"; String[] roles = {"国贸-业务人员"}; Map map = new HashMap(); map.put("role",roles); map.put("title","国贸订单审核"); map.put("message",soketMessage); map.put("tips","您好,您提交的订单已被撤回,请注意查看。"); soketMessage= JSON.toJSONString(map); webSocket.sendAllMessage(soketMessage); } } return success(); } @ApiOperation(value="获取列表", notes="分页模糊查询") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer") }) @GetMapping("/getGmDates") public RESTfulResult getGmDates(@RequestParam HashMap parmas,Integer pageNum,Integer pageSize){ if(parmas.get("workprocType") != null && !parmas.get("workprocType").toString().isEmpty()){ String workprocType = parmas.get("workprocType").toString(); if(!workprocType.startsWith("'")){ workprocType = "'" + workprocType.replaceAll(",", "','").replaceAll(",", "','") + "'"; } parmas.put("workprocType", workprocType); } PageList> gmPcJhDataForPage = emsGmPcJhService.getGmPcJhDataForPage(parmas, pageNum, pageSize); return success(gmPcJhDataForPage); } @ApiOperation(value="获取列表", notes="分页模糊查询") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer") }) @GetMapping("/getXsDdDate") public RESTfulResult getXsDdDate(@RequestParam HashMap parmas,Integer pageNum,Integer pageSize){ if(parmas.get("workprocType") != null && !parmas.get("workprocType").toString().isEmpty()){ String workprocType = parmas.get("workprocType").toString(); if(!workprocType.startsWith("'")){ workprocType = "'" + workprocType.replaceAll(",", "','").replaceAll(",", "','") + "'"; } parmas.put("workprocType", workprocType); } if(parmas.get("auditStatus") != null && !parmas.get("auditStatus").toString().isEmpty()){ String auditStatus = parmas.get("auditStatus").toString(); if(!auditStatus.startsWith("'")){ auditStatus = "'" + auditStatus.replaceAll(",", "','").replaceAll(",", "','") + "'"; } parmas.put("auditStatus", auditStatus); } PageList> getXsDdDateForPage= emsGmPcJhService.getXsDdDate(parmas, pageNum, pageSize); return success(getXsDdDateForPage); } @ApiOperation(value="获取列表", notes="分页模糊查询") @ApiImplicitParams({ @ApiImplicitParam(name = "pageNum", value = "查询页数", required = false, dataType = "Integer"), @ApiImplicitParam(name = "pageSize", value = "每页记录数", required = false, dataType = "Integer") }) @GetMapping("/getShData") public RESTfulResult getShData(@RequestParam HashMap parmas,Integer pageNum,Integer pageSize){ if(parmas.get("workprocType") != null && !parmas.get("workprocType").toString().isEmpty()){ String workprocType = parmas.get("workprocType").toString(); if(!workprocType.startsWith("'")){ workprocType = "'" + workprocType.replaceAll(",", "','").replaceAll(",", "','") + "'"; } parmas.put("workprocType", workprocType); } PageList> xsShData = emsGmPcJhService.getXsShData(parmas, pageNum, pageSize); return success(xsShData); } @ApiOperation(value="更新详细信息", notes="根据url的id来指定更新对象,并根据传过来的emsGmPcJh信息来更新详细信息") @ApiImplicitParams({ @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "String"), @ApiImplicitParam(name = "emsGmPcJh", value = "详细实体emsGmPcJh", required = true, dataType = "EmsGmPcJh") }) //@RequiresPermissions("emsgmpcjh:update") @PutMapping(value = "/batchcopy", produces = "application/json;charset=UTF-8") public RESTfulResult batchcopy(@RequestBody EmsGmPcJh[] models){ String userId = JwtUtil.getUseridByToken(); for (EmsGmPcJh model : models) { String yyyymmdd = DateUtils.dateStr(model.getJhTime(), "yyyyMMdd"); model.setStartTime(yyyymmdd); model.setType(this.getType(model)); String maxid = emsGmPcJhService.getMaxid(model); model.setId(maxid); model.setState("0"); model.setKxfWeight(model.getPlanWeight()); model.setYxfWeight(new BigDecimal("0")); model.setUpdateTime(null); model.setUpdateMan(null); model.setCreateTime(new Date()); model.setCreateMan(userId); emsGmPcJhService.add(model); } return success(); } /** * @MethodName excelimport * @Author TZH * @Description 导入文件 * @Date 2021/01/12 15:20 **/ @PostMapping(value = "excelimport") public RESTfulResult excelimport(@RequestParam("file") MultipartFile file) throws Exception { RESTfulResult rs= null; try { if(file.isEmpty()){ return failed(null,"上传失败,请选择文件"); } String fileNmae = file.getOriginalFilename(); File files = ExcelToolUtils.multipartFileToFile(file); rs = emsGmPcJhService.insertexcel(files); ExcelToolUtils.delteTempFile(files); } catch (Exception e){ e.printStackTrace(); rs.setCode("500"); rs.setMessage("服务端异常!"); }finally { } return rs; } public String getType (EmsGmPcJh emsGmPcJh){ if (emsGmPcJh.getWorkprocType().equals("AT2004")){ return AT2004; } if(emsGmPcJh.getWorkprocType().equals("AT2005")){ return AT2005; } if (emsGmPcJh.getWorkprocType().equals("AT2006")){ return AT2006; } if (emsGmPcJh.getWorkprocType().equals("AT2007")) { return AT2007; } return null; } public String getNbJH (EmsGmPcJh emsGmPcJh){ if (emsGmPcJh.getWorkprocType().equals("AT2004")){ return "N-L1-"; } if(emsGmPcJh.getWorkprocType().equals("AT2005")){ return "N-G1-"; } if (emsGmPcJh.getWorkprocType().equals("AT2006")){ return "N-G2-"; } if (emsGmPcJh.getWorkprocType().equals("AT2007")) { return "N-X1-"; } return null; } }