Controller
/**
* 新增知情同意书模板
*
* @param
* @return
*/
@ResponseBody
@PostMapping("/insertOrUpdateConsent")
@ApiOperation(value = "新增知情同意书模板信息")
@LoginRequired
@RequiredPermission("/insertOrUpdateConsent") // 权限注解
public ResponseMessage insertOrUpdateConsent(@RequestBody InformedConsentTemplet informedConsentTempLet) {
try {
if (informedConsentTempLet == null) {
return ResponseMessage.createErrResponseMessage("没有知情同意书模板信息");
}
//记录用户操作
OperationLog operationLog = OperationLogUtil.setParam(request, "新增知情同意书模板信息", JSON.toJSONString(informedConsentTempLet, SerializerFeature.WriteMapNullValue));
operationLog.setOperation(this.getClass().getSimpleName() + "-" + Thread.currentThread().getStackTrace()[1].getMethodName());
this.informedConsentTemletService.insert(informedConsentTempLet);
operationLogMapper.insert(operationLog);
return ResponseMessage.createSucResponseMessage();
} catch (Exception e) {
log.error("新增知情同意书模板异常", e);
return ResponseMessage.createErrResponseMessage("新增知情同意书模板失败");
}
}
Service
/**
* 新增知情同意书模板新增修改
*
* @param informedConsent
* @throws Exception
*/
public void insert(InformedConsentTemplet informedConsent) throws Exception {
try {
//没有id进行创建,有id进行修改
String consentId = informedConsent.getConsentId();
if (StringUtils.isBlank(consentId)) {
informedConsent.setConsentId(UUID.randomUUID().toString().replace("-", ""));
informedConsent.setCreateDate(new Date());
int i = this.informedConsentTempletMapper.insert(informedConsent);
if (i > 0) {
log.info("【知情同意书模板新增方法成功】");
}
} else {
List selectAll = this.informedConsentTempletMapper.selectAll(consentId, null);
if (selectAll.size() < 0) {
throw new BusinessException("数据库中不存在该条数据");
}
informedConsent.setUpdateDate(new Date());
int i = this.informedConsentTempletMapper.updateByPrimaryKey(informedConsent);
if (i > 0) {
log.info("【知情同意书模板修改方法成功】");
}
}
} catch (Exception e) {
log.error("【新增同意书模板方法异常】异常信息为:" + e.getMessage());
throw new Exception(e.getMessage());
}
}
XML
update INFORMED_CONSENT_TEMPLET
set CONSENT_NAME = #{consentName,jdbcType=VARCHAR},
CONSENT_DESC = #{consentDesc,jdbcType=VARCHAR},
CONSENT_VERSION = #{consentVersion,jdbcType=VARCHAR},
USEFLAG = #{useflag,jdbcType=VARCHAR},
CREATE_DATE = #{createDate,jdbcType=DATE},
UPDATE_DATE = #{updateDate,jdbcType=DATE},
CREATOR_ID = #{creatorId,jdbcType=NUMERIC},
UPDATOR_ID = #{updatorId,jdbcType=NUMERIC},
CONTENT = utl_raw.cast_to_raw(#{content,jdbcType=BLOB})
where CONSENT_ID = #{consentId,jdbcType=VARCHAR}