春风项目四线(合箱线、总装线)
wujian
2024-08-18 8876c234904459d038a2b282b3fdc30e006f9925
提交 | 用户 | 时间
fd2207 1 package com.jcdm.main.om.productionOrde.controller;
2
8876c2 3 import cn.hutool.core.collection.CollUtil;
W 4 import cn.hutool.core.util.ObjectUtil;
131e8c 5 import cn.hutool.core.util.StrUtil;
7dc046 6 import com.jcdm.common.annotation.Log;
W 7 import com.jcdm.common.core.controller.BaseController;
8 import com.jcdm.common.core.domain.AjaxResult;
9 import com.jcdm.common.core.page.TableDataInfo;
10 import com.jcdm.common.enums.BusinessType;
131e8c 11 import com.jcdm.common.exception.ServiceException;
7dc046 12 import com.jcdm.common.utils.poi.ExcelUtil;
749044 13 import com.jcdm.main.bs.modelNumber.domain.BsModelNumber;
C 14 import com.jcdm.main.bs.modelNumber.service.IBsModelNumberService;
05d425 15 import com.jcdm.main.bs.orderScheduling.domain.BsOrderScheduling;
C 16 import com.jcdm.main.bs.orderScheduling.service.IBsOrderSchedulingService;
fd2207 17 import com.jcdm.main.om.productionOrde.domain.OmProductionOrdeInfo;
18 import com.jcdm.main.om.productionOrde.service.IOmProductionOrdeInfoService;
df1f2b 19 import com.jcdm.main.webservice.service.ReceivingServices;
05d425 20 import org.apache.commons.lang3.StringUtils;
fd2207 21 import org.springframework.beans.factory.annotation.Autowired;
7dc046 22 import org.springframework.security.access.prepost.PreAuthorize;
W 23 import org.springframework.web.bind.annotation.*;
24
25 import javax.servlet.http.HttpServletResponse;
26 import java.time.LocalDateTime;
27 import java.time.format.DateTimeFormatter;
8876c2 28 import java.util.Comparator;
7dc046 29 import java.util.List;
8876c2 30 import java.util.stream.Collectors;
f11989 31
32 import static org.apache.commons.lang3.SystemUtils.getUserName;
fd2207 33
34 /**
35  * 生产工单Controller
36  * 
37  * @author ruimin
38  * @date 2023-12-11
39  */
40 @RestController
41 @RequestMapping("/om/productionOrde")
42 public class OmProductionOrdeInfoController extends BaseController
43 {
44     @Autowired
45     private IOmProductionOrdeInfoService omProductionOrdeInfoService;
05d425 46
C 47     @Autowired
48     private IBsOrderSchedulingService bsOrderSchedulingService;
749044 49
C 50     @Autowired
51     private IBsModelNumberService bsModelNumberService;
fd2207 52
53     /**
54      * 查询生产工单列表
55      */
56     @PreAuthorize("@ss.hasPermi('om:productionOrde:list')")
57     @GetMapping("/list")
58     public TableDataInfo list(OmProductionOrdeInfo omProductionOrdeInfo)
59     {
60         startPage();
61         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
62         return getDataTable(list);
63     }
64
65     /**
66      * 导出生产工单列表
67      */
68     @PreAuthorize("@ss.hasPermi('om:productionOrde:export')")
69     @Log(title = "生产工单", businessType = BusinessType.EXPORT)
70     @PostMapping("/export")
71     public void export(HttpServletResponse response, OmProductionOrdeInfo omProductionOrdeInfo)
72     {
73         List<OmProductionOrdeInfo> list = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
74         ExcelUtil<OmProductionOrdeInfo> util = new ExcelUtil<OmProductionOrdeInfo>(OmProductionOrdeInfo.class);
75         util.exportExcel(response, list, "生产工单数据");
76     }
77
78     /**
79      * 获取生产工单详细信息
80      */
696fd5 81     @PreAuthorize("@ss.hasPermi('om:productionOrde:query')")
Y 82     @GetMapping(value = "/{id}")
83     public AjaxResult getInfo(@PathVariable("id") Long id)
84     {
85         return success(omProductionOrdeInfoService.selectOmProductionOrdeInfoById(id));
86     }
d4f437 87
Y 88     /**
89      * 获取生产工单详细信息
90      */
fd2207 91     @PreAuthorize("@ss.hasPermi('om:productionOrde:query')")
696fd5 92     @GetMapping("/ids/{ids}")
d4f437 93     public AjaxResult getInfo(@PathVariable Long[] ids)
fd2207 94     {
8876c2 95         List<OmProductionOrdeInfo> omProductionOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrderListById(ids);
W 96         if (CollUtil.isNotEmpty(omProductionOrdeInfos)){
97             List<String> collect = omProductionOrdeInfos.stream().map(OmProductionOrdeInfo::getProductCode).distinct().collect(Collectors.toList());
98             if (CollUtil.isNotEmpty(collect)){
99                 if (collect.size()>1){
100                     return error("存在多个不同的产品编号,请检查");
101                 }
102             }
103             List<String> collect1 = omProductionOrdeInfos.stream().map(OmProductionOrdeInfo::getOrderStatus).distinct().collect(Collectors.toList());
104             if (CollUtil.isNotEmpty(collect1)){
105                 if (collect1.size()>1){
106                     return error("存在多个不同的工单状态,请检查");
107                 }
108             }
109         }
d4f437 110         return success(omProductionOrdeInfoService.selectOmProductionOrdeInfoByIds(ids));
fd2207 111     }
112
113     /**
114      * 新增生产工单
115      */
116     @PreAuthorize("@ss.hasPermi('om:productionOrde:add')")
117     @Log(title = "生产工单", businessType = BusinessType.INSERT)
118     @PostMapping
119     public AjaxResult add(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
120     {
121         return toAjax(omProductionOrdeInfoService.insertOmProductionOrdeInfo(omProductionOrdeInfo));
122     }
123
124     /**
e0a2b8 125      * 生成按钮
05d425 126      */
C 127     @PostMapping("/orderSchedulingForBoxCode")
128     public AjaxResult addOrderSchedulingForBoxCode(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
129     {
696fd5 130
64e175 131         //获取当前时间
132         LocalDateTime date= LocalDateTime.now();
133         //创建日期时间对象格式化器,日期格式类似: 2023-05-23 22:18:38
134         DateTimeFormatter formatter= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
135         //将时间转化为对应格式的字符串
136         String fomateDate=date.format(formatter).toString();
749044 137
05d425 138         Integer startCode = Integer.parseInt(omProductionOrdeInfo.getStartCode());//开始编号
696fd5 139
05d425 140         String dateTimeRule = omProductionOrdeInfo.getDateTimeRule();
C 141
8876c2 142         //校验编号重复
W 143         BsModelNumber bsModelNumberCheck = new BsModelNumber();
144         bsModelNumberCheck.setModel(omProductionOrdeInfo.getTypeZ());
145         bsModelNumberCheck.setModelDate(dateTimeRule);
146         List<BsModelNumber> numbers = bsModelNumberService.selectBsModelNumberList(bsModelNumberCheck);
147         BsModelNumber bsModelNumber = new BsModelNumber();
148         Integer maxNum = 0;
149         if (CollUtil.isNotEmpty(numbers)){
150             bsModelNumber = numbers.get(0);
151             String maxnumValue = bsModelNumber.getMaxnumValue();
152             if (StrUtil.isNotBlank(maxnumValue)){
153                 maxNum = Integer.parseInt(maxnumValue);
749044 154             }
8876c2 155         }
W 156         if (startCode<=maxNum){
157             return AjaxResult.error("编号重复,请检查!");
158         }
159         Long[] id=omProductionOrdeInfo.getIdNums();
160         List<OmProductionOrdeInfo> omProductionOrdeInfoList = omProductionOrdeInfoService.selectOmProductionOrderListById(id);
161         if (CollUtil.isNotEmpty(omProductionOrdeInfoList)){
162             omProductionOrdeInfoList.forEach(x -> {
163                 if (ObjectUtil.isNotNull(x.getWorkOrderNo())){
164                     long l = Long.parseLong(x.getWorkOrderNo());
165                     x.setWorkOrderNoLong(l);
166                 }
167             });
168             List<OmProductionOrdeInfo> sortList = omProductionOrdeInfoList.stream().sorted(Comparator.comparing(OmProductionOrdeInfo::getWorkOrderNoLong)).collect(Collectors.toList());
169             for (OmProductionOrdeInfo ProductionOrde : sortList) {
170                 Integer planQty = Math.toIntExact(ProductionOrde.getPlanQty());//计划数量
171                 if(planQty>0) {
172                     for (int i = 0; i < planQty; i++) {
173                         String engineNo = omProductionOrdeInfo.getTypeZ() + " " + dateTimeRule + StringUtils.leftPad(String.valueOf(startCode), 3, "0");
174                         BsOrderScheduling bsOrderScheduling = new BsOrderScheduling();
175                         bsOrderScheduling.setOrderNo(ProductionOrde.getWorkOrderNo());
176                         bsOrderScheduling.setWorkingHours(String.valueOf(i+1));
177                         bsOrderScheduling.setModel(ProductionOrde.getTypeZ());
178                         bsOrderScheduling.setEngineNo(engineNo);
179                         bsOrderScheduling.setProductionStatus("1");
180                         bsOrderScheduling.setOperator(getUserName());
181                         bsOrderScheduling.setOperateTime(fomateDate);
182                         bsOrderScheduling.setProductType(ProductionOrde.getTypeL());//产品类型
183                         bsOrderScheduling.setWhetherOrPrint("0");
184                         bsOrderSchedulingService.insertBsOrderScheduling(bsOrderScheduling);
185                         startCode++;
186                     }
187                 }
188                 //更新工单状态
189                 ProductionOrde.setOrderStatus("2");
190                 omProductionOrdeInfoService.updateOmProductionOrdeInfo(ProductionOrde);
191             }
749044 192         }
696fd5 193         //新增机型序号
8876c2 194         if (ObjectUtil.isNotNull(bsModelNumber.getId())){
W 195             bsModelNumber.setMaxnumValue((startCode - 1) + "");
196             bsModelNumber.setSaveTime(fomateDate);
197             bsModelNumber.setLastNumber((startCode - 1) + "");
198             bsModelNumberService.updateBsModelNumber(bsModelNumber);
199         } else {
200             BsModelNumber bsModelNumberSave = new BsModelNumber();
201             bsModelNumberSave.setModel(omProductionOrdeInfo.getTypeZ());
202             bsModelNumberSave.setModelDate(dateTimeRule);
203             bsModelNumberSave.setMaxnumValue((startCode - 1) + "");
204             bsModelNumberSave.setSaveTime(fomateDate);
205             bsModelNumberSave.setLastNumber((startCode - 1) + "");
206             bsModelNumberService.insertBsModelNumber(bsModelNumberSave);
207         }
696fd5 208         return toAjax(1);
05d425 209     }
C 210
211     /**
fd2207 212      * 修改生产工单
213      */
214     @PreAuthorize("@ss.hasPermi('om:productionOrde:edit')")
215     @Log(title = "生产工单", businessType = BusinessType.UPDATE)
216     @PutMapping
217     public AjaxResult edit(@RequestBody OmProductionOrdeInfo omProductionOrdeInfo)
218     {
219         return toAjax(omProductionOrdeInfoService.updateOmProductionOrdeInfo(omProductionOrdeInfo));
220     }
221
222     /**
223      * 删除生产工单
224      */
225     @PreAuthorize("@ss.hasPermi('om:productionOrde:remove')")
226     @Log(title = "生产工单", businessType = BusinessType.DELETE)
227     @DeleteMapping("/{ids}")
228     public AjaxResult remove(@PathVariable Long[] ids)
229     {
230         return toAjax(omProductionOrdeInfoService.deleteOmProductionOrdeInfoByIds(ids));
231     }
232
233     /**
234      * table列上移下移
235      */
236     @Log(title = "生产工单", businessType = BusinessType.DELETE)
237     @GetMapping("/upDownMove")
238     public AjaxResult upDownMove(OmProductionOrdeInfo omProductionOrdeInfo)
239     {
240         return omProductionOrdeInfoService.upDownMove(omProductionOrdeInfo);
241     }
df1f2b 242
243     /**
1391b3 244      * 接收工单
df1f2b 245      */
1391b3 246     @PreAuthorize("@ss.hasPermi('om:productionOrde:receive')")
df1f2b 247     @GetMapping("/getProductionNotice")
248     public AjaxResult getProductionNotice(OmProductionOrdeInfo omProductionOrdeInfo)
249     {
131e8c 250         String factory = omProductionOrdeInfo.getWorkshopCode();
5f7e70 251         String productionNotice = omProductionOrdeInfo.getProductionNotice();
131e8c 252         if (StrUtil.isBlank(productionNotice)){
W 253             throw new ServiceException("请输入生产通知单号");
254         }
255         if (StrUtil.isBlank(factory)){
256             throw new ServiceException("请选择工厂编号");
257         }
5f7e70 258         List<OmProductionOrdeInfo> omProductionOrdeInfos = omProductionOrdeInfoService.selectOmProductionOrdeInfoList(omProductionOrdeInfo);
259         if(omProductionOrdeInfos.size() == 0){
260             try {
b4ff0d 261                 logger.info("接收工单号:,{}",productionNotice);
131e8c 262                 ReceivingServices.insertWebserviceData(factory,productionNotice);
5f7e70 263             } catch (Exception e) {
264                 return error("接收失败!请检查通知单号");
265             }
1de44b 266         }else {
e4f64a 267             return warn("该通知单已经接收完毕,不能重复接收!");
5f7e70 268         }
1de44b 269         return AjaxResult.success("接收成功!");
df1f2b 270     }
fd2207 271 }