班次奶量和羊奶出入库bug修改
This commit is contained in:
@@ -4,6 +4,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.enums.BusinessType;
|
||||
import com.zhyc.module.dairyProducts.domain.NpMilkInOutStore; // 引入实体类
|
||||
import com.zhyc.module.dairyProducts.service.INpMilkInOutStoreService;
|
||||
import com.zhyc.common.utils.poi.ExcelUtil;
|
||||
import com.zhyc.common.core.page.TableDataInfo;
|
||||
@@ -32,7 +33,16 @@ public class NpMilkInOutStoreController extends BaseController {
|
||||
@RequestParam(required=false) Date datetimeEnd
|
||||
) {
|
||||
startPage();
|
||||
List<Map<String, Object>> rows = service.selectWithDynamicColumns(datetimeStart, datetimeEnd);
|
||||
// 修改:封装查询参数到实体对象,以便利用 BaseEntity 的 params 属性传递数据权限
|
||||
NpMilkInOutStore query = new NpMilkInOutStore();
|
||||
if (datetimeStart != null) {
|
||||
query.getParams().put("beginTime", datetimeStart);
|
||||
}
|
||||
if (datetimeEnd != null) {
|
||||
query.getParams().put("endTime", datetimeEnd);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> rows = service.selectWithDynamicColumns(query);
|
||||
return getDataTable(rows);
|
||||
}
|
||||
|
||||
@@ -45,6 +55,7 @@ public class NpMilkInOutStoreController extends BaseController {
|
||||
service.batchInsertFromRows(list);
|
||||
return AjaxResult.success("导入成功");
|
||||
}
|
||||
|
||||
/** 导出 Excel */
|
||||
@PreAuthorize("@ss.hasPermi('milkInOutStore:export')")
|
||||
@Log(title="导出羊奶出入库", businessType=BusinessType.EXPORT)
|
||||
@@ -53,10 +64,20 @@ public class NpMilkInOutStoreController extends BaseController {
|
||||
@RequestParam(required=false) Date datetimeStart,
|
||||
@RequestParam(required=false) Date datetimeEnd
|
||||
) {
|
||||
List<Map<String,Object>> rows = service.selectWithDynamicColumns(datetimeStart, datetimeEnd);
|
||||
// 修改:封装查询参数到实体对象
|
||||
NpMilkInOutStore query = new NpMilkInOutStore();
|
||||
if (datetimeStart != null) {
|
||||
query.getParams().put("beginTime", datetimeStart);
|
||||
}
|
||||
if (datetimeEnd != null) {
|
||||
query.getParams().put("endTime", datetimeEnd);
|
||||
}
|
||||
|
||||
List<Map<String,Object>> rows = service.selectWithDynamicColumns(query);
|
||||
// 解决方案:强制转换并压制警告
|
||||
@SuppressWarnings("unchecked")
|
||||
ExcelUtil<Map<String,Object>> util = new ExcelUtil<>((Class<Map<String,Object>>) (Class<?>) Map.class);
|
||||
util.exportExcel(response, rows, "羊奶出入库数据");
|
||||
}
|
||||
|
||||
/** 获取可选列定义(饲喂来源 + 销售去向) */
|
||||
@@ -66,4 +87,3 @@ public class NpMilkInOutStoreController extends BaseController {
|
||||
return AjaxResult.success(service.getAllColumnOptions());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,20 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.zhyc.common.annotation.Excel;
|
||||
import com.zhyc.common.core.domain.BaseEntity;
|
||||
|
||||
public class NpMilkProdClasses implements Serializable {
|
||||
/**
|
||||
* 班次奶量对象 np_milk_prod_classes
|
||||
* * 修改说明:继承 BaseEntity 以支持数据权限(params.dataScope)
|
||||
*/
|
||||
public class NpMilkProdClasses extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Long id;
|
||||
|
||||
// 注意:BaseEntity 中通常已包含 createTime 和 updateTime。
|
||||
// 如果父类已有,此处保留会发生字段遮蔽(Shadowing),但能保证代码兼容性。
|
||||
// 为了修复 params 报错,保留原样即可,核心是 extends BaseEntity。
|
||||
private Date createTime;
|
||||
private Date updateTime;
|
||||
|
||||
|
||||
@@ -3,16 +3,16 @@ package com.zhyc.module.dairyProducts.mapper;
|
||||
import com.zhyc.module.dairyProducts.domain.NpMilkInOutStore;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface NpMilkInOutStoreMapper {
|
||||
/**
|
||||
* 动态列查询
|
||||
* 修改:使用 @Param("queryParams") 传递实体,包含 params.dataScope
|
||||
*/
|
||||
List<Map<String,Object>> selectWithColumns(
|
||||
@Param("start") Date start, @Param("end") Date end,
|
||||
@Param("queryParams") NpMilkInOutStore queryParams,
|
||||
@Param("feedSources") List<String> feedSources,
|
||||
@Param("saleDestinations") List<String> saleDestinations
|
||||
);
|
||||
@@ -23,7 +23,7 @@ public interface NpMilkInOutStoreMapper {
|
||||
int insertStore(NpMilkInOutStore store);
|
||||
|
||||
/**
|
||||
* 插入饲喂子表(已修正:增加 userId 和 deptId 参数)
|
||||
* 插入饲喂子表
|
||||
*/
|
||||
void insertFeedRecord(
|
||||
@Param("storeId") Integer storeId,
|
||||
@@ -34,7 +34,7 @@ public interface NpMilkInOutStoreMapper {
|
||||
);
|
||||
|
||||
/**
|
||||
* 插入销售子表(已修正:增加 userId 和 deptId 参数)
|
||||
* 插入销售子表
|
||||
*/
|
||||
void insertSaleRecord(
|
||||
@Param("storeId") Integer storeId,
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.zhyc.module.dairyProducts.service;
|
||||
|
||||
import com.zhyc.module.dairyProducts.domain.NpMilkInOutStore; // 引入实体
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface INpMilkInOutStoreService {
|
||||
List<Map<String,Object>> selectWithDynamicColumns(Date start, Date end);
|
||||
// 修改参数为实体对象
|
||||
List<Map<String,Object>> selectWithDynamicColumns(NpMilkInOutStore query);
|
||||
|
||||
List<Map<String,Object>> getAllColumnOptions();
|
||||
List<Map<String,Object>> parseImportExcel(MultipartFile file) throws Exception;
|
||||
void batchInsertFromRows(List<Map<String,Object>> rows) throws Exception;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,11 +21,12 @@ public class NpMilkInOutStoreServiceImpl implements INpMilkInOutStoreService {
|
||||
private NpMilkInOutStoreMapper mapper;
|
||||
|
||||
@Override
|
||||
@DataScope(deptAlias = "s", userAlias = "s")
|
||||
public List<Map<String, Object>> selectWithDynamicColumns(Date start, Date end) {
|
||||
@DataScope(deptAlias = "s", userAlias = "s") // 启用数据权限注解
|
||||
public List<Map<String, Object>> selectWithDynamicColumns(NpMilkInOutStore query) {
|
||||
List<String> feed = mapper.selectFeedSources();
|
||||
List<String> sale = mapper.selectSaleDestinations();
|
||||
return mapper.selectWithColumns(start, end, feed, sale);
|
||||
// 将实体对象传递给 Mapper
|
||||
return mapper.selectWithColumns(query, feed, sale);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,6 +36,7 @@ public class NpMilkInOutStoreServiceImpl implements INpMilkInOutStoreService {
|
||||
m.put("sale", mapper.selectSaleDestinations());
|
||||
return Collections.singletonList(m);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> parseImportExcel(MultipartFile file) throws Exception {
|
||||
// 用 Apache POI 解析 Excel 第一行标题,动态映射列名跟 unit cells
|
||||
@@ -61,10 +63,8 @@ public class NpMilkInOutStoreServiceImpl implements INpMilkInOutStoreService {
|
||||
|
||||
@Override
|
||||
public void batchInsertFromRows(List<Map<String, Object>> rows) throws Exception {
|
||||
// === 修改开始:获取当前用户和部门ID ===
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
Long deptId = SecurityUtils.getDeptId();
|
||||
// === 修改结束 ===
|
||||
|
||||
for (Map<String,Object> row : rows) {
|
||||
// 提取主表字段
|
||||
@@ -76,10 +76,8 @@ public class NpMilkInOutStoreServiceImpl implements INpMilkInOutStoreService {
|
||||
// 手动填充其它主表字段,这里省略了具体的 get 调用,请根据您的 Excel 列名自行补充
|
||||
// store.setColostSheep(...);
|
||||
|
||||
// === 修改开始:给主表实体注入用户和部门ID ===
|
||||
store.setUserId(userId);
|
||||
store.setDeptId(deptId);
|
||||
// === 修改结束 ===
|
||||
|
||||
mapper.insertStore(store);
|
||||
Integer sid = store.getId();
|
||||
@@ -94,10 +92,8 @@ public class NpMilkInOutStoreServiceImpl implements INpMilkInOutStoreService {
|
||||
BigDecimal amt = new BigDecimal(ent.getValue().toString());
|
||||
|
||||
if (mapper.selectFeedSources().contains(col)) {
|
||||
// === 修改开始:插入饲喂子表时传入 userId 和 deptId ===
|
||||
mapper.insertFeedRecord(sid, col, amt, userId, deptId);
|
||||
} else if (mapper.selectSaleDestinations().contains(col)) {
|
||||
// === 修改开始:插入销售子表时传入 userId 和 deptId ===
|
||||
mapper.insertSaleRecord(sid, col, amt, userId, deptId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,10 +18,14 @@
|
||||
LEFT JOIN np_milk_feed_records fr ON fr.store_id = s.id
|
||||
LEFT JOIN np_milk_sale_records sr ON sr.store_id = s.id
|
||||
<where>
|
||||
<if test="start != null"> s.datetime >= #{start}</if>
|
||||
<if test="end != null"> AND s.datetime <= #{end}</if>
|
||||
<if test="queryParams.params.beginTime != null and queryParams.params.beginTime != ''">
|
||||
AND s.datetime >= #{queryParams.params.beginTime}
|
||||
</if>
|
||||
<if test="queryParams.params.endTime != null and queryParams.params.endTime != ''">
|
||||
AND s.datetime <= #{queryParams.params.endTime}
|
||||
</if>
|
||||
|
||||
${params.dataScope}
|
||||
${queryParams.params.dataScope}
|
||||
</where>
|
||||
GROUP BY s.id
|
||||
ORDER BY s.datetime
|
||||
|
||||
Reference in New Issue
Block a user