|
@@ -0,0 +1,140 @@
|
|
|
+package com.qunzhixinxi.hnqz.admin.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+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.qunzhixinxi.hnqz.admin.api.entity.SysDeptRelation;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.MedicalEquipment;
|
|
|
+import com.qunzhixinxi.hnqz.admin.entity.WmDaDrugEnt;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.MedicalEquipmentService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.SysDeptRelationService;
|
|
|
+import com.qunzhixinxi.hnqz.admin.service.WmDaDrugEntService;
|
|
|
+import com.qunzhixinxi.hnqz.common.core.util.R;
|
|
|
+import com.qunzhixinxi.hnqz.common.security.util.SecurityUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author: lixuesong
|
|
|
+ * @createTime: 2022/11/08 10:07
|
|
|
+ * @description: 医疗企业前端控制器
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/medical-equipment")
|
|
|
+public class MedicalEquipmentController {
|
|
|
+
|
|
|
+ private final MedicalEquipmentService medicalEquipmentService;
|
|
|
+
|
|
|
+ private final WmDaDrugEntService wmDaDrugEntService;
|
|
|
+
|
|
|
+ private final SysDeptRelationService sysDeptRelationService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增
|
|
|
+ *
|
|
|
+ * @param medicalEquipment
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping
|
|
|
+ public R<?> save(@RequestBody MedicalEquipment medicalEquipment) {
|
|
|
+ int count = medicalEquipmentService.count(Wrappers.<MedicalEquipment>lambdaQuery()
|
|
|
+ .eq(MedicalEquipment::getDrugEntId, medicalEquipment.getDrugEntId())
|
|
|
+ .eq(MedicalEquipment::getName, medicalEquipment.getName()));
|
|
|
+ if (count > 0) {
|
|
|
+ return R.failed("所属企业下已存在");
|
|
|
+ }
|
|
|
+ medicalEquipmentService.save(medicalEquipment);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ *
|
|
|
+ * @param medicalEquipment
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PutMapping
|
|
|
+ public R<?> update(@RequestBody MedicalEquipment medicalEquipment) {
|
|
|
+ int count = medicalEquipmentService.count(Wrappers.<MedicalEquipment>lambdaQuery()
|
|
|
+ .eq(MedicalEquipment::getDrugEntId, medicalEquipment.getDrugEntId())
|
|
|
+ .eq(MedicalEquipment::getName, medicalEquipment.getName())
|
|
|
+ .ne(MedicalEquipment::getId, medicalEquipment.getId()));
|
|
|
+ if (count > 0) {
|
|
|
+ return R.failed("所属企业下已存在");
|
|
|
+ }
|
|
|
+ medicalEquipmentService.updateById(medicalEquipment);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
+ public R<?> remove(@PathVariable("id") Integer id) {
|
|
|
+ medicalEquipmentService.removeById(id);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询
|
|
|
+ *
|
|
|
+ * @param page
|
|
|
+ * @param medicalEquipment
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/page")
|
|
|
+ public R<?> page(Page<MedicalEquipment> page, MedicalEquipment medicalEquipment) {
|
|
|
+ LambdaQueryWrapper<MedicalEquipment> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ if (StrUtil.isNotBlank(medicalEquipment.getName())) {
|
|
|
+ queryWrapper.like(MedicalEquipment::getName, medicalEquipment.getName());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(medicalEquipment.getManufacturer())) {
|
|
|
+ queryWrapper.like(MedicalEquipment::getManufacturer, medicalEquipment.getManufacturer());
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(medicalEquipment.getDrugEntName())) {
|
|
|
+ queryWrapper.like(MedicalEquipment::getDrugEntName, medicalEquipment.getDrugEntName());
|
|
|
+ }
|
|
|
+ Page<MedicalEquipment> equipmentPage = medicalEquipmentService.page(page, queryWrapper);
|
|
|
+ return R.ok(equipmentPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询当前企业对应的医疗器械 TODO
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/list-current")
|
|
|
+ public R<?> listByDrugId() {
|
|
|
+ Integer deptId = SecurityUtils.getUser().getDeptId();
|
|
|
+ // 查询父级企业id
|
|
|
+ SysDeptRelation deptRelation = sysDeptRelationService.getOne(Wrappers.<SysDeptRelation>lambdaQuery()
|
|
|
+ .eq(SysDeptRelation::getDescendant, deptId)
|
|
|
+ .ne(SysDeptRelation::getAncestor, deptId));
|
|
|
+ if (deptRelation == null) {
|
|
|
+ return R.ok(Collections.emptyList());
|
|
|
+ }
|
|
|
+ // 查询企业对应药企id
|
|
|
+ WmDaDrugEnt wmDaDrugEnt = wmDaDrugEntService.selectByDeptId(deptRelation.getAncestor());
|
|
|
+
|
|
|
+ List<MedicalEquipment> medicalEquipmentList = medicalEquipmentService.list(Wrappers.<MedicalEquipment>lambdaQuery()
|
|
|
+ .eq(MedicalEquipment::getDrugEntId, wmDaDrugEnt.getId()));
|
|
|
+ return R.ok(medicalEquipmentList);
|
|
|
+ }
|
|
|
+}
|