新增羊只完善

This commit is contained in:
zyh 2025-08-20 13:15:17 +08:00
parent 861dae546a
commit a1972a86eb
4 changed files with 53 additions and 6 deletions

View File

@ -7,8 +7,10 @@ import com.zhyc.common.exception.ServiceException;
import com.zhyc.common.utils.poi.ExcelUtil;
import com.zhyc.module.base.domain.BasSheepType;
import com.zhyc.module.base.domain.BasSheepVariety;
import com.zhyc.module.base.domain.DaRanch;
import com.zhyc.module.base.service.IBasSheepTypeService;
import com.zhyc.module.base.service.IBasSheepVarietyService;
import com.zhyc.module.base.service.IDaRanchService;
import com.zhyc.module.produce.manage_sheep.domain.ScAddSheep;
import com.zhyc.module.produce.manage_sheep.service.IScAddSheepService;
import com.zhyc.module.base.domain.DaSheepfold;
@ -40,6 +42,9 @@ public class ScAddSheepController {
private IBasSheepVarietyService basSheepVarietyMapper;
@Autowired
private IBasSheepTypeService basSheepTypeService;
@Autowired
private IDaRanchService daRanchService;
//新增羊只验证
@PreAuthorize("@ss.hasPermi('produce:add_sheep:add')")
@Log(title = "新增", businessType = BusinessType.INSERT)
@ -48,6 +53,9 @@ public class ScAddSheepController {
if (scAddSheep.getEarNumber() == null || scAddSheep.getEarNumber().isEmpty()) {
return AjaxResult.error("耳号不能为空");
}
if (scAddSheep.getRanchId() == null || scAddSheep.getRanchId() == 0) {
return AjaxResult.error("牧场不能为空");
}
if (scAddSheep.getSheepfold() == null || scAddSheep.getSheepfold() == 0) {
return AjaxResult.error("羊舍不能为空");
}
@ -83,6 +91,14 @@ public class ScAddSheepController {
public void exportForm(HttpServletResponse response, @RequestBody ScAddSheep scAddSheep) throws IOException {
ExcelUtil<ScAddSheep> util = new ExcelUtil<>(ScAddSheep.class);
List<ScAddSheep> list = new ArrayList<>();
//处理牧场名称
if (scAddSheep.getRanchId() != null) {
// 根据牧场ID查询牧场信息
DaRanch ranch = daRanchService.selectDaRanchById(scAddSheep.getRanchId().longValue());
if (ranch != null) {
scAddSheep.setRanchName(ranch.getRanch()); // 将牧场名称设置到实体中
}
}
// 处理羊舍名称
if (scAddSheep.getSheepfold() != null) {
DaSheepfold fold = daSheepfoldMapper.selectDaSheepfoldById(scAddSheep.getSheepfold().longValue());
@ -109,6 +125,7 @@ public class ScAddSheepController {
list.add(scAddSheep);
util.exportExcel(response, list, "羊只信息");
}
//导入
@PostMapping("/importData")
@PreAuthorize("@ss.hasPermi('produce:add_sheep:import')")

View File

@ -27,6 +27,11 @@ public class ScAddSheep extends BaseEntity {
@Excel(name = "耳号")
private String earNumber;
/** 牧场 */
private Integer ranchId;
@Excel(name = "牧场名称")
private String ranchName;
/** 羊舍编号 */
private Integer sheepfold;

View File

@ -3,8 +3,10 @@ package com.zhyc.module.produce.manage_sheep.service.impl;
import com.zhyc.common.exception.ServiceException;
import com.zhyc.common.utils.StringUtils;
import com.zhyc.module.base.domain.BasSheepType;
import com.zhyc.module.base.domain.DaRanch;
import com.zhyc.module.base.mapper.BasSheepVarietyMapper;
import com.zhyc.module.base.service.IBasSheepTypeService;
import com.zhyc.module.base.service.IDaRanchService;
import com.zhyc.module.produce.manage_sheep.domain.ScAddSheep;
import com.zhyc.module.produce.manage_sheep.mapper.ScAddSheepMapper;
import com.zhyc.module.produce.manage_sheep.service.IScAddSheepService;
@ -36,6 +38,9 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
@Autowired
private IBasSheepTypeService basSheepTypeService;
@Autowired
private IDaRanchService daRanchService;
//新增
@Override
@Transactional(rollbackFor = Exception.class)
@ -51,6 +56,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
BasSheep bs = new BasSheep();
bs.setManageTags(scAddSheep.getEarNumber());
// bs.setElectronicTags(scAddSheep.getEarNumber());
bs.setRanchId(scAddSheep.getRanchId().longValue());
bs.setSheepfoldId(scAddSheep.getSheepfold().longValue());
bs.setFatherId(null);
bs.setMotherId(null);
@ -108,6 +114,23 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
for (int i = 0; i < list.size(); i++) {
ScAddSheep sheep = list.get(i);
try {
if (StringUtils.isBlank(sheep.getRanchName())) {
failure++;
failureMsg.append("<br/>第").append(i + 1).append("行:牧场名称不能为空");
continue;
}
DaRanch ranchParam = new DaRanch();
ranchParam.setRanch(sheep.getRanchName().trim());
List<DaRanch> ranchList = daRanchService.selectDaRanchList(ranchParam);
if (ranchList == null || ranchList.isEmpty()) {
failure++;
failureMsg.append("<br/>第").append(i + 1)
.append("行:牧场名称不存在【").append(sheep.getRanchName()).append("");
continue;
}
sheep.setRanchId(ranchList.get(0).getId().intValue());
if (StringUtils.isNotBlank(sheep.getVarietyName())) {
Long varietyId = basSheepVarietyMapper.selectIdByName(sheep.getVarietyName());
if (varietyId == null) {
@ -131,6 +154,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
if (StringUtils.isNotBlank(sheep.getSheepfoldNameExcel())) {
DaSheepfold param = new DaSheepfold();
param.setSheepfoldName(sheep.getSheepfoldNameExcel());
param.setRanchId(sheep.getRanchId().longValue());
List<DaSheepfold> foldList = daSheepfoldMapper.selectDaSheepfoldList(param);
if (foldList == null || foldList.isEmpty()) {
failure++;

View File

@ -61,18 +61,19 @@
<insert id="insert" parameterType="ScAddSheep" useGeneratedKeys="true" keyProperty="id">
INSERT INTO sc_add_sheep
(ear_number, sheepfold, father, mother, born_weight, birthday,
gender, parity, variety_id, type_id, join_date, comment, technician,
create_by, create_time)
VALUES (#{earNumber}, #{sheepfold}, #{father}, #{mother}, #{bornWeight},
#{birthday}, #{gender}, #{parity}, #{varietyId}, #{typeId}, #{joinDate},
#{comment}, #{technician}, #{createBy}, #{createTime})
(ear_number, sheepfold, ranch_id, father, mother, born_weight, birthday,
gender, parity, variety_id, type_id, join_date, comment, technician,
create_by, create_time)
VALUES (#{earNumber}, #{sheepfold}, #{ranchId}, #{father}, #{mother}, #{bornWeight},
#{birthday}, #{gender}, #{parity}, #{varietyId}, #{typeId}, #{joinDate},
#{comment}, #{technician}, #{createBy}, #{createTime})
</insert>
<update id="updateScAddSheep" parameterType="ScAddSheep">
UPDATE sc_add_sheep
<set>
ear_number = #{earNumber},
ranch_id = #{ranchId},
sheepfold = #{sheepfold},
father = #{father},
mother = #{mother},