guoyuji
2024-02-23 7a9d934dc16861a5b08db18669f53e2c4d1fb69e
提交产品新增代码
8个文件已修改
521 ■■■■ 已修改文件
north-glass-erp/northglass-erp/src/views/sd/product/CreateProduct.vue 374 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/src/main/java/com/example/erp/controller/sd/ProductController.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/src/main/java/com/example/erp/entity/sd/ProductDetail.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/src/main/java/com/example/erp/mapper/sd/ProductDetailMapper.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/src/main/java/com/example/erp/mapper/sd/ProductMapper.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/src/main/java/com/example/erp/service/sd/ProductService.java 92 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/src/main/resources/mapper/sd/ProductDetail.xml 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/target/classes/mapper/sd/ProductDetail.xml 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
north-glass-erp/northglass-erp/src/views/sd/product/CreateProduct.vue
@@ -1,8 +1,10 @@
<script setup>
import request from "@/utils/request"
import deepClone from "@/utils/deepClone";
import {ElMessage} from "element-plus";
import {ref} from "vue";
import deepClone from "@/utils/deepClone"
import {ElMessage} from "element-plus"
import {computed, ref} from "vue"
import  useUserInfo from "@/stores/userInfo"
let  userInfo = useUserInfo()
const disposeList = $ref([
  '彩釉',
  '蒙砂',
@@ -10,22 +12,6 @@
  '贴膜',
  '喷砂',
  '磨边'
])
let processList = $ref([
    '磨边',
    '镀膜',
    '倒角',
    '清洗',
    '打孔',
    '挖缺',
    '挖槽',
    '水切割',
    '丝印',
    '半钢化',
    '钢化',
    '夹层',
    '中空',
    '包装'
])
let BasicData = ref({
  stuffColor:null,
@@ -56,15 +42,66 @@
  lowE:''
})
let processChecked = ref([])
let hollowBasic = ref({
  thickness:"",
  gasType:"",
  Type:"",
  GlueDepth:""
})
let InterlayerBasic = ref({
  thickness:"",
  color:"",
  type:""
})
let productDetailList = ref([])
let productTotal = ref({
  productName:'',
  creator:userInfo.user.userName
})
//页面加载请求
request.get(`/basicData/BasicDataByType/product`).then((res) => {
  if(res.code==200){
    console.log(res.data)
    BasicData.value = res.data
  }else{
    ElMessage.warning(res.msg)
  }
})
const saveProduct = () => {
  if(productDetailList.value.length===0){
    ElMessage.warning("请添加产品详情")
    return
  }else if(productDetailList.value[productDetailList.value.length-1].detailType!=='glass'){
    ElMessage.warning("产品详情最后一条不是玻璃,请完善")
    return
  }
  let productName = ""
  productDetailList.value.forEach(item =>{
    switch(item.detailType){
      case 'glass' :{
        productName+=item.detail
        break
      }
      case 'Interlayer' :{
        productName+='+'+item.detail
      }
      case 'hollow' :{
        productName+='*'+item.detail
      }
    }
  })
  productTotal.value.productName=productName
  let product = {
    title: productTotal.value,
    detail:productDetailList.value
  }
  request.post(`/product/saveProduct`,product).then((res) =>{
    if(res.code==200){
      ElMessage.success(res.msg)
    }
  })
}
const reset = () => {
  processChecked.value=[]
@@ -72,6 +109,211 @@
    stuff.value[item]=''
  })
}
const glassSure =  () => {
  let childName = ''
  Object.keys(stuff.value).forEach((item,index)=>{
    childName+=stuff.value[item]
  })
  let rege = /^\s*$/
  if(rege.test(childName) || processChecked.value.length===0){
    ElMessage.warning('请输入产品材料属性与工艺属性')
    return
  }
  let productDetail = {
    detailType:'glass',
    detail:childName,
    process:processChecked.value.join('->'),
    separation:Object.assign({}, stuff.value)
  }
  if(glassFlag.value.flag){
    if(productDetailList.value.length ===0 ){
      productDetailList.value.push(productDetail)
    }else{
      if (productDetailList.value[productDetailList.value.length-1].detailType === 'glass') {
        ElMessage.warning('请先选择间隔物')
        return
      }
      productDetailList.value.push(productDetail)
    }
  }else{
    productDetailList.value[glassFlag.value.index] = productDetail
  }
  reset()
}
//添加中空间隔物
const addHollow = () => {
  let childName = ''
  try {
    Object.keys(hollowBasic.value).forEach((item, index) => {
      if (hollowBasic.value[item] === '') {
        throw new Error("请选择全部中空间隔物下拉框")
      }
      childName += hollowBasic.value[item]
    })
  }catch (e){
    ElMessage.warning(e.message)
    return
  }
  let hollowDetail = {
    detailType:'hollow',
    detail:childName,
    separation:Object.assign({}, hollowBasic.value)
  }
  if(hollowFlag.value.flag){
    if (productDetailList.value.length ===0) {
      ElMessage.warning('请先选择产品')
      return
    }else if(productDetailList.value[productDetailList.value.length-1].detailType !== 'glass'){
      ElMessage.warning('请先选择产品')
      return
    }
    productDetailList.value.push(Object.assign({},hollowDetail))
  }else {
    productDetailList.value[hollowFlag.value.index] = hollowDetail
  }
  Object.keys(hollowBasic.value).forEach((item,index)=>{
    hollowBasic.value[item]=''
  })
}
//添加夹层间隔物
const addInterlayer = () => {
  let childName = ''
  try {
    Object.keys(InterlayerBasic.value).forEach((item, index) => {
      if (InterlayerBasic.value[item] === '') {
        throw new Error("请选择全部中空间隔物下拉框")
      }
      childName += InterlayerBasic.value[item]
    })
  }catch (e){
    ElMessage.warning(e.message)
    return
  }
  let InterlayerDetail = {
    detailType:'Interlayer',
    detail:childName,
    separation:Object.assign({}, InterlayerBasic.value)
  }
  if(InterlayerFlag.value.flag){
    if (productDetailList.value.length ===0) {
      ElMessage.warning('请先选择产品')
      return
    }else if(productDetailList.value[productDetailList.value.length-1].detailType !== 'glass'){
      ElMessage.warning('请先选择产品')
      return
    }
    productDetailList.value.push(Object.assign({},InterlayerDetail))
  }else{
    productDetailList.value[InterlayerFlag.value.index] = InterlayerDetail
  }
  Object.keys(InterlayerBasic.value).forEach((item,index)=>{
    InterlayerBasic.value[item]=''
  })
}
const deleteProductDetail =  (index) => {
  const detailType = productDetailList.value[index].detailType
  switch (detailType) {
    case 'glass':{
      glassFlag.value = {
        flag:true,
        index:null
      }
      break
    }
    case 'Interlayer':{
      InterlayerFlag.value = {
        flag:true,
        index:null
      }
      break
    }
    case 'hollow':{
      hollowFlag.value = {
        flag:true,
        index:null
      }
    }
  }
  productDetailList.value.splice(index,1)
}
let glassFlag = ref({
  flag:true,
  index:null
})
const updateGlass = (index) => {
  stuff.value = productDetailList.value[index].separation
  processChecked.value = productDetailList.value[index].process.split("->")
  glassFlag.value.flag=false
  glassFlag.value.index=index
}
const updateGlassSure = ()=> {
  glassSure()
  glassFlag.value.flag=true
  glassFlag.value.index=null
}
let InterlayerFlag = ref({
  flag:true,
  index:null
})
const updateInterlayer  = (index) => {
  InterlayerBasic.value = productDetailList.value[index].separation
  InterlayerFlag.value.flag=false
  InterlayerFlag.value.index=index
}
const updateInterlayerSure = () => {
  addInterlayer()
  InterlayerFlag.value.flag=true
  InterlayerFlag.value.index=null
}
let  hollowFlag = ref({
  flag:true,
  index:null
})
const updateHollow = (index) => {
  hollowBasic.value = productDetailList.value[index].separation
  hollowFlag.value.flag=false
  hollowFlag.value.index=index
}
const updateHollowSure = () => {
  addHollow()
  hollowFlag.value.flag=true
  hollowFlag.value.index=null
}
const productName = computed(() =>{
  let productName = ""
  productDetailList.value.forEach(item =>{
    switch(item.detailType){
      case 'glass' :{
        productName+=item.detail
        break
      }
      case 'Interlayer' :{
        productName+='+'+item.detail
      }
      case 'hollow' :{
        productName+='*'+item.detail
      }
    }
  })
  return productName
})
</script>
<template>
@@ -180,6 +422,7 @@
      <div class="glass-spacer">
        <div class="glass-spacer-jc">
          <el-select
              v-model="hollowBasic.thickness"
              size="small"
              style="width: 100px"
              clearable placeholder="*中空厚度:" >
@@ -190,6 +433,7 @@
            />
          </el-select>
          <el-select
              v-model="hollowBasic.gasType"
              size="small"
              style="width: 100px"
              clearable placeholder="*充气方式:" >
@@ -200,6 +444,7 @@
            />
          </el-select>
          <el-select
              v-model="hollowBasic.Type"
              size="small"
              style="width: 100px"
              clearable placeholder="*封胶:" >
@@ -210,6 +455,7 @@
            />
          </el-select>
          <el-select
              v-model="hollowBasic.GlueDepth"
              size="small"
              style="width: 100px"
              clearable placeholder="*默认胶深:" >
@@ -220,13 +466,21 @@
            />
          </el-select>
          <el-button
              v-if="hollowFlag.flag"
              @click="addHollow"
              size="small"
              type="primary"
              round>中空间隔物</el-button>
          <el-button
              v-else
              @click="updateHollowSure"
              size="small"
              type="primary"
              round>夹层间隔物修改</el-button>
        </div>
        <div class="glass-spacer-zk">
          <el-select
              v-model="InterlayerBasic.thickness"
              size="small"
              style="width: 100px"
              clearable placeholder="*夹层厚度:" >
@@ -237,6 +491,7 @@
            />
          </el-select>
          <el-select
              v-model="InterlayerBasic.type"
              size="small"
              style="width: 100px"
              clearable placeholder="*类型:" >
@@ -247,6 +502,7 @@
            />
          </el-select>
          <el-select
              v-model="InterlayerBasic.color"
              size="small"
              style="width: 100px"
              clearable placeholder="*颜色:" >
@@ -257,10 +513,19 @@
            />
          </el-select>
          <el-button
              v-if="InterlayerFlag.flag"
              @click="addInterlayer"
              size="small"
              type="primary"
              style="margin-left: 100px"
              round>夹层间隔物</el-button>
          <el-button
              v-else
              @click="updateInterlayerSure"
              size="small"
              type="primary"
              style="margin-left: 100px"
              round>夹层间隔物修改</el-button>
        </div>
      </div>
      <div class="line"/>
@@ -302,10 +567,16 @@
            </el-col>
            <el-col :span="3">
              <div class="grid-content ep-bg-purple" >
                <el-button
                <el-button v-if="glassFlag.flag"
                    @click="glassSure"
                    size="small"
                    type="primary"
                    round>确认</el-button>
                <el-button v-else
                           @click="updateGlassSure"
                           size="small"
                           type="primary"
                           round>修改</el-button>
              </div>
            </el-col>
          </el-row>
@@ -368,64 +639,57 @@
          </el-col>
          <el-col :span="20">
            <div class="grid-content ep-bg-purple" >
              <el-input size="large" disabled  />
              <el-input :value="productName" size="large" disabled  />
            </div>
          </el-col>
        </el-row>
      </div>
      <div class="glass-part-detail">
        <el-row style="width: 90%" >
          <el-col :span="4">
        <el-row style="width: 90%"  v-for="(item,index) in productDetailList">
          <el-col :span="4" v-show="item.detailType === 'glass'">
            <el-button
                @click = "updateGlass(index)"
                size="small"
                type="primary"
                round>修改玻璃</el-button>
                type="primary">修改玻璃</el-button>
          </el-col>
          <el-col :span="4" v-show="item.detailType === 'Interlayer'">
            <el-button
                @click = "updateInterlayer(index)"
                size="small"
                type="primary">修改夹层</el-button>
          </el-col>
          <el-col :span="4" v-show="item.detailType === 'hollow'">
            <el-button
                @click = "updateHollow(index)"
                size="small"
                type="primary">修改中空</el-button>
          </el-col>
          <el-col :span="16">
            <el-input
                :value="item.detail"
                value="5mm白玻"
                size="small"
                disabled  />
          </el-col>
        </el-row>
        <el-row style="width: 90%" >
          <el-col :span="4">
          <el-col
              v-show="index+1 === productDetailList.length"
              :span="4">
            <el-button
                @click="deleteProductDetail(index)"
                size="small"
                type="primary"
                round>修改夹层</el-button>
          </el-col>
          <el-col :span="16">
            <el-input
                value="5mmPVB透明"
                size="small"
                disabled  />
          </el-col>
        </el-row>
        <el-row style="width: 90%" >
          <el-col :span="4">
            <el-button
                size="small"
                type="primary"
                round>修改玻璃</el-button>
          </el-col>
          <el-col :span="16">
            <el-input
                value="5mm白玻"
                size="small"
                disabled  />
                type="primary">删除</el-button>
          </el-col>
        </el-row>
      </div>
      <el-button
          @click="saveProduct"
          style="float: right;
          margin-right: 0.5rem;"
          size="large"
          type="primary"
          round>重置</el-button>
          round>创建</el-button>
    </div>
  </div>
</template>
north-glass-erp/src/main/java/com/example/erp/controller/sd/ProductController.java
@@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/product")
@@ -19,4 +20,9 @@
    public Result defaultDateProduct(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @PathVariable List<String> glassType, @RequestBody Product product){
        return Result.seccess(productService.defaultDateProduct(pageNum,pageSize,glassType,product));
    }
    @PostMapping("/saveProduct")
    public Result saveProduct(@RequestBody Map<String,Object> product){
        return Result.seccess(productService.saveProduct(product));
    }
}
north-glass-erp/src/main/java/com/example/erp/entity/sd/ProductDetail.java
@@ -6,15 +6,16 @@
import java.time.LocalDate;
import java.util.Map;
@Data
public class ProductDetail    {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String prodId;
    private String sortNum;
    private String glassSort;
    private Long prodId;
    private Integer sortNum;
    private Integer glassSort;
    private String detailType;
    private String detail;
    private Integer glassGroup;
north-glass-erp/src/main/java/com/example/erp/mapper/sd/ProductDetailMapper.java
@@ -9,4 +9,5 @@
public interface ProductDetailMapper {
    List<ProductDetail> getGlassDetailList();
    boolean insertList(List<ProductDetail> getProductDetails);
}
north-glass-erp/src/main/java/com/example/erp/mapper/sd/ProductMapper.java
@@ -1,5 +1,6 @@
package com.example.erp.mapper.sd;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.erp.entity.sd.Product;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -7,7 +8,7 @@
import java.util.List;
@Mapper
public interface ProductMapper {
public interface ProductMapper extends BaseMapper<Product> {
    List<Product> defaultProduct(@Param("offset") Integer offset,
                                 @Param("pageSize") Integer pageSiz,
                                 @Param("glassTypeId") String glassTypeId,
north-glass-erp/src/main/java/com/example/erp/service/sd/ProductService.java
@@ -1,20 +1,36 @@
package com.example.erp.service.sd;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.erp.entity.sd.Product;
import com.example.erp.entity.sd.ProductDetail;
import com.example.erp.mapper.sd.ProductDetailMapper;
import com.example.erp.mapper.sd.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@Service
@DS("sd")
@Transactional
public class ProductService {
    @Autowired
    private final
    ProductMapper productMapper;
    private final
    ProductDetailMapper productDetailMapper;
    public ProductService(ProductMapper productMapper, ProductDetailMapper productDetailMapper) {
        this.productMapper = productMapper;
        this.productDetailMapper = productDetailMapper;
    }
//产品查询方法
    public Map<String,Object> defaultDateProduct(Integer pageNum, Integer pageSize, List<String> glassType, Product product) {
        Integer offset = (pageNum-1)*pageSize;
        String glassTypeId = null;
@@ -27,5 +43,77 @@
        return map;
    }
//产品保存方法
    public boolean saveProduct(Map<String,Object>  productObject) {
        //把传入主附表的object类型转换成实体类类型
        JSONObject productJson = new JSONObject(productObject);
        System.out.println(JSONObject.toJSONString(productJson.get("title")));
        Product product = JSONObject.parseObject(JSONObject.toJSONString(productJson.get("title")), Product.class);
        List<ProductDetail> productDetails = JSONArray.parseArray(JSONObject.toJSONString(productJson.get("detail")), ProductDetail.class);
        //完善主附表信息并返回
        Map<String,Object> getProductJson = updateProduct(productDetails,product);
        Product getProduct = JSONObject.parseObject(JSONObject.toJSONString(getProductJson.get("title")), Product.class);
        List<ProductDetail> getProductDetails = JSONArray.parseArray(JSONObject.toJSONString(getProductJson.get("detail")), ProductDetail.class);
        //插入主表数据
        productMapper.insert(getProduct);
        //给副表添加产品id
        for (ProductDetail getProductDetail : getProductDetails) {
            getProductDetail.setProdId(getProduct.getId());
        }
        //插入副表
        productDetailMapper.insertList(getProductDetails);
        return false;
    }
    private Map<String,Object> updateProduct(List<ProductDetail> productDetailList,Product product) {
        Map<String,Object> map = new HashMap<>();
        //定义产品玻璃厚度累加
        double thickness1 = 0;
        //定义产品总厚度累加
        double totalThickness = 0;
        //定义快速查询
        StringBuilder query = new StringBuilder();
        //定义副表玻璃与间隔物排序
        int sortNum = 0;
        //定义副表玻璃排序
        int glassSort = 0;
        //定义副表中空分组
        int glassGroup = 1;
        for (ProductDetail productDetail : productDetailList) {
            sortNum+=1;
            productDetail.setSortNum(sortNum);
            JSONObject separation = JSONObject.parseObject( productDetail.getSeparation());
            String  getThickness = (String) separation.get("thickness");
            double thicknessDetail = Double.parseDouble(getThickness.replace("mm",""));
            totalThickness += thicknessDetail;
            if(Objects.equals(productDetail.getDetailType(), "glass")){
                glassSort+=1;
                productDetail.setGlassSort(glassSort);
                productDetail.setGlassGroup(glassGroup);
                thickness1 += thicknessDetail;
                DecimalFormat decimalFormat = new DecimalFormat("###");
                query.append(decimalFormat.format(thicknessDetail));
            }
            else if (Objects.equals(productDetail.getDetailType(), "Interlayer")) {
                query.append("+");
            }else if(Objects.equals(productDetail.getDetailType(), "hollow")){
                glassGroup+=1;
                query.append("*");
            }
        }
        product.setThickness(thickness1);
        product.setTotalThickness(totalThickness);
        product.setQuery(String.valueOf(query));
        map.put("title",product);
        map.put("detail",productDetailList);
        return map;
    }
}
north-glass-erp/src/main/resources/mapper/sd/ProductDetail.xml
@@ -6,4 +6,23 @@
    <select id="getGlassDetailList">
        select * from product_detail where prod_id = #{productId} and detail_type = 'glass'
    </select>
    <insert id="insertList">
        insert into product_detail (
            prod_id, sort_num, glass_sort, detail_type, detail, glass_group, process,separation
        )
        values
        <foreach collection ="getProductDetails" item="ProductDetail" separator =",">
            (
                #{ProductDetail.prodId},
                #{ProductDetail.sortNum},
                #{ProductDetail.glassSort},
                #{ProductDetail.detailType},
                #{ProductDetail.detail},
                #{ProductDetail.glassGroup},
                #{ProductDetail.process},
               #{ProductDetail.separation}
                )
        </foreach>
    </insert>
</mapper>
north-glass-erp/target/classes/mapper/sd/ProductDetail.xml
@@ -6,4 +6,23 @@
    <select id="getGlassDetailList">
        select * from product_detail where prod_id = #{productId} and detail_type = 'glass'
    </select>
    <insert id="insertList">
        insert into product_detail (
            prod_id, sort_num, glass_sort, detail_type, detail, glass_group, process,separation
        )
        values
        <foreach collection ="getProductDetails" item="ProductDetail" separator =",">
            (
                #{ProductDetail.prodId},
                #{ProductDetail.sortNum},
                #{ProductDetail.glassSort},
                #{ProductDetail.detailType},
                #{ProductDetail.detail},
                #{ProductDetail.glassGroup},
                #{ProductDetail.process},
               #{ProductDetail.separation}
                )
        </foreach>
    </insert>
</mapper>