zjh
2025-06-09 a5b599d34b1cbe6f4e84708d1165cce6fb9ef896
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
package com.ltkj.web.controller.system;/*
 * @作者  zjh
 * @时间  2024-06-26  9:44
 * */
 
import cn.hutool.extra.pinyin.PinyinUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ltkj.common.annotation.Log;
import com.ltkj.common.core.controller.BaseController;
import com.ltkj.common.core.domain.AjaxResult;
import com.ltkj.common.enums.BusinessType;
import com.ltkj.hosp.domain.*;
import com.ltkj.hosp.dto.QianDaoDto;
import com.ltkj.hosp.service.ITjProjectService;
import com.ltkj.hosp.service.TjZhxmService;
import com.ltkj.hosp.service.TjZhxmglproService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
 
 
@RestController
@RequestMapping("/system/zhxm")
@Api(tags = "PC端组合项目相关接口")
@Slf4j
public class TjZhxmController extends BaseController {
 
    @Autowired
    private TjZhxmglproService tjZhxmglproService;
    @Autowired
    private TjZhxmService zhxmService;
    @Resource
    private ITjProjectService tjProjectService;
 
    @GetMapping("/getZhList")
    @ApiOperation(value = "查询组合集合")
    public AjaxResult getZhList(@ApiParam(value = "体检组合名称或拼音码") @RequestParam(required = false) String zhmc) {
        LambdaQueryWrapper<TjZhxm> wq2=new LambdaQueryWrapper<>();
        if (zhmc != null) wq2.like(TjZhxm::getZhmc,zhmc).or().like(TjZhxm::getPym,zhmc);
        List<TjZhxm> lists = zhxmService.list(wq2);
            if (null != lists && lists.size()>0) {
                for (TjZhxm zhxm : lists) {
                    LambdaQueryWrapper<TjZhxmglpro> wq = new LambdaQueryWrapper<>();
                    wq.eq(TjZhxmglpro::getZhId, zhxm.getId());
                    List<TjZhxmglpro> list = tjZhxmglproService.list(wq);
                    StringBuilder allName = new StringBuilder();
                    if (null != list && list.size() > 0) {
                        List<TjProject> projectList = new ArrayList<>();
                        BigDecimal money = new BigDecimal("0.00");
                        for (TjZhxmglpro zhxmglpro : list) {
                            TjProject project = tjProjectService.getById(zhxmglpro.getProId());
                            if (null != project) {
                                projectList.add(project);
                                allName.append(project.getProName()).append(";");
                                money=money.add(project.getProPrice());
                            }
                        }
                        zhxm.setPrice(money);
                        zhxm.setAllProName(allName.toString());
                        zhxm.setZhxmglpros(list);
                        zhxm.setTjProjectList(projectList);
                    }
                }
                return AjaxResult.success(lists);
        }
        return AjaxResult.success("暂时没有数据");
    }
 
 
    @Log(title = "体检组合项目", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增体检组合")
    @Transactional
    public AjaxResult add(@RequestBody @ApiParam(value = "体检组合对象") TjZhxm zhxm) {
        LambdaQueryWrapper<TjZhxm> wq = new LambdaQueryWrapper<>();
        wq.eq(TjZhxm::getZhmc, zhxm.getZhmc());
        TjZhxm one = zhxmService.getOne(wq);
        if (null != one) {
            return AjaxResult.error("该组合已存在,不可重复添加!");
        }
        zhxm.setPym(PinyinUtil.getFirstLetter(zhxm.getZhmc(), ""));
        if (zhxmService.save(zhxm)) {
            List<TjZhxmglpro> zhxmglpros = zhxm.getZhxmglpros();
            if (null != zhxmglpros && !zhxmglpros.isEmpty()) {
                for (TjZhxmglpro zhxmglpro : zhxmglpros) {
                    TjZhxmglpro pro = new TjZhxmglpro();
                    pro.setZhId(zhxm.getId());
                    pro.setProId(zhxmglpro.getProId());
                    tjZhxmglproService.save(pro);
                }
            }
            return AjaxResult.success();
        }
        return AjaxResult.error("新增失败");
    }
 
    /**
     * 修改体检组合
     */
    @Log(title = "体检组合", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改体检组合")
    @Transactional
    public AjaxResult edit(@RequestBody @ApiParam(value = "体检组合对象") TjZhxm zhxm) {
        zhxm.setPym(PinyinUtil.getFirstLetter(zhxm.getZhmc(), ""));
        if (zhxmService.updateById(zhxm)) {
            List<TjZhxmglpro> zhxmglpros = zhxm.getZhxmglpros();
            if (null != zhxmglpros && !zhxmglpros.isEmpty()) {
                LambdaQueryWrapper<TjZhxmglpro> wq = new LambdaQueryWrapper<>();
                wq.eq(TjZhxmglpro::getZhId, zhxm.getId());
                tjZhxmglproService.remove(wq);
                for (TjZhxmglpro zhxmglpro : zhxmglpros) {
                    TjZhxmglpro pro = new TjZhxmglpro();
                    pro.setZhId(zhxm.getId());
                    pro.setProId(zhxmglpro.getProId());
                    tjZhxmglproService.save(pro);
                }
            }
 
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }
 
 
    @GetMapping("/listByZhId")
    @ApiOperation(value = "根据组合id获取体检组合详细信息")
    public AjaxResult listByZhId(@ApiParam(value = "体检组合id") @RequestParam Long zhId) {
        if (zhId != null) {
            TjZhxm zhxm = zhxmService.getById(zhId);
            if (null != zhxm) {
                LambdaQueryWrapper<TjZhxmglpro> wq = new LambdaQueryWrapper<>();
                wq.eq(TjZhxmglpro::getZhId, zhxm.getId());
                List<TjZhxmglpro> list = tjZhxmglproService.list(wq);
                StringBuilder allName = new StringBuilder();
//                StringBuilder allSonName = new StringBuilder();
                if (null != list && !list.isEmpty()) {
                    List<TjProject> projectList = new ArrayList<>();
                    BigDecimal money = new BigDecimal("0.00");
                    for (TjZhxmglpro zhxmglpro : list) {
                        TjProject project = tjProjectService.getById(zhxmglpro.getProId());
                        if (null != project) {
                            projectList.add(project);
                            allName.append(project.getProName()).append(";");
                            money=money.add(project.getProPrice());
                        }
                    }
                    zhxm.setAllProName(allName.toString());
                    zhxm.setPrice(money);
                    zhxm.setZhxmglpros(list);
                    zhxm.setTjProjectList(projectList);
 
                    return AjaxResult.success(zhxm);
                }
            }
            return success("暂时没有数据");
        }
        return error("组合ID不能为空");
    }
 
 
    @DeleteMapping("/{zhIds}")
    @ApiOperation(value = "删除体检组合")
    public AjaxResult remove(@PathVariable Long[] zhIds) {
        if (null != zhIds && zhIds.length > 0) {
            for (Long zhId : zhIds) {
                TjZhxm byId = zhxmService.getById(zhId);
                if (zhxmService.removeById(byId)) {
                    LambdaQueryWrapper<TjZhxmglpro> wq = new LambdaQueryWrapper<>();
                    wq.eq(TjZhxmglpro::getZhId,zhId);
                    tjZhxmglproService.remove(wq);
                }
            }
            return AjaxResult.success("删除成功");
        }
        return AjaxResult.error("请选择要删除的组合");
    }
 
 
}