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