admin
2019-03-14 eed607d87b2eee1f09b4a28da614f3ad0b46601d
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package com.yeshi.fanli.service.impl.homemodule;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.annotation.Resource;
import javax.transaction.Transactional;
 
import org.apache.commons.beanutils.PropertyUtils;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.homemodule.SpecialCardMapper;
import com.yeshi.fanli.dao.mybatis.homemodule.SuperSpecialCardMapper;
import com.yeshi.fanli.entity.bus.homemodule.SpecialCard;
import com.yeshi.fanli.entity.bus.homemodule.SuperSpecialCard;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.homemodule.SpecialCardService;
import com.yeshi.fanli.service.inter.homemodule.SpecialService;
 
 
@Service
public class SpecialCardServiceImpl implements SpecialCardService {
    
    @Resource
    private SpecialCardMapper specialCardMapper;
 
    @Resource
    private BusinessSystemService businessSystemService;
    
    @Resource
    private SpecialService specialService;
    
    @Resource
    private SuperSpecialCardMapper superSpecialCardMapper;
    
    @Override
    public int deleteByPrimaryKey(Long id) {
        return specialCardMapper.deleteByPrimaryKey(id);
    }
 
    @Override
    public int insert(SpecialCard record) {
        return specialCardMapper.insert(record);
    }
 
    @Override
    public int insertSelective(SpecialCard record) {
        return specialCardMapper.insertSelective(record);
    }
 
    @Override
    public SpecialCard selectByPrimaryKey(Long id) {
        return specialCardMapper.selectByPrimaryKey(id);
    }
 
    @Override
    public int updateByPrimaryKeySelective(SpecialCard record) {
        return specialCardMapper.updateByPrimaryKeySelective(record);
    }
 
    @Override
    public int updateByPrimaryKey(SpecialCard record) {
        return specialCardMapper.updateByPrimaryKey(record);
    }
 
    
    @Override
    @Transactional
    public int deleteBatchByPrimaryKey(List<Long> list) throws Exception{
        
        specialService.deleteBatchByCardID(list);
        superSpecialCardMapper.deleteBatchByCardId(list);
        
        return specialCardMapper.deleteBatchByPrimaryKey(list);
    }
    
    @Override
    public List<SpecialCard> listQuery(long start, int count, String key, Integer sort) {
        
        List<SpecialCard> listObj = specialCardMapper.listQuery(start, count, key, sort);
        if (listObj == null || listObj.size() == 0) {
            return null;
        }
        
        List<BusinessSystem> systemList = businessSystemService.getBusinessSystems();
        
        List<Long> listCardId = new ArrayList<Long>();
        for (SpecialCard specialCard: listObj) {
            listCardId.add(specialCard.getId());
        }
        
        List<SuperSpecialCard> listSuper = superSpecialCardMapper.listByCardIDs(listCardId);
        
        if (listSuper == null || listSuper.size() == 0) {
            
            for (SpecialCard specialCard: listObj) {
                specialCard.setSystemList(systemList);
            }
            
        } else {
            for (SpecialCard specialCard: listObj) {
                
                Long id = specialCard.getId();
                
                List<BusinessSystem> newList = new ArrayList<BusinessSystem>();
                // 是否有关联系统选项
                for (BusinessSystem dsystem : systemList) {
                    
                    BusinessSystem newsystem = new BusinessSystem();
                    
                    try {
                        PropertyUtils.copyProperties(newsystem, dsystem);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    
                    
                    
                    if (listSuper != null && listSuper.size() > 0) {
                        
                        Long systemId = newsystem.getId();
                        
                        for (SuperSpecialCard superSpecialCard : listSuper) {
                            SpecialCard special = superSpecialCard.getSpecialCard();
                            BusinessSystem system = superSpecialCard.getSystem();
                            
                            // 当前专题 、当前系统
                            if (special != null && system != null && id == special.getId() 
                                    && systemId == system.getId()) {
                                newsystem.setCheck(1);
                                break;
                            }
                        }
                    }
                    
                    if (newsystem.getCheck() != 1) {
                        newsystem.setCheck(0);
                    }
                    
                    newList.add(newsystem);
                }
                
                specialCard.setSystemList(newList);
            }
        }
        
        return listObj;
    }
    
    @Override
    public long countlistQuery(String key) {
        return specialCardMapper.countlistQuery(key);
    }
 
}