yangdamao 2 lat temu
rodzic
commit
679334b543

+ 12 - 0
zhongzheng-admin/src/main/java/com/zhongzheng/controller/common/CommonController.java

@@ -34,6 +34,7 @@ import com.zhongzheng.modules.distribution.vo.DistributionSellerVo;
 import com.zhongzheng.modules.exam.bo.ExamApplyDetailBo;
 import com.zhongzheng.modules.exam.bo.ExamApplyResultBo;
 import com.zhongzheng.modules.exam.bo.ExamApplySubscribeBo;
+import com.zhongzheng.modules.exam.bo.UpdateStudentImageBo;
 import com.zhongzheng.modules.exam.service.IExamApplyService;
 import com.zhongzheng.modules.exam.vo.ExamApplyDetailVo;
 import com.zhongzheng.modules.goods.bo.AlikeGoodsBo;
@@ -285,6 +286,17 @@ public class CommonController extends BaseController {
     }
 
 
+    @ApiOperation("学员学时图片修改")
+    @PostMapping("common/student/image/update")
+    public AjaxResult updateStudentImage(@RequestBody UpdateStudentImageBo bo) {
+        if (!ToolsUtils.checkSignFromOldSys(bo.getStamp().toString(), bo.getSign())) {
+            return AjaxResult.error("签名错误");
+        }
+        iUserSubscribeService.updateStudentImage(bo);
+        return AjaxResult.success();
+    }
+
+
     @ApiOperation("获取某场考试信息")
     @PostMapping("common/apply/detail")
     public AjaxResult examApplyDetail(@RequestBody ExamApplyDetailBo bo) {

+ 20 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/file/ImageUtils.java

@@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
 import sun.misc.BASE64Encoder;
 
 import javax.imageio.ImageIO;
+import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.*;
 import java.net.URL;
@@ -106,4 +107,23 @@ public class ImageUtils
         return s;
 
     }
+
+    /** * 旋转图片为指定角度  图片宽高不变*
+     * @param bufferedimage * 目标图像 *
+     * @param degree * 旋转角度 *
+     * @return */
+    public static BufferedImage rotateImage(final BufferedImage bufferedimage, final int degree)
+    {
+        int w= bufferedimage.getWidth(); // 得到图片宽度。
+        int h= bufferedimage.getHeight();// 得到图片高度。
+        int type= bufferedimage.getColorModel().getTransparency();// 得到图片透明度。
+        BufferedImage img;// 空的图片。
+        Graphics2D graphics2d;// 空的画笔。
+        (graphics2d= (img= new BufferedImage(w, h, type)).createGraphics()).setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
+        graphics2d.rotate(Math.toRadians(degree), w/2, h/2);// 旋转,degree是整型,度数,比如垂直90度。   •rotate(double arc,double x, double y):图形以点(x,y)为轴点,旋转arc弧度。
+        graphics2d.drawImage(bufferedimage, 0, 0, null);// 从bufferedimagecopy图片至img,0,0是img的坐标。
+        graphics2d.dispose();
+
+        return img;// 返回复制好的图片,原图片依然没有变,没有旋转,下次还可以使用。
+    }
 }

+ 1 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/config/SecurityConfig.java

@@ -140,6 +140,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
                 .antMatchers("/common/get/goods").anonymous()
                 .antMatchers("/common/get/goods/studyUrl").anonymous()
                 .antMatchers("/common/apply/detail").anonymous()
+                .antMatchers("/common/student/image/update").anonymous()
                 .antMatchers("/common/platform/pay").anonymous()
                 .antMatchers("/common/platform/pay/handle").anonymous()
                 .antMatchers("/common/alike/goods").anonymous()

+ 5 - 0
zhongzheng-framework/src/main/java/com/zhongzheng/framework/web/service/UserServiceImpl.java

@@ -1568,6 +1568,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
         return vo;
     }
 
+    @Override
+    public List<User> listByIdsNotTenant(List<Long> userIds) {
+        return baseMapper.listByIdsNotTenant(userIds);
+    }
+
 
     @Override
     public Map<String, Object> accountLogin(UserAppAccountLoginBo bo) {

+ 32 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/exam/bo/UpdateStudentImageBo.java

@@ -0,0 +1,32 @@
+package com.zhongzheng.modules.exam.bo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+import java.io.Serializable;
+
+/**
+ * @author yangdamao
+ * @date 2023年07月18日 14:25
+ */
+@Data
+public class UpdateStudentImageBo implements Serializable {
+
+    @ApiModelProperty("当前时间戳")
+    @NotBlank(message = "当前时间戳不能为空")
+    private Long stamp;
+
+    @ApiModelProperty("签名")
+    @NotBlank(message = "签名不能为空")
+    private String sign;
+
+    @ApiModelProperty("图片地址")
+    private String imageUrl;
+
+    @ApiModelProperty("学员身份证")
+    private String idCard;
+
+    @ApiModelProperty("旋转角度")
+    private Integer degree;
+}

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/mapper/UserMapper.java

@@ -72,4 +72,7 @@ public interface UserMapper extends BaseMapper<User> {
 
     @InterceptorIgnore(tenantLine = "true")
     User getUserByAccount(@Param("userAccount")String userAccount);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<User> listByIdsNotTenant(@Param("userIds")List<Long> userIds);
 }

+ 7 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/mapper/UserStudyRecordPhotoMapper.java

@@ -1,5 +1,6 @@
 package com.zhongzheng.modules.user.mapper;
 
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
 import com.zhongzheng.modules.user.domain.UserStudyRecordPhoto;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
@@ -18,4 +19,10 @@ public interface UserStudyRecordPhotoMapper extends BaseMapper<UserStudyRecordPh
     String selectGradeRecentOnePhoto(@Param("userId") Long userId,@Param("gradeId") Long gradeId);
 
     List<String> selectGradePhotoWeek(@Param("userId") Long userId,@Param("gradeId") Long gradeId,@Param("searchWeekStartTime") Long searchWeekStartTime,@Param("searchWeekEndTime") Long searchWeekEndTime);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<UserStudyRecordPhoto> listByPhoto(@Param("imageUrl") String imageUrl);
+
+    @InterceptorIgnore(tenantLine = "true")
+    void updateBatchByIdNotTenant(@Param("ids") List<Long> ids,@Param("upload") String upload);
 }

+ 2 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/IUserService.java

@@ -133,4 +133,6 @@ public interface IUserService extends IService<User> {
 	UserLiveAccountLoginVo smsLiveUnifyLogin(UserLiveAccountLoginBo bo);
 
 	UserLiveAccountLoginVo liveUnifyLoginRefresh(UserLiveAccountLoginBo bo);
+
+    List<User> listByIdsNotTenant(List<Long> userIds);
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/IUserStudyRecordPhotoService.java

@@ -57,4 +57,7 @@ public interface IUserStudyRecordPhotoService extends IService<UserStudyRecordPh
 
 	List<String> selectGradePhotoWeek(Long userId,Long gradeId,Long searchWeekStartTime,Long searchWeekEndTime);
 
+    List<UserStudyRecordPhoto> getListByPhoto(String imageUrl);
+
+	void updateBatchByIdNotTenant(List<Long> ids, String upload);
 }

+ 3 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/IUserSubscribeService.java

@@ -2,6 +2,7 @@ package com.zhongzheng.modules.user.service;
 
 import com.zhongzheng.modules.base.bo.ConsoleQueryBo;
 import com.zhongzheng.modules.exam.bo.ExamApplySubscribeBo;
+import com.zhongzheng.modules.exam.bo.UpdateStudentImageBo;
 import com.zhongzheng.modules.exam.vo.ExamSessionVo;
 import com.zhongzheng.modules.user.bo.*;
 import com.zhongzheng.modules.user.domain.UserSubscribe;
@@ -107,4 +108,6 @@ public interface IUserSubscribeService extends IService<UserSubscribe> {
 	List<ExamSessionVo> getExamSession(String applyDate);
 
     void examApplySubscribe(ExamApplySubscribeBo bo);
+
+    void updateStudentImage(UpdateStudentImageBo bo);
 }

+ 10 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserStudyRecordPhotoServiceImpl.java

@@ -135,4 +135,14 @@ public class UserStudyRecordPhotoServiceImpl extends ServiceImpl<UserStudyRecord
     public List<String> selectGradePhotoWeek(Long userId, Long gradeId,Long searchWeekStartTime,Long searchWeekEndTime) {
         return this.baseMapper.selectGradePhotoWeek(userId,gradeId,searchWeekStartTime,searchWeekEndTime);
     }
+
+    @Override
+    public List<UserStudyRecordPhoto> getListByPhoto(String imageUrl) {
+        return baseMapper.listByPhoto(imageUrl);
+    }
+
+    @Override
+    public void updateBatchByIdNotTenant(List<Long> ids, String upload) {
+        baseMapper.updateBatchByIdNotTenant(ids, upload);
+    }
 }

+ 66 - 4
zhongzheng-system/src/main/java/com/zhongzheng/modules/user/service/impl/UserSubscribeServiceImpl.java

@@ -24,6 +24,8 @@ import com.zhongzheng.common.utils.DateUtils;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.common.utils.ToolsUtils;
 import com.zhongzheng.common.utils.file.FileUtils;
+import com.zhongzheng.common.utils.file.ImageUtils;
+import com.zhongzheng.modules.alioss.bo.OssRequest;
 import com.zhongzheng.modules.alioss.service.OssService;
 import com.zhongzheng.modules.alioss.vo.FileBean;
 import com.zhongzheng.modules.base.bo.ConsoleQueryBo;
@@ -31,10 +33,7 @@ import com.zhongzheng.modules.base.bo.UserProfileFit;
 import com.zhongzheng.modules.course.domain.Major;
 import com.zhongzheng.modules.course.mapper.CourseMapper;
 import com.zhongzheng.modules.course.service.IMajorService;
-import com.zhongzheng.modules.exam.bo.ExamApplyQueryBo;
-import com.zhongzheng.modules.exam.bo.ExamApplySiteTimeJson;
-import com.zhongzheng.modules.exam.bo.ExamApplySiteTimeTwoAddBo;
-import com.zhongzheng.modules.exam.bo.ExamApplySubscribeBo;
+import com.zhongzheng.modules.exam.bo.*;
 import com.zhongzheng.modules.exam.domain.ExamApply;
 import com.zhongzheng.modules.exam.domain.ExamApplySite;
 import com.zhongzheng.modules.exam.domain.ExamApplySiteTime;
@@ -64,17 +63,21 @@ import com.zhongzheng.modules.order.service.IOrderGoodsService;
 import com.zhongzheng.modules.user.bo.*;
 import com.zhongzheng.modules.user.domain.User;
 import com.zhongzheng.modules.user.domain.UserExamGoods;
+import com.zhongzheng.modules.user.domain.UserStudyRecordPhoto;
 import com.zhongzheng.modules.user.domain.UserSubscribe;
 import com.zhongzheng.modules.user.mapper.UserSubscribeMapper;
 import com.zhongzheng.modules.user.service.IUserExamGoodsService;
 import com.zhongzheng.modules.user.service.IUserService;
+import com.zhongzheng.modules.user.service.IUserStudyRecordPhotoService;
 import com.zhongzheng.modules.user.service.IUserSubscribeService;
 import com.zhongzheng.modules.user.vo.*;
 import com.zhongzheng.modules.wx.service.IWxLoginService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 import org.thymeleaf.util.StringUtils;
 
 import javax.imageio.ImageIO;
@@ -151,6 +154,8 @@ public class UserSubscribeServiceImpl extends ServiceImpl<UserSubscribeMapper, U
     private IOrderGoodsService iOrderGoodsService;
     @Autowired
     private IClassGradeUserService iClassGradeUserService;
+    @Autowired
+    private IUserStudyRecordPhotoService iUserStudyRecordPhotoService;
 
     @Value("${aliyun.sms.cancellationReminder}")
     private String cancellationReminder;
@@ -2376,6 +2381,63 @@ public class UserSubscribeServiceImpl extends ServiceImpl<UserSubscribeMapper, U
         sendExamSucceed(userSubscribeAddBo);
     }
 
+    /**
+     * 学员学时图片修改
+     * @author change
+     * @date 2023/7/18 14:29
+     * @param bo
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateStudentImage(UpdateStudentImageBo bo) {
+        //校验图片是否存在
+        List<UserStudyRecordPhoto> recordPhotos = iUserStudyRecordPhotoService.getListByPhoto(bo.getImageUrl());
+        if (CollectionUtils.isEmpty(recordPhotos)){
+            throw new CustomException("图片不存在,请检查图片!");
+        }
+        List<Long> userIds = recordPhotos.stream().map(UserStudyRecordPhoto::getUserId).collect(Collectors.toList());
+        List<User> users = iUserService.listByIdsNotTenant(userIds);
+        if (CollectionUtils.isEmpty(users)){
+            throw new CustomException("学员不存在,请检查!");
+        }
+        String encrypt = EncryptHandler.encrypt(bo.getIdCard());
+        if (users.stream().anyMatch(x -> !x.getIdCard().equals(encrypt))){
+            throw new CustomException("照片和学员不匹配,请检查!");
+        }
+        try {
+            InputStream in = ossService.getStreamByObject(bo.getImageUrl());
+            BufferedImage img = ImageIO.read(in);
+            BufferedImage bufferedImage = ImageUtils.rotateImage(img, bo.getDegree());
+            OssRequest oss = new OssRequest();
+            oss.setImageStatus(0);
+            oss.setGradeId(0L);
+            oss.setUserId(0L);
+
+            //创建一个ByteArrayOutputStream
+            ByteArrayOutputStream os = new ByteArrayOutputStream();
+            //把BufferedImage写入ByteArrayOutputStream
+            ImageIO.write(bufferedImage, "jpg", os);
+            //ByteArrayOutputStream转成InputStream
+            InputStream input = new ByteArrayInputStream(os.toByteArray());
+            //InputStream转成MultipartFile
+            MultipartFile multipartFile =new MockMultipartFile(DateUtils.getNowTime().toString(), DateUtils.getNowTime()+".jpg", "text/plain", input);
+
+//            //将newImage写入字节数组输出流
+//            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+//            ImageIO.write( bufferedImage, "jpg", baos);
+//            //转换为MultipartFile
+//            MultipartFile multipartFile = new MockMultipartFile(DateUtils.getNowTime().toString(), baos.toByteArray());
+
+            oss.setFile(multipartFile);
+            String upload = ossService.upload(oss);
+            List<Long> ids = recordPhotos.stream().map(UserStudyRecordPhoto::getId).collect(Collectors.toList());
+            iUserStudyRecordPhotoService.updateBatchByIdNotTenant(ids,upload);
+        }catch (Exception e){
+            e.printStackTrace();
+            throw new CustomException("修改图片错误!");
+        }
+    }
+
 
     private Integer getSeatNumber(UserSubscribeAddBo bo,Long userNum) {
         List<UserSubscribe> list = list(new LambdaQueryWrapper<UserSubscribe>().eq(UserSubscribe::getApplyId, bo.getApplyId())

+ 12 - 0
zhongzheng-system/src/main/resources/mapper/modules/user/UserMapper.xml

@@ -484,6 +484,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           AND user_account = #{userAccount}
     </select>
 
+    <select id="listByIdsNotTenant" parameterType="java.lang.Long" resultType="com.zhongzheng.modules.user.domain.User">
+        SELECT
+            *
+        FROM
+            `user`
+        WHERE
+            status = 1 AND user_id IN
+            <foreach collection="userIds" item="item" index="index" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+    </select>
+
     <select id="getUserOrderCount" parameterType="map" resultType="java.lang.Long">
         SELECT
             COUNT(o.order_sn)

+ 11 - 0
zhongzheng-system/src/main/resources/mapper/modules/user/UserStudyRecordPhotoMapper.xml

@@ -65,4 +65,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             rp.id DESC
             LIMIT 1
     </select>
+
+    <select id="listByPhoto" parameterType="java.lang.String" resultType="com.zhongzheng.modules.user.domain.UserStudyRecordPhoto">
+        SELECT * FROM `user_study_record_photo` WHERE photo = #{imageUrl}
+    </select>
+
+    <update id="updateBatchByIdNotTenant" parameterType="map" >
+        UPDATE user_study_record_photo SET photo = #{upload} WHERE id IN
+        <foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
+            #{item}
+        </foreach>
+    </update>
 </mapper>