治疗记录,不许重复的数据
This commit is contained in:
parent
3af62e205c
commit
03fef7af49
@ -10,8 +10,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
|||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
||||||
public class SheepApplication
|
public class SheepApplication {
|
||||||
{
|
|
||||||
public static void main(String[] args)
|
public static void main(String[] args)
|
||||||
{
|
{
|
||||||
// System.setProperty("spring.devtools.restart.enabled", "false");
|
// System.setProperty("spring.devtools.restart.enabled", "false");
|
||||||
|
|||||||
@ -0,0 +1,8 @@
|
|||||||
|
package com.zhyc.module.Exception;
|
||||||
|
|
||||||
|
// 业务异常
|
||||||
|
public class BusinessException extends RuntimeException {
|
||||||
|
public BusinessException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -50,7 +50,7 @@ public class SwMedicineUsageDetails extends BaseEntity
|
|||||||
private String usageId;
|
private String usageId;
|
||||||
|
|
||||||
/** 使用时间 */
|
/** 使用时间 */
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
// @Excel(name = "使用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
// @Excel(name = "使用时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date usetime;
|
private Date usetime;
|
||||||
|
|
||||||
|
|||||||
@ -107,8 +107,16 @@ public class Treatment extends BaseEntity
|
|||||||
@Excel(name = "备注")
|
@Excel(name = "备注")
|
||||||
private String comment;
|
private String comment;
|
||||||
public void setGender(String gender) {
|
public void setGender(String gender) {
|
||||||
this.gender = gender;
|
this.gender = gender; // 保留原始字符串
|
||||||
this.genderName = Gender.getDescByCode(Integer.valueOf(gender));
|
this.genderName = null; // 先清空
|
||||||
|
if (gender != null && !gender.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
this.genderName = Gender.getDescByCode(Integer.valueOf(gender.trim()));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// 可选:记录日志、或抛业务异常
|
||||||
|
this.genderName = "未知";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 排序查询
|
// 排序查询
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
import com.zhyc.common.utils.DateUtils;
|
import com.zhyc.common.utils.DateUtils;
|
||||||
import com.zhyc.common.utils.SecurityUtils;
|
import com.zhyc.common.utils.SecurityUtils;
|
||||||
import com.zhyc.common.utils.bean.BeanUtils;
|
import com.zhyc.common.utils.bean.BeanUtils;
|
||||||
|
import com.zhyc.module.Exception.BusinessException;
|
||||||
import com.zhyc.module.base.domain.SheepFile;
|
import com.zhyc.module.base.domain.SheepFile;
|
||||||
import com.zhyc.module.base.mapper.SheepFileMapper;
|
import com.zhyc.module.base.mapper.SheepFileMapper;
|
||||||
import com.zhyc.module.biosafety.domain.Diagnosis;
|
import com.zhyc.module.biosafety.domain.Diagnosis;
|
||||||
@ -77,10 +78,10 @@ public class TreatmentServiceImpl implements ITreatmentService
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public int insertTreatment(Treatment treatment)
|
public int insertTreatment(Treatment treatment) {
|
||||||
{
|
|
||||||
String username = SecurityUtils.getLoginUser().getUser().getNickName();
|
String username = SecurityUtils.getLoginUser().getUser().getNickName();
|
||||||
// 使用记录的文件
|
|
||||||
|
// 药品使用记录公共字段
|
||||||
SwMedicineUsage medicineUsage = new SwMedicineUsage();
|
SwMedicineUsage medicineUsage = new SwMedicineUsage();
|
||||||
medicineUsage.setSwMedicineUsageDetailsList(treatment.getUsageDetails());
|
medicineUsage.setSwMedicineUsageDetailsList(treatment.getUsageDetails());
|
||||||
medicineUsage.setName("羊只治疗");
|
medicineUsage.setName("羊只治疗");
|
||||||
@ -88,25 +89,76 @@ public class TreatmentServiceImpl implements ITreatmentService
|
|||||||
medicineUsage.setDatetime(treatment.getDatetime());
|
medicineUsage.setDatetime(treatment.getDatetime());
|
||||||
medicineUsage.setCreateBy(username);
|
medicineUsage.setCreateBy(username);
|
||||||
medicineUsage.setCreateTime(DateUtils.getNowDate());
|
medicineUsage.setCreateTime(DateUtils.getNowDate());
|
||||||
// 新增单挑数据
|
|
||||||
if (treatment.getSheepId()!=null){
|
/* ---------------- 单只插入 ---------------- */
|
||||||
|
if (treatment.getSheepId() != null) {
|
||||||
|
// 1. 重复校验
|
||||||
|
Treatment query = new Treatment();
|
||||||
|
query.setDiseaseId(treatment.getDiseaseId());
|
||||||
|
query.setDiseasePid(treatment.getDiseasePid());
|
||||||
|
query.setSheepId(treatment.getSheepId());
|
||||||
|
query.setStatus("0");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 2. 羊只档案信息
|
||||||
|
SheepFile sheepFile = sheepFileMapper.selectSheepFileById(treatment.getSheepId());
|
||||||
|
|
||||||
|
if (!treatmentMapper.selectTreatmentList(query).isEmpty()) {
|
||||||
|
throw new BusinessException("该羊只已存在相同疾病的治疗记录,不能重复添加");
|
||||||
|
}
|
||||||
|
// 3. 保存药品使用记录
|
||||||
medicineUsage.setSheepId(Math.toIntExact(treatment.getSheepId()));
|
medicineUsage.setSheepId(Math.toIntExact(treatment.getSheepId()));
|
||||||
// 药品使用记录
|
Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage);
|
||||||
Integer id=medicineUsageService.insertSwMedicineUsage(medicineUsage);
|
|
||||||
// 药品使用记录id
|
// 4. 组装治疗记录
|
||||||
treatment.setUsageId(id);
|
treatment.setUsageId(usageId);
|
||||||
treatment.setCreateTime(DateUtils.getNowDate());
|
treatment.setCreateTime(DateUtils.getNowDate());
|
||||||
|
treatment.setVariety(sheepFile.getVariety());
|
||||||
|
treatment.setSheepType(sheepFile.getName());
|
||||||
|
treatment.setMonthAge(sheepFile.getMonthAge());
|
||||||
|
treatment.setGender(String.valueOf(sheepFile.getGender()));
|
||||||
|
treatment.setBreed(sheepFile.getBreed());
|
||||||
|
treatment.setParity(sheepFile.getParity());
|
||||||
|
treatment.setLactDay(sheepFile.getLactationDay());
|
||||||
|
treatment.setGestDay(sheepFile.getGestationDay());
|
||||||
|
|
||||||
|
// 5. 插入
|
||||||
return treatmentMapper.insertTreatment(treatment);
|
return treatmentMapper.insertTreatment(treatment);
|
||||||
|
}
|
||||||
|
|
||||||
// 批量新增
|
/* ---------------- 批量插入 ---------------- */
|
||||||
}else {
|
// 1. 收集所有重复耳号
|
||||||
|
List<String> duplicateSheepIds = new ArrayList<>();
|
||||||
|
for (String sheepId : treatment.getSheepIds()) {
|
||||||
|
Treatment query = new Treatment();
|
||||||
|
query.setDiseaseId(treatment.getDiseaseId());
|
||||||
|
query.setDiseasePid(treatment.getDiseasePid());
|
||||||
|
query.setSheepId(Long.valueOf(sheepId));
|
||||||
|
query.setStatus("0");
|
||||||
|
|
||||||
|
if (!treatmentMapper.selectTreatmentList(query).isEmpty()) {
|
||||||
|
String bsManageTags = sheepFileMapper.selectSheepFileById(Long.valueOf(sheepId)).getBsManageTags();
|
||||||
|
duplicateSheepIds.add(bsManageTags);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 存在重复则一次性提示
|
||||||
|
if (!duplicateSheepIds.isEmpty()) {
|
||||||
|
|
||||||
|
throw new BusinessException("以下耳号已存在相同疾病记录,无法添加:" + String.join("、", duplicateSheepIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 全部合法,开始批量组装
|
||||||
List<Treatment> treatments = new ArrayList<>();
|
List<Treatment> treatments = new ArrayList<>();
|
||||||
treatment.setCreateTime(DateUtils.getNowDate());
|
treatment.setCreateTime(DateUtils.getNowDate());
|
||||||
|
|
||||||
for (String sheepId : treatment.getSheepIds()) {
|
for (String sheepId : treatment.getSheepIds()) {
|
||||||
SheepFile sheepFile = sheepFileMapper.selectSheepFileById(Long.valueOf(sheepId));
|
SheepFile sheepFile = sheepFileMapper.selectSheepFileById(Long.valueOf(sheepId));
|
||||||
|
|
||||||
Treatment treat = new Treatment();
|
Treatment treat = new Treatment();
|
||||||
BeanUtils.copyProperties(treatment, treat);
|
BeanUtils.copyProperties(treatment, treat);
|
||||||
|
|
||||||
treat.setSheepId(Long.valueOf(sheepId));
|
treat.setSheepId(Long.valueOf(sheepId));
|
||||||
treat.setVariety(sheepFile.getVariety());
|
treat.setVariety(sheepFile.getVariety());
|
||||||
treat.setSheepType(sheepFile.getName());
|
treat.setSheepType(sheepFile.getName());
|
||||||
@ -117,23 +169,17 @@ public class TreatmentServiceImpl implements ITreatmentService
|
|||||||
treat.setLactDay(sheepFile.getLactationDay());
|
treat.setLactDay(sheepFile.getLactationDay());
|
||||||
treat.setGestDay(sheepFile.getGestationDay());
|
treat.setGestDay(sheepFile.getGestationDay());
|
||||||
|
|
||||||
|
// 药品使用记录
|
||||||
medicineUsage.setSheepId(Integer.valueOf(sheepId));
|
medicineUsage.setSheepId(Integer.valueOf(sheepId));
|
||||||
// 获取药品使用记录的id
|
|
||||||
Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage);
|
Integer usageId = medicineUsageService.insertSwMedicineUsage(medicineUsage);
|
||||||
System.out.println(medicineUsage);
|
|
||||||
System.out.println(usageId);
|
|
||||||
treat.setUsageId(usageId);
|
treat.setUsageId(usageId);
|
||||||
|
|
||||||
treatments.add(treat);
|
treatments.add(treat);
|
||||||
}
|
}
|
||||||
// 药品使用记录
|
|
||||||
medicineUsage.setSwMedicineUsageDetailsList(treatment.getUsageDetails());
|
|
||||||
|
|
||||||
|
|
||||||
|
// 4. 批量插入
|
||||||
return treatmentMapper.insertTreatmentList(treatments);
|
return treatmentMapper.insertTreatmentList(treatments);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改治疗记录
|
* 修改治疗记录
|
||||||
*
|
*
|
||||||
@ -153,7 +199,9 @@ public class TreatmentServiceImpl implements ITreatmentService
|
|||||||
swMedicineUsage.setId(treatment.getUsageId());
|
swMedicineUsage.setId(treatment.getUsageId());
|
||||||
swMedicineUsage.setUpdateBy(username);
|
swMedicineUsage.setUpdateBy(username);
|
||||||
medicineUsageMapper.updateSwMedicineUsage(swMedicineUsage);
|
medicineUsageMapper.updateSwMedicineUsage(swMedicineUsage);
|
||||||
|
if (!treatment.getUsageDetails().isEmpty() || treatment.getUsageDetails().size() != 0){
|
||||||
medicineUsageMapper.batchSwMedicineUsageDetails(treatment.getUsageDetails());
|
medicineUsageMapper.batchSwMedicineUsageDetails(treatment.getUsageDetails());
|
||||||
|
}
|
||||||
treatment.setUpdateBy(username);
|
treatment.setUpdateBy(username);
|
||||||
treatment.setUpdateTime(DateUtils.getNowDate());
|
treatment.setUpdateTime(DateUtils.getNowDate());
|
||||||
return treatmentMapper.updateTreatment(treatment);
|
return treatmentMapper.updateTreatment(treatment);
|
||||||
|
|||||||
@ -193,10 +193,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
delete from sw_medicine_usage_details where medi_usage = #{mediUsage}
|
delete from sw_medicine_usage_details where medi_usage = #{mediUsage}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<insert id="batchSwMedicineUsageDetails">
|
|
||||||
insert into sw_medicine_usage_details( id, medi_usage, medi_id, dosage, unit, usageId,usetime, manufacturer, batch_number) values
|
<!-- 修改后的正确SQL -->
|
||||||
<foreach item="item" index="index" collection="list" separator=",">
|
<insert id="batchSwMedicineUsageDetails" parameterType="java.util.List">
|
||||||
( #{item.id}, #{item.mediUsage}, #{item.mediId}, #{item.dosage}, #{item.unit}, #{item.usageId}, #{item.usetime},#{item.manufacturer}, #{item.batchNumber})
|
insert into sw_medicine_usage_details(id, medi_usage, medi_id, dosage, unit, usageId, usetime, manufacturer, batch_number)
|
||||||
|
values
|
||||||
|
<foreach collection="list" item="item" separator=",">
|
||||||
|
(#{item.id}, #{item.mediUsage}, #{item.mediId}, #{item.dosage},
|
||||||
|
#{item.unit}, #{item.usageId}, #{item.usetime},
|
||||||
|
#{item.manufacturer}, #{item.batchNumber})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
x
Reference in New Issue
Block a user