|
|
@@ -0,0 +1,221 @@
|
|
|
+/*
|
|
|
+ * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+ *
|
|
|
+ * Redistribution and use in source and binary forms, with or without
|
|
|
+ * modification, are permitted provided that the following conditions are met:
|
|
|
+ *
|
|
|
+ * Redistributions of source code must retain the above copyright notice,
|
|
|
+ * this list of conditions and the following disclaimer.
|
|
|
+ * Redistributions in binary form must reproduce the above copyright
|
|
|
+ * notice, this list of conditions and the following disclaimer in the
|
|
|
+ * documentation and/or other materials provided with the distribution.
|
|
|
+ * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+ * contributors may be used to endorse or promote products derived from
|
|
|
+ * this software without specific prior written permission.
|
|
|
+ * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+ */
|
|
|
+package org.springblade.school.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.school.dto.ProductMockRecordsDTO;
|
|
|
+import org.springblade.school.dto.ProductMockStationDTO;
|
|
|
+import org.springblade.school.dto.ProductMockWeekDTO;
|
|
|
+import org.springblade.school.entity.ProductMockRecords;
|
|
|
+import org.springblade.school.entity.ProductMockStation;
|
|
|
+import org.springblade.school.entity.ProductMockWeek;
|
|
|
+import org.springblade.school.mapper.ProductMockStationMapper;
|
|
|
+import org.springblade.school.mapper.ProductMockWeekMapper;
|
|
|
+import org.springblade.school.vo.ProductMockRecordsVO;
|
|
|
+import org.springblade.school.mapper.ProductMockRecordsMapper;
|
|
|
+import org.springblade.school.service.IProductMockRecordsService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
+
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 生产记录 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2023-07-14
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class ProductMockRecordsServiceImpl extends ServiceImpl<ProductMockRecordsMapper, ProductMockRecords> implements IProductMockRecordsService {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生产模拟星期mapple
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private ProductMockWeekMapper productMockWeekMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生产模拟岗位mapple
|
|
|
+ */
|
|
|
+ @Autowired
|
|
|
+ private ProductMockStationMapper productMockStationMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<ProductMockRecordsVO> selectProductMockRecordsPage(IPage<ProductMockRecordsVO> page, ProductMockRecordsVO productMockRecords) {
|
|
|
+ return page.setRecords(baseMapper.selectProductMockRecordsPage(page, productMockRecords));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增或修改生产模拟
|
|
|
+ *
|
|
|
+ * @param productMockRecordsDTO 包含岗位的生产记录实体
|
|
|
+ * @return 保存或更新后的数据
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public R saveOrUpdateProductMockRecords(ProductMockRecordsDTO productMockRecordsDTO) {
|
|
|
+
|
|
|
+ ProductMockRecords productMockRecords = new ProductMockRecords();
|
|
|
+ BeanUtils.copyProperties(productMockRecordsDTO, productMockRecords);
|
|
|
+
|
|
|
+ // 没有id新数据保存
|
|
|
+ if (productMockRecordsDTO.getId() == null) {
|
|
|
+
|
|
|
+ // 设置租户id
|
|
|
+ productMockRecords.setTenantId(SecureUtil.getTenantId());
|
|
|
+ // 设置创建人
|
|
|
+ productMockRecords.setCreateUser(SecureUtil.getUserId());
|
|
|
+ // 设置创建部门
|
|
|
+// productMockRecords.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ // 设置创建时间
|
|
|
+ productMockRecords.setCreateTime(new Date());
|
|
|
+
|
|
|
+ // 新增数据
|
|
|
+ int i = baseMapper.insert(productMockRecords);
|
|
|
+
|
|
|
+ if (i != 1) {
|
|
|
+ // 新增失败手动归滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ R<String> R = new R<>();
|
|
|
+ R.setCode(500);
|
|
|
+ R.setSuccess(false);
|
|
|
+ R.setMsg("保存操作记录失败");
|
|
|
+ return R;
|
|
|
+ }
|
|
|
+ productMockRecordsDTO.setId(productMockRecords.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 星期表
|
|
|
+ ProductMockWeekDTO productMockWeekDTO = productMockRecordsDTO.getProductMockWeekDTO();
|
|
|
+ ProductMockWeek productMockWeek = new ProductMockWeek();
|
|
|
+ BeanUtils.copyProperties(productMockWeekDTO, productMockWeek);
|
|
|
+ // 设置记录表id
|
|
|
+ productMockWeek.setRecordsId(productMockRecords.getId());
|
|
|
+ // 设置租户id
|
|
|
+ productMockWeek.setTenantId(SecureUtil.getTenantId());
|
|
|
+ // 设置创建人
|
|
|
+ productMockWeek.setCreateUser(SecureUtil.getUserId());
|
|
|
+ // 设置创建部门
|
|
|
+// productMockWeek.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ // 设置创建时间
|
|
|
+ productMockWeek.setCreateTime(new Date());
|
|
|
+
|
|
|
+ int insert = productMockWeekMapper.insert(productMockWeek);
|
|
|
+
|
|
|
+ if (insert != 1) {
|
|
|
+ // 新增失败手动归滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ R<String> R = new R<>();
|
|
|
+ R.setCode(500);
|
|
|
+ R.setSuccess(false);
|
|
|
+ R.setMsg("保存星期失败");
|
|
|
+ return R;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理工位数据
|
|
|
+ List<ProductMockStation> productMockStationList = productMockWeekDTO.getProductMockStationList();
|
|
|
+
|
|
|
+ for (ProductMockStation productMockStation : productMockStationList) {
|
|
|
+
|
|
|
+ // 设置星期表id
|
|
|
+ productMockStation.setWeekId(productMockWeek.getId());
|
|
|
+ // 设置租户id
|
|
|
+ productMockStation.setTenantId(SecureUtil.getTenantId());
|
|
|
+ // 设置创建人
|
|
|
+ productMockStation.setCreateUser(SecureUtil.getUserId());
|
|
|
+ // 设置创建部门
|
|
|
+// productMockStation.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
|
|
|
+ // 设置创建时间
|
|
|
+
|
|
|
+ productMockStation.setCreateTime(new Date());
|
|
|
+
|
|
|
+ int y = productMockStationMapper.insert(productMockStation);
|
|
|
+ if (y != 1) {
|
|
|
+ // 新增失败手动归滚
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ R<String> R = new R<>();
|
|
|
+ R.setCode(500);
|
|
|
+ R.setSuccess(false);
|
|
|
+ R.setMsg("保存工位数据失败");
|
|
|
+ return R;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存成功
|
|
|
+ return R.data(productMockRecordsDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询详情,包含星期,岗位信息
|
|
|
+ *
|
|
|
+ * @param queryWrapper id
|
|
|
+ * @return 详情
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ProductMockRecordsDTO getProductMockRecordsByid(QueryWrapper<ProductMockRecords> queryWrapper) {
|
|
|
+ ProductMockRecordsDTO productMockRecordsDTO = new ProductMockRecordsDTO();
|
|
|
+ // 获取生产模拟记录
|
|
|
+ ProductMockRecords productMockRecords = baseMapper.selectOne(queryWrapper);
|
|
|
+ BeanUtils.copyProperties(productMockRecords, productMockRecordsDTO);
|
|
|
+
|
|
|
+ // 获取星期记录
|
|
|
+ QueryWrapper<ProductMockWeek> weekqw = new QueryWrapper<>();
|
|
|
+ weekqw.eq("records_id", productMockRecords.getId());
|
|
|
+ List<ProductMockWeek> productMockWeeks = productMockWeekMapper.selectList(weekqw);
|
|
|
+ List<ProductMockWeekDTO> weekDTOAList = new ArrayList<>();
|
|
|
+ BeanUtils.copyProperties(productMockWeeks, weekDTOAList);
|
|
|
+ productMockRecordsDTO.setProductMockWeekDTOList(weekDTOAList);
|
|
|
+
|
|
|
+ for (ProductMockWeekDTO productMockWeekDTO : weekDTOAList) {
|
|
|
+ // 获取工位记录
|
|
|
+ QueryWrapper<ProductMockStation> pmsqw = new QueryWrapper<>();
|
|
|
+ pmsqw.eq("week_id", productMockWeekDTO.getId());
|
|
|
+ List<ProductMockStation> productMockStations = productMockStationMapper.selectList(pmsqw);
|
|
|
+
|
|
|
+ // 根据日期正序排序
|
|
|
+ Comparator<ProductMockStation> comparing = Comparator.comparing(ProductMockStation::getData);
|
|
|
+ productMockStations.sort(comparing);
|
|
|
+
|
|
|
+ List<ProductMockStationDTO> productMockStationDTOList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 计算合计
|
|
|
+ for (ProductMockStation productMockStation : productMockStations) {
|
|
|
+
|
|
|
+ ProductMockStationDTO productMockStationDTO = new ProductMockStationDTO();
|
|
|
+ BeanUtils.copyProperties(productMockStation, productMockStationDTO);
|
|
|
+ productMockStationDTO.setTotalAmounts(productMockStationDTO.getProductQuantity() * productMockStationDTO.getSaleUnitPrice());
|
|
|
+
|
|
|
+ productMockStationDTOList.add(productMockStationDTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 放置岗位信息
|
|
|
+ productMockWeekDTO.setProductMockStationDTOList(productMockStationDTOList);
|
|
|
+ }
|
|
|
+
|
|
|
+ return productMockRecordsDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|