新增羊只完善
This commit is contained in:
parent
861dae546a
commit
a1972a86eb
@ -7,8 +7,10 @@ import com.zhyc.common.exception.ServiceException;
|
|||||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||||
import com.zhyc.module.base.domain.BasSheepType;
|
import com.zhyc.module.base.domain.BasSheepType;
|
||||||
import com.zhyc.module.base.domain.BasSheepVariety;
|
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.IBasSheepTypeService;
|
||||||
import com.zhyc.module.base.service.IBasSheepVarietyService;
|
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.domain.ScAddSheep;
|
||||||
import com.zhyc.module.produce.manage_sheep.service.IScAddSheepService;
|
import com.zhyc.module.produce.manage_sheep.service.IScAddSheepService;
|
||||||
import com.zhyc.module.base.domain.DaSheepfold;
|
import com.zhyc.module.base.domain.DaSheepfold;
|
||||||
@ -40,6 +42,9 @@ public class ScAddSheepController {
|
|||||||
private IBasSheepVarietyService basSheepVarietyMapper;
|
private IBasSheepVarietyService basSheepVarietyMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private IBasSheepTypeService basSheepTypeService;
|
private IBasSheepTypeService basSheepTypeService;
|
||||||
|
@Autowired
|
||||||
|
private IDaRanchService daRanchService;
|
||||||
|
|
||||||
//新增羊只验证
|
//新增羊只验证
|
||||||
@PreAuthorize("@ss.hasPermi('produce:add_sheep:add')")
|
@PreAuthorize("@ss.hasPermi('produce:add_sheep:add')")
|
||||||
@Log(title = "新增", businessType = BusinessType.INSERT)
|
@Log(title = "新增", businessType = BusinessType.INSERT)
|
||||||
@ -48,6 +53,9 @@ public class ScAddSheepController {
|
|||||||
if (scAddSheep.getEarNumber() == null || scAddSheep.getEarNumber().isEmpty()) {
|
if (scAddSheep.getEarNumber() == null || scAddSheep.getEarNumber().isEmpty()) {
|
||||||
return AjaxResult.error("耳号不能为空");
|
return AjaxResult.error("耳号不能为空");
|
||||||
}
|
}
|
||||||
|
if (scAddSheep.getRanchId() == null || scAddSheep.getRanchId() == 0) {
|
||||||
|
return AjaxResult.error("牧场不能为空");
|
||||||
|
}
|
||||||
if (scAddSheep.getSheepfold() == null || scAddSheep.getSheepfold() == 0) {
|
if (scAddSheep.getSheepfold() == null || scAddSheep.getSheepfold() == 0) {
|
||||||
return AjaxResult.error("羊舍不能为空");
|
return AjaxResult.error("羊舍不能为空");
|
||||||
}
|
}
|
||||||
@ -83,6 +91,14 @@ public class ScAddSheepController {
|
|||||||
public void exportForm(HttpServletResponse response, @RequestBody ScAddSheep scAddSheep) throws IOException {
|
public void exportForm(HttpServletResponse response, @RequestBody ScAddSheep scAddSheep) throws IOException {
|
||||||
ExcelUtil<ScAddSheep> util = new ExcelUtil<>(ScAddSheep.class);
|
ExcelUtil<ScAddSheep> util = new ExcelUtil<>(ScAddSheep.class);
|
||||||
List<ScAddSheep> list = new ArrayList<>();
|
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) {
|
if (scAddSheep.getSheepfold() != null) {
|
||||||
DaSheepfold fold = daSheepfoldMapper.selectDaSheepfoldById(scAddSheep.getSheepfold().longValue());
|
DaSheepfold fold = daSheepfoldMapper.selectDaSheepfoldById(scAddSheep.getSheepfold().longValue());
|
||||||
@ -109,6 +125,7 @@ public class ScAddSheepController {
|
|||||||
list.add(scAddSheep);
|
list.add(scAddSheep);
|
||||||
util.exportExcel(response, list, "羊只信息");
|
util.exportExcel(response, list, "羊只信息");
|
||||||
}
|
}
|
||||||
|
|
||||||
//导入
|
//导入
|
||||||
@PostMapping("/importData")
|
@PostMapping("/importData")
|
||||||
@PreAuthorize("@ss.hasPermi('produce:add_sheep:import')")
|
@PreAuthorize("@ss.hasPermi('produce:add_sheep:import')")
|
||||||
|
@ -27,6 +27,11 @@ public class ScAddSheep extends BaseEntity {
|
|||||||
@Excel(name = "耳号")
|
@Excel(name = "耳号")
|
||||||
private String earNumber;
|
private String earNumber;
|
||||||
|
|
||||||
|
/** 牧场 */
|
||||||
|
private Integer ranchId;
|
||||||
|
@Excel(name = "牧场名称")
|
||||||
|
private String ranchName;
|
||||||
|
|
||||||
/** 羊舍编号 */
|
/** 羊舍编号 */
|
||||||
private Integer sheepfold;
|
private Integer sheepfold;
|
||||||
|
|
||||||
|
@ -3,8 +3,10 @@ package com.zhyc.module.produce.manage_sheep.service.impl;
|
|||||||
import com.zhyc.common.exception.ServiceException;
|
import com.zhyc.common.exception.ServiceException;
|
||||||
import com.zhyc.common.utils.StringUtils;
|
import com.zhyc.common.utils.StringUtils;
|
||||||
import com.zhyc.module.base.domain.BasSheepType;
|
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.mapper.BasSheepVarietyMapper;
|
||||||
import com.zhyc.module.base.service.IBasSheepTypeService;
|
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.domain.ScAddSheep;
|
||||||
import com.zhyc.module.produce.manage_sheep.mapper.ScAddSheepMapper;
|
import com.zhyc.module.produce.manage_sheep.mapper.ScAddSheepMapper;
|
||||||
import com.zhyc.module.produce.manage_sheep.service.IScAddSheepService;
|
import com.zhyc.module.produce.manage_sheep.service.IScAddSheepService;
|
||||||
@ -36,6 +38,9 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IBasSheepTypeService basSheepTypeService;
|
private IBasSheepTypeService basSheepTypeService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IDaRanchService daRanchService;
|
||||||
//新增
|
//新增
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@ -51,6 +56,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
|
|||||||
BasSheep bs = new BasSheep();
|
BasSheep bs = new BasSheep();
|
||||||
bs.setManageTags(scAddSheep.getEarNumber());
|
bs.setManageTags(scAddSheep.getEarNumber());
|
||||||
// bs.setElectronicTags(scAddSheep.getEarNumber());
|
// bs.setElectronicTags(scAddSheep.getEarNumber());
|
||||||
|
bs.setRanchId(scAddSheep.getRanchId().longValue());
|
||||||
bs.setSheepfoldId(scAddSheep.getSheepfold().longValue());
|
bs.setSheepfoldId(scAddSheep.getSheepfold().longValue());
|
||||||
bs.setFatherId(null);
|
bs.setFatherId(null);
|
||||||
bs.setMotherId(null);
|
bs.setMotherId(null);
|
||||||
@ -108,6 +114,23 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
|
|||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
ScAddSheep sheep = list.get(i);
|
ScAddSheep sheep = list.get(i);
|
||||||
try {
|
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())) {
|
if (StringUtils.isNotBlank(sheep.getVarietyName())) {
|
||||||
Long varietyId = basSheepVarietyMapper.selectIdByName(sheep.getVarietyName());
|
Long varietyId = basSheepVarietyMapper.selectIdByName(sheep.getVarietyName());
|
||||||
if (varietyId == null) {
|
if (varietyId == null) {
|
||||||
@ -131,6 +154,7 @@ public class ScAddSheepServiceImpl implements IScAddSheepService {
|
|||||||
if (StringUtils.isNotBlank(sheep.getSheepfoldNameExcel())) {
|
if (StringUtils.isNotBlank(sheep.getSheepfoldNameExcel())) {
|
||||||
DaSheepfold param = new DaSheepfold();
|
DaSheepfold param = new DaSheepfold();
|
||||||
param.setSheepfoldName(sheep.getSheepfoldNameExcel());
|
param.setSheepfoldName(sheep.getSheepfoldNameExcel());
|
||||||
|
param.setRanchId(sheep.getRanchId().longValue());
|
||||||
List<DaSheepfold> foldList = daSheepfoldMapper.selectDaSheepfoldList(param);
|
List<DaSheepfold> foldList = daSheepfoldMapper.selectDaSheepfoldList(param);
|
||||||
if (foldList == null || foldList.isEmpty()) {
|
if (foldList == null || foldList.isEmpty()) {
|
||||||
failure++;
|
failure++;
|
||||||
|
@ -61,18 +61,19 @@
|
|||||||
|
|
||||||
<insert id="insert" parameterType="ScAddSheep" useGeneratedKeys="true" keyProperty="id">
|
<insert id="insert" parameterType="ScAddSheep" useGeneratedKeys="true" keyProperty="id">
|
||||||
INSERT INTO sc_add_sheep
|
INSERT INTO sc_add_sheep
|
||||||
(ear_number, sheepfold, father, mother, born_weight, birthday,
|
(ear_number, sheepfold, ranch_id, father, mother, born_weight, birthday,
|
||||||
gender, parity, variety_id, type_id, join_date, comment, technician,
|
gender, parity, variety_id, type_id, join_date, comment, technician,
|
||||||
create_by, create_time)
|
create_by, create_time)
|
||||||
VALUES (#{earNumber}, #{sheepfold}, #{father}, #{mother}, #{bornWeight},
|
VALUES (#{earNumber}, #{sheepfold}, #{ranchId}, #{father}, #{mother}, #{bornWeight},
|
||||||
#{birthday}, #{gender}, #{parity}, #{varietyId}, #{typeId}, #{joinDate},
|
#{birthday}, #{gender}, #{parity}, #{varietyId}, #{typeId}, #{joinDate},
|
||||||
#{comment}, #{technician}, #{createBy}, #{createTime})
|
#{comment}, #{technician}, #{createBy}, #{createTime})
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
<update id="updateScAddSheep" parameterType="ScAddSheep">
|
<update id="updateScAddSheep" parameterType="ScAddSheep">
|
||||||
UPDATE sc_add_sheep
|
UPDATE sc_add_sheep
|
||||||
<set>
|
<set>
|
||||||
ear_number = #{earNumber},
|
ear_number = #{earNumber},
|
||||||
|
ranch_id = #{ranchId},
|
||||||
sheepfold = #{sheepfold},
|
sheepfold = #{sheepfold},
|
||||||
father = #{father},
|
father = #{father},
|
||||||
mother = #{mother},
|
mother = #{mother},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user