|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
package com.cjy.traceability.module.traceability.service.product; |
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.LocalDateTimeUtil; |
|
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.cjy.traceability.framework.common.pojo.PageResult; |
|
|
|
|
@ -10,6 +11,7 @@ import com.cjy.traceability.module.system.api.user.AdminUserApi; |
|
|
|
|
import com.cjy.traceability.module.traceability.controller.admin.product.vo.ProductCodePageRespVO; |
|
|
|
|
import com.cjy.traceability.module.traceability.controller.admin.product.vo.ProductPageReqVO; |
|
|
|
|
import com.cjy.traceability.module.traceability.controller.admin.product.vo.ProductSaveReqVO; |
|
|
|
|
import com.cjy.traceability.module.traceability.controller.admin.product.vo.ScanProductVO; |
|
|
|
|
import com.cjy.traceability.module.traceability.dal.dataobject.company.CompanyDO; |
|
|
|
|
import com.cjy.traceability.module.traceability.dal.dataobject.materials.MaterialsDO; |
|
|
|
|
import com.cjy.traceability.module.traceability.dal.dataobject.product.ProductDO; |
|
|
|
|
@ -194,33 +196,38 @@ public class ProductServiceImpl implements ProductService { |
|
|
|
|
@Override |
|
|
|
|
public Map<String, Object> scanTheCode(String traceabilityCode, String province, String city, String country) { |
|
|
|
|
Map<String, Object> map = new HashMap<>(5); |
|
|
|
|
//1.产品基本信息
|
|
|
|
|
Map<String, Object> productMap = productMapper.selectProduct(traceabilityCode); |
|
|
|
|
if (null == productMap) { |
|
|
|
|
return new HashMap<>(); |
|
|
|
|
/*产品基本信息*/ |
|
|
|
|
ScanProductVO scanProductVO = productMapper.selectScanProduct(traceabilityCode); |
|
|
|
|
if(scanProductVO == null){ |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
productMap.put("authenticationType", dictDataApi.getDictData("authentication_type", productMap.get("authenticationType").toString()).getLabel()); |
|
|
|
|
productMap.put("qualityResult", dictDataApi.getDictData("quality_result", productMap.get("qualityResult").toString()).getLabel()); |
|
|
|
|
map.put("basicInformation", productMap); |
|
|
|
|
//2.产品加工
|
|
|
|
|
Map<String, Object> machiningRecord = productMapper.selectProductProcessing(Integer.parseInt(productMap.get("id").toString())); |
|
|
|
|
List<Map<String, Object>> rawMaterials = materialsMapper.selectMaterialsByProductId(productMap.get("id").toString()); |
|
|
|
|
scanProductVO.setAuthenticationType(dictDataApi.getDictData("authentication_type", scanProductVO.getAuthenticationType()).getLabel()); |
|
|
|
|
scanProductVO.setQualityResult(dictDataApi.getDictData("quality_result", scanProductVO.getQualityResult()).getLabel()); |
|
|
|
|
map.put("basicInformation", scanProductVO); |
|
|
|
|
/*产品加工记录*/ |
|
|
|
|
Map<String, Object> machiningRecord = productMapper.selectProductProcessing(scanProductVO.getId()); |
|
|
|
|
List<Map<String, Object>> rawMaterials = materialsMapper.selectMaterialsByProductId(scanProductVO.getId()+""); |
|
|
|
|
machiningRecord.put("rawMaterials", rawMaterials); |
|
|
|
|
map.put("machiningRecord", machiningRecord); |
|
|
|
|
//3. 产品配送
|
|
|
|
|
List<Map<String, Object>> deliveryRecord = deliveryRecordMapper.selectProductDeliveryRecord(Integer.parseInt(productMap.get("id").toString())); |
|
|
|
|
/*产品配送*/ |
|
|
|
|
List<Map<String, Object>> deliveryRecord = deliveryRecordMapper.selectProductDeliveryRecord(scanProductVO.getId()); |
|
|
|
|
map.put("deliveryRecord", deliveryRecord); |
|
|
|
|
//4. 产品销售
|
|
|
|
|
List<Map<String, Object>> saleRecordList = saleRecordMapper.selectProductSaleRecord(Integer.parseInt(productMap.get("id").toString())); |
|
|
|
|
/*产品销售*/ |
|
|
|
|
List<Map<String, Object>> saleRecordList = saleRecordMapper.selectProductSaleRecord(scanProductVO.getId()); |
|
|
|
|
saleRecordList.stream().forEach(item ->{ |
|
|
|
|
if(null != item.get("salesType")){ |
|
|
|
|
item.put("salesType",dictDataApi.getDictData("sales_type",item.get("salesType")+"").getLabel()); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
map.put("saleRecord", saleRecordList); |
|
|
|
|
//5. 产品农业
|
|
|
|
|
if ( 1==Integer.parseInt(productMap.get("sourceType").toString())) { |
|
|
|
|
/*农产品记录*/ |
|
|
|
|
if(1 == scanProductVO.getSourceType()){ |
|
|
|
|
Map<String, Object> cropperAgriculture = new HashMap<>(1); |
|
|
|
|
List<Map<String, Object>> agriculture = husbandryRecordService.getHusbandryRecordListByBatch(Integer.parseInt(productMap.get("cropperId").toString()), Integer.parseInt(productMap.get("batch").toString())); |
|
|
|
|
cropperAgriculture.put("cropperName", productMap.get("processingName").toString()); |
|
|
|
|
List<Map<String, Object>> agriculture = husbandryRecordService.getHusbandryRecordListByBatch(scanProductVO.getCropperId(),scanProductVO.getBatch()); |
|
|
|
|
cropperAgriculture.put("cropperName", scanProductVO.getProcessingName()); |
|
|
|
|
cropperAgriculture.put("agriculture", agriculture); |
|
|
|
|
map.put("agricultureRecord", cropperAgriculture); |
|
|
|
|
} else { |
|
|
|
|
}else{ |
|
|
|
|
List<Map<String, Object>> agricultureRecord = new ArrayList<>(); |
|
|
|
|
for (Map<String, Object> rawMaterial : rawMaterials) { |
|
|
|
|
//TODO: 奇怪的数据逻辑 二级加工产品生成原料表cropper_id(农作物id)存的是溯源产品id
|
|
|
|
|
@ -233,12 +240,12 @@ public class ProductServiceImpl implements ProductService { |
|
|
|
|
} |
|
|
|
|
map.put("agricultureRecord", agricultureRecord); |
|
|
|
|
} |
|
|
|
|
/*作物地块信息*/ |
|
|
|
|
List<Map<String, Object>> materialList = new ArrayList<>(); |
|
|
|
|
// 获取地块 基地信息
|
|
|
|
|
if ( 1== Integer.parseInt(productMap.get("sourceType").toString())) { |
|
|
|
|
List<Map<String, Object>> baseBlockList = blockMapper.selectBaseBlock(productMap.get("cropperId").toString()); |
|
|
|
|
if ( 1== scanProductVO.getSourceType()) { |
|
|
|
|
List<Map<String, Object>> baseBlockList = blockMapper.selectBaseBlock(scanProductVO.getCropperId()+""); |
|
|
|
|
Map<String, Object> baseBlockMap = new HashMap<>(1); |
|
|
|
|
baseBlockMap.put("cropperName", productMap.get("processingName").toString()); |
|
|
|
|
baseBlockMap.put("cropperName", scanProductVO.getProcessingName()); |
|
|
|
|
baseBlockMap.put("baseBlockList", baseBlockList); |
|
|
|
|
materialList.add(baseBlockMap); |
|
|
|
|
} else { |
|
|
|
|
@ -253,20 +260,20 @@ public class ProductServiceImpl implements ProductService { |
|
|
|
|
} |
|
|
|
|
map.put("baseBlock", materialList); |
|
|
|
|
List<CompanyDO> companyList = companyMapper.selectList(); |
|
|
|
|
if(companyList !=null && companyList.size() >0){ |
|
|
|
|
map.put("company",companyList.get(0)); |
|
|
|
|
}else{ |
|
|
|
|
map.put("company",new CompanyDO()); |
|
|
|
|
} |
|
|
|
|
if(companyList !=null && companyList.size() >0){ |
|
|
|
|
map.put("company",companyList.get(0)); |
|
|
|
|
}else{ |
|
|
|
|
map.put("company",new CompanyDO()); |
|
|
|
|
} |
|
|
|
|
ScanRecordDO scanRecordDO = new ScanRecordDO(); |
|
|
|
|
scanRecordDO.setProvince(province); |
|
|
|
|
scanRecordDO.setCity(city); |
|
|
|
|
scanRecordDO.setCountry(country); |
|
|
|
|
scanRecordDO.setCreator("访客"); |
|
|
|
|
scanRecordDO.setUpdater("访客"); |
|
|
|
|
scanRecordDO.setProductId(Integer.parseInt(productMap.get("id").toString())); |
|
|
|
|
scanRecordDO.setProductId(scanProductVO.getId()); |
|
|
|
|
scanRecordMapper.insert(scanRecordDO); |
|
|
|
|
return map; |
|
|
|
|
return map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|