111
k94314517
2023-10-16 ca73a173f008c8d7a9d700bad897ca24fe2d2203
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package doumeemes.service.business.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import doumeemes.core.constants.ResponseStatus;
import doumeemes.core.exception.BusinessException;
import doumeemes.core.model.LoginUserInfo;
import doumeemes.core.model.PageData;
import doumeemes.core.model.PageWrap;
import doumeemes.core.utils.Constants;
import doumeemes.core.utils.DateUtil;
import doumeemes.core.utils.redis.RedisUtil;
import doumeemes.dao.business.ApplianceChangeDetialMapper;
import doumeemes.dao.business.ApplianceChangeMapper;
import doumeemes.dao.business.model.ApplianceChange;
import doumeemes.dao.business.model.ApplianceChangeDetial;
import doumeemes.dao.ext.dto.QueryApplianceChangeDetailExtDTO;
import doumeemes.dao.ext.dto.QueryApplianceChangeExtDTO;
import doumeemes.dao.ext.vo.ApplianceChangeDetailExtListVO;
import doumeemes.dao.ext.vo.ApplianceChangeExtListVO;
import doumeemes.service.business.ApplianceChangeService;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.util.Date;
import java.util.List;
 
/**
 * 设置类-工装器具更换记录表Service实现
 * @author 江蹄蹄
 * @date 2022/07/19 14:29
 */
@Service
public class ApplianceChangeServiceImpl implements ApplianceChangeService {
 
    @Autowired
    private ApplianceChangeMapper applianceChangeMapper;
 
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;
    @Autowired
    private ApplianceChangeDetialServiceImpl applianceChangeDetialServiceimpl;
    @Autowired
    private AppliancesServiceImpl appliancesServiceimpl;
 
 
    @Autowired
    private ApplianceChangeDetialMapper applianceChangeDetialMapper;
 
    @Override
    public Integer create(ApplianceChange applianceChange) {
        applianceChangeMapper.insert(applianceChange);
        return applianceChange.getId();
    }
 
    @Override
    public void deleteById(Integer id) {
        applianceChangeMapper.deleteById(id);
    }
 
    @Override
    public void delete(ApplianceChange applianceChange) {
        UpdateWrapper<ApplianceChange> deleteWrapper = new UpdateWrapper<>(applianceChange);
        applianceChangeMapper.delete(deleteWrapper);
    }
 
    @Override
    public void deleteByIdInBatch(List<Integer> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return;
        }
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        for (Integer id: ids) {
 
            ApplianceChange applianceChange =applianceChangeMapper.selectById(id);
            applianceChange.setDeleted(Constants.ONE);
            applianceChange.setUpdateTime(new Date());
            applianceChange.setUpdateUser(user.getId());
            this.updateById(applianceChange);
 
            ApplianceChangeDetial applianceChangeDetial =new ApplianceChangeDetial();
            applianceChangeDetial.setDeleted(Constants.ONE);
            applianceChangeDetial.setUpdateTime(new Date());
            applianceChangeDetial.setUpdateUser(user.getId());
            applianceChangeDetial.setChaneId(applianceChange.getId());
            applianceChangeDetialServiceimpl.updateBycondition(applianceChangeDetial);
        }
        //applianceChangeMapper.deleteBatchIds(ids);
    }
 
    @Override
    public void updateById(ApplianceChange applianceChange) {
        applianceChangeMapper.updateById(applianceChange);
    }
 
    @Override
    public void updateByIdInBatch(List<ApplianceChange> applianceChanges) {
        if (CollectionUtils.isEmpty(applianceChanges)) {
            return;
        }
        for (ApplianceChange applianceChange: applianceChanges) {
            this.updateById(applianceChange);
        }
    }
 
    @Override
    public ApplianceChange findById(Integer id) {
        return applianceChangeMapper.selectById(id);
    }
 
    @Override
    public ApplianceChange findOne(ApplianceChange applianceChange) {
        QueryWrapper<ApplianceChange> wrapper = new QueryWrapper<>(applianceChange);
        return applianceChangeMapper.selectOne(wrapper);
    }
 
    @Override
    public List<ApplianceChange> findList(ApplianceChange applianceChange) {
        QueryWrapper<ApplianceChange> wrapper = new QueryWrapper<>(applianceChange);
        return applianceChangeMapper.selectList(wrapper);
    }
  
    @Override
    public PageData<ApplianceChange> findPage(PageWrap<ApplianceChange> pageWrap) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
        }
        //只能查看当前根组织的数据
        pageWrap.getModel().setDeleted(Constants.ZERO);
        pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId());
//        if(!Constants.equalsInteger(user.getCurComDepartment().getId(),user.getRootDepartment().getId())){
        //如果当前选择的公司级组织非根组织信息,只能查看当前选择公司级组织数据
        pageWrap.getModel().setDepartId(user.getCurComDepartment().getId());
//        }
        //数据权限
     /*   List<Integer> dataPermission = user.getDepartPermissionList();
        if(dataPermission!=null){
            if(dataPermission.size() == 0){
                //只能看自己的
              //  pageWrap.getModel().setPmodelUserId(user.getId());
            }else{
                //否则走数据权限
                pageWrap.getModel().setDepartIds(dataPermission);
            }
        }*/
        PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
        List<ApplianceChange> result = null;//applianceChangeMapper.selectList(pageWrap.getModel());
 
        return PageData.from(new PageInfo<>(result));
    }
 
 
    @Override
    public PageData<ApplianceChangeExtListVO> findListPage(PageWrap<QueryApplianceChangeExtDTO> pageWrap) {
        LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
        if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!");
        }
        //只能查看当前根组织的数据
        pageWrap.getModel().setDeleted(Constants.ZERO);
        pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId());
//        if(!Constants.equalsInteger(user.getCurComDepartment().getId(),user.getRootDepartment().getId())){
        //如果当前选择的公司级组织非根组织信息,只能查看当前选择公司级组织数据
        pageWrap.getModel().setDepartId(user.getCurComDepartment().getId());
//        }
        //数据权限
        List<Integer> dataPermission = user.getDepartPermissionList();
        if(dataPermission!=null){
            pageWrap.getModel().setCreateUser(user.getId());
            pageWrap.getModel().setDepartIds(dataPermission);
        /*    if(dataPermission.size() == 0){
                //只能看自己的
              //  pageWrap.getModel().setPmodelUserId(user.getId());
 
            }else{
                //否则走数据权限
 
            }*/
        }
        PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity());
        List<ApplianceChangeExtListVO> result = applianceChangeMapper.selectList(pageWrap.getModel());
        if(result.size()>0){
            for(int i=0;i<result.size();i++){
                ApplianceChangeExtListVO acev=result.get(i);
 
                QueryApplianceChangeDetailExtDTO acd=new QueryApplianceChangeDetailExtDTO();
                acd.setChaneId(acev.getId());
                acd.setType(Constants.ONE);
                List<ApplianceChangeDetailExtListVO> listacd= applianceChangeDetialMapper.selectList(acd);
                Integer changenum=0;
                if(listacd!=null&&listacd.size()>0){
                    for(int j=0;j<listacd.size();j++){
                        ApplianceChangeDetailExtListVO acddata=listacd.get(j);
 
                            changenum=changenum+ acddata.getNum();
 
                    }
                    acev.setChangenum(changenum);
                /*    Appliances app= appliancesServiceimpl.findById(listacd.get(0).getApplianceId());
                   if(app!=null&&app.getQualityType()!=null){
                       acev.setQualityType(app.getQualityType()+"");
                   }*/
 
 
                }
 
            }
        }
 
        return PageData.from(new PageInfo<>(result));
    }
 
    @Override
    public long count(ApplianceChange applianceChange) {
        QueryWrapper<ApplianceChange> wrapper = new QueryWrapper<>(applianceChange);
        return applianceChangeMapper.selectCount(wrapper);
    }
 
 
    @Override
    public synchronized  String  getNextCode(Integer comId ){
        String prefix = "GHD"+DateUtil.getDate(new Date(),"yyyyMMdd") +"-";
        Integer countNum  = RedisUtil.getObject(redisTemplate, Constants.RedisKeys.COM_APPLIANCECHANGER_CODE_KEY+comId,Integer.class);
        countNum = Constants.formatIntegerNum(countNum)+1;
        //更新缓存
        RedisUtil.addObject(redisTemplate,Constants.RedisKeys.COM_APPLIANCECHANGER_CODE_KEY+comId,countNum);
        String nextIndex =Integer.toString( countNum);
        return prefix + StringUtils.leftPad(nextIndex,4,"0");
    }
 
}