package com.ltkj.web.controller.mall;
|
|
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.framework.config.UserHoder;
|
import com.ltkj.hosp.domain.*;
|
import com.ltkj.hosp.service.*;
|
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.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 问卷记录Controller
|
* @Company: 西安路泰科技有限公司
|
* @Author: zjh
|
* @Date: 2023/7/26 08:50
|
*/
|
@RestController
|
@RequestMapping("/cus/surveyRecord")
|
@Api(tags = "体检小程序端问卷记录调查接口")
|
public class WxTjSurveyRecordController extends BaseController {
|
|
@Resource
|
private ITjSurveyRecordService tjSurveyRecordService;
|
@Resource
|
private ITjCustomerService tjCustomerService;
|
@Resource
|
private ITjOrderService tjOrderService;
|
@Resource
|
private TjSurveyRecordDetailService tjSurveyRecordDetailService;
|
@Autowired
|
private ITjSurveyTemplateService tjSurveyTemplateService;
|
@Autowired
|
private ITjSurveyQuestionService tjSurveyQuestionService;
|
|
/**
|
* 小程序判断是否填写过问卷(0未填1已填)
|
*/
|
@GetMapping("/appSurveyByIdCard")
|
@ApiOperation(value = "小程序判断是否填写过问卷(0未填1已填)")
|
public AjaxResult appSurveyByIdCard(@RequestParam @ApiParam(value = "tjNumber") String tjNumber) {
|
LambdaQueryWrapper<TjSurveyRecord> wqqq = new LambdaQueryWrapper<>();
|
wqqq.eq(TjSurveyRecord::getTjnumber, tjNumber);
|
List<TjSurveyRecord> byId = tjSurveyRecordService.list(wqqq);
|
if (byId != null) {
|
if (byId.size() > 0) {
|
return AjaxResult.success(1);
|
} else {
|
return AjaxResult.success(0);
|
}
|
}
|
return AjaxResult.success(0);
|
|
}
|
|
/**
|
* 小程序端问卷查询记录
|
*/
|
@GetMapping("/appGetTiJian")
|
@ApiOperation(value = "小程序端问卷查询记录")
|
public AjaxResult appGetTiJian(@RequestParam @ApiParam(value = "cusIdCard") String cusIdCard) {
|
Map<String, Object> res = new HashMap<>();
|
LambdaQueryWrapper<TjCustomer> wqqq = new LambdaQueryWrapper<>();
|
wqqq.eq(TjCustomer::getCusIdcard, cusIdCard);
|
TjCustomer one1 = tjCustomerService.getOne(wqqq);
|
if (one1 == null) {
|
return AjaxResult.error("查无此人");
|
}
|
LambdaQueryWrapper<TjOrder> wq0 = new LambdaQueryWrapper<>();
|
wq0.eq(TjOrder::getUserId, one1.getCusId());
|
List<TjOrder> tjOrders = tjOrderService.list(wq0);
|
|
if (tjOrders != null && tjOrders.size() > 0) {
|
for (TjOrder tjOrder : tjOrders) {
|
if (tjOrder.getFinishTime() != null) {
|
tjOrder.setTjFinishStatus("已完成");
|
} else {
|
tjOrder.setTjFinishStatus("未完成");
|
}
|
}
|
}
|
res.put("tjOrders", tjOrders);
|
res.put("customer", one1);
|
return AjaxResult.success(res);
|
}
|
|
|
/**
|
* 新增问卷记录
|
*/
|
@ApiOperation(value = "新增问卷记录")
|
@PostMapping
|
public AjaxResult add(@RequestBody List<TjSurveyRecord> tjSurveyRecord) {
|
if (tjSurveyRecord != null && tjSurveyRecord.size() > 0) {
|
List<TjSurveyRecord> a = new ArrayList<>();
|
//先放第一个
|
a.add(tjSurveyRecord.get(0));
|
//对集合进行遍历 如果集合的问题id和第一个id一样
|
for (int i = 1; i < tjSurveyRecord.size(); i++) {
|
if (a.size()<=1){
|
continue;
|
}
|
if ((tjSurveyRecord.get(i)).getQid().equals((a.get(i - 1)).getQid())) {
|
a.get(i - 1).getTjSurveyRecordDetailList().add((tjSurveyRecord.get(i).getTjSurveyRecordDetailList()).get(0));
|
} else {
|
a.add(tjSurveyRecord.get(i));
|
}
|
}
|
Wxuser wxuser = UserHoder.getWxuser();
|
for (TjSurveyRecord surveyRecord : a) {
|
surveyRecord.setOpenId(wxuser.getOpenid());
|
surveyRecord.setPhone(wxuser.getPhone());
|
surveyRecord.setUserName(wxuser.getNickname());
|
surveyRecord.setCreateId(String.valueOf(wxuser.getId()));
|
surveyRecord.setUpdateId(String.valueOf(wxuser.getId()));
|
tjSurveyRecordService.save(surveyRecord);
|
List<TjSurveyRecordDetail> recordDetailList = surveyRecord.getTjSurveyRecordDetailList();
|
if (null != recordDetailList && recordDetailList.size() > 0) {
|
tjSurveyRecordDetailService.saveBatch(recordDetailList);
|
}
|
}
|
}
|
return AjaxResult.success();
|
}
|
|
|
/**
|
* 获取问卷模板
|
*/
|
@GetMapping("/getQuesByMid")
|
@ApiOperation(value = "获取问卷模板信息")
|
public AjaxResult getQuesByMid(@RequestParam Long mid) {
|
List<TjSurveyQuestion> l1=new ArrayList<>();
|
TjSurveyTemplate byId = tjSurveyTemplateService.selectTjSurveyTemplateByMid(mid);
|
List<TjSurveyTempQues> tjSurveyTempQuesList = byId.getTjSurveyTempQuesList();
|
if (tjSurveyTempQuesList!=null){
|
for (TjSurveyTempQues tjSurveyTempQues : tjSurveyTempQuesList) {
|
TjSurveyQuestion byId1 = tjSurveyQuestionService.selectTjSurveyQuestionByQid(tjSurveyTempQues.getQid());
|
if (byId1!=null){
|
l1.add(byId1);
|
}
|
}
|
return AjaxResult.success(l1);
|
}
|
return AjaxResult.success("暂无信息");
|
}
|
}
|