lxw
2022-08-27 09e69838d9e7be10acebe6f4e692d7195df07630
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whyc.dto.Response;
import com.whyc.mapper.ProductMapper;
import com.whyc.pojo.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
 
@Service
public class ProductService {
    @Autowired(required = false)
    private ProductMapper mapper;
 
    //查询出所有的产品信息(分页加模糊查询<产品的编码,型号,名字,定制表编号>
    public Response getAllProduct(String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) {
        PageHelper.startPage(pageCurr,pageSize);
        QueryWrapper wrapper=new QueryWrapper();
        if(parentCode!=null&&!parentCode.isEmpty()){
            wrapper.like("parent_code",parentCode);
        }
        if(parentName!=null&&!parentName.isEmpty()){
            wrapper.like("parent_name",parentName);
        }
        if(parentModel!=null&&!parentModel.isEmpty()){
            wrapper.like("parent_model",parentModel);
        }
        if(customCode!=null&&!customCode.isEmpty()){
            wrapper.like("custom_code",customCode);
        }
        wrapper.orderByAsc("id");
        List list=mapper.selectList(wrapper);
        PageInfo pageInfo=new PageInfo(list);
        return new Response().setII(1,list.size()>0?true:false,pageInfo,"返回产品信息");
    }
 
    public Product getVersion(String parentCode, String customCode) {
        QueryWrapper<Product> query = Wrappers.query();
        query.eq("parent_code",parentCode).eq("custom_code",customCode).last(" limit 1");
        return mapper.selectOne(query);
    }
 
    public Product getVersion(Integer productId) {
        QueryWrapper<Product> query = Wrappers.query();
        query.eq("product_id",productId);
        return mapper.selectOne(query);
    }
 
    public int updateVersion(String parentCode, String customCode, Integer nextVersion) {
        UpdateWrapper<Product> update = Wrappers.update();
        update.set("version",nextVersion).eq("parent_code",parentCode).eq("custom_code",customCode);
        mapper.update(null,update);
 
        QueryWrapper<Product> query = Wrappers.query();
        query.select("id").eq("parent_code",parentCode).eq("custom_code",customCode);
        return mapper.selectOne(query).getId();
    }
 
    public Product getById(Integer id) {
        return mapper.selectById(id);
    }
 
    public void deleteByParentCodeAndCustomCode(String parentCode, String customCode) {
        UpdateWrapper<Product> update = Wrappers.update();
        update.eq("parent_code",parentCode).eq("custom_code",customCode);
        mapper.delete(update);
    }
 
    public void insert(Product product) {
        mapper.insert(product);
    }
}