zjh
2025-02-18 0ebcb0aae7ebe897bfbf81a239d3c702f041c533
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
package com.ltkj.web.controller.app;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.framework.config.UserHoder;
import com.ltkj.hosp.domain.TjPackage;
import com.ltkj.hosp.domain.TjPackageProject;
import com.ltkj.hosp.domain.TjProject;
import com.ltkj.hosp.domain.Wxuser;
import com.ltkj.hosp.service.ITjPackageProjectService;
import com.ltkj.hosp.service.ITjPackageService;
import com.ltkj.hosp.service.ITjProjectService;
import com.ltkj.mall.domain.MallCategory;
import com.ltkj.mall.domain.MallFootprint;
import com.ltkj.mall.domain.MallKeyword;
import com.ltkj.mall.domain.MallSearchHistory;
import com.ltkj.mall.service.IMallCategoryService;
import com.ltkj.mall.service.IMallFootprintService;
import com.ltkj.mall.service.IMallKeywordService;
import com.ltkj.mall.service.IMallSearchHistoryService;
import com.ltkj.system.service.ISysConfigService;
import freemarker.template.utility.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @Author: 西安路泰科技有限公司/lige
 * @Date: 2023/1/10 16:37
 */
 
@RestController
@RequestMapping("/cus/package")
@Api(tags = "小程序-体检套餐")
public class PackageController extends BaseController {
 
    @Resource
    private ITjPackageService tjPackageService;
 
    @Autowired
    private IMallCategoryService mallCategoryService;
 
    @Resource
    private ITjPackageProjectService ppservice;
 
    @Autowired
    private IMallKeywordService mallKeywordService;
 
    @Resource
    private ITjProjectService tjProjectService;
 
    @Autowired
    private IMallFootprintService footprintService;
 
    @Resource
    private ISysConfigService configService;
 
    @Autowired
    private IMallSearchHistoryService mallSearchHistoryService;
 
    /**
     * 小程序查询体检套餐列表
     */
    @GetMapping("/getPackageList")
    @ApiOperation(value = "小程序查询体检套餐列表")
    public AjaxResult getPackageList(@RequestParam(required = false) @ApiParam(value = "分类Id") String categoryId,
                                     @RequestParam(required = false) @ApiParam(value = "套餐名") String pacName) {
        List<TjPackage> packageList = null;
        LambdaQueryWrapper<TjPackage> wq = new LambdaQueryWrapper<>();
        wq.eq(TjPackage::getPacStatus, 0);
        wq.orderByAsc(TjPackage::getSort);
        if (null != pacName) {
            wq.like(TjPackage::getPacName, pacName);
            //添加搜索历史
            Wxuser wxuser = UserHoder.getWxuser();
            if (null != wxuser) {
                MallSearchHistory mallSearchHistory=new MallSearchHistory();
                mallSearchHistory.setUserId(wxuser.getId());
                mallSearchHistory.setFromType("小程序");
                mallSearchHistory.setKeyword(pacName);
                mallSearchHistoryService.insertMallSearchHistory(mallSearchHistory);
            }
        }
        if (categoryId == null) {
            //查询所有套餐
            packageList = tjPackageService.list(wq);
        } else {
            LambdaQueryWrapper<TjPackage> wqqq=new LambdaQueryWrapper<>();
            wqqq.eq(TjPackage::getCategoryId,categoryId);
            packageList =tjPackageService.list(wqqq);
        }
        if (null != packageList && packageList.size() > 0) {
            for (TjPackage tjPackage : packageList) {
 
                StringBuffer a = new StringBuffer();
                List<String> b = new ArrayList<>();
                final String keywords = tjPackage.getKeywords();
                if (keywords != null) {
                    final String[] strings = keywords.split(",");
                    for (String string : strings) {
                        final MallKeyword byId = mallKeywordService.getById(string);
                        if (byId != null) {
                            a.append(byId.getKeyword());
                            a.append(";");
                            b.add((byId.getId()).toString());
                        }
                    }
                    tjPackage.setKeyNames(String.valueOf(a));
                    tjPackage.setKeyIds(b);
                }
            }
        }
        return AjaxResult.success(packageList);
    }
 
 
    /**
     * 小程序点击套餐获取项目详情
     */
    @GetMapping("/projectListByPacId/{pacId}")
    @ApiOperation(value = "小程序点击套餐获取项目详情")
    public AjaxResult projectListByPacId(@ApiParam(value = "体检套餐id") @PathVariable("pacId") String pacId) {
        if (pacId != null) {
            TjPackage tjPackage = tjPackageService.getById(Long.valueOf(pacId));
            List<TjPackageProject> packageProjectList = ppservice.getTjPackageProjectListByPacId(pacId);
            BigDecimal money = new BigDecimal(0);
            if (null != packageProjectList && packageProjectList.size() > 0) {
                List<TjProject> projectList = tjProjectService.getTjParentProjectListByPacId(pacId);
                tjPackage.setAllProName(tjProjectService.getAllNamesByPacId(pacId));
                for (TjProject tjProject : projectList) {
                    tjProject.setTjProjectList(tjProjectService.getTjProjectListBySoneId(String.valueOf(tjProject.getProId())));
                    money = money.add(tjProjectService.getMoneys(String.valueOf(tjProject.getProId())));
                    tjProject.setAllSonProName(tjProjectService.getAllSonNames(String.valueOf(tjProject.getProId())));
                }
                tjPackage.setYuanjia(money.setScale(Integer.parseInt(configService.selectConfigByKey("sys.price.save")), Integer.parseInt(configService.selectConfigByKey("sys.price"))));  //保留两位小数
                tjPackage.setProNumber(projectList.size());
                tjPackage.setTjProjectList(projectList);
 
                // 记录用户的足迹
                Wxuser wxuser = UserHoder.getWxuser();
                if (null != wxuser) {
                    LambdaQueryWrapper<MallFootprint> wq=new LambdaQueryWrapper<>();
                    wq.eq(MallFootprint::getUserId,wxuser.getId());
                    wq.eq(MallFootprint::getGoodsId,pacId);
                    final List<MallFootprint> list = footprintService.list(wq);
                    if (list!=null&&list.size()==0){
                        MallFootprint footprint = new MallFootprint();
                        footprint.setUserId(wxuser.getId());
                        footprint.setGoodsId(pacId);
                        footprintService.insertMallFootprint(footprint);
                    }
                }
                return AjaxResult.success(tjPackage);
            }
            return success("暂时没有数据");
        }
        return error("套餐ID不能为空");
    }
}