whycxzp
2022-08-25 09fa946e0679c6ea6248c9223f64621675db5fa8
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
39
40
41
42
43
44
45
46
47
48
49
50
51
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);
    }
 
    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);
    }
}