| | |
| | | package com.whyc.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.mapper.ProductBomHistoryMapper; |
| | | import com.whyc.mapper.ProductBomMapper; |
| | | import com.whyc.mapper.ProductHistoryMapper; |
| | | import com.whyc.mapper.ProductMapper; |
| | | import com.whyc.pojo.Product; |
| | | import com.whyc.pojo.ProductBom; |
| | | import com.whyc.pojo.ProductBomHistory; |
| | | import com.whyc.pojo.ProductHistory; |
| | | import org.apache.poi.hssf.record.ProtectionRev4Record; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.awt.print.PrinterJob; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | |
| | | @Autowired(required = false) |
| | | private ProductHistoryMapper mapper; |
| | | |
| | | @Autowired(required = false) |
| | | private ProductMapper productMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private ProductBomMapper productBomMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private ProductBomHistoryMapper productBomHistoryMapper; |
| | | |
| | | //产品详情查看版本信息 |
| | | public Response getProductVersion(String parentModel,String customCode) { |
| | | public Response getProductVersion(String parentCode,String customCode) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_model",parentModel); |
| | | wrapper.eq("parent_code",parentCode); |
| | | wrapper.eq("custom_code",customCode); |
| | | wrapper.orderByDesc("version_time"); |
| | | List<ProductHistory> list=mapper.selectList(wrapper); |
| | | return new Response().setII(1,list.size()>0?true:false,list,"返回产品版信息"); |
| | | return new Response().setII(1,list.size()>0,list,"返回产品版信息"); |
| | | } |
| | | |
| | | /**新增追加的版本并将原先的版本的启用设置为未启用*/ |
| | | public void insertAndUpdateEnabled(ProductHistory productHistory) { |
| | | UpdateWrapper<ProductHistory> update = Wrappers.update(); |
| | | update.set("enabled",0).eq("parent_code",productHistory.getParentCode()) |
| | | .eq("custom_code",productHistory.getCustomCode()).eq("enabled",1); |
| | | mapper.update(null,update); |
| | | |
| | | mapper.insert(productHistory); |
| | | } |
| | | |
| | | public void updateEnabledStatus(String parentCode, String customCode, int status) { |
| | | int anotherStatus = 0; |
| | | if(status==0){ |
| | | anotherStatus=1; |
| | | }else{ |
| | | anotherStatus=0; |
| | | } |
| | | UpdateWrapper<ProductHistory> update = Wrappers.update(); |
| | | update.set("enabled",status).eq("parent_code",parentCode) |
| | | .eq("custom_code",customCode).eq("enabled",anotherStatus); |
| | | mapper.update(null,update); |
| | | } |
| | | |
| | | public ProductHistory getEnabledByParentCodeAndCustomCode(String parentCode, String customCode) { |
| | | QueryWrapper<ProductHistory> query = Wrappers.query(); |
| | | query.eq("parent_code",parentCode).eq("custom_code",customCode).eq("enabled",1) |
| | | .last(" limit 1"); |
| | | return mapper.selectOne(query); |
| | | } |
| | | |
| | | public ProductHistory getLatestVersion(String parentCode, String customCode) { |
| | | QueryWrapper<ProductHistory> query = Wrappers.query(); |
| | | query.eq("parent_code",parentCode).eq("custom_code",customCode).orderByDesc("version").last(" limit 1"); |
| | | return mapper.selectOne(query); |
| | | } |
| | | //历史版本可用性设定 |
| | | public Response setpHistoryEnable(String parentCode, String customCode, int version, int enabled) { |
| | | UpdateWrapper wrapper=new UpdateWrapper(); |
| | | wrapper.eq("parent_code",parentCode); |
| | | wrapper.eq("custom_code",customCode); |
| | | int flag=0; |
| | | if(enabled==1){ |
| | | //先将所有的锁定 |
| | | wrapper.set("enabled",0); |
| | | flag=mapper.update(null,wrapper); |
| | | //再将选中的设为可用 |
| | | wrapper.eq("version",version); |
| | | wrapper.set("enabled",1); |
| | | flag=mapper.update(null,wrapper); |
| | | if(flag>0){ |
| | | QueryWrapper qWrapper=new QueryWrapper(); |
| | | qWrapper.eq("parent_code",parentCode); |
| | | qWrapper.eq("custom_code",customCode); |
| | | //1.查询当前product中的信息 |
| | | Product product=productMapper.selectOne(qWrapper); |
| | | //2.将选中的版本的历史信息查询出来 |
| | | qWrapper.eq("version",version); |
| | | ProductHistory pHistory=mapper.selectOne(qWrapper); |
| | | //3:prodcut中删除旧的产品信息 |
| | | UpdateWrapper deleteWrapper=new UpdateWrapper(); |
| | | deleteWrapper.eq("parent_code",parentCode); |
| | | deleteWrapper.eq("custom_code",customCode); |
| | | productMapper.delete(deleteWrapper); |
| | | //4.productBom中删除旧的信息 |
| | | if(product!=null){ |
| | | UpdateWrapper bomWrapper=new UpdateWrapper(); |
| | | bomWrapper.eq("product_id",product.getId()); |
| | | productBomMapper.delete(bomWrapper); |
| | | } |
| | | if(pHistory!=null){ |
| | | // 5.在product中插入设定可用的pHistory |
| | | productMapper.insertPselectPH(pHistory.getId()); |
| | | //6.在productBom中插入pHsitoryBom查询出的数据 |
| | | productBomMapper.insertBomSelectBomH(pHistory.getId()); |
| | | } |
| | | } |
| | | }else{ |
| | | wrapper.eq("version",version); |
| | | wrapper.set("enabled",0); |
| | | flag=mapper.update(null,wrapper); |
| | | if(flag>0){ |
| | | QueryWrapper qWrapper=new QueryWrapper(); |
| | | qWrapper.eq("parent_code",parentCode); |
| | | qWrapper.eq("custom_code",customCode); |
| | | //1.查询当前product中的信息 |
| | | Product product=productMapper.selectOne(qWrapper); |
| | | |
| | | //2.prodcut中删除旧的产品信息 |
| | | UpdateWrapper deleteWrapper=new UpdateWrapper(); |
| | | deleteWrapper.eq("parent_code",parentCode); |
| | | deleteWrapper.eq("custom_code",customCode); |
| | | productMapper.delete(deleteWrapper); |
| | | |
| | | //3.删除productBom |
| | | if(product!=null){ |
| | | UpdateWrapper bomWrapper=new UpdateWrapper(); |
| | | bomWrapper.eq("product_id",product.getId()); |
| | | productBomMapper.delete(bomWrapper); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | return new Response().set(1,flag>0,"历史版本可用性设定"); |
| | | } |
| | | |
| | | public void insert(ProductHistory his) { |
| | | mapper.insert(his); |
| | | } |
| | | } |