liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
/**
 * Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.test.service.onetomany;
 
import java.util.List;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import com.jeeplus.common.persistence.Page;
import com.jeeplus.common.service.CrudService;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.modules.test.entity.onetomany.TestDataMain;
import com.jeeplus.modules.test.dao.onetomany.TestDataMainDao;
import com.jeeplus.modules.test.entity.onetomany.TestDataChild;
import com.jeeplus.modules.test.dao.onetomany.TestDataChildDao;
import com.jeeplus.modules.test.entity.onetomany.TestDataChild2;
import com.jeeplus.modules.test.dao.onetomany.TestDataChild2Dao;
import com.jeeplus.modules.test.entity.onetomany.TestDataChild3;
import com.jeeplus.modules.test.dao.onetomany.TestDataChild3Dao;
 
/**
 * 票务代理Service
 * @author liugf
 * @version 2016-03-13
 */
@Service
@Transactional(readOnly = true)
public class TestDataMainService extends CrudService<TestDataMainDao, TestDataMain> {
 
    @Autowired
    private TestDataChildDao testDataChildDao;
    @Autowired
    private TestDataChild2Dao testDataChild2Dao;
    @Autowired
    private TestDataChild3Dao testDataChild3Dao;
    
    public TestDataMain get(String id) {
        TestDataMain testDataMain = super.get(id);
        testDataMain.setTestDataChildList(testDataChildDao.findList(new TestDataChild(testDataMain)));
        testDataMain.setTestDataChild2List(testDataChild2Dao.findList(new TestDataChild2(testDataMain)));
        testDataMain.setTestDataChild3List(testDataChild3Dao.findList(new TestDataChild3(testDataMain)));
        return testDataMain;
    }
    
    public List<TestDataMain> findList(TestDataMain testDataMain) {
        return super.findList(testDataMain);
    }
    
    public Page<TestDataMain> findPage(Page<TestDataMain> page, TestDataMain testDataMain) {
        return super.findPage(page, testDataMain);
    }
    
    @Transactional(readOnly = false)
    public void save(TestDataMain testDataMain) {
        super.save(testDataMain);
        for (TestDataChild testDataChild : testDataMain.getTestDataChildList()){
            if (testDataChild.getId() == null){
                continue;
            }
            if (TestDataChild.DEL_FLAG_NORMAL.equals(testDataChild.getDelFlag())){
                if (StringUtils.isBlank(testDataChild.getId())){
                    testDataChild.setTestDataMain(testDataMain);
                    testDataChild.preInsert();
                    testDataChildDao.insert(testDataChild);
                }else{
                    testDataChild.preUpdate();
                    testDataChildDao.update(testDataChild);
                }
            }else{
                testDataChildDao.delete(testDataChild);
            }
        }
        for (TestDataChild2 testDataChild2 : testDataMain.getTestDataChild2List()){
            if (testDataChild2.getId() == null){
                continue;
            }
            if (TestDataChild2.DEL_FLAG_NORMAL.equals(testDataChild2.getDelFlag())){
                if (StringUtils.isBlank(testDataChild2.getId())){
                    testDataChild2.setTestDataMain(testDataMain);
                    testDataChild2.preInsert();
                    testDataChild2Dao.insert(testDataChild2);
                }else{
                    testDataChild2.preUpdate();
                    testDataChild2Dao.update(testDataChild2);
                }
            }else{
                testDataChild2Dao.delete(testDataChild2);
            }
        }
        for (TestDataChild3 testDataChild3 : testDataMain.getTestDataChild3List()){
            if (testDataChild3.getId() == null){
                continue;
            }
            if (TestDataChild3.DEL_FLAG_NORMAL.equals(testDataChild3.getDelFlag())){
                if (StringUtils.isBlank(testDataChild3.getId())){
                    testDataChild3.setTestDataMain(testDataMain);
                    testDataChild3.preInsert();
                    testDataChild3Dao.insert(testDataChild3);
                }else{
                    testDataChild3.preUpdate();
                    testDataChild3Dao.update(testDataChild3);
                }
            }else{
                testDataChild3Dao.delete(testDataChild3);
            }
        }
    }
    
    @Transactional(readOnly = false)
    public void delete(TestDataMain testDataMain) {
        super.delete(testDataMain);
        testDataChildDao.delete(new TestDataChild(testDataMain));
        testDataChild2Dao.delete(new TestDataChild2(testDataMain));
        testDataChild3Dao.delete(new TestDataChild3(testDataMain));
    }
    
}