Merge remote-tracking branch 'origin/main'

main
862857010@qq.com 2 years ago
commit 139e8ae45a
  1. 14
      cjy-module-system/cjy-module-system-biz/src/main/java/com/cjy/traceability/module/system/controller/admin/auth/AuthController.java
  2. 3
      cjy-module-system/cjy-module-system-biz/src/main/java/com/cjy/traceability/module/system/controller/admin/auth/vo/ResetPwdReqVO.java
  3. 2
      cjy-module-system/cjy-module-system-biz/src/main/java/com/cjy/traceability/module/system/service/auth/AdminAuthServiceImpl.java
  4. 72
      cjy-module-traceability/cjy-module-traceability-biz/src/main/java/com/cjy/traceability/module/traceability/controller/admin/product/vo/ScanProductVO.java
  5. 2
      cjy-module-traceability/cjy-module-traceability-biz/src/main/java/com/cjy/traceability/module/traceability/dal/mysql/block/BlockMapper.java
  6. 1
      cjy-module-traceability/cjy-module-traceability-biz/src/main/java/com/cjy/traceability/module/traceability/dal/mysql/product/ProductMapper.java
  7. 67
      cjy-module-traceability/cjy-module-traceability-biz/src/main/java/com/cjy/traceability/module/traceability/service/product/ProductServiceImpl.java
  8. 39
      cjy-module-traceability/cjy-module-traceability-biz/src/main/resources/mapper/product/ProductMapper.xml

@ -195,11 +195,11 @@ public class AuthController {
@PermitAll
@Operation(summary = "忘记密码-验证邮箱验证码", description = "适合未登录的用户,已忘记密码账户")
public CommonResult<Boolean> checkRandomCode(@RequestParam("username") String userName,@RequestParam("captchaVerification") String captchaVerification){
String verification = stringRedisTemplate.opsForValue().get(captchaVerification);
String verification = stringRedisTemplate.opsForValue().get(userName);
if(StrUtil.isBlank(verification)){
return error(505,"请获取邮箱验证码!");
}
if(!verification.equals(userName)){
if(!verification.equals(captchaVerification)){
return error(505,"验证码错误,请检查!");
}else{
return success(true);
@ -218,21 +218,25 @@ public class AuthController {
@Operation(summary = "忘记密码-重置密码", description = "适合未登录的用户,已忘记密码账户")
@OperateLog(enable = false) // 避免 Post 请求被记录操作日志
public CommonResult<String> resetPassword(@RequestBody @Valid ResetPwdReqVO reqVO) throws Exception {
String verification = stringRedisTemplate.opsForValue().get(reqVO.getCaptchaVerification());
String verification = stringRedisTemplate.opsForValue().get(reqVO.getUsername());
if(StrUtil.isBlank(verification)){
ErrorCode errorCode = new ErrorCode(505,"验证码过期");
return error(errorCode);
}
if(!verification.equals(reqVO.getCaptchaVerification())){
return error(505,"验证码错误,请检查!");
}
//修改密码
AdminUserDO user = userService.getUserByUsername(verification);
AdminUserDO user = userService.getUserByUsername(reqVO.getUsername());
if (user.getStatus().equals(CommonStatusEnum.DISABLE)) {
ErrorCode errorCode = new ErrorCode(505,"该账号已停用");
return error(errorCode);
}
String plainText = CryptoUtils.decryptByRSA(CryptoUtils.PRIVATE_KEY, reqVO.getPassword());
userService.updateUserPassword(user.getId(),plainText);
//踢出该账号登录信息
//密码重置完成废弃验证码
stringRedisTemplate.delete(reqVO.getCaptchaVerification());
return success("重置成功");
}
}

@ -21,8 +21,7 @@ public class ResetPwdReqVO {
// @Length(min = 4, max = 16, message = "账号长度为 4-16 位")
// @Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母")
private String password;
private String username;
// ========== 图片验证码相关 ==========
@Schema(description = "验证码,验证码开启时,需要传递", requiredMode = Schema.RequiredMode.REQUIRED,

@ -252,7 +252,7 @@ public class AdminAuthServiceImpl implements AdminAuthService {
// 发送邮箱验证码
mailSendApi.sendSingleMailToAdmin(userReqDTO);
stringRedisTemplate.opsForValue().set(randomCode,user.getUsername(),10,TimeUnit.MINUTES);
stringRedisTemplate.opsForValue().set(user.getUsername(),randomCode,10,TimeUnit.MINUTES);
String email = StrUtil.hide(user.getEmail(),3,6);
return CommonResult.success("验证码已发送到"+email+"邮箱,请注意查收!");
}

@ -0,0 +1,72 @@
package com.cjy.traceability.module.traceability.controller.admin.product.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;
/**
* app扫码获取产品信息
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ScanProductVO {
/**
* 产品名称
*/
private String processingName;
/**
* 生产数量
*/
private Integer processingProduction;
/**
* 生产时间
*/
private LocalDateTime processingTime;
/**
* 溯源码
*/
private String traceabilityCode;
/**
* 认证类型
*/
private String authenticationType;
/**
* 质检结论
*/
private String qualityResult;
/**
* 产品来源 1自产 2加工
*/
private Integer sourceType;
/**
* 农作物id
*/
private Integer cropperId;
/**
* 产品批次
*/
private Integer productBreed;
/**
* 产品图片
*/
private String productPic;
/**
* 品种名称
*/
private String speciesName;
/**
* 种类名称
*/
private String varietyName;
/**
* 批次
*/
private Integer batch;
private Integer id;
}

@ -48,7 +48,7 @@ public interface BlockMapper extends BaseMapperX<BlockDO> {
.selectAs(BlockDO :: getBlockColor,"blockColor")
.selectAs(BlockDO :: getPositionStr,"positionStr")
.selectAs(TraceabilityBaseDO :: getBaseName,"baseName")
.leftJoin(TraceabilityBaseDO.class,TraceabilityBaseDO::getBaseName,BlockDO :: getBaseId)
.leftJoin(TraceabilityBaseDO.class,TraceabilityBaseDO:: getId,BlockDO :: getBaseId)
.leftJoin(CropperDO.class,CropperDO ::getBlockId,BlockDO :: getId)
.eq(CropperDO :: getId, cropperId)
);

@ -177,4 +177,5 @@ public interface ProductMapper extends BaseMapperX<ProductDO> {
}
ProductDO selectById2(@Param("id") Integer productId);
ScanProductVO selectScanProduct(@Param("traceabilityCode") String traceabilityCode);
}

@ -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

@ -1,6 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.cjy.traceability.module.traceability.dal.mysql.product.ProductMapper">
<resultMap id="ScanPro" type="com.cjy.traceability.module.traceability.controller.admin.product.vo.ScanProductVO">
<result column="processing_name" property="processingName"/>
<result column="processing_production" property="processingProduction"/>
<result column="processing_time" property="processingTime"/>
<result column="traceability_code" property="traceabilityCode"/>
<result column="authentication_type" property="authenticationType"/>
<result column="quality_inspection" property="qualityResult"/>
<result column="source_type" property="sourceType"/>
<result column="cropper_id" property="cropperId"/>
<result column="id" property="id"/>
<result column="batch" property="batch"/>
<result column="product_pic" property="productPic"/>
<result column="species_name" property="speciesName"/>
<result column="variety_name" property="varietyName"/>
</resultMap>
<update id="updateInStock">
update traceability_product set inventory_production=#{inventoryProduction} where id=#{id}
</update>
@ -136,4 +153,26 @@
from traceability_product
where id=#{id}
</select>
<select id="selectScanProduct"
resultMap="ScanPro">
select t1.processing_name,
t1.processing_production,
t1.processing_time,
t1.traceability_code,
t1.authentication_type,
t1.quality_inspection,
t1.source_type,
t1.cropper_id,
t1.batch,
t1.id,
t4.species_name,t5.variety_name,t3.product_pic
from traceability_product t1
left join traceability_cropper t2 on t2.id = t1.cropper_id
left join traceability_agricultural_product t3 on t3.id =t2.product_id
left join traceability_species t4 on t4.id = t2.species_id
left join traceability_variety t5 on t5.id = t3.product_variety
where t1.traceability_code = #{traceabilityCode}
</select>
</mapper>
Loading…
Cancel
Save