101captain
2021-10-14 9bee54a71a0121009969ecc55b2839c4f32887df
Merge branch 'test_warehouse' of http://gitlab.nhys.cdnhxx.com/root/zhihuishequ into test_warehouse
7个文件已修改
1个文件已添加
208 ■■■■ 已修改文件
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/WarehouseDonatesExcelListen.java 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/dtos/community/warehouse/ComActWarehouseApplyDTO.java 54 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActWarehouseDonatesApi.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/ComActWarehouseDonatesApi.java 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActWarehouseDonatesService.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActWarehouseDonatesServiceImpl.java 61 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/resources/mapper/ComActWarehouseDonatesMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/listen/WarehouseDonatesExcelListen.java
@@ -1,8 +1,10 @@
package com.panzhihua.common.listen;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.alibaba.excel.context.AnalysisContext;
@@ -39,26 +41,33 @@
    @Override
    public void invoke(WarehouseDonatesExcelVO warehouseDonatesExcelVO, AnalysisContext analysisContext) {
        if (StringUtils.isEmpty(warehouseDonatesExcelVO.getItem())) {
            throw new ServiceException("捐赠物品名称不可为空");
        }
        Integer quantity = warehouseDonatesExcelVO.getQuantity();
        if (isNull(quantity) || quantity <= 0) {
            throw new ServiceException("捐赠数量有误");
        }
        if (StringUtils.isEmpty(warehouseDonatesExcelVO.getName())) {
            warehouseDonatesExcelVO.setIsAnonymous("是");
        }
        warehouseDonatesExcelVO.setCommunityId(this.communityId);
        warehouseDonatesExcelVO.setStatus(2);
        warehouseDonatesExcelVO.setSurplusQuantity(quantity);
        warehouseDonatesExcelVO.setRegisterBy(this.registerBy);
        warehouseDonatesExcelVO.setSigningBy(this.registerBy);
        list.add(warehouseDonatesExcelVO);
        // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
        if (list.size() >= BATCH_COUNT) {
            doAfterAllAnalysed(analysisContext);
            list.clear();
        if (!StringUtils.isEmpty(warehouseDonatesExcelVO.getItem()) && nonNull(quantity)) {
            if (quantity <= 0) {
                throw new ServiceException("捐赠数量有误");
            }
            if (StringUtils.isEmpty(warehouseDonatesExcelVO.getName())
                    || isNull(warehouseDonatesExcelVO.getIsAnonymous())) {
                warehouseDonatesExcelVO.setIsAnonymous("是");
            }
            if (isNull(warehouseDonatesExcelVO.getSigningAt())) {
                Date nowDate = new Date();
                warehouseDonatesExcelVO.setSigningAt(nowDate);
                warehouseDonatesExcelVO.setRegisterAt(nowDate);
            } else {
                warehouseDonatesExcelVO.setRegisterAt(warehouseDonatesExcelVO.getSigningAt());
            }
            warehouseDonatesExcelVO.setCommunityId(this.communityId);
            warehouseDonatesExcelVO.setStatus(2);
            warehouseDonatesExcelVO.setSurplusQuantity(quantity);
            warehouseDonatesExcelVO.setRegisterBy(this.registerBy);
            warehouseDonatesExcelVO.setSigningBy(this.registerBy);
            list.add(warehouseDonatesExcelVO);
            // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
            if (list.size() >= BATCH_COUNT) {
                doAfterAllAnalysed(analysisContext);
                list.clear();
            }
        }
    }
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/model/dtos/community/warehouse/ComActWarehouseApplyDTO.java
New file
@@ -0,0 +1,54 @@
package com.panzhihua.common.model.dtos.community.warehouse;
import java.util.List;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
import org.hibernate.validator.constraints.Length;
import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseApplyVO;
import com.panzhihua.common.validated.AddGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
 * @title: ComActWarehouseApplyDTO
 * @projectName: 成都呐喊信息技术有限公司-智慧社区项目
 * @description: 后台物品领用信息
 * @author: hans
 * @date: 2021/10/13 14:33
 */
@Data
@ApiModel("后台物品领用信息")
public class ComActWarehouseApplyDTO {
    @ApiModelProperty("领用人")
    @Length(groups = {AddGroup.class}, max = 10, message = "领用人最多支持10个字符")
    private String applyName;
    @ApiModelProperty("联系电话")
    @Pattern(groups = {AddGroup.class}, message = "联系电话格式错误", regexp = "^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\\d{8}$")
    private String applyPhone;
    @ApiModelProperty("领用物品,传入goodsId,goodsNum即可")
    @NotEmpty(groups = {AddGroup.class}, message = "领用物品不能为空")
    private List<ComActWarehouseApplyVO> applyItems;
    @ApiModelProperty("遇到的困难")
    @NotBlank(groups = {AddGroup.class}, message = "困难描述不可为空")
    @Length(groups = {AddGroup.class}, max = 100, message = "遇到的困难最多支持100个字符")
    private String reason;
    @ApiModelProperty("领用图片")
    private String receiveUrl;
    @ApiModelProperty(value = "操作人id", hidden = true)
    private Long operateUserId;
    @ApiModelProperty(value = "社区id", hidden = true)
    private Long communityId;
}
springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/service/community/CommunityService.java
@@ -2,6 +2,7 @@
import java.util.List;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseApplyDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@@ -6855,4 +6856,12 @@
     */
    @PostMapping("/comActWarehouseOperation/queryAll")
    public R comActWarehouseOperationSelectAll(@RequestBody CommonPage commonPage);
    /**
     * 物品领用
     * @param comActWarehouseApplyDTO
     * @return
     */
    @PostMapping("/comActWarehouseDonates/donates/apply")
    R applyDonates(@RequestBody ComActWarehouseApplyDTO comActWarehouseApplyDTO);
}
springcloud_k8s_panzhihuazhihuishequ/community_backstage/src/main/java/com/panzhihua/community_backstage/api/ComActWarehouseDonatesApi.java
@@ -24,6 +24,7 @@
import com.alibaba.fastjson.JSONArray;
import com.panzhihua.common.controller.BaseController;
import com.panzhihua.common.listen.WarehouseDonatesExcelListen;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseApplyDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ExportDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.PageDonatesDTO;
@@ -185,4 +186,13 @@
    public R getDonatesStatistics() {
        return communityService.getDonatesStatistics(getCommunityId());
    }
    @ApiOperation("物品领用")
    @PostMapping("/apply")
    public R applyDonates(@RequestBody @Validated(AddGroup.class) ComActWarehouseApplyDTO comActWarehouseApplyDTO) {
        LoginUserInfoVO loginUserInfo = getLoginUserInfo();
        comActWarehouseApplyDTO.setOperateUserId(loginUserInfo.getUserId());
        comActWarehouseApplyDTO.setCommunityId(loginUserInfo.getCommunityId());
        return communityService.applyDonates(comActWarehouseApplyDTO);
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/api/ComActWarehouseDonatesApi.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseApplyDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ExportDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.PageDonatesDTO;
@@ -168,4 +169,14 @@
    public R getDonatesStatistics(@RequestParam("communityId") Long communityId) {
        return comActWarehouseDonatesService.getDonatesStatistics(communityId);
    }
    /**
     * 社区后台物品领用
     * @param comActWarehouseApplyDTO
     * @return
     */
    @PostMapping("/donates/apply")
    public R applyDonates(@RequestBody ComActWarehouseApplyDTO comActWarehouseApplyDTO) {
        return comActWarehouseDonatesService.applyDonates(comActWarehouseApplyDTO);
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/ComActWarehouseDonatesService.java
@@ -1,5 +1,6 @@
package com.panzhihua.service_community.service;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseApplyDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ExportDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.PageDonatesDTO;
@@ -78,4 +79,11 @@
     * @return
     */
    R getDonatesStatistics(Long communityId);
    /**
     * 社区后台物品领用
     * @param comActWarehouseApplyDTO
     * @return
     */
    R applyDonates(ComActWarehouseApplyDTO comActWarehouseApplyDTO);
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComActWarehouseDonatesServiceImpl.java
@@ -14,28 +14,32 @@
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.panzhihua.common.exceptions.ServiceException;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseApplyDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ComActWarehouseDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.ExportDonatesDTO;
import com.panzhihua.common.model.dtos.community.warehouse.PageDonatesDTO;
import com.panzhihua.common.model.dtos.property.CommonPage;
import com.panzhihua.common.model.vos.R;
import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseApplyVO;
import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseDonatesVO;
import com.panzhihua.common.model.vos.community.warehouse.ComActWarehouseOperationVO;
import com.panzhihua.common.model.vos.community.warehouse.DonatesStatisticsVO;
import com.panzhihua.common.model.vos.community.warehouse.WarehouseDonatesExcelVO;
import com.panzhihua.service_community.dao.ComActWarehouseApplyDao;
import com.panzhihua.service_community.dao.ComActWarehouseDonatesDao;
import com.panzhihua.service_community.dao.ComActWarehouseOperationDao;
import com.panzhihua.service_community.entity.ComActWarehouseApply;
import com.panzhihua.service_community.entity.ComActWarehouseDonates;
import com.panzhihua.service_community.entity.ComActWarehouseOperation;
import com.panzhihua.service_community.service.ComActWarehouseDonatesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
/**
 * 爱心义仓/物品捐赠表(ComActWarehouseDonates)表服务实现类
@@ -49,6 +53,8 @@
    @Resource
    private ComActWarehouseOperationDao comActWarehouseOperationDao;
    @Resource
    private ComActWarehouseApplyDao comActWarehouseApplyDao;
    @Override
    public R pageList(CommonPage commonPage) {
@@ -68,6 +74,11 @@
                List<ComActWarehouseDonates> donateList = list.stream().map(excelVO -> {
                    ComActWarehouseDonates donates = new ComActWarehouseDonates();
                    BeanUtils.copyProperties(excelVO, donates);
                    if (excelVO.getIsAnonymous().equals("是")) {
                        donates.setIsAnonymous(1);
                    } else {
                        donates.setIsAnonymous(2);
                    }
                    return donates;
                }).collect(Collectors.toList());
                this.baseMapper.batchInsertDonates(donateList);
@@ -291,4 +302,50 @@
        donatesStatisticsVO.setTotalDec(donatesStatisticsVO.getTotalInc().intValue() - donatesStatisticsVO.getSurplus().intValue());
        return R.ok(donatesStatisticsVO);
    }
    /**
     * 社区后台物品领用
     * @param comActWarehouseApplyDTO
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R applyDonates(ComActWarehouseApplyDTO comActWarehouseApplyDTO) {
        List<ComActWarehouseApplyVO> applyItems = comActWarehouseApplyDTO.getApplyItems();
        if (!applyItems.isEmpty()) {
            Date nowDate = new Date();
            applyItems.forEach(item -> {
                Integer goodsId = item.getGoodsId();
                Integer goodsNum = item.getGoodsNum();
                if (isNull(goodsId) || isNull(goodsNum)) {
                    throw new ServiceException("请求参数有误");
                }
                ComActWarehouseDonates warehouseDonates = this.baseMapper.selectById(goodsId);
                if (nonNull(warehouseDonates) && warehouseDonates.getSurplusQuantity() - goodsNum >= 0) {
                    warehouseDonates.setSurplusQuantity(warehouseDonates.getSurplusQuantity() - goodsNum);
                    this.baseMapper.updateById(warehouseDonates);
                    ComActWarehouseApply apply = new ComActWarehouseApply();
                    BeanUtils.copyProperties(comActWarehouseApplyDTO, apply);
                    apply.setActualTime(nowDate);
                    apply.setCreateTime(nowDate);
                    apply.setGoodsId(goodsId);
                    apply.setGoodsNum(goodsNum);
                    apply.setReserveTime(nowDate);
                    apply.setStatus(ComActWarehouseApplyVO.status.ylq);
                    apply.setWriteOffUserId(comActWarehouseApplyDTO.getOperateUserId());
                    comActWarehouseApplyDao.insert(apply);
                    ComActWarehouseOperation comActWarehouseOperation=new ComActWarehouseOperation();
                    comActWarehouseOperation.setGoodsId(goodsId);
                    comActWarehouseOperation.setCreateTime(nowDate);
                    comActWarehouseOperation.setContent("爱心传递给了"+comActWarehouseApplyDTO.getApplyName().charAt(0)+"**,"+"减少了"+comActWarehouseApplyDTO.getReason()+"的困难,谢谢你的帮助");
                    comActWarehouseOperation.setType(ComActWarehouseOperation.type.xs);
                    comActWarehouseOperation.setApplyId(apply.getId());
                    comActWarehouseOperationDao.insert(comActWarehouseOperation);
                }
            });
        }
        return R.ok("领取成功,部分物品可能因剩余数量不足领取失败,请以实际领取记录为准");
    }
}
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/resources/mapper/ComActWarehouseDonatesMapper.xml
@@ -21,13 +21,13 @@
        <result property="registerBy" column="register_by"/>
        <result property="signingBy" column="signing_by"/>
    </resultMap>
    <insert id="batchInsertDonates" parameterType="java.util.List">
    <insert id="batchInsertDonates" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO `com_act_warehouse_donates`(`name`,phone,item,quantity,surplus_quantity,
        is_anonymous,message,register_at,signing_at,status,community_id,register_by)
        is_anonymous,message,register_at,signing_at,status,community_id,register_by,signing_by)
        VALUES
        <foreach collection="donateList" item="item" index="index" separator="," >
            (#{item.name}, #{item.phone}, #{item.phone}, #{item.item}, #{item.quantity}, #{item.surplusQuantity},
            #{item.isAnonymous}, #{item.message}, #{item.registerAt}, #{item.signingAt}, #{item.status}, #{item.communityId}, #{item.registerBy})
            (#{item.name}, #{item.phone}, #{item.item}, #{item.quantity}, #{item.surplusQuantity},#{item.isAnonymous},
            #{item.message}, #{item.registerAt}, #{item.signingAt}, #{item.status}, #{item.communityId}, #{item.registerBy}, #{item.signingBy})
        </foreach>
    </insert>
    <select id="exportDonatesByIds"