feat:设备流程接口
This commit is contained in:
@@ -52,15 +52,18 @@ public class DeviceApplyController extends AbstractFileUploadController implemen
|
||||
}
|
||||
}
|
||||
|
||||
@Resource
|
||||
private DeviceApplyService deviceApplyService;
|
||||
@Resource private DeviceApplyService deviceApplyService;
|
||||
|
||||
//todo 通过设备通用流程配置创建
|
||||
@PostMapping("/createTempData")
|
||||
@Operation(summary = "创建创建临时数据")
|
||||
// @PreAuthorize("@ss.hasPermission('qms:device-apply:create')")
|
||||
public CommonResult<DeviceApplyRespVO> createTempData(@Valid @RequestBody DeviceApplySaveReqVO createReqVO) {
|
||||
return success(deviceApplyService.createTempData(createReqVO));
|
||||
@RequestMapping("/createTempData")
|
||||
@Operation(summary = "创建临时数据")
|
||||
public CommonResult<DeviceApplyRespVO> createTempData(@RequestBody DeviceApplySaveReqVO createReqVO) {
|
||||
return deviceApplyService.createTempData(createReqVO);
|
||||
}
|
||||
|
||||
@RequestMapping("/saveDeviceApply")
|
||||
@Operation(summary = "保存申请数据")
|
||||
public CommonResult<Boolean> saveDeviceApply(@Valid @RequestBody DeviceApplySaveReqVO createReqVO) {
|
||||
return deviceApplyService.saveDeviceApply(createReqVO);
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.zt.plat.module.qms.resource.device.controller.vo;
|
||||
|
||||
import com.zt.plat.module.qms.core.aspect.annotation.Dict;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
|
||||
@@ -49,6 +50,7 @@ public class DeviceApplyRespVO {
|
||||
|
||||
@Schema(description = "业务状态", example = "1")
|
||||
@ExcelProperty("业务状态")
|
||||
@Dict(dicCode = "flow_status")
|
||||
private String businessStatus;
|
||||
|
||||
@Schema(description = "借用人")
|
||||
|
||||
@@ -45,7 +45,7 @@ public class DeviceApplyDO extends BusinessBaseDO {
|
||||
* 申请部门ID
|
||||
*/
|
||||
@TableField("APL_DEPT")
|
||||
private String applyDepartment;
|
||||
private Long applyDepartment;
|
||||
/**
|
||||
* 申请人
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ public class DeviceApplyDO extends BusinessBaseDO {
|
||||
* 申请人ID
|
||||
*/
|
||||
@TableField("APL_USER")
|
||||
private String applyUser;
|
||||
private Long applyUser;
|
||||
/**
|
||||
* 业务编码
|
||||
*/
|
||||
@@ -115,7 +115,7 @@ public class DeviceApplyDO extends BusinessBaseDO {
|
||||
* 表单模板ID
|
||||
*/
|
||||
@TableField("TMPL_ID")
|
||||
private String templateId;
|
||||
private Long templateId;
|
||||
/**
|
||||
* 表单组件
|
||||
*/
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.zt.plat.module.qms.resource.device.service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplyPageReqVO;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplyRespVO;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplySaveReqVO;
|
||||
@@ -25,7 +26,9 @@ public interface DeviceApplyService {
|
||||
DeviceApplyRespVO createDeviceApply(@Valid DeviceApplySaveReqVO createReqVO);
|
||||
|
||||
//创建临时数据
|
||||
DeviceApplyRespVO createTempData(@Valid DeviceApplySaveReqVO createReqVO);
|
||||
CommonResult<DeviceApplyRespVO> createTempData(@Valid DeviceApplySaveReqVO createReqVO);
|
||||
|
||||
CommonResult<Boolean> saveDeviceApply(@Valid DeviceApplySaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 更新设备通用流程,验收、降级、停用、报废、还原、启用
|
||||
@@ -34,6 +37,7 @@ public interface DeviceApplyService {
|
||||
*/
|
||||
void updateDeviceApply(@Valid DeviceApplySaveReqVO updateReqVO);
|
||||
|
||||
|
||||
/**
|
||||
* 删除设备通用流程,验收、降级、停用、报废、还原、启用
|
||||
*
|
||||
|
||||
@@ -1,14 +1,31 @@
|
||||
package com.zt.plat.module.qms.resource.device.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
||||
import com.zt.plat.framework.security.core.LoginUser;
|
||||
import com.zt.plat.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.zt.plat.module.qms.common.data.dal.dataobject.DataCollectionDO;
|
||||
import com.zt.plat.module.qms.common.data.dal.dataobject.DataTemplateDO;
|
||||
import com.zt.plat.module.qms.common.data.service.DataCollectionService;
|
||||
import com.zt.plat.module.qms.common.data.service.DataTemplateService;
|
||||
import com.zt.plat.module.qms.enums.QmsCommonConstant;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplyPageReqVO;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplyRespVO;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceApplySaveReqVO;
|
||||
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceConfigFlowDO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
import com.zt.plat.module.qms.resource.device.dal.dataobject.DeviceApplyDO;
|
||||
@@ -28,10 +45,13 @@ import static com.zt.plat.module.qms.enums.ErrorCodeConstants.DEVICE_APPLY_NOT_E
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class DeviceApplyServiceImpl implements DeviceApplyService {
|
||||
|
||||
@Resource
|
||||
private DeviceApplyMapper deviceApplyMapper;
|
||||
@Resource private DeviceApplyMapper deviceApplyMapper;
|
||||
@Resource private DeviceConfigFlowService deviceConfigFlowService;
|
||||
@Resource private DataCollectionService dataCollectionService;
|
||||
@Resource private DataTemplateService dataTemplateService;
|
||||
|
||||
@Override
|
||||
public DeviceApplyRespVO createDeviceApply(DeviceApplySaveReqVO createReqVO) {
|
||||
@@ -43,14 +63,71 @@ public class DeviceApplyServiceImpl implements DeviceApplyService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceApplyRespVO createTempData(DeviceApplySaveReqVO createReqVO) {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CommonResult<DeviceApplyRespVO> createTempData(DeviceApplySaveReqVO createReqVO) {
|
||||
String businessType = createReqVO.getBusinessCode();
|
||||
if(ObjectUtils.isEmpty(businessType))
|
||||
return CommonResult.error(DEVICE_APPLY_NOT_EXISTS.getCode(), "请选择业务类型");
|
||||
DeviceConfigFlowDO config = deviceConfigFlowService.getByBusinessType(businessType);
|
||||
if(ObjectUtils.isEmpty(config))
|
||||
return CommonResult.error(DEVICE_APPLY_NOT_EXISTS.getCode(), "业务类型配置不存在("+businessType+"),请联系管理员处理");
|
||||
DeviceApplyDO deviceApply = BeanUtils.toBean(createReqVO, DeviceApplyDO.class);
|
||||
if(!ObjectUtils.isEmpty(config.getTemplateKey())){
|
||||
DataTemplateDO dataTemplate = dataTemplateService.getLatestDataByKey(config.getTemplateKey());
|
||||
if(ObjectUtils.isEmpty(dataTemplate))
|
||||
return CommonResult.error(DEVICE_APPLY_NOT_EXISTS.getCode(), "表单编辑器模板不存在("+config.getTemplateKey()+"),请联系管理员处理");
|
||||
deviceApply.setTemplateId(dataTemplate.getId());
|
||||
}
|
||||
DataCollectionDO dataCollection = dataCollectionService.getLatestDataCollectionByKey(config.getDataCollectionKey());
|
||||
if(ObjectUtils.isEmpty(dataCollection))
|
||||
return CommonResult.error(DEVICE_APPLY_NOT_EXISTS.getCode(), "数据集不存在("+config.getDataCollectionKey()+"),请联系管理员处理");
|
||||
deviceApply.setBusinessName(config.getBusinessName());
|
||||
deviceApply.setDataCollectionId(dataCollection.getId());
|
||||
//取当前用户
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
String nickName = SecurityFrameworkUtils.getLoginUserNickname();
|
||||
deviceApply.setApplyUser(loginUser.getId());
|
||||
deviceApply.setApplyUserName(nickName);
|
||||
deviceApply.setApplyDepartment(loginUser.getVisitDeptId());
|
||||
deviceApply.setApplyDepartmentName(loginUser.getVisitDeptName());
|
||||
deviceApply.setBusinessStatus(QmsCommonConstant.TEMP_DATA_CODE);
|
||||
deviceApplyMapper.insert(deviceApply);
|
||||
// 返回
|
||||
return BeanUtils.toBean(deviceApply, DeviceApplyRespVO.class);
|
||||
return CommonResult.success(BeanUtils.toBean(deviceApply, DeviceApplyRespVO.class));
|
||||
}
|
||||
|
||||
//保存
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public CommonResult<Boolean> saveDeviceApply(DeviceApplySaveReqVO updateReqVO) {
|
||||
|
||||
// 校验存在
|
||||
DeviceApplyDO backData = getDeviceApply(updateReqVO.getId());
|
||||
if(backData == null)
|
||||
throw exception(DEVICE_APPLY_NOT_EXISTS);
|
||||
if(QmsCommonConstant.TEMP_DATA_CODE.equals(backData.getBusinessStatus())){
|
||||
updateReqVO.setBusinessStatus(QmsCommonConstant.NOT_START);
|
||||
}
|
||||
//处理动态表单字段
|
||||
String formData = updateReqVO.getFormData();
|
||||
if(!ObjectUtils.isEmpty(formData)) {
|
||||
assembleFormData(formData, updateReqVO);
|
||||
}
|
||||
// 更新
|
||||
DeviceApplyDO updateObj = BeanUtils.toBean(updateReqVO, DeviceApplyDO.class);
|
||||
deviceApplyMapper.updateById(updateObj);
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
private void assembleFormData(String formData, DeviceApplySaveReqVO updateReqVO){
|
||||
JSONObject jsonObject = JSONObject.parseObject(formData);
|
||||
DeviceApplySaveReqVO jsonVo = jsonObject.toJavaObject(DeviceApplySaveReqVO.class);
|
||||
CopyOptions copyOptions = CopyOptions.create();
|
||||
copyOptions.setIgnoreNullValue(true);
|
||||
BeanUtil.copyProperties(jsonVo, updateReqVO, copyOptions);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateDeviceApply(DeviceApplySaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
|
||||
@@ -18,6 +18,8 @@ public interface DeviceConfigFlowService {
|
||||
|
||||
List<DeviceConfigFlowDO> getEnableList(DeviceConfigFlowPageReqVO pageReqVO);
|
||||
|
||||
DeviceConfigFlowDO getByBusinessType(String code);
|
||||
|
||||
/**
|
||||
* 创建设备通用流程配置
|
||||
*
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.zt.plat.module.qms.resource.device.service;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceConfigFlowPageReqVO;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceConfigFlowRespVO;
|
||||
import com.zt.plat.module.qms.resource.device.controller.vo.DeviceConfigFlowSaveReqVO;
|
||||
@@ -37,6 +38,15 @@ public class DeviceConfigFlowServiceImpl implements DeviceConfigFlowService {
|
||||
return deviceConfigFlowMapper.selectList(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceConfigFlowDO getByBusinessType(String code) {
|
||||
LambdaQueryWrapper<DeviceConfigFlowDO> query = new LambdaQueryWrapper<>();
|
||||
query.eq(DeviceConfigFlowDO::getBusinessType, code);
|
||||
query.orderByDesc(DeviceConfigFlowDO::getUpdateTime);
|
||||
query.last("limit 1");
|
||||
return deviceConfigFlowMapper.selectOne(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceConfigFlowRespVO createDeviceConfigFlow(DeviceConfigFlowSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
|
||||
Reference in New Issue
Block a user