修改羊只档案导出功能
This commit is contained in:
@@ -5,6 +5,7 @@ import com.zhyc.common.annotation.Log;
|
||||
import com.zhyc.common.core.controller.BaseController;
|
||||
import com.zhyc.common.core.domain.AjaxResult;
|
||||
import com.zhyc.common.core.page.TableDataInfo;
|
||||
import com.zhyc.common.core.text.Convert;
|
||||
import com.zhyc.common.enums.BusinessType;
|
||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||
import com.zhyc.module.base.domain.SheepFile;
|
||||
@@ -19,6 +20,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 羊只档案Controller
|
||||
*
|
||||
@@ -147,68 +151,80 @@ public class SheepFileController extends BaseController
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('sheep_file:sheep_file:export')")
|
||||
@Log(title = "羊只档案", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export") // 改为 POST 请求
|
||||
public void export(HttpServletResponse response, @RequestBody(required = false) Map<String, Object> queryParams)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, HttpServletRequest request)
|
||||
{
|
||||
// 解析查询参数
|
||||
// 构建查询条件对象
|
||||
SheepFile sheepFile = new SheepFile();
|
||||
Map<String, Object> customParams = new HashMap<>();
|
||||
|
||||
if (queryParams != null && !queryParams.isEmpty()) {
|
||||
// 提取常规查询参数到 SheepFile 对象
|
||||
if (queryParams.containsKey("bsManageTags") && queryParams.get("bsManageTags") != null) {
|
||||
sheepFile.setBsManageTags(queryParams.get("bsManageTags").toString());
|
||||
}
|
||||
if (queryParams.containsKey("electronicTags") && queryParams.get("electronicTags") != null) {
|
||||
sheepFile.setElectronicTags(queryParams.get("electronicTags").toString());
|
||||
}
|
||||
if (queryParams.containsKey("drRanch") && queryParams.get("drRanch") != null) {
|
||||
sheepFile.setDrRanch(queryParams.get("drRanch").toString());
|
||||
}
|
||||
if (queryParams.containsKey("variety") && queryParams.get("variety") != null) {
|
||||
sheepFile.setVariety(queryParams.get("variety").toString());
|
||||
}
|
||||
if (queryParams.containsKey("name") && queryParams.get("name") != null) {
|
||||
sheepFile.setName(queryParams.get("name").toString());
|
||||
}
|
||||
if (queryParams.containsKey("gender") && queryParams.get("gender") != null) {
|
||||
sheepFile.setGender(convertToLong(queryParams.get("gender")));
|
||||
}
|
||||
if (queryParams.containsKey("statusId") && queryParams.get("statusId") != null) {
|
||||
sheepFile.setStatusId(convertToLong(queryParams.get("statusId")));
|
||||
}
|
||||
if (queryParams.containsKey("breed") && queryParams.get("breed") != null) {
|
||||
sheepFile.setBreed(queryParams.get("breed").toString());
|
||||
}
|
||||
// 解析所有请求参数
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
|
||||
// 提取自定义筛选参数
|
||||
for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
for (Map.Entry<String, String[]> entry : parameterMap.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
String[] values = entry.getValue();
|
||||
|
||||
// 跳过常规参数和分页参数
|
||||
if ("bsManageTags".equals(key) || "electronicTags".equals(key) ||
|
||||
"drRanch".equals(key) || "variety".equals(key) ||
|
||||
"name".equals(key) || "gender".equals(key) ||
|
||||
"statusId".equals(key) || "breed".equals(key) ||
|
||||
"pageNum".equals(key) || "pageSize".equals(key)) {
|
||||
continue;
|
||||
}
|
||||
if (values != null && values.length > 0 && StringUtils.isNotBlank(values[0])) {
|
||||
String value = values[0];
|
||||
|
||||
// 添加到自定义参数中
|
||||
if (value != null) {
|
||||
customParams.put(key, value);
|
||||
// 使用若依框架的工具方法处理参数
|
||||
switch (key) {
|
||||
case "bsManageTags":
|
||||
sheepFile.setBsManageTags(convertToString(value));
|
||||
break;
|
||||
case "electronicTags":
|
||||
sheepFile.setElectronicTags(convertToString(value));
|
||||
break;
|
||||
case "drRanch":
|
||||
sheepFile.setDrRanch(convertToString(value));
|
||||
break;
|
||||
case "variety":
|
||||
sheepFile.setVariety(convertToString(value));
|
||||
break;
|
||||
case "name":
|
||||
sheepFile.setName(convertToString(value));
|
||||
break;
|
||||
case "gender":
|
||||
sheepFile.setGender(Convert.toLong(value));
|
||||
break;
|
||||
case "statusId":
|
||||
sheepFile.setStatusId(Convert.toLong(value));
|
||||
break;
|
||||
case "breed":
|
||||
sheepFile.setBreed(convertToString(value));
|
||||
break;
|
||||
case "pageNum":
|
||||
case "pageSize":
|
||||
// 忽略分页参数
|
||||
break;
|
||||
default:
|
||||
// 自定义参数
|
||||
customParams.put(key, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 调用支持复杂查询的Service方法获取数据(不分页)
|
||||
// 调用Service获取数据
|
||||
List<SheepFile> list = sheepFileService.selectSheepFileListByCondition(customParams, sheepFile);
|
||||
|
||||
ExcelUtil<SheepFile> util = new ExcelUtil<SheepFile>(SheepFile.class);
|
||||
// 使用若依框架的Excel工具类导出
|
||||
ExcelUtil<SheepFile> util = new ExcelUtil<>(SheepFile.class);
|
||||
util.exportExcel(response, list, "羊只档案数据");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 字符串转换工具方法
|
||||
*/
|
||||
private String convertToString(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return value.toString().trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取羊只档案详细信息
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,7 @@ public class SheepFile extends BaseEntity
|
||||
private String bsManageTags;
|
||||
|
||||
/** 牧场id */
|
||||
@Excel(name = "牧场id")
|
||||
// @Excel(name = "牧场id")
|
||||
private Long ranchId;
|
||||
|
||||
/** 牧场名称 */
|
||||
@@ -38,7 +38,7 @@ public class SheepFile extends BaseEntity
|
||||
private String drRanch;
|
||||
|
||||
/** 羊舍id */
|
||||
@Excel(name = "羊舍id")
|
||||
// @Excel(name = "羊舍id")
|
||||
private Long sheepfoldId;
|
||||
|
||||
/** 羊舍名称 */
|
||||
@@ -50,7 +50,7 @@ public class SheepFile extends BaseEntity
|
||||
private String electronicTags;
|
||||
|
||||
/** 品种id */
|
||||
@Excel(name = "品种id")
|
||||
// @Excel(name = "品种id")
|
||||
private Long varietyId;
|
||||
|
||||
/** 品种 */
|
||||
@@ -65,8 +65,12 @@ public class SheepFile extends BaseEntity
|
||||
@Excel(name = "羊只类型")
|
||||
private String name;
|
||||
|
||||
/** 性别 */
|
||||
@Excel(name = "性别")
|
||||
// /** 性别 */
|
||||
//// @Excel(name = "性别")
|
||||
// private Long gender;
|
||||
|
||||
/** 性别 - 使用字典转换 */
|
||||
@Excel(name = "性别", dictType = "sheep_gender") // 添加 dictType
|
||||
private Long gender;
|
||||
|
||||
/** 出生日期 */
|
||||
@@ -95,10 +99,11 @@ public class SheepFile extends BaseEntity
|
||||
@Excel(name = "断奶日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date weaningDate;
|
||||
|
||||
/** 羊只状态 */
|
||||
@Excel(name = "羊只状态")
|
||||
/** 羊只状态 - 使用字典转换 */
|
||||
@Excel(name = "羊只状态", dictType = "sheep_status")
|
||||
private Long statusId;
|
||||
|
||||
|
||||
/** 断奶体重 */
|
||||
@Excel(name = "断奶体重")
|
||||
private Double weaningWeight;
|
||||
@@ -117,7 +122,7 @@ public class SheepFile extends BaseEntity
|
||||
private Double weaningDailyGain;
|
||||
|
||||
/** 繁育状态id */
|
||||
@Excel(name = "繁育状态id")
|
||||
// @Excel(name = "繁育状态id")
|
||||
private Long breedStatusId;
|
||||
|
||||
/** 繁殖状态 */
|
||||
@@ -125,7 +130,7 @@ public class SheepFile extends BaseEntity
|
||||
private String breed;
|
||||
|
||||
/** 父号id */
|
||||
@Excel(name = "父号id")
|
||||
// @Excel(name = "父号id")
|
||||
private Long bsFatherId;
|
||||
|
||||
/** 父亲管理耳号 */
|
||||
@@ -133,7 +138,7 @@ public class SheepFile extends BaseEntity
|
||||
private String fatherManageTags;
|
||||
|
||||
/** 母号id */
|
||||
@Excel(name = "母号id")
|
||||
// @Excel(name = "母号id")
|
||||
private Long bsMotherId;
|
||||
|
||||
/** 母亲管理耳号 */
|
||||
@@ -141,7 +146,7 @@ public class SheepFile extends BaseEntity
|
||||
private String motherManageTags;
|
||||
|
||||
/** 受体id */
|
||||
@Excel(name = "受体id")
|
||||
// @Excel(name = "受体id")
|
||||
private Long receptorId;
|
||||
|
||||
/** 受体管理耳号 */
|
||||
@@ -149,7 +154,7 @@ public class SheepFile extends BaseEntity
|
||||
private String receptorManageTags;
|
||||
|
||||
/** 祖父号id */
|
||||
@Excel(name = "祖父号id")
|
||||
// @Excel(name = "祖父号id")
|
||||
private Long fatherFatherId;
|
||||
|
||||
/** 祖父管理耳号 */
|
||||
@@ -157,7 +162,7 @@ public class SheepFile extends BaseEntity
|
||||
private String grandfatherManageTags;
|
||||
|
||||
/** 祖母号id */
|
||||
@Excel(name = "祖母号id")
|
||||
// @Excel(name = "祖母号id")
|
||||
private Long fatherMotherId;
|
||||
|
||||
/** 祖母管理耳号 */
|
||||
@@ -165,7 +170,7 @@ public class SheepFile extends BaseEntity
|
||||
private String grandmotherManageTags;
|
||||
|
||||
/** 外祖父号id */
|
||||
@Excel(name = "外祖父号id")
|
||||
// @Excel(name = "外祖父号id")
|
||||
private Long fatherId;
|
||||
|
||||
/** 外祖父管理耳号 */
|
||||
@@ -173,7 +178,7 @@ public class SheepFile extends BaseEntity
|
||||
private String maternalGrandfatherManageTags;
|
||||
|
||||
/** 外祖母号id */
|
||||
@Excel(name = "外祖母号id")
|
||||
// @Excel(name = "外祖母号id")
|
||||
private Long motherId;
|
||||
|
||||
/** 外祖母管理耳号 */
|
||||
@@ -186,7 +191,7 @@ public class SheepFile extends BaseEntity
|
||||
private Date matingDate;
|
||||
|
||||
/** 配种类型 */
|
||||
@Excel(name = "配种类型")
|
||||
@Excel(name = "配种类型",dictType = "breed_type")
|
||||
private Long matingTypeId;
|
||||
|
||||
/** 孕检日期 */
|
||||
@@ -245,7 +250,7 @@ public class SheepFile extends BaseEntity
|
||||
private String comment;
|
||||
|
||||
/** 是否性控 */
|
||||
@Excel(name = "是否性控")
|
||||
@Excel(name = "是否性控",dictType = "controlled")
|
||||
private Long controlled;
|
||||
|
||||
/** 体况评分 */
|
||||
@@ -257,7 +262,7 @@ public class SheepFile extends BaseEntity
|
||||
private Long breast;
|
||||
|
||||
/** 入群来源 */
|
||||
@Excel(name = "入群来源")
|
||||
@Excel(name = "入群来源",dictType = "source")
|
||||
private String source;
|
||||
|
||||
/** 入群日期 */
|
||||
@@ -266,7 +271,7 @@ public class SheepFile extends BaseEntity
|
||||
private Date sourceDate;
|
||||
|
||||
/** 来源牧场id */
|
||||
@Excel(name = "来源牧场id")
|
||||
// @Excel(name = "来源牧场id")
|
||||
private Long sourceRanchId;
|
||||
|
||||
/** 来源牧场 */
|
||||
@@ -276,5 +281,25 @@ public class SheepFile extends BaseEntity
|
||||
/** 是否删除 */
|
||||
private Long isDelete;
|
||||
|
||||
/** 修改人 */
|
||||
@Excel(name = "修改人")
|
||||
private String updateBy;
|
||||
|
||||
|
||||
/** 修改日期 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "修改日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date updateTime;
|
||||
|
||||
/** 创建人 */
|
||||
@Excel(name = "创建人")
|
||||
private String createBy;
|
||||
|
||||
|
||||
/** 创建日期 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||
@Excel(name = "创建日期", width = 30, dateFormat = "yyyy-MM-dd")
|
||||
private Date createTime;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user