whycxzp
2022-08-23 3504ed684a4e947787644c1003a2b7d40e684820
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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.ProductHistoryMapper;
import com.whyc.pojo.ProductHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
public class ProductHistoryService {
    @Autowired(required = false)
    private ProductHistoryMapper mapper;
 
 
    //产品详情查看版本信息
    public Response getProductVersion(String parentModel,String customCode) {
        QueryWrapper wrapper=new QueryWrapper();
        wrapper.eq("parent_model",parentModel);
        wrapper.eq("custom_code",customCode);
        List<ProductHistory> list=mapper.selectList(wrapper);
        return new Response().setII(1,list.size()>0?true:false,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);
    }
}