New file |
| | |
| | | package com.example.erp.service.sd; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.TypeReference; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.example.erp.entity.sd.GlassPriceBasic; |
| | | import com.example.erp.entity.sd.ProductDetail; |
| | | import com.example.erp.mapper.sd.GlassPriceBasicMapper; |
| | | import com.example.erp.mapper.sd.ProductDetailMapper; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | @Service |
| | | @DS("sd") |
| | | public class GlassPriceBasicService { |
| | | private final GlassPriceBasicMapper glassPriceBasicMapper; |
| | | private final ProductDetailMapper productDetailMapper; |
| | | |
| | | public GlassPriceBasicService(GlassPriceBasicMapper glassPriceBasicMapper, ProductDetailMapper productDetailMapper) { |
| | | this.glassPriceBasicMapper = glassPriceBasicMapper; |
| | | this.productDetailMapper = productDetailMapper; |
| | | } |
| | | |
| | | //保存玻璃价格 |
| | | public Boolean save(Map<String, Object> prams) { |
| | | GlassPriceBasic glassPriceBasic = new GlassPriceBasic(); |
| | | glassPriceBasic.setThickness( |
| | | Double.parseDouble(prams.get("thickness").toString().replaceAll("[^0-9\\.]", "")) |
| | | ); |
| | | glassPriceBasic.setPrice(Double.parseDouble(prams.get("price").toString())); |
| | | glassPriceBasic.setJson(prams.toString()); |
| | | glassPriceBasic.setType(prams.get("type").toString()); |
| | | String type = prams.get("type").toString(); |
| | | //判断 是哪种类型 |
| | | if(Objects.equals(type, "glass")) { |
| | | glassPriceBasic.setName(prams.get("thickness").toString() + prams.get("color").toString()); |
| | | }else if(Objects.equals(type, "hollow")){ |
| | | glassPriceBasic.setName( |
| | | prams.get("thickness").toString() |
| | | + prams.get("gasType").toString() |
| | | + prams.get("types").toString()); |
| | | } else if (Objects.equals(type, "interlayer")) { |
| | | glassPriceBasic.setName( |
| | | prams.get("thickness").toString() |
| | | + prams.get("color").toString() |
| | | + prams.get("types").toString()); |
| | | } else if (Objects.equals(type, "process")) { |
| | | glassPriceBasic.setName(prams.get("thickness").toString() + prams.get("color").toString()+prams.get("process").toString()); |
| | | glassPriceBasic.setProcess(prams.get("process").toString()); |
| | | } |
| | | GlassPriceBasic glassPriceBasic1 = glassPriceBasicMapper.selectOne( |
| | | new QueryWrapper<GlassPriceBasic>() |
| | | .eq("name", glassPriceBasic.getName()) |
| | | ); |
| | | if(glassPriceBasic1 != null){ |
| | | return false; |
| | | } |
| | | return glassPriceBasicMapper.insert(glassPriceBasic)>0; |
| | | } |
| | | |
| | | public Double glassPriceComputed(String productId) { |
| | | List<ProductDetail> productDetails = productDetailMapper |
| | | .selectList(new QueryWrapper<ProductDetail>().eq("prod_id", productId)); |
| | | |
| | | final Double[] money = {0.0}; |
| | | for (ProductDetail productDetail : productDetails){ |
| | | Map<String,String> separation = JSON.parseObject( |
| | | productDetail.getSeparation(), new TypeReference<Map<String, String>>(){}); |
| | | String name = ""; |
| | | switch (productDetail.getDetailType()) { |
| | | case "glass": |
| | | name = separation.get("thickness") + separation.get("color"); |
| | | String[] process = productDetail.getProcess().split("->"); |
| | | for (String s : process) { |
| | | GlassPriceBasic glassPriceBasic = glassPriceBasicMapper.selectOne( |
| | | new QueryWrapper<GlassPriceBasic>() |
| | | .eq("name", name+s)); |
| | | if(glassPriceBasic == null) { |
| | | return 0.0; |
| | | }else{ |
| | | money[0] += glassPriceBasic.getPrice(); |
| | | } |
| | | |
| | | } |
| | | break; |
| | | case "hollow": |
| | | name = separation.get("thickness") + separation.get("gasType") + separation.get("Type"); |
| | | break; |
| | | case "interlayer": |
| | | name = separation.get("thickness") + separation.get("color") + separation.get("type"); |
| | | break; |
| | | } |
| | | |
| | | GlassPriceBasic glassPriceBasic = glassPriceBasicMapper |
| | | .selectOne(new QueryWrapper<GlassPriceBasic>().eq("name", name)); |
| | | if(glassPriceBasic == null) { |
| | | money[0]= 0.0; |
| | | return money[0]; |
| | | } |
| | | money[0] += glassPriceBasic.getPrice(); |
| | | } |
| | | return money[0]; |
| | | } |
| | | |
| | | public List<GlassPriceBasic> searchGlassPrice() { |
| | | return glassPriceBasicMapper.selectList(null); |
| | | } |
| | | |
| | | public Boolean updateGlassPriceById(GlassPriceBasic glassPriceBasic) { |
| | | return glassPriceBasicMapper.update( |
| | | null, |
| | | new LambdaUpdateWrapper<>(GlassPriceBasic.class) |
| | | .setSql("price = " + glassPriceBasic.getPrice()) |
| | | .eq(GlassPriceBasic::getId, glassPriceBasic.getId()) |
| | | )>0; |
| | | } |
| | | |
| | | public Boolean deleteGlassPriceById(String id) { |
| | | return glassPriceBasicMapper.deleteById(id)>0; |
| | | } |
| | | } |