Administrator
2025-07-09 44aa87717297bb4fca4bb83ba631646a87749174
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
package cc.mrbird.febs.mall.service.impl;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.enumerates.*;
import cc.mrbird.febs.common.exception.FebsException;
import cc.mrbird.febs.common.utils.LoginUserUtil;
import cc.mrbird.febs.mall.dto.clothes.*;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
import cc.mrbird.febs.mall.service.ApiClothesSocialService;
import cc.mrbird.febs.mall.vo.activity.ApiScCategoryInfoVo;
import cc.mrbird.febs.mall.vo.clothes.*;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
 
@Slf4j
@Service
@RequiredArgsConstructor
public class ApiClothesSocialServiceImpl extends ServiceImpl<ClothesSocialMapper, ClothesSocial> implements ApiClothesSocialService {
 
    private final ClothesSocialMapper clothesSocialMapper;
    private final ClothesSocialFileMapper clothesSocialFileMapper;
    private final ClothesSocialMuseMapper clothesSocialMuseMapper;
    private final ClothesSocialCategoryMapper clothesSocialCategoryMapper;
    private final MallMemberMapper mallMemberMapper;
 
 
    private final ClothesTypeMapper clothesTypeMapper;
    private final ClothesSizeMapper clothesSizeMapper;
    private final ClothesPatternMapper clothesPatternMapper;
    private final ClothesLocationMapper clothesLocationMapper;
    private final ClothesClothMapper clothesClothMapper;
    private final ClothesArtMapper clothesArtMapper;
    private final ClothesOrderMapper clothesOrderMapper;
    private final ClothesOrderItemMapper clothesOrderItemMapper;
    private final ClothesSocialFollowMapper clothesSocialFollowMapper;
 
 
    private final ClothesTypeClothMapper clothesTypeClothMapper;
    private final ClothesTypePatternMapper clothesTypePatternMapper;
    private final ClothesTypeSizeMapper clothesTypeSizeMapper;
    private final ClothesTypeLocationMapper clothesTypeLocationMapper;
    private final ClothesTypeArtMapper clothesTypeArtMapper;
 
 
    @Override
    public FebsResponse allCategory() {
        List<ApiClothesCategoryInfoVo> vos = new ArrayList<>();
        List<ClothesSocialCategory> list = clothesSocialCategoryMapper.selectList(
                Wrappers.lambdaQuery(ClothesSocialCategory.class)
                        .select(ClothesSocialCategory::getId, ClothesSocialCategory::getName)
                        .eq(ClothesSocialCategory::getState, ClothesEnum.UP.getCode())
                        .eq(ClothesSocialCategory::getDeleteFlag, ClothesEnum.DOWN.getCode())
                        .orderByAsc(ClothesSocialCategory::getOrderCnt)
        );
        if(CollUtil.isNotEmpty(list)){
            vos = buildApiClothesCategoryInfoVo(list, vos);
        }
        return new FebsResponse().success().data(vos);
    }
 
    private List<ApiClothesCategoryInfoVo> buildApiClothesCategoryInfoVo(List<ClothesSocialCategory> list, List<ApiClothesCategoryInfoVo> vos) {
        for (ClothesSocialCategory entity : list) {
            ApiClothesCategoryInfoVo vo = new ApiClothesCategoryInfoVo();
            vo.setId(entity.getId());
            vo.setName(entity.getName());
            vos.add(vo);
        }
        return vos;
    }
 
    @Override
    public FebsResponse indexCategory() {
        List<ApiClothesCategoryInfoVo> vos = new ArrayList<>();
        List<ClothesSocialCategory> list = clothesSocialCategoryMapper.selectList(
                Wrappers.lambdaQuery(ClothesSocialCategory.class)
                        .select(ClothesSocialCategory::getId, ClothesSocialCategory::getName)
                        .eq(ClothesSocialCategory::getState, ClothesEnum.UP.getCode())
                        .eq(ClothesSocialCategory::getHotState, ClothesEnum.UP.getCode())
                        .eq(ClothesSocialCategory::getDeleteFlag, ClothesEnum.DOWN.getCode())
                        .orderByAsc(ClothesSocialCategory::getOrderCnt)
        );
        if(CollUtil.isNotEmpty(list)){
            vos = buildApiClothesCategoryInfoVo(list, vos);
        }
        return new FebsResponse().success().data(vos);
    }
 
    @Override
    public FebsResponse allSocial(ApiAllSocialDto dto) {
        // 创建分页对象,传入当前页和每页大小
        Page<ApiAllSocialVo> page = new Page<>(dto.getPageNow(), dto.getPageSize());
        // 调用Mapper方法获取活动分页数据
        Page<ApiAllSocialVo> voPage = clothesSocialMapper.selectPageInSocial(page, dto);
 
        return new FebsResponse().success().data(voPage);
    }
 
    @Override
    public FebsResponse socialInfo(ApiSocialInfoDto dto) {
        ApiSocialInfoVo apiSocialInfoVo = new ApiSocialInfoVo();
        Long socialId = dto.getSocialId();
        ClothesSocial clothesSocial = clothesSocialMapper.selectById(socialId);
        if(ObjectUtil.isNotNull(clothesSocial)){
            MallMember mallMember = mallMemberMapper.selectById(clothesSocial.getMemberId());
            apiSocialInfoVo.setId(clothesSocial.getId());
            apiSocialInfoVo.setMemberName(mallMember.getName());
            apiSocialInfoVo.setMemberAvatar(mallMember.getAvatar());
            apiSocialInfoVo.setName(clothesSocial.getName());
            apiSocialInfoVo.setContent(clothesSocial.getContent());
            apiSocialInfoVo.setCreatedTime(clothesSocial.getCreatedTime());
 
            List<ClothesSocialFile> clothesSocialFiles = clothesSocialFileMapper.selectList(
                    Wrappers.lambdaQuery(ClothesSocialFile.class)
                            .select(ClothesSocialFile::getFileUrl)
                            .eq(ClothesSocialFile::getSocialId, socialId)
                            .orderByAsc(ClothesSocialFile::getSeq)
            );
            if(CollUtil.isNotEmpty(clothesSocialFiles)){
                apiSocialInfoVo.setImages(clothesSocialFiles.stream().map(ClothesSocialFile::getFileUrl).collect(Collectors.toList()));
            }
 
            ApiSocialMuseVo apiSocialMuseVo = new ApiSocialMuseVo();
            ClothesSocialMuse clothesSocialMuse = clothesSocialMuseMapper.selectOne(
                    Wrappers.lambdaQuery(ClothesSocialMuse.class)
                            .eq(ClothesSocialMuse::getSocialId, socialId)
                            .last("LIMIT 1")
            );
            if(ObjectUtil.isNotNull(clothesSocialMuse)){
                BigDecimal totalAmount = BigDecimal.ZERO;
                apiSocialMuseVo.setMuseId(clothesSocialMuse.getId());
 
                apiSocialMuseVo.setPatternImage(clothesSocialMuse.getPatternImage());
                apiSocialMuseVo.setPatternText(clothesSocialMuse.getPatternText());
 
                ClothesType clothesType = clothesTypeMapper.selectById(clothesSocialMuse.getTypeId());
                if(ObjectUtil.isNotNull(clothesType)){
                    apiSocialMuseVo.setTypeName(clothesType.getName());
                    apiSocialMuseVo.setTypeImg(clothesType.getImage());
                }
                ClothesSize clothesSize = clothesSizeMapper.selectById(clothesSocialMuse.getSizeId());
                if(ObjectUtil.isNotNull(clothesSize)){
                    apiSocialMuseVo.setSizeName(clothesSize.getName());
                    totalAmount = totalAmount.add(clothesSize.getPrice());
                }
                ClothesPattern clothesPattern = clothesPatternMapper.selectById(clothesSocialMuse.getPatternId());
                if(ObjectUtil.isNotNull(clothesPattern)){
                    apiSocialMuseVo.setPatternName(clothesPattern.getName());
                    totalAmount = totalAmount.add(clothesPattern.getPrice());
                }
                ClothesLocation clothesLocation = clothesLocationMapper.selectById(clothesSocialMuse.getLocationId());
                if(ObjectUtil.isNotNull(clothesLocation)){
                    apiSocialMuseVo.setLocationName(clothesLocation.getName());
                    totalAmount = totalAmount.add(clothesLocation.getPrice());
                }
                ClothesCloth clothesCloth = clothesClothMapper.selectById(clothesSocialMuse.getClothId());
                if(ObjectUtil.isNotNull(clothesCloth)){
                    apiSocialMuseVo.setClothName(clothesCloth.getName());
                    totalAmount = totalAmount.add(clothesCloth.getPrice());
                }
                ClothesArt clothesArt = clothesArtMapper.selectById(clothesSocialMuse.getArtId());
                if(ObjectUtil.isNotNull(clothesArt)){
                    apiSocialMuseVo.setArtName(clothesArt.getName());
                    totalAmount = totalAmount.add(clothesArt.getPrice());
                }
                apiSocialMuseVo.setTotalAmount(totalAmount.setScale(2, RoundingMode.DOWN));
            }
        }
 
 
        return new FebsResponse().success().data(apiSocialInfoVo);
    }
 
    @Override
    @Transactional
    public FebsResponse socialAdd(ApiSocialAddDto dto) {
 
        Long memberId = LoginUserUtil.getLoginUser().getId();
        Long orderId = dto.getOrderId();
        ClothesOrder order = clothesOrderMapper.selectOne(
                Wrappers.lambdaQuery(ClothesOrder.class)
                        .eq(ClothesOrder::getId, orderId)
                        .eq(ClothesOrder::getMemberId, memberId)
        );
        if(ObjectUtil.isNull( order)){
            throw new FebsException("请选择订单");
        }
        if(ClothesOrderStatusEnum.FINISH.getValue() != order.getStatus()){
            throw new FebsException("订单未确认收货");
        }
 
        String content = dto.getContent();
        List<String> contentFile = dto.getContentFile();
        String indexFile = dto.getIndexFile();
        String title = dto.getTitle();
 
        ClothesSocial clothesSocial = new ClothesSocial();
        clothesSocial.setMemberId(memberId);
        clothesSocial.setName(title);
        clothesSocial.setContent(content);
        clothesSocial.setIndexFile(indexFile);
        clothesSocialMapper.insert(clothesSocial);
 
        if(CollUtil.isNotEmpty(contentFile)){
            int i = 0;
            for (String file : contentFile){
                ClothesSocialFile clothesSocialFile = new ClothesSocialFile();
                clothesSocialFile.setSocialId(clothesSocial.getId());
                clothesSocialFile.setFileUrl(file);
                clothesSocialFile.setSeq(i);
                clothesSocialFileMapper.insert(clothesSocialFile);
                i++;
            }
        }
 
        ClothesSocialMuse clothesSocialMuse = new ClothesSocialMuse();
        clothesSocialMuse.setSocialId(clothesSocial.getId());
        clothesSocialMuse.setTypeId(order.getTypeId());
 
        List<ClothesOrderItem> clothesOrderItems = clothesOrderItemMapper.selectList(
                Wrappers.lambdaQuery(ClothesOrderItem.class)
                        .eq(ClothesOrderItem::getOrderId, orderId)
        );
        if(CollUtil.isEmpty(clothesOrderItems)){
            for (ClothesOrderItem item : clothesOrderItems){
                if (ClothesOrderItemEnum.CLOTH.getCode() == item.getType()) {
                    ClothesCloth cloth = clothesClothMapper.selectById(item.getItemId());
                    clothesSocialMuse.setClothId(cloth.getId());
                    continue;
                } else if (ClothesOrderItemEnum.SIZE.getCode() == item.getType()) {
                    ClothesSize size = clothesSizeMapper.selectById(item.getItemId());
                    clothesSocialMuse.setSizeId(size.getId());
                    continue;
                } else if (ClothesOrderItemEnum.LOCATION.getCode() == item.getType()) {
                    ClothesLocation location = clothesLocationMapper.selectById(item.getItemId());
                    clothesSocialMuse.setLocationId(location.getId());
                    continue;
                } else if (ClothesOrderItemEnum.PATTERN.getCode() == item.getType()) {
                    ClothesPattern pattern = clothesPatternMapper.selectById(item.getItemId());
                    clothesSocialMuse.setPatternId(pattern.getId());
                    clothesSocialMuse.setPatternRemark(item.getRemark());
                    continue;
                } else if (ClothesOrderItemEnum.ART.getCode() == item.getType()) {
                    ClothesArt art = clothesArtMapper.selectById(item.getItemId());
                    clothesSocialMuse.setArtId(art.getId());
                    continue;
                }else{
                    continue;
                }
            }
        }
        clothesSocialMuseMapper.insert(clothesSocialMuse);
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse addLike(ApiSocialLikeAddDto dto) {
 
        Long memberId = LoginUserUtil.getLoginUser().getId();
        Long socialId = dto.getSocialId();
        ClothesSocial clothesSocial = clothesSocialMapper.selectById(socialId);
        if(ObjectUtil.isNotNull(clothesSocial)){
            ClothesSocialFollow clothesSocialFollow = new ClothesSocialFollow();
            clothesSocialFollow.setMemberId(memberId);
            clothesSocialFollow.setSourceType(SocialSourceTypeEnum.SOCIAL.getValue());
            clothesSocialFollow.setSourceId(socialId);
            clothesSocialFollow.setType(SocialTypeEnum.LIKE.getValue());
            clothesSocialFollowMapper.insert(clothesSocialFollow);
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse addCommentLike(ApiSocialCommentLikeAddDto dto) {
        Long memberId = LoginUserUtil.getLoginUser().getId();
        Long socialId = dto.getSocialId();
        ClothesSocial clothesSocial = clothesSocialMapper.selectById(socialId);
        if(ObjectUtil.isNotNull(clothesSocial)){
            ClothesSocialFollow clothesSocialFollow = new ClothesSocialFollow();
            clothesSocialFollow.setMemberId(memberId);
            clothesSocialFollow.setSourceType(SocialSourceTypeEnum.COMMENT.getValue());
            clothesSocialFollow.setSourceId(socialId);
            clothesSocialFollow.setSourceOptionId(dto.getCommentId());
            clothesSocialFollow.setType(SocialTypeEnum.LIKE.getValue());
            clothesSocialFollowMapper.insert(clothesSocialFollow);
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse addCollect(ApiSocialCollectAddDto dto) {
 
        Long memberId = LoginUserUtil.getLoginUser().getId();
        Long socialId = dto.getSocialId();
        ClothesSocial clothesSocial = clothesSocialMapper.selectById(socialId);
        if(ObjectUtil.isNotNull(clothesSocial)){
            ClothesSocialFollow clothesSocialFollow = new ClothesSocialFollow();
            clothesSocialFollow.setMemberId(memberId);
            clothesSocialFollow.setSourceType(SocialSourceTypeEnum.SOCIAL.getValue());
            clothesSocialFollow.setSourceId(socialId);
            clothesSocialFollow.setType(SocialTypeEnum.COLLECT.getValue());
            clothesSocialFollowMapper.insert(clothesSocialFollow);
        }
        return new FebsResponse().success().message("操作成功");
    }
 
    @Override
    public FebsResponse museToDesign(ApiClothesSocialMuseDto dto) {
 
        Long memberId = LoginUserUtil.getLoginUser().getId();
        ApiClothesSocialMuseVo record = new ApiClothesSocialMuseVo();
 
        Long id = dto.getMuseId();
        ClothesSocialMuse entity = clothesSocialMuseMapper.selectById(id);
 
 
        if (ObjectUtil.isNotNull(entity)){
            Long typeId = entity.getTypeId();
            ClothesType clothesType = clothesTypeMapper.selectById(typeId);
            record.setTypeId(typeId);
            record.setTypeName(clothesType.getName());
            record.setTypeImage(clothesType.getImage());
            record.setPatternRemark(entity.getPatternRemark());
 
            Long sizeId = ObjectUtil.defaultIfNull(entity.getSizeId(),0L);
            List<ClothesTypeSize> clothesTypeSizes = clothesTypeSizeMapper.selectList(Wrappers.<ClothesTypeSize>lambdaQuery().eq(ClothesTypeSize::getTypeId, typeId));
            if (CollUtil.isNotEmpty(clothesTypeSizes)){
                Set<Long> collect = clothesTypeSizes.stream().map(ClothesTypeSize::getSizeId).collect(Collectors.toSet());
                if(CollUtil.isNotEmpty( collect) && collect.contains(sizeId)){
                    ClothesSize clothesSize = clothesSizeMapper.selectById(sizeId);
                    if(ObjectUtil.isNotNull(clothesSize)){
                        record.setSizeId(sizeId);
                        record.setSizeName(clothesSize.getName());
                        record.setSizePrice(clothesSize.getPrice());
                    }
                }
            }
 
            Long patternId = ObjectUtil.defaultIfNull(entity.getPatternId(),0L);
            List<ClothesTypePattern> clothesTypePatterns = clothesTypePatternMapper.selectList(Wrappers.<ClothesTypePattern>lambdaQuery().eq(ClothesTypePattern::getTypeId, typeId));
            if (CollUtil.isNotEmpty(clothesTypePatterns)){
                Set<Long> patternIds = clothesTypePatterns.stream().map(ClothesTypePattern::getPatternId).collect(Collectors.toSet());
                if(CollUtil.isNotEmpty( patternIds) && patternIds.contains(patternId)){
                    ClothesPattern clothesPattern = clothesPatternMapper.selectById(patternId);
                    if (ObjectUtil.isNotNull(clothesPattern)){
                        record.setPatternId(patternId);
                        record.setPatternName(clothesPattern.getName());
                        record.setPatternPrice(clothesPattern.getPrice());
                    }
                }
            }
 
            Long locationId = ObjectUtil.defaultIfNull(entity.getLocationId(),0L);
            List<ClothesTypeLocation> clothesTypeLocations = clothesTypeLocationMapper.selectList(Wrappers.<ClothesTypeLocation>lambdaQuery().eq(ClothesTypeLocation::getTypeId, typeId));
            if (CollUtil.isNotEmpty(clothesTypeLocations)){
                Set<Long> locationIds = clothesTypeLocations.stream().map(ClothesTypeLocation::getLocationId).collect(Collectors.toSet());
                if(CollUtil.isNotEmpty( locationIds) && locationIds.contains(locationId)){
                    ClothesLocation clothesLocation = clothesLocationMapper.selectById(locationId);
                    if (ObjectUtil.isNotNull(clothesLocation)){
                        record.setLocationId(locationId);
                        record.setLocationName(clothesLocation.getName());
                        record.setLocationPrice(clothesLocation.getPrice());
                    }
                }
            }
 
            Long artId = ObjectUtil.defaultIfNull(entity.getArtId(),0L);
            List<ClothesTypeArt> clothesTypeArts = clothesTypeArtMapper.selectList(Wrappers.lambdaQuery(ClothesTypeArt.class).eq(ClothesTypeArt::getTypeId, typeId));
            if(CollUtil.isNotEmpty(clothesTypeArts)){
                Set<Long> artIds = clothesTypeArts.stream().map(ClothesTypeArt::getArtId).collect(Collectors.toSet());
                if (CollUtil.isNotEmpty(artIds) && artIds.contains(artId)){
                    ClothesArt clothesArt = clothesArtMapper.selectById(artId);
                    if (ObjectUtil.isNotNull(clothesArt)){
                        record.setArtId(artId);
                        record.setArtName(clothesArt.getName());
                        record.setArtPrice(clothesArt.getPrice());
                    }
                }
            }
 
            Long clothId = ObjectUtil.defaultIfNull(entity.getClothId(),0L);
            List<ClothesTypeCloth> clothesTypeCloths = clothesTypeClothMapper.selectList(Wrappers.lambdaQuery(ClothesTypeCloth.class).eq(ClothesTypeCloth::getTypeId, typeId));
            if(CollUtil.isNotEmpty(clothesTypeCloths)){
                Set<Long> clothIds = clothesTypeCloths.stream().map(ClothesTypeCloth::getClothId).collect(Collectors.toSet());
                if (CollUtil.isNotEmpty(clothIds) && clothIds.contains(clothId)){
                    ClothesCloth clothesCloth = clothesClothMapper.selectById(clothId);
                    if (ObjectUtil.isNotNull(clothesCloth)){
                        record.setClothId(clothId);
                        record.setClothName(clothesCloth.getName());
                        record.setClothPrice(clothesCloth.getPrice());
                    }
                }
            }
 
            BigDecimal amount =
                    record.getClothPrice()
                            .add(record.getLocationPrice())
                            .add(record.getArtPrice())
                            .add(record.getSizePrice())
                            .add(record.getPatternPrice()).setScale(2, RoundingMode.DOWN);
            record.setAmount(amount);
        }
 
        return new FebsResponse().success().data(record);
    }
 
    public static void main(String[] args) {
        JSONObject jsonObject = new JSONObject();
        jsonObject.putByPath("text", "123");
        jsonObject.putByPath("file", "https://excoin.oss-cn-hangzhou.aliyuncs.com/hc/175196952995698f416e2e70648328d04364340c3a36d.png");
 
        String jsonStr = jsonObject.toString();
        System.out.println(jsonStr);
    }
}