chenjiahe
2021-12-14 00565f063877182ef44aec700cffacf00c7a6d26
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
package com.hx.phip.deduction.controller;
 
import com.hx.common.BaseController;
import com.hx.phiappt.common.DeductionSingleConstants;
import com.hx.phiappt.model.BaseEntity;
import com.hx.phiappt.model.ComparePhotoRecord;
import com.hx.phiappt.model.ComparePhotoRecordPictures;
import com.hx.phiappt.model.deduction.*;
import com.hx.phip.deduction.service.*;
import com.hx.phip.dto.DeductionDto;
import com.hx.phip.service.ComparePhotoRecordPicturesService;
import com.hx.phip.service.ComparePhotoRecordService;
import com.hx.resultTool.Result;
import com.hx.util.StringUtils;
import com.platform.constants.LoginConstant;
import com.platform.entity.ThirtApplication;
import com.platform.exception.PlatTipsException;
import com.platform.resultTool.PlatformCode;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 执行划扣控制器
 * @USER: Andru
 * @DATE: 2021/12/10
 */
@RestController
@RequestMapping("/deduction")
public class DeductionController extends BaseController {
 
    @Resource
    private DeductionSingleService deductionSingleService;
    @Resource
    private DeductionProjectService deductionProjectService;
    @Resource
    private DeductionJoinService deductionJoinService;
    @Resource
    private DeductionSignService deductionSignService;
    @Resource
    private DeductionDrugsService deductionDrugsService;
    @Resource
    private DeductionDeviceParameterService deductionDeviceParameterService;
    @Resource
    private ComparePhotoRecordService comparePhotoRecordService;
    @Resource
    private ComparePhotoRecordPicturesService comparePhotoRecordPicturesService;
 
    /**
     *查看记录
     */
    @RequestMapping(value = "/see")
    public Result seeData(HttpServletRequest request,String deductionSingleId){
        // 获取用户信息
        ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
        if(thirtApplication == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"登入失败,请登入后在试!");
        }
 
        Map<String,Object> mapData = new HashMap<>();
        DeductionSingle deductionSingle = deductionSingleService.selectOneByKey(deductionSingleId);
        if(deductionSingle != null) {
            // 划扣记录
            mapData.put("deductionSingle", deductionSingle);
            // 项目划扣
            DeductionProject deductionProject = deductionProjectService.selectOneByDeductionSingleId(deductionSingle.getId());
            mapData.put("deductionProject", deductionProject);
            if(deductionProject != null) {
                // 参与人员信息
                List<DeductionJoin> deductionJoinList = deductionJoinService.selectListByDeductionSingleId(deductionSingle.getId(), deductionProject.getId());
                mapData.put("deductionJoinList", deductionJoinList);
                // 消耗物品信息
                List<DeductionDrugs> deductionDrugsList = deductionDrugsService.selectListByDeductionSingleId(deductionSingle.getId(), deductionProject.getId());
                mapData.put("deductionDrugsList", deductionDrugsList);
                // 治疗参数(设备)信息
                List<DeductionDeviceParameter> deductionDeviceParameterList = deductionDeviceParameterService.selectListByDeductionSingleId(deductionSingle.getId(), deductionProject.getId());
                mapData.put("deductionDeviceParameterList", deductionDeviceParameterList);
                // 客户签名信息
                List<DeductionSign> deductionSignList = deductionSignService.selectListByDeductionSingleId(deductionSingle.getId(), deductionProject.getId());
                mapData.put("deductionSignList", deductionSignList);
                // 治疗图片
                ComparePhotoRecord comparePhotoRecord = comparePhotoRecordService.selectOneByDeductionSingleId(deductionSingle.getId(), deductionProject.getId());
                if(comparePhotoRecord != null) {
                    List<ComparePhotoRecordPictures> comparePhotoRecordPicturesList = comparePhotoRecordPicturesService.selectListByComparePhotoRecordId(comparePhotoRecord.getId());
                    mapData.put("comparePhotoRecordPicturesList", comparePhotoRecordPicturesList);
                }else{
                    mapData.put("comparePhotoRecordPicturesList", null);
                }
            }
        }
        return Result.success(mapData);
    }
 
    /**
     * 新增划扣记录
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result addData(HttpServletRequest request, DeductionDto deductionDto) {
        // 校验参数
        checkParam(deductionDto);
        // 获取用户信息
        ThirtApplication thirtApplication= (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
        if(thirtApplication == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"登入失败,请登入后在试!");
        }
        // 填充接口登入信息
        deductionDto.setSourceCode(thirtApplication.getAppId());
        deductionDto.setSourceName(thirtApplication.getName());
 
        // 添加数据
        deductionSingleService.editInfo(deductionDto, BaseEntity.YES);
 
        return Result.success();
    }
 
    /**
     * 修改划扣记录
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result updateData(HttpServletRequest request, DeductionDto deductionDto) {
        // 判断deductionSingleId 是否为空
        if(StringUtils.isEmpty(deductionDto.getDeductionSingleId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"deductionSingleId不能为空");
        }
        // 校验参数
        checkParam(deductionDto);
        // 获取用户信息
        ThirtApplication thirtApplication = (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
        if(thirtApplication == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"登入失败,请登入后在试!");
        }
        // 填充接口登入信息
        deductionDto.setSourceCode(thirtApplication.getAppId());
        deductionDto.setSourceName(thirtApplication.getName());
 
        // 添加数据
        deductionSingleService.editInfo(deductionDto, BaseEntity.NO);
 
        return Result.success();
    }
 
    /**
     * 删除记录
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result deleteData(HttpServletRequest request,String deductionSingleId){
        if(StringUtils.isEmpty(deductionSingleId)){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"deductionSingleId不能为空");
        }
 
        ThirtApplication thirtApplication = (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
        if(thirtApplication == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"登入失败,请登入后在试!");
        }
 
        // 删除数据
        deductionSingleService.deleteOne(deductionSingleId,thirtApplication.getAppId(),thirtApplication.getName(), DeductionSingleConstants.STATUS_CANCEL);
        return Result.success();
    }
 
    /**
     * 撤销记录
     */
    @RequestMapping(value = "/rescinded", method = RequestMethod.POST)
    public Result rescindedData(HttpServletRequest request,String deductionSingleId){
        if(StringUtils.isEmpty(deductionSingleId)){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"deductionSingleId不能为空");
        }
 
        ThirtApplication thirtApplication = (ThirtApplication) request.getSession().getAttribute(LoginConstant.LOGIN_APPLY);
        if(thirtApplication == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"登入失败,请登入后在试!");
        }
 
        // 删除数据
        deductionSingleService.deleteOne(deductionSingleId,thirtApplication.getAppId(),thirtApplication.getName(), DeductionSingleConstants.STATUS_RESCINDED);
        return Result.success();
    }
 
    /**
     * 校验参数
     * @param deductionDto 参数对象
     */
    private void checkParam(DeductionDto deductionDto){
        if(StringUtils.isEmpty(deductionDto.getUserProjectId())){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"userProjectId不能为空");
        }
 
        if(deductionDto.getDeductionNum() <= 0){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"数量/划扣次数需要大于0");
        }
 
        if(deductionDto.getExecuteStartTime() == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"执行开始时间不内为空!");
        }
 
        if(deductionDto.getExecuteEndTime() == null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"执行结束时间不内为空!");
        }
    }
}