MesOrderJjllController.java 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. package com.jeesite.modules.mes.web;
  2. import java.math.BigDecimal;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.servlet.http.HttpServletRequest;
  8. import javax.servlet.http.HttpServletResponse;
  9. import org.apache.shiro.authz.annotation.RequiresPermissions;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.Model;
  13. import org.springframework.validation.annotation.Validated;
  14. import org.springframework.web.bind.annotation.ModelAttribute;
  15. import org.springframework.web.bind.annotation.PostMapping;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.ResponseBody;
  18. import com.alibaba.fastjson.JSONObject;
  19. import com.jeesite.common.config.Global;
  20. import com.jeesite.common.collect.ListUtils;
  21. import com.jeesite.common.entity.Page;
  22. import com.jeesite.common.lang.DateUtils;
  23. import com.jeesite.common.lang.StringUtils;
  24. import com.jeesite.common.mybatis.mapper.query.QueryType;
  25. import com.jeesite.common.utils.excel.ExcelExport;
  26. import com.jeesite.common.utils.excel.annotation.ExcelField.Type;
  27. import org.springframework.web.multipart.MultipartFile;
  28. import com.jeesite.common.web.BaseController;
  29. import com.jeesite.modules.erp.entity.MesProductOrder;
  30. import com.jeesite.modules.erp.service.MesProductOrderService;
  31. import com.jeesite.modules.mes.entity.MesMaterialBl;
  32. import com.jeesite.modules.mes.entity.MesOrderJjll;
  33. import com.jeesite.modules.mes.entity.MesProduct;
  34. import com.jeesite.modules.mes.service.MesMaterialBlService;
  35. import com.jeesite.modules.mes.service.MesOrderJjllService;
  36. import com.jeesite.modules.mes.service.MesProductService;
  37. import org.springframework.util.ObjectUtils;
  38. /**
  39. * 机加订单领料工件绑定Controller
  40. * @author sxl
  41. * @version 2026-10-26
  42. */
  43. @Controller
  44. @RequestMapping(value = "${adminPath}/mes/mesOrderJjll")
  45. public class MesOrderJjllController extends BaseController {
  46. @Autowired
  47. private MesOrderJjllService mesOrderJjllService;
  48. @Autowired
  49. private MesProductOrderService mesProductOrderService;
  50. @Autowired
  51. private MesMaterialBlService mesMaterialBlService;
  52. @Autowired
  53. private MesProductService mesProductService;
  54. /**
  55. * 获取数据
  56. */
  57. @ModelAttribute
  58. public MesOrderJjll get(String id, boolean isNewRecord) {
  59. return mesOrderJjllService.get(id, isNewRecord);
  60. }
  61. /**
  62. * 机加订单领料显示列表:
  63. * mes_product_order 中 lineSn 以 B0106 开头;
  64. * 返回订单编号、备料表 erpSn 以 B0110 开头的确认数量合计、MesOrderJjll 绑定记录数;
  65. * 支持 pageNo、pageSize 分页,并在返回 data 中带回。
  66. */
  67. @RequestMapping(value = "orderDisplayList")
  68. @ResponseBody
  69. public String orderDisplayList(HttpServletRequest request, HttpServletResponse response) {
  70. MesProductOrder orderQuery = new MesProductOrder();
  71. orderQuery.getSqlMap().getWhere().and("a.line_sn", QueryType.RIGHT_LIKE, "B0106");
  72. Page<MesProductOrder> page = new Page<>(request, response);
  73. orderQuery.setPage(page);
  74. page = mesProductOrderService.findPage(orderQuery);
  75. List<Map<String, Object>> list = new ArrayList<>();
  76. if (page.getList() != null) {
  77. for (MesProductOrder order : page.getList()) {
  78. if (order == null || StringUtils.isBlank(order.getSn())) {
  79. continue;
  80. }
  81. BigDecimal numsQr = sumBlNumsQrDecimal(order.getSn(), "B0110");
  82. MesOrderJjll jjllQuery = new MesOrderJjll();
  83. jjllQuery.setOrderJj(order.getSn());
  84. long jjllCount = mesOrderJjllService.findCount(jjllQuery);
  85. // 确认数量与已绑定数量相同则不返回
  86. if (BigDecimal.valueOf(jjllCount).compareTo(numsQr) == 0) {
  87. continue;
  88. }
  89. Map<String, Object> item = new HashMap<>();
  90. item.put("orderId", order.getSn());
  91. item.put("numsQr", numsQr.stripTrailingZeros().toPlainString());
  92. item.put("jjllCount", jjllCount);
  93. list.add(item);
  94. }
  95. }
  96. JSONObject resp = new JSONObject();
  97. resp.put("result", Global.TRUE);
  98. resp.put("message", text("查询成功!"));
  99. resp.put("data", list);
  100. resp.put("pageNo", page.getPageNo());
  101. resp.put("pageSize", page.getPageSize());
  102. resp.put("count", page.getCount());
  103. return resp.toJSONString();
  104. }
  105. /**
  106. * 机加订单领料绑定工件码(同一工件码只能绑定一次;已绑定数不能大于备料确认数量)
  107. * 参数:orderJj=机加订单号,sn=工件码
  108. */
  109. @RequestMapping(value = "bandJjllSn")
  110. @ResponseBody
  111. public String bandJjllSn(String orderJj, String sn) {
  112. if (StringUtils.isBlank(orderJj)) {
  113. return renderResult(Global.FALSE, text("机加订单号不能为空!"));
  114. }
  115. if (StringUtils.isBlank(sn)) {
  116. return renderResult(Global.FALSE, text("工件码不能为空!"));
  117. }
  118. orderJj = orderJj.trim();
  119. sn = sn.trim();
  120. MesProduct mesProductQuery = new MesProduct();
  121. mesProductQuery.setSn(sn);
  122. List<MesProduct> productList = mesProductService.findList(mesProductQuery);
  123. if (productList == null || productList.isEmpty() || ObjectUtils.isEmpty(productList.get(0))) {
  124. return renderResult(Global.FALSE, text("工件不存在!"));
  125. }
  126. MesOrderJjll existQuery = new MesOrderJjll();
  127. existQuery.setSn(sn);
  128. if (mesOrderJjllService.findCount(existQuery) > 0) {
  129. return renderResult(Global.FALSE, text("该工件码已绑定机加订单,不允许重复绑定!"));
  130. }
  131. MesProductOrder orderQuery = new MesProductOrder();
  132. orderQuery.setSn(orderJj);
  133. List<MesProductOrder> orderList = mesProductOrderService.findList(orderQuery);
  134. if (orderList == null || orderList.isEmpty() || ObjectUtils.isEmpty(orderList.get(0))) {
  135. return renderResult(Global.FALSE, text("机加订单不存在!"));
  136. }
  137. BigDecimal numsQrTotal = sumBlNumsQrDecimal(orderJj, "B0110");
  138. if (numsQrTotal.compareTo(BigDecimal.ZERO) <= 0) {
  139. return renderResult(Global.FALSE, text("备料确认数量未配置!"));
  140. }
  141. MesOrderJjll boundQuery = new MesOrderJjll();
  142. boundQuery.setOrderJj(orderJj);
  143. long boundCount = mesOrderJjllService.findCount(boundQuery);
  144. if (BigDecimal.valueOf(boundCount).compareTo(numsQrTotal) >= 0) {
  145. return renderResult(Global.FALSE, text("该订单已绑定数量已达备料确认数量,不允许再绑定!"));
  146. }
  147. MesOrderJjll mesOrderJjll = new MesOrderJjll();
  148. mesOrderJjll.setOrderJj(orderJj);
  149. mesOrderJjll.setSn(sn);
  150. mesOrderJjllService.save(mesOrderJjll);
  151. return renderResult(Global.TRUE, text("绑定成功!"));
  152. }
  153. /** 按订单号汇总备料表中 erpSn 以前缀开头的确认数量 */
  154. private String sumBlNumsQrByOrderAndErpPrefix(String orderId, String erpPrefix) {
  155. return sumBlNumsQrDecimal(orderId, erpPrefix).stripTrailingZeros().toPlainString();
  156. }
  157. private BigDecimal sumBlNumsQrDecimal(String orderId, String erpPrefix) {
  158. MesMaterialBl blQuery = new MesMaterialBl();
  159. blQuery.setOrderId(orderId);
  160. blQuery.getSqlMap().getWhere().and("a.erp_sn", QueryType.RIGHT_LIKE, erpPrefix);
  161. List<MesMaterialBl> blList = mesMaterialBlService.findList(blQuery);
  162. BigDecimal total = BigDecimal.ZERO;
  163. if (blList != null) {
  164. for (MesMaterialBl bl : blList) {
  165. if (bl == null || StringUtils.isBlank(bl.getNumsQr())) {
  166. continue;
  167. }
  168. try {
  169. total = total.add(new BigDecimal(bl.getNumsQr().trim()));
  170. } catch (Exception ignore) {
  171. // 非数字确认数量忽略
  172. }
  173. }
  174. }
  175. return total;
  176. }
  177. /**
  178. * 查询列表
  179. */
  180. @RequiresPermissions("mes:mesOrderJjll:view")
  181. @RequestMapping(value = {"list", ""})
  182. public String list(MesOrderJjll mesOrderJjll, Model model) {
  183. model.addAttribute("mesOrderJjll", mesOrderJjll);
  184. return "modules/mes/mesOrderJjllList";
  185. }
  186. /**
  187. * 查询列表数据
  188. */
  189. @RequiresPermissions("mes:mesOrderJjll:view")
  190. @RequestMapping(value = "listData")
  191. @ResponseBody
  192. public Page<MesOrderJjll> listData(MesOrderJjll mesOrderJjll, HttpServletRequest request, HttpServletResponse response) {
  193. mesOrderJjll.setPage(new Page<>(request, response));
  194. Page<MesOrderJjll> page = mesOrderJjllService.findPage(mesOrderJjll);
  195. return page;
  196. }
  197. /**
  198. * 查看编辑表单
  199. */
  200. @RequiresPermissions("mes:mesOrderJjll:view")
  201. @RequestMapping(value = "form")
  202. public String form(MesOrderJjll mesOrderJjll, Model model) {
  203. model.addAttribute("mesOrderJjll", mesOrderJjll);
  204. return "modules/mes/mesOrderJjllForm";
  205. }
  206. /**
  207. * 保存数据
  208. */
  209. @RequiresPermissions("mes:mesOrderJjll:edit")
  210. @PostMapping(value = "save")
  211. @ResponseBody
  212. public String save(@Validated MesOrderJjll mesOrderJjll) {
  213. mesOrderJjllService.save(mesOrderJjll);
  214. return renderResult(Global.TRUE, text("保存机加订单领料工件绑定成功!"));
  215. }
  216. /**
  217. * 导出数据
  218. */
  219. @RequiresPermissions("mes:mesOrderJjll:view")
  220. @RequestMapping(value = "exportData")
  221. public void exportData(MesOrderJjll mesOrderJjll, HttpServletResponse response) {
  222. List<MesOrderJjll> list = mesOrderJjllService.findList(mesOrderJjll);
  223. String fileName = "机加订单领料工件绑定" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
  224. try(ExcelExport ee = new ExcelExport("机加订单领料工件绑定", MesOrderJjll.class)){
  225. ee.setDataList(list).write(response, fileName);
  226. }
  227. }
  228. /**
  229. * 下载模板
  230. */
  231. @RequiresPermissions("mes:mesOrderJjll:view")
  232. @RequestMapping(value = "importTemplate")
  233. public void importTemplate(HttpServletResponse response) {
  234. MesOrderJjll mesOrderJjll = new MesOrderJjll();
  235. List<MesOrderJjll> list = ListUtils.newArrayList(mesOrderJjll);
  236. String fileName = "机加订单领料工件绑定模板.xlsx";
  237. try(ExcelExport ee = new ExcelExport("机加订单领料工件绑定", MesOrderJjll.class, Type.IMPORT)){
  238. ee.setDataList(list).write(response, fileName);
  239. }
  240. }
  241. /**
  242. * 导入数据
  243. */
  244. @ResponseBody
  245. @RequiresPermissions("mes:mesOrderJjll:edit")
  246. @PostMapping(value = "importData")
  247. public String importData(MultipartFile file) {
  248. try {
  249. String message = mesOrderJjllService.importData(file);
  250. return renderResult(Global.TRUE, "posfull:"+message);
  251. } catch (Exception ex) {
  252. return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
  253. }
  254. }
  255. /**
  256. * 删除数据
  257. */
  258. @RequiresPermissions("mes:mesOrderJjll:edit")
  259. @RequestMapping(value = "delete")
  260. @ResponseBody
  261. public String delete(MesOrderJjll mesOrderJjll) {
  262. mesOrderJjllService.delete(mesOrderJjll);
  263. return renderResult(Global.TRUE, text("删除机加订单领料工件绑定成功!"));
  264. }
  265. }