package cn.besteam.modules.medical.controller;
|
|
import cn.besteam.common.api.vo.Result;
|
import cn.besteam.common.aspect.annotation.AutoLog;
|
import cn.besteam.common.constant.CommonConstant;
|
import cn.besteam.modules.medical.dto.MwDeviceAgentDeviceDTO;
|
import cn.besteam.modules.medical.entity.MwDeviceAgent;
|
import cn.besteam.modules.medical.entity.MwDeviceAgentDevice;
|
import cn.besteam.modules.medical.service.IMwDeviceAgentDeviceService;
|
import cn.besteam.modules.medical.service.IMwDeviceAgentService;
|
import cn.besteam.modules.medical.vo.MwDeviceAgentVO;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* @Title: Controller
|
* @Description: 设备代理商
|
* @author: besteam
|
* @date: 2020-04-25
|
* @version: V1.0
|
*/
|
@RestController
|
@RequestMapping("/medical/mwDeviceAgent")
|
@Slf4j
|
@Api(description = "设备代理商")
|
public class MwDeviceAgentController {
|
|
@Autowired
|
private IMwDeviceAgentService mwDeviceAgentService;
|
|
@Autowired
|
private IMwDeviceAgentDeviceService mwDeviceAgentDeviceService;
|
|
/**
|
* 分页列表查询
|
*
|
* @param name
|
* @param pageNo
|
* @param pageSize
|
* @return
|
*/
|
@GetMapping(value = "/list")
|
@ApiOperation(value = "获取设备代理商数据列表", notes = "获取所有设备代理商数据列表", produces = "application/json")
|
public Result<IPage<MwDeviceAgentVO>> queryPageList(String name, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
|
|
QueryWrapper<MwDeviceAgent> queryWrapper = new QueryWrapper<MwDeviceAgent>();
|
if (StringUtils.isNotEmpty(name)) {
|
queryWrapper.lambda().like(MwDeviceAgent::getName, name);
|
}
|
Page<MwDeviceAgent> page = new Page<MwDeviceAgent>(pageNo, pageSize);
|
IPage<MwDeviceAgent> pageList = mwDeviceAgentService.page(page, queryWrapper);
|
List<MwDeviceAgentVO> voList = new ArrayList<>();
|
for (MwDeviceAgent record : pageList.getRecords()) {
|
MwDeviceAgentVO vo = new MwDeviceAgentVO();
|
BeanUtils.copyProperties(record, vo);
|
//
|
int count = mwDeviceAgentDeviceService.count(new QueryWrapper<MwDeviceAgentDevice>().lambda().eq(MwDeviceAgentDevice::getDeviceAgentId, record.getId()));
|
if (count > 0) {
|
vo.setCanDelete(false);
|
}
|
voList.add(vo);
|
}
|
IPage<MwDeviceAgentVO> result = new Page<>();
|
result.setCurrent(page.getCurrent());
|
result.setSize(pageSize);
|
result.setRecords(voList);
|
result.setTotal(page.getTotal());
|
return Result.ok(result);
|
}
|
|
/**
|
* 添加
|
*
|
* @param mwDeviceAgent
|
* @return
|
*/
|
@PostMapping(value = "/add")
|
@AutoLog(value = "添加设备代理商")
|
@ApiOperation(value = "添加设备代理商", notes = "添加设备代理商", produces = "application/json")
|
public Result<MwDeviceAgent> add(@RequestBody MwDeviceAgent mwDeviceAgent) {
|
|
Result<MwDeviceAgent> result = new Result<MwDeviceAgent>();
|
try {
|
MwDeviceAgent mwDeviceAgentEntity = mwDeviceAgentService.getOne(new QueryWrapper<MwDeviceAgent>().lambda().eq(MwDeviceAgent::getName, mwDeviceAgent.getName()));
|
if (mwDeviceAgentEntity != null) {
|
result.error500("设备厂商信息已经存在");
|
return result;
|
}
|
mwDeviceAgent.setStatus(CommonConstant.STATUS_NORMAL);
|
mwDeviceAgentService.save(mwDeviceAgent);
|
result.success("添加成功!");
|
} catch (Exception e) {
|
log.error("", e);
|
result.error500("操作失败");
|
}
|
return result;
|
}
|
|
/**
|
* 编辑
|
*
|
* @param mwDeviceAgent
|
* @return
|
*/
|
@PostMapping(value = "/edit")
|
@AutoLog(value = "编辑设备代理商")
|
@ApiOperation(value = "编辑设备代理商", notes = "编辑设备代理商", produces = "application/json")
|
public Result<MwDeviceAgent> edit(@RequestBody MwDeviceAgent mwDeviceAgent) {
|
|
Result<MwDeviceAgent> result = new Result<MwDeviceAgent>();
|
MwDeviceAgent mwDeviceAgentEntity = mwDeviceAgentService.getOne(new QueryWrapper<MwDeviceAgent>().lambda().eq(MwDeviceAgent::getName, mwDeviceAgent.getName()));
|
if (mwDeviceAgentEntity != null && !mwDeviceAgentEntity.getId().equals(mwDeviceAgent.getId())) {
|
result.error500("设备厂商信息已经存在");
|
return result;
|
}
|
mwDeviceAgentEntity = mwDeviceAgentService.getById(mwDeviceAgent.getId());
|
if (mwDeviceAgentEntity == null) {
|
result.error500("未找到对应实体");
|
} else {
|
boolean ok = mwDeviceAgentService.updateById(mwDeviceAgent);
|
if (ok) {
|
result.success("修改成功!");
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 通过id删除
|
*
|
* @param dto
|
* @return
|
*/
|
@PostMapping(value = "/delete")
|
@AutoLog(value = "删除设备代理商")
|
@ApiOperation(value = "删除设备代理商", notes = "删除设备代理商", produces = "application/json")
|
public Result<MwDeviceAgent> delete(@RequestBody MwDeviceAgentDeviceDTO dto) {
|
|
Result<MwDeviceAgent> result = new Result<MwDeviceAgent>();
|
MwDeviceAgent mwDeviceAgent = mwDeviceAgentService.getById(dto.getId());
|
if (mwDeviceAgent == null) {
|
result.error500("未找到对应实体");
|
} else {
|
boolean ok = mwDeviceAgentService.delete(dto.getId());
|
if (ok) {
|
result.success("删除成功!");
|
}
|
}
|
return result;
|
}
|
|
/**
|
* 批量删除
|
*
|
* @param dto
|
* @return
|
*/
|
@PostMapping(value = "/deleteBatch")
|
@AutoLog(value = "批量删除设备代理商")
|
@ApiOperation(value = "批量删除设备代理商", notes = "批量删除设备代理商", produces = "application/json")
|
public Result<MwDeviceAgent> deleteBatch(@RequestBody MwDeviceAgentDeviceDTO dto) {
|
|
Result<MwDeviceAgent> result = new Result<MwDeviceAgent>();
|
if (dto.getIds() == null || "".equals(dto.getIds().trim())) {
|
result.error500("参数不识别!");
|
} else {
|
this.mwDeviceAgentService.removeByIds(Arrays.asList(dto.getIds().split(",")));
|
result.success("删除成功!");
|
}
|
return result;
|
}
|
|
/**
|
* 通过id查询
|
*
|
* @param id
|
* @return
|
*/
|
@GetMapping(value = "/queryById")
|
@ApiOperation(value = "通过id查询设备代理商", notes = "通过id查询设备代理商", produces = "application/json")
|
public Result<MwDeviceAgent> queryById(@RequestParam(name = "id", required = true) String id) {
|
|
Result<MwDeviceAgent> result = new Result<MwDeviceAgent>();
|
MwDeviceAgent mwDeviceAgent = mwDeviceAgentService.getById(id);
|
if (mwDeviceAgent == null) {
|
result.error500("未找到对应实体");
|
} else {
|
result.setResult(mwDeviceAgent);
|
result.setSuccess(true);
|
}
|
return result;
|
}
|
|
}
|