|
|
@@ -0,0 +1,134 @@
|
|
|
+/*
|
|
|
+ * 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.salesPart.produce.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.core.secure.utils.AuthUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.salesPart.produce.entity.ProductWorkmanship;
|
|
|
+import org.springblade.salesPart.produce.entity.ProductWorkmanshipItems;
|
|
|
+import org.springblade.salesPart.produce.mapper.ProductWorkmanshipMapper;
|
|
|
+import org.springblade.salesPart.produce.service.IProductWorkmanshipItemsService;
|
|
|
+import org.springblade.salesPart.produce.service.IProductWorkmanshipService;
|
|
|
+import org.springblade.salesPart.produce.vo.ProductWorkmanshipVO;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 产品工艺 服务实现类
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2025-02-10
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@AllArgsConstructor
|
|
|
+public class ProductWorkmanshipServiceImpl extends ServiceImpl<ProductWorkmanshipMapper, ProductWorkmanship> implements IProductWorkmanshipService {
|
|
|
+
|
|
|
+ private final IProductWorkmanshipItemsService productWorkmanshipItemsService;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public IPage<ProductWorkmanshipVO> selectProductWorkmanshipPage(IPage<ProductWorkmanshipVO> page, ProductWorkmanshipVO productWorkmanship) {
|
|
|
+ return page.setRecords(baseMapper.selectProductWorkmanshipPage(page, productWorkmanship));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ProductWorkmanship detail(ProductWorkmanship productWorkmanship) {
|
|
|
+ ProductWorkmanship detail = baseMapper.selectById(productWorkmanship.getId());
|
|
|
+ List<ProductWorkmanshipItems> attributeItemsList = productWorkmanshipItemsService.list(new LambdaQueryWrapper<ProductWorkmanshipItems>()
|
|
|
+ .eq(ProductWorkmanshipItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(ProductWorkmanshipItems::getIsDeleted, 0)
|
|
|
+ .eq(ProductWorkmanshipItems::getPid, productWorkmanship.getId())
|
|
|
+ .eq(ProductWorkmanshipItems::getType, "1"));
|
|
|
+ detail.setAttributeItemsList(attributeItemsList != null ? attributeItemsList : new ArrayList<>());
|
|
|
+ List<ProductWorkmanshipItems> craftItemsList = productWorkmanshipItemsService.list(new LambdaQueryWrapper<ProductWorkmanshipItems>()
|
|
|
+ .eq(ProductWorkmanshipItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(ProductWorkmanshipItems::getIsDeleted, 0)
|
|
|
+ .eq(ProductWorkmanshipItems::getPid, productWorkmanship.getId())
|
|
|
+ .eq(ProductWorkmanshipItems::getType, "2"));
|
|
|
+ detail.setCraftItemsList(craftItemsList != null ? craftItemsList : new ArrayList<>());
|
|
|
+ return detail;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R submit(ProductWorkmanship productWorkmanship) {
|
|
|
+ List<ProductWorkmanship> workmanshipList = baseMapper.selectList(new LambdaQueryWrapper<ProductWorkmanship>()
|
|
|
+ .eq(ProductWorkmanship::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(ProductWorkmanship::getIsDeleted, 0)
|
|
|
+ .eq(ProductWorkmanship::getGoodsId, productWorkmanship.getGoodsId()));
|
|
|
+ if (productWorkmanship.getId() == null) {
|
|
|
+ if (!workmanshipList.isEmpty()) {
|
|
|
+ throw new RuntimeException("产品:" + productWorkmanship.getGoodsName() + "已存在");
|
|
|
+ }
|
|
|
+ productWorkmanship.setCreateTime(new Date());
|
|
|
+ productWorkmanship.setCreateUser(AuthUtil.getUserId());
|
|
|
+ productWorkmanship.setCreateUserName(AuthUtil.getUserName());
|
|
|
+ } else {
|
|
|
+ if (!workmanshipList.isEmpty() && workmanshipList.stream().anyMatch(e -> !e.getId().equals(productWorkmanship.getId()))) {
|
|
|
+ throw new RuntimeException("产品:" + productWorkmanship.getGoodsName() + "已存在");
|
|
|
+ }
|
|
|
+ productWorkmanship.setUpdateTime(new Date());
|
|
|
+ productWorkmanship.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ productWorkmanship.setUpdateUserName(AuthUtil.getUserName());
|
|
|
+ }
|
|
|
+ this.saveOrUpdate(productWorkmanship);
|
|
|
+ if (ObjectUtils.isNotNull(productWorkmanship.getAttributeItemsList())) {
|
|
|
+ for (ProductWorkmanshipItems item : productWorkmanship.getAttributeItemsList()) {
|
|
|
+ item.setPid(productWorkmanship.getId());
|
|
|
+ item.setType("1");
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ } else {
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!productWorkmanship.getAttributeItemsList().isEmpty()) {
|
|
|
+ productWorkmanshipItemsService.saveOrUpdateBatch(productWorkmanship.getAttributeItemsList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(productWorkmanship.getCraftItemsList())) {
|
|
|
+ for (ProductWorkmanshipItems item : productWorkmanship.getCraftItemsList()) {
|
|
|
+ item.setPid(productWorkmanship.getId());
|
|
|
+ item.setType("2");
|
|
|
+ if (item.getId() == null) {
|
|
|
+ item.setCreateTime(new Date());
|
|
|
+ item.setCreateUser(AuthUtil.getUserId());
|
|
|
+ } else {
|
|
|
+ item.setUpdateTime(new Date());
|
|
|
+ item.setUpdateUser(AuthUtil.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!productWorkmanship.getCraftItemsList().isEmpty()) {
|
|
|
+ productWorkmanshipItemsService.saveOrUpdateBatch(productWorkmanship.getCraftItemsList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.data(productWorkmanship);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|