Ver código fonte

授权牌模板part5

Aslee 2 anos atrás
pai
commit
aaef244b4c

+ 27 - 5
src/main/java/com/caimei/controller/admin/auth/AuthTemplateApi.java

@@ -28,9 +28,6 @@ public class AuthTemplateApi {
 
     private final AuthTemplateService authTemplateService;
 
-    /**
-     * 授权牌模板列表
-     */
     @ApiOperation("授权牌模板列表")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "listType", required = true, value = "列表类型:1管理员列表,2供应商列表"),
@@ -45,10 +42,26 @@ public class AuthTemplateApi {
         return authTemplateService.getTemplateList(listType, authUserId, pageNum, pageSize);
     }
 
+    @ApiOperation("授权牌模板表单")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "templateId", required = false, value = "模板id"),
+            @ApiImplicitParam(name = "authId", required = false, value = "机构id"),
+            @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"),
+            @ApiImplicitParam(name = "authFlag", required = false, value = "是否作为机构授权牌模板:1是0否"),
+            @ApiImplicitParam(name = "status", required = false, value = "启用状态:0停用,1启用")
+    })
+    @GetMapping("/form/data")
+    public ResponseJson<TemplateVo> getTemplateFormData(Integer templateId, Integer authId, Integer authUserId, Integer authFlag, Integer status) {
+        if (null == templateId && null == authId && null == authUserId) {
+            return ResponseJson.error("参数异常", null);
+        }
+        return authTemplateService.getTemplateFormData(templateId, authId, authUserId, authFlag, status);
+    }
+
     @ApiOperation("添加/编辑授权模板")
     @ApiImplicitParam(name = "params", required = true, value = "templateId:模板id;templateImage:模板图片;" +
             "authUserId:供应商用户id;status:状态:1启用,0停用;qrPosition:二维码位置;qrSize:二维码尺寸;" +
-            "authFlag:1设置为机构授权牌模板;productFlag:1设置为设备授权牌模板")
+            "logoSize:logo尺寸;authFlag:1设置为机构授权牌模板;productFlag:1设置为设备授权牌模板")
     @PostMapping("/save")
     public ResponseJson saveTemplate(@RequestBody String params){
         JSONObject parseObject = JSONObject.parseObject(params);
@@ -58,14 +71,23 @@ public class AuthTemplateApi {
         Integer status = parseObject.getInteger("status");
         String qrPosition = parseObject.getString("qrPosition");
         Integer qrSize = parseObject.getInteger("qrSize");
+        String logoSize = parseObject.getString("logoSize");
         Integer authFlag = parseObject.getInteger("authFlag");
         Integer productFlag = parseObject.getInteger("productFlag");
         if (null != templateId) {
             if ((null != authFlag || null != productFlag) && null == authUserId) {
                 return ResponseJson.error("供应商用户id不能为空");
             }
+        } else {
+            if (StringUtils.isEmpty(templateImage)) {
+                return ResponseJson.error("模板图片不能为空");
+            }
+        }
+        if (StringUtils.isEmpty(qrPosition)) {
+            // 默认左上角
+            qrPosition = "0,0";
         }
-        return authTemplateService.saveTemplate(templateId, templateImage, authUserId, status, qrPosition, qrSize, authFlag, productFlag);
+        return authTemplateService.saveTemplate(templateId, templateImage, authUserId, status, qrPosition, qrSize, logoSize, authFlag, productFlag);
     }
 
 }

+ 4 - 2
src/main/java/com/caimei/mapper/cmMapper/AuthTemplateMapper.java

@@ -22,11 +22,13 @@ public interface AuthTemplateMapper {
      */
     List<TemplateVo> getTemplateList(@Param("listType") Integer listType, @Param("authUserId") Integer authUserId);
 
-    void insertTemplate(@Param("templateImage") String templateImage, @Param("authUserId") Integer authUserId, @Param("templateSize") String templateSize, @Param("qrPosition") String qrPosition, @Param("qrSize") Integer qrSize);
+    void insertTemplate(@Param("templateImage") String templateImage, @Param("authUserId") Integer authUserId, @Param("templateSize") String templateSize, @Param("qrPosition") String qrPosition, @Param("qrSize") Integer qrSize, @Param("logoSize") String logoSize);
 
-    void updateSelective(@Param("templateId") Integer templateId, @Param("templateImage") String templateImage, @Param("authUserId") Integer authUserId, @Param("status") Integer status, @Param("qrPosition") String qrPosition, @Param("authFlag") Integer authFlag, @Param("productFlag") Integer productFlag);
+    void updateSelective(@Param("templateId") Integer templateId, @Param("templateImage") String templateImage, @Param("authUserId") Integer authUserId, @Param("status") Integer status, @Param("qrPosition") String qrPosition, @Param("qrSize") Integer qrSize, String logoSize, @Param("authFlag") Integer authFlag, @Param("productFlag") Integer productFlag);
 
     void clearAuthFlag(Integer authUserId);
 
     void clearProductFlag(Integer authUserId);
+
+    TemplateVo getTemplateFormData(@Param("templateId") Integer templateId, @Param("authId") Integer authId, @Param("authUserId") Integer authUserId, @Param("authFlag") Integer authFlag, @Param("status") Integer status);
 }

+ 5 - 0
src/main/java/com/caimei/model/vo/AuthFormVo.java

@@ -160,4 +160,9 @@ public class AuthFormVo implements Serializable {
      * 是否已绑定用户账号:0未绑定,1已绑定
      */
     private Integer bindStatus;
+
+    /**
+     * 机构授权牌模板
+     */
+    private TemplateVo authTemplate;
 }

+ 5 - 0
src/main/java/com/caimei/model/vo/TemplateVo.java

@@ -56,6 +56,11 @@ public class TemplateVo {
      */
     private Integer qrSize;
 
+    /**
+     * logo尺寸
+     */
+    private String logoSize;
+
     /**
      * 状态:0停用,1启用
      */

+ 2 - 1
src/main/java/com/caimei/service/auth/AuthService.java

@@ -4,6 +4,7 @@ import com.caimei.model.ResponseJson;
 import com.caimei.model.po.CmBrandAuthPo;
 import com.caimei.model.vo.AuthFormVo;
 import com.caimei.model.vo.AuthVo;
+import com.caimei.model.vo.TemplateVo;
 import com.github.pagehelper.PageInfo;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -115,7 +116,7 @@ public interface AuthService {
      * @param auth
      * @return
      */
-    String generateAuthImage(CmBrandAuthPo auth);
+    String generateAuthImage(TemplateVo authTemplate, CmBrandAuthPo auth);
 
     /**
      * 添加水印

+ 13 - 1
src/main/java/com/caimei/service/auth/AuthTemplateService.java

@@ -31,11 +31,23 @@ public interface AuthTemplateService {
      * @param status
      * @param qrPosition
      * @param qrSize
+     * @param logoSize
      * @param authFlag
      * @param productFlag
      * @return
      */
-    ResponseJson saveTemplate(Integer templateId, String templateImage, Integer authUserId, Integer status, String qrPosition, Integer qrSize, Integer authFlag, Integer productFlag);
+    ResponseJson saveTemplate(Integer templateId, String templateImage, Integer authUserId, Integer status, String qrPosition, Integer qrSize, String logoSize, Integer authFlag, Integer productFlag);
+
+    /**
+     * 模板表单数据
+     * @param templateId    模板id
+     * @param authId
+     * @param authUserId
+     * @param authFlag
+     * @param status
+     * @return
+     */
+    ResponseJson<TemplateVo> getTemplateFormData(Integer templateId, Integer authId, Integer authUserId, Integer authFlag, Integer status);
 }
 
 

+ 27 - 19
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -289,7 +289,9 @@ public class AuthServiceImpl implements AuthService {
         String authImage = null;
         if (1 == auth.getAuthImageType()) {
             // 模板库生成
-            authImage = generateAuthImage(auth);
+            // 获取对应模板
+            TemplateVo authTemplate = authMapper.getAuthTemplate(auth.getId(), null, 1);
+            authImage = generateAuthImage(authTemplate, auth);
             auth.setAuthImage(authImage);
             // 添加水印
             if (StringUtils.isNotEmpty(authImage)) {
@@ -334,25 +336,29 @@ public class AuthServiceImpl implements AuthService {
     }
 
     @Override
-    public String generateAuthImage(CmBrandAuthPo auth) {
-        TemplateVo authTemplate = authMapper.getAuthTemplate(auth.getId(), null, 1);
+    public String generateAuthImage(TemplateVo authTemplate, CmBrandAuthPo auth) {
         if (null != authTemplate) {
             // 根据模板id设置相关数据
             Map<String, Object> templateInfo = getTemplateInfo(authTemplate, auth);
-            String authImage = ImageUtils.generateAuthImage(templateInfo);
-            log.info("【图片上传】>>>>>>>>>>>>>>>>图片临时路径:" + authImage);
-            // 临时图片
-            File tempFile = new File(authImage);
-            String imageUrl = null;
-            try {
-                imageUrl = imageDomain + "/" + client.uploadFile(authImage);
-            } catch (Exception e) {
-                e.printStackTrace();
+            Object templateImage = templateInfo.get("templateImage");
+            if (null != templateImage) {
+                String authImage = ImageUtils.generateAuthImage(templateInfo);
+                log.info("【图片上传】>>>>>>>>>>>>>>>>图片临时路径:" + authImage);
+                // 临时图片
+                File tempFile = new File(authImage);
+                String imageUrl = null;
+                try {
+                    imageUrl = imageDomain + "/" + client.uploadFile(authImage);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+                // 删除临时图片
+                boolean delete = tempFile.delete();
+                log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时图片:" + delete);
+                return imageUrl;
+            } else {
+                return null;
             }
-            // 删除临时图片
-            boolean delete = tempFile.delete();
-            log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时图片:" + delete);
-            return imageUrl;
         }
         return null;
     }
@@ -360,8 +366,8 @@ public class AuthServiceImpl implements AuthService {
     private Map<String,Object> getTemplateInfo(TemplateVo template, CmBrandAuthPo auth) {
         HashMap<String, Object> map = new HashMap<>();
         Integer templateId = template.getTemplateId();
-        map.put("templateImage", template.getTemplateImage());
         if (1 == templateId) {
+            map.put("templateImage", template.getTemplateImage());
             double rate = 0.15;
             if (StringUtils.isNotEmpty(auth.getAuthImageLogo())) {
                 // 获取授权牌logo位置
@@ -408,8 +414,10 @@ public class AuthServiceImpl implements AuthService {
                 map.put("addQr1_link", qrCodeLink);
                 map.put("addQr1_size", template.getQrSize());
                 String[] split = template.getQrPosition().split(",");
-                map.put("addQr1_x", Integer.parseInt(split[0]));
-                map.put("addQr1_y", Integer.parseInt(split[1]));
+                if (split.length == 2) {
+                    map.put("addQr1_x", Integer.parseInt(split[0]));
+                    map.put("addQr1_y", Integer.parseInt(split[1]));
+                }
             }
         }
         return map;

+ 10 - 3
src/main/java/com/caimei/service/auth/impl/AuthTemplateServiceImpl.java

@@ -43,7 +43,7 @@ public class AuthTemplateServiceImpl implements AuthTemplateService {
     }
 
     @Override
-    public ResponseJson saveTemplate(Integer templateId, String templateImage, Integer authUserId, Integer status, String qrPosition, Integer qrSize, Integer authFlag, Integer productFlag) {
+    public ResponseJson saveTemplate(Integer templateId, String templateImage, Integer authUserId, Integer status, String qrPosition, Integer qrSize, String logoSize, Integer authFlag, Integer productFlag) {
         boolean insertFlag = null == templateId;
         if (insertFlag) {
             Integer width = null;
@@ -56,7 +56,7 @@ public class AuthTemplateServiceImpl implements AuthTemplateService {
                 e.printStackTrace();
             }
             String templateSize = (null == width ? 0 : width) + "," + (null == height ? 0 : height);
-            authTemplateMapper.insertTemplate(templateImage, authUserId, templateSize, qrPosition, qrSize);
+            authTemplateMapper.insertTemplate(templateImage, authUserId, templateSize, qrPosition, qrSize, logoSize);
         } else {
             if (null != authFlag && 1 == authFlag) {
                 authTemplateMapper.clearAuthFlag(authUserId);
@@ -64,8 +64,15 @@ public class AuthTemplateServiceImpl implements AuthTemplateService {
             if (null != productFlag && 1 == productFlag) {
                 authTemplateMapper.clearProductFlag(authUserId);
             }
-            authTemplateMapper.updateSelective(templateId, templateImage, authUserId, status, qrPosition, authFlag, productFlag);
+            authTemplateMapper.updateSelective(templateId, templateImage, authUserId, status, qrPosition, qrSize, logoSize, authFlag, productFlag);
         }
         return ResponseJson.success();
     }
+
+    @Override
+    public ResponseJson<TemplateVo> getTemplateFormData(Integer templateId, Integer authId, Integer authUserId, Integer authFlag, Integer status) {
+        TemplateVo templateVo = authTemplateMapper.getTemplateFormData(templateId, authId, authUserId, authFlag, status);
+        return ResponseJson.success(templateVo);
+    }
+
 }

+ 6 - 1
src/main/java/com/caimei/service/auth/impl/ShopServiceImpl.java

@@ -510,10 +510,15 @@ public class ShopServiceImpl implements ShopService {
     @Override
     public ResponseJson updateAllAuthImage(Integer authUserId) {
         List<CmBrandAuthPo> authList = authMapper.getAllAuth(authUserId);
+        // 获取对应模板
+        TemplateVo authTemplate = authMapper.getAuthTemplate(null, authUserId, 1);
+        if (null == authTemplate) {
+            return ResponseJson.error("请选择使用位置");
+        }
         authList.forEach(auth->{
             String authImage;
             if (1 == auth.getAuthImageType()) {
-                authImage = authService.generateAuthImage(auth);
+                authImage = authService.generateAuthImage(authTemplate, auth);
                 auth.setAuthImage(authImage);
                 if (StringUtils.isNotEmpty(authImage)) {
                     auth.setPcAuthImage(authService.addWaterMark(authImage, 1));

+ 35 - 6
src/main/resources/mapper/AuthTemplateMapper.xml

@@ -2,14 +2,14 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.cmMapper.AuthTemplateMapper">
     <insert id="insertTemplate">
-        insert into cm_brand_auth_template (authUserId, templateImage, templateSize, qrPosition, qrSize, addTime)
-        values (#{authUserId}, #{templateImage}, #{templateSize}, #{qrPosition}, #{qrSize}, NOW())
+        insert into cm_brand_auth_template (authUserId, templateImage, templateSize, qrPosition, qrSize, logoSize, addTime)
+        values (#{authUserId}, #{templateImage}, #{templateSize}, #{qrPosition}, #{qrSize}, #{logoSize}, NOW())
     </insert>
     <update id="updateSelective">
         update cm_brand_auth_template
         <set>
             <if test="authUserId != null and null == authFlag and null == productFlag">
-                authUserId = #{authUserId},
+                authUserId = #{authUserId}, authFlag = 0, productFlag = 0,
             </if>
             <if test="templateImage != null and templateImage != ''">
                 templateImage = #{templateImage},
@@ -20,6 +20,12 @@
             <if test="qrPosition != null and qrPosition != ''">
                 qrPosition = #{qrPosition},
             </if>
+            <if test="qrSize != null">
+                qrSize = #{qrSize},
+            </if>
+            <if test="logoSize != null and logoSize != ''">
+                logoSize = #{logoSize},
+            </if>
             <if test="authFlag != null and authFlag == 1">
                 authFlag = 1,
             </if>
@@ -41,9 +47,10 @@
     </update>
 
     <select id="getTemplateList" resultType="com.caimei.model.vo.TemplateVo">
-        select t.id as templateId,t.authUserId,u.name as shopName, templateImage, templateSize, authFlag, productFlag, qrPosition,
-        qrSize, t.status, addTime
-        from cm_brand_auth_template t left join cm_brand_auth_user u on t.authUserId = u.authUserId
+        select t.id as templateId,t.authUserId,u.name as shopName, templateImage, templateSize, authFlag, productFlag,
+        qrPosition, qrSize, logoSize, t.status, addTime
+        from cm_brand_auth_template t
+        left join cm_brand_auth_user u on t.authUserId = u.authUserId
         <where>
             <if test="authUserId != null">
                 and t.authUserId = #{authUserId}
@@ -54,4 +61,26 @@
         </where>
         order by t.addTime desc
     </select>
+    <select id="getTemplateFormData" resultType="com.caimei.model.vo.TemplateVo">
+        select t.id as templateId, templateImage, t.authUserId, qrPosition, qrSize, logoSize
+        from cm_brand_auth_template t left join cm_brand_auth a on t.authUserId = a.authUserId
+        <where>
+            <if test="templateId != null">
+                and t.id = #{templateId}
+            </if>
+            <if test="authId != null">
+                and a.id = #{authId}
+            </if>
+            <if test="authUserId != null">
+                and t.authUserId = #{authUserId}
+            </if>
+            <if test="authFlag != null">
+                and t.authFlag = #{authFlag}
+            </if>
+            <if test="status != null">
+                and t.status = #{status}
+            </if>
+        </where>
+        limit 1
+    </select>
 </mapper>