Fancy
2024-08-20 1ade3411b380253e8789fa85aeeb70c4d64530dd
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package com.dy.pmsProduct.order;
 
import cn.hutool.core.codec.Base64;
import com.dy.common.webUtil.QueryResultVo;
import com.dy.pmsGlobal.daoOth.OthFileMapper;
import com.dy.pmsGlobal.daoPr.*;
import com.dy.pmsGlobal.dyFile.FileOperate;
import com.dy.pmsGlobal.pojoPlt.PltProduct;
import com.dy.pmsGlobal.pojoPr.*;
import com.dy.pmsGlobal.util.UserUtil;
import com.dy.pmsProduct.order.QueryVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.common.utils.PojoUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.io.IOException;
import java.util.List;
import java.util.Map;
 
@Slf4j
@Service
public class OrderSv {
    private PrOrderMapper orderDao;
    private PrOrderItemMapper orderItemDao;
    private UserUtil userUtil;
    private FileOperate fileOperate;
    private OthFileMapper othFileMapper;
    @Value("${dy.webFile.fmUrl}")
    private String fmUrl;
    @Autowired
    public void setOrderDao(PrOrderMapper orderDao) {
        this.orderDao = orderDao;
    }
 
    @Autowired
    public void setOrderItemDao(PrOrderItemMapper orderItemDao) {
        this.orderItemDao = orderItemDao;
    }
 
    @Autowired
    public void setUserUtil(UserUtil userUtil) {
        this.userUtil = userUtil;
    }
 
    @Autowired
    public void setFileOperate(FileOperate fileOperate) {
        this.fileOperate = fileOperate;
    }
 
    @Autowired
    public void setOthFileMapper(OthFileMapper othFileMapper) {
        this.othFileMapper = othFileMapper;
    }
 
    @Transactional
    public int save(PrOrder p) {
        //判断产品不能重名
        if (orderDao.exists(p.name, p.id)) {
            throw new RuntimeException("订单名称不能重复");
        }
        int count = orderDao.insertSelective(p);
        saveOrderItems(p);
        return count;
    }
    @Transactional
    public int update(PrOrder p) {
        if (orderDao.exists(p.name, p.id)) {
            throw new RuntimeException("订单名称不能重复");
        }
        int count = orderDao.updateByPrimaryKeySelective(p);
        saveOrderItems(p);
        return count;
    }
    private void saveOrderItems(PrOrder p) {
        p.items.forEach(param->{
            param.orderId=p.id;
            if(param.id !=null){
                orderItemDao.updateByPrimaryKeySelective(param);
            }else{
                param.deleted=false;
                orderItemDao.insert(param);
            }
        });
    }
 
    /**
     * 逻辑删除实体
     * @param id 实体ID
     * @return 影响记录数量
     */
    @Transactional
    public int delete(Long id) {
        return orderDao.deleteLogicById(id);
    }
 
    public PrOrder selectById(String proId) {
        PrOrder pro=orderDao.selectByPrimaryKey(Long.valueOf(proId));
        return pro;
    }
 
    /**
     * 获取订单列表
     */
    public QueryResultVo<List<PrOrder>> selectSome(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
 
        //查询符合条件的记录总数
        Long itemTotal = orderDao.selectSomeCount(params);
 
        QueryResultVo<List<PrOrder>> rsVo = new QueryResultVo<>(queryVo.pageSize, queryVo.pageCurr);
        //计算分页等信息
        rsVo.calculateAndSet(itemTotal, params);
 
        //查询符合条件的记录
        rsVo.obj = orderDao.selectSome(params);
        return rsVo;
    }
 
    public List<PrOrder> selectAll(QueryVo queryVo) {
        Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo);
        return orderDao.selectAll(params);
    }
}