| | |
| | | package org.springblade.modules.traceability.service.impl; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.zxing.WriterException; |
| | | import org.springblade.common.config.TraceabilityCodeConfig; |
| | | import org.springblade.common.utils.QRCodeUtil; |
| | | import org.springblade.modules.farm.entity.Farm; |
| | | import org.springblade.modules.farm.entity.FarmPaper; |
| | | import org.springblade.modules.farm.entity.FarmingRecord; |
| | | import org.springblade.modules.farm.service.FarmPaperService; |
| | | import org.springblade.modules.farm.service.FarmService; |
| | | import org.springblade.modules.farm.service.FarmingRecordService; |
| | | import org.springblade.modules.farm.vo.FarmPaperVO; |
| | | import org.springblade.modules.farm.vo.FarmVO; |
| | | import org.springblade.modules.farm.vo.FarmingRecordVO; |
| | | import org.springblade.modules.lang.entity.Land; |
| | | import org.springblade.modules.lang.service.ILandService; |
| | | import org.springblade.modules.lang.vo.LandVO; |
| | | import org.springblade.modules.recovery.service.RecoveryService; |
| | | import org.springblade.modules.recovery.vo.RecoveryVO; |
| | | import org.springblade.modules.traceability.dto.TraceabilityDTO; |
| | | import org.springblade.modules.traceability.dto.TraceabilityDetailDTO; |
| | | import org.springblade.modules.traceability.entity.SweepRecord; |
| | | import org.springblade.modules.traceability.entity.Traceability; |
| | | import org.springblade.modules.traceability.mapper.TraceabilityMapper; |
| | | import org.springblade.modules.traceability.service.SweepRecordService; |
| | | import org.springblade.modules.traceability.service.TraceabilityService; |
| | | import org.springblade.modules.traceability.vo.TraceabilityVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | | import javax.sound.midi.Receiver; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Service |
| | | public class TraceabilityServiceImpl extends ServiceImpl<TraceabilityMapper, Traceability> implements TraceabilityService { |
| | | |
| | | @Autowired |
| | | private RecoveryService recoveryService; |
| | | |
| | | @Autowired |
| | | private FarmingRecordService farmingRecordService; |
| | | |
| | | @Autowired |
| | | private FarmService farmService; |
| | | |
| | | @Autowired |
| | | private FarmPaperService farmPaperService; |
| | | |
| | | @Autowired |
| | | private ILandService landService; |
| | | |
| | | @Autowired |
| | | private SweepRecordService sweepRecordService; |
| | | |
| | | /** |
| | | * 自定义分页 |
| | |
| | | public IPage<TraceabilityVO> selectTraceabilityPage(IPage<TraceabilityVO> page, TraceabilityVO traceability) { |
| | | return page.setRecords(baseMapper.selectTraceabilityPage(page, traceability)); |
| | | } |
| | | |
| | | @Override |
| | | public String selectRevorid(String code) { |
| | | return baseMapper.selectRevorid(code); |
| | | } |
| | | |
| | | /** |
| | | * 获取溯源简介信息 |
| | | * @param traceability |
| | | * @return |
| | | */ |
| | | @Override |
| | | public TraceabilityDTO getSimpleInfo(Traceability traceability) { |
| | | TraceabilityDTO simpleInfo = baseMapper.getSimpleInfo(traceability); |
| | | simpleInfo.setCode(traceability.getCode()); |
| | | //获取二维码信息 |
| | | String url = TraceabilityCodeConfig.getCodeUrl(); |
| | | String encoded = null; |
| | | try { |
| | | encoded = URLEncoder.encode(traceability.getCode(),"UTF-8"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String content = url + "?code=" + encoded; |
| | | byte[] qrCodeImage = new byte[0]; |
| | | try { |
| | | qrCodeImage = QRCodeUtil.getQRCodeImage(content, 350, 350); |
| | | } catch (WriterException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | String encode = new BASE64Encoder().encode(qrCodeImage); |
| | | simpleInfo.setQrcode("data:image/png;base64,"+encode); |
| | | //返回 |
| | | return simpleInfo; |
| | | } |
| | | |
| | | /** |
| | | * 获取溯源详情信息(包含农产品信息,认证检测信息,产地(地块信息),农事记录,企业信息) |
| | | * @param traceability |
| | | * @return |
| | | */ |
| | | @Override |
| | | public TraceabilityDetailDTO getTraceabilityDetailInfo(Traceability traceability) { |
| | | |
| | | TraceabilityDetailDTO dto = new TraceabilityDetailDTO(); |
| | | int count = 0; |
| | | //根据溯源码编号查询溯源信息 |
| | | Traceability traceability1 = baseMapper.selectOne(new QueryWrapper<>(traceability)); |
| | | //记录扫描记录 |
| | | if (null!=traceability.getBind() && traceability.equals("1")){ |
| | | //插入扫描记录 |
| | | SweepRecord sweepRecord = new SweepRecord(); |
| | | sweepRecord.setCreateTime(new Date()); |
| | | sweepRecord.setCode(traceability.getId().toString()); |
| | | sweepRecord.setDeptId(traceability1.getDeptId()); |
| | | //新增 |
| | | sweepRecordService.save(sweepRecord); |
| | | } |
| | | //1. 查询农产品采收记录信息 |
| | | RecoveryVO recoveryVO = recoveryService.getRecoveryDetail(traceability1.getRecoveryId()); |
| | | //2. 查询相关检测信息 |
| | | List<FarmPaperVO> farmPaperList = farmPaperService.getFarmPaperList(traceability1.getDeptId()); |
| | | //3. 查询产地(地块)信息 |
| | | LandVO land = new LandVO(); |
| | | land.setId(Long.parseLong(recoveryVO.getLandId())); |
| | | LandVO landInfo = (LandVO)landService.getLandInfo(land); |
| | | //4. 查询农事记录信息(种植开始起) |
| | | List<FarmingRecordVO> farmingRecordVOList = farmingRecordService.getFarmingRecordByFarmPlantId(recoveryVO); |
| | | //5. 查询企业信息 |
| | | Farm farm = new Farm(); |
| | | farm.setDeptId(traceability1.getDeptId()); |
| | | Farm farmVO = farmService.getOne(new QueryWrapper<>(farm)); |
| | | //6. 数据封装 |
| | | dto.setRecoveryVO(recoveryVO); |
| | | dto.setFarm(farmVO); |
| | | dto.setRecordVOList(farmingRecordVOList); |
| | | dto.setPaperVOList(farmPaperList); |
| | | dto.setLandVO(landInfo); |
| | | //计算百分比 |
| | | if (null!=recoveryVO){ |
| | | count = count + 20; |
| | | } |
| | | if (null!=farmVO){ |
| | | count = count + 20; |
| | | } |
| | | if (null==landInfo){ |
| | | count = count + 20; |
| | | } |
| | | if (farmingRecordVOList.size()>0){ |
| | | count = count + 20; |
| | | } |
| | | if (farmPaperList.size()>0){ |
| | | count = count + 20; |
| | | } |
| | | dto.setNum(count); |
| | | //返回数据 |
| | | return dto; |
| | | } |
| | | |
| | | /** |
| | | * 自定义查询,不分页 |
| | | * @param traceability |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<TraceabilityVO> getTraceabilityList(TraceabilityVO traceability) { |
| | | return baseMapper.getTraceabilityList(traceability); |
| | | } |
| | | } |