heheng
2025-12-03 430477c7e0777531f22fc18dc8906ea75cdc21d9
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
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.exception.ApiException;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.CustomerRecord;
import com.gkhy.exam.system.domain.CustomerRecordNeed;
import com.gkhy.exam.system.mapper.CustomerRecordMapper;
import com.gkhy.exam.system.mapper.CustomerRecordNeedMapper;
import com.gkhy.exam.system.service.CustomerRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.time.LocalDateTime;
import java.util.List;
 
@Service
public class CustomerRecordServiceImpl extends ServiceImpl<CustomerRecordMapper, CustomerRecord> implements CustomerRecordService {
 
 
    @Autowired
    private CustomerRecordMapper customerRecordMapper;
 
    @Autowired
    private CustomerRecordNeedMapper customerRecordNeedMapper;
 
    @Override
    public CommonPage selectCustomerRecordList(CustomerRecord customerRecord) {
        if (!SecurityUtils.adminUser()){
            if (customerRecord.getCompanyId()==null){
                throw new ApiException("非管理员操作,查询条件不可为空");
            }
        }
        PageUtils.startPage();
        List<CustomerRecord> customerRecords = customerRecordMapper.selectRecordList(customerRecord);
        for (CustomerRecord record : customerRecords) {
            List<CustomerRecordNeed> customerRecordNeeds = customerRecordNeedMapper.selectByRecordId(record.getId());
            record.setCustomerRecordNeeds(customerRecordNeeds);
        }
        return CommonPage.restPage(customerRecords);
    }
 
    @Override
    @Transactional
    public CommonResult insertCustomerRecord(CustomerRecord customerRecord) {
        customerRecord.setCreateBy(SecurityUtils.getUsername());
        customerRecord.setCreateTime(LocalDateTime.now());
        int insert = customerRecordMapper.insert(customerRecord);
        if (insert>0){
            List<CustomerRecordNeed> customerRecordNeeds = customerRecord.getCustomerRecordNeeds();
            for (CustomerRecordNeed customerRecordNeed : customerRecordNeeds) {
                customerRecordNeed.setRecordId(customerRecord.getId());
            }
            Integer i = customerRecordNeedMapper.insertNeeds(customerRecordNeeds);
            if (i>0){
                return CommonResult.success();
            }else {
                return CommonResult.failed();
            }
        }
        return CommonResult.failed();
    }
 
    @Override
    @Transactional
    public CommonResult updateCustomerRecord(CustomerRecord customerRecord) {
        customerRecord.setUpdateBy(SecurityUtils.getUsername());
        customerRecord.setUpdateTime(LocalDateTime.now());
        int insert = customerRecordMapper.updateById(customerRecord);
        if (insert>0){
            customerRecordNeedMapper.deleteByRecordId(customerRecord.getId());
            Integer i = customerRecordNeedMapper.insertNeeds(customerRecord.getCustomerRecordNeeds());
            if (i>0){
                return CommonResult.success();
            }else {
                return CommonResult.failed();
            }
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult deletedCustomerRecord(Integer recordId) {
        CustomerRecord customerRecord = new CustomerRecord();
        customerRecord.setId(recordId);
        customerRecord.setUpdateBy(SecurityUtils.getUsername());
        customerRecord.setUpdateTime(LocalDateTime.now());
        customerRecord.setDelFlag(2);
        int i = customerRecordMapper.updateById(customerRecord);
        if (i>0){
            return CommonResult.success();
        }else {
            return CommonResult.failed();
        }
    }
}