Browse Source

1.7.1-导入机构信息

Aslee 2 years ago
parent
commit
8576c5200c

+ 77 - 0
src/main/java/com/caimei/controller/admin/auth/AuthTemplateApi.java

@@ -0,0 +1,77 @@
+package com.caimei.controller.admin.auth;
+
+import com.alibaba.fastjson.JSONObject;
+import com.caimei.model.ResponseJson;
+import com.caimei.model.dto.ProductSaveDto;
+import com.caimei.model.vo.ProductFormVo;
+import com.caimei.model.vo.ProductListVo;
+import com.caimei.model.vo.ProductTypeListVo;
+import com.caimei.model.vo.TemplateListVo;
+import com.caimei.service.auth.AuthProductService;
+import com.caimei.service.auth.AuthTemplateService;
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 授权牌模板API
+ * @author Aslee
+ * @date 2022/7/6
+ */
+@Api(tags = "授权牌模板API")
+@Slf4j
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("/auth/template")
+public class AuthTemplateApi {
+
+    private final AuthTemplateService authTemplateService;
+
+    /**
+     * 授权牌模板列表
+     */
+    @ApiOperation("授权牌模板列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "listType", required = true, value = "列表类型:1管理员列表,2供应商列表"),
+            @ApiImplicitParam(name = "authUserId", required = false, value = "供应商用户id"),
+            @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
+            @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
+    })
+    @GetMapping("/list")
+    public ResponseJson<PageInfo<TemplateListVo>> getTemplateList(Integer listType, Integer authUserId,
+                                                                  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
+                                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
+        return authTemplateService.getTemplateList(listType, authUserId, pageNum, pageSize);
+    }
+
+    @ApiOperation("添加/编辑授权模板")
+    @ApiImplicitParam(name = "params", required = true, value = "templateId:模板id;templateImage:模板图片;authUserId:供应商用户id")
+    @PostMapping("/save")
+    public ResponseJson saveTemplate(@RequestBody String params){
+        JSONObject parseObject = JSONObject.parseObject(params);
+        Integer templateId = parseObject.getInteger("templateId");
+        String templateImage = parseObject.getString("templateImage");
+        Integer authUserId = parseObject.getInteger("authUserId");
+        Integer status = parseObject.getInteger("status");
+        String qrPosition = parseObject.getString("qrPosition");
+        if (null != templateId) {
+            if (StringUtils.isEmpty(templateImage)) {
+                return ResponseJson.error("授权牌模板不能为空");
+            }
+            if (null == authUserId) {
+                return ResponseJson.error("供应商用户id不能为空");
+            }
+        }
+        return authTemplateService.saveTemplate(templateId, templateImage, authUserId, status, qrPosition);
+    }
+}

+ 1 - 1
src/main/java/com/caimei/controller/admin/auth/ShopApi.java

@@ -40,7 +40,7 @@ public class ShopApi {
      */
     @ApiOperation("供应商列表")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1供应商列表,2授权信息审核列表,3资料审核列表,4医师审核列表,5添加会员列表,6设备分类审核列表,7授权牌物流列表"),
+            @ApiImplicitParam(name = "listType", required = false, value = "列表类型:1供应商列表,2授权信息审核列表,3资料审核列表,4医师审核列表,5已启用供应商列表,6设备分类审核列表,7授权牌物流列表"),
             @ApiImplicitParam(name = "shopName", required = false, value = "供应商名称"),
             @ApiImplicitParam(name = "loginAccount", required = false, value = "登录账号"),
             @ApiImplicitParam(name = "shopType", required = false, value = "供应商类型:1品牌方,2代理商"),

+ 28 - 0
src/main/java/com/caimei/mapper/cmMapper/AuthTemplateMapper.java

@@ -0,0 +1,28 @@
+package com.caimei.mapper.cmMapper;
+
+import com.caimei.model.vo.*;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2022/7/6
+ */
+@Mapper
+public interface AuthTemplateMapper {
+    /**
+     * 模板列表
+     * @param listType
+     * @param authUserId
+     * @return
+     */
+    List<TemplateListVo> getTemplateList(@Param("listType") Integer listType, @Param("authUserId") Integer authUserId);
+
+    void insertTemplate(@Param("templateImage") String templateImage, @Param("authUserId") Integer authUserId);
+
+    void updateSelective(@Param("templateId") Integer templateId, @Param("templateImage") String templateImage, @Param("authUserId") Integer authUserId, @Param("status") Integer status, @Param("qrPosition") String qrPosition);
+}

+ 48 - 0
src/main/java/com/caimei/model/vo/TemplateListVo.java

@@ -0,0 +1,48 @@
+package com.caimei.model.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.Date;
+
+/**
+ * @author Aslee
+ * @date 2022/7/6
+ */
+@Data
+public class TemplateListVo {
+    /**
+     * 模板id
+     */
+    private Integer templateId;
+
+    /**
+     *供应商用户id
+     */
+    private Integer authUserId;
+
+    /**
+     *作为机构认证模板:1是,其余否
+     */
+    private Integer authFlag;
+
+    /**
+     *作为设备认证模板:1是,其余否
+     */
+    private Integer productFlag;
+
+    /**
+     * 二维码位置:top,left
+     */
+    private String qrPosition;
+
+    /**
+     * 状态:0停用,1启用
+     */
+    private Integer status;
+
+    /**
+     * 添加时间
+     */
+    private Date addTime;
+}

+ 38 - 0
src/main/java/com/caimei/service/auth/AuthTemplateService.java

@@ -0,0 +1,38 @@
+package com.caimei.service.auth;
+
+import com.caimei.model.ResponseJson;
+import com.caimei.model.vo.*;
+import com.github.pagehelper.PageInfo;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2022/7/6
+ */
+public interface AuthTemplateService {
+
+    /**
+     * 授权牌模板列表
+     * @param listType
+     * @param authUserId
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    ResponseJson<PageInfo<TemplateListVo>> getTemplateList(Integer listType, Integer authUserId, Integer pageNum, Integer pageSize);
+
+    /**
+     * 保存授权牌模板
+     *
+     * @param templateId
+     * @param templateImage
+     * @param authUserId
+     * @param status
+     * @param qrPosition
+     * @return
+     */
+    ResponseJson saveTemplate(Integer templateId, String templateImage, Integer authUserId, Integer status, String qrPosition);
+}
+
+

+ 168 - 0
src/main/java/com/caimei/service/auth/impl/AuthServiceImpl.java

@@ -452,6 +452,7 @@ public class AuthServiceImpl implements AuthService {
         }
     }
 
+
     private ResponseJson saveExcelData(String filePath, Integer authUserId, Integer createBy) {
         //判断是否为excel类型文件
         if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx")) {
@@ -460,6 +461,173 @@ public class AuthServiceImpl implements AuthService {
         // 获取供应商品牌
         List<String> shopBrands = shopService.getShopBrands(authUserId);
 
+        // 授权列表
+        List<CmBrandAuthPo> authImportList = new ArrayList<>();
+
+        try {
+            FileInputStream fis = new FileInputStream(filePath);
+            // 得到表格数据
+            XSSFWorkbook workbook = new XSSFWorkbook(fis);
+
+            //得到第一个工作表(机构表)
+            XSSFSheet authPartySheet = workbook.getSheetAt(0);
+            //获得表头
+            Row rowHead = authPartySheet.getRow(0);
+            //判断表头是否正确
+            if (7 != rowHead.getLastCellNum() || !"机构名称".equals(rowHead.getCell(0).getStringCellValue())) {
+                return ResponseJson.error("授权机构表格式错误");
+            }
+            // 获得数据的总行数
+            int authPartyRowNum = authPartySheet.getLastRowNum();
+
+            //获得所有数据
+            for (int i = 1; i <= authPartyRowNum; i++) {
+                //获得第i行对象
+                Row authPartyRow = authPartySheet.getRow(i);
+                // 校验机构名称
+                String authParty = authPartyRow.getCell(0).getStringCellValue();
+                if (StringUtils.isEmpty(authParty)) {
+                    return ResponseJson.error("第" + i + 1 + "行机构名称不能为空");
+                }
+                // 校验省市区
+                String area = authPartyRow.getCell(1).getStringCellValue();
+                if (StringUtils.isEmpty(area)) {
+                    return ResponseJson.error("第" + i + 1 + "行所在地区不能为空");
+                }
+                String[] areaSplit = area.split("/");
+                if (areaSplit.length < 2 || areaSplit.length > 3) {
+                    return ResponseJson.error("第" + i + 1 + "行所在地区格式错误");
+                }
+                // 省份
+                String provinceName = areaSplit[0];
+                if (StringUtils.isEmpty(provinceName)) {
+                    return ResponseJson.error("第" + i + 1 + "行省份不能为空");
+                }
+                if (provinceName.length() > 2) {
+                    provinceName = provinceName.substring(0, provinceName.length() - 1).trim();
+                }
+                Integer provinceId = authMapper.getProvinceId(provinceName);
+                // 市名
+                String cityName = areaSplit[1];
+                if (StringUtils.isEmpty(cityName)) {
+                    return ResponseJson.error("第" + i + 1 + "行市名不能为空");
+                }
+                if (cityName.length() > 2) {
+                    cityName = cityName.substring(0, cityName.length() - 1).trim();
+                }
+                Integer cityId = authMapper.getCityId(cityName);
+                // 区名
+                Integer townId = null;
+                if (areaSplit.length > 2) {
+                    String townName = areaSplit[2];
+                    if (StringUtils.isNotEmpty(townName) && townName.length() > 2) {
+                        townName = townName.substring(0, townName.length() - 1).trim();
+                    }
+                    List<TownPo> townList = authMapper.getTownList(townName);
+                    for (int j = 0; j < townList.size(); i++) {
+                        TownPo town = townList.get(j);
+                        if (null == townId) {
+                            if (null != cityId) {
+                                if (town.getCityId().equals(cityId)) {
+                                    townId = town.getTownId();
+                                }
+                            } else {
+                                Integer checkCityId = authMapper.getCityIdByTownId(town.getTownId());
+                                if (null != provinceId && null != checkCityId) {
+                                    Integer checkProvinceId = authMapper.getProvinceIdByCityId(cityId);
+                                    if (provinceId.equals(checkProvinceId)) {
+                                        cityId = checkCityId;
+                                        townId = town.getTownId();
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+                // 校验详细地址
+                String address = authPartyRow.getCell(2).getStringCellValue();
+                if (StringUtils.isEmpty(address)) {
+                    return ResponseJson.error("第" + i + 1 + "行所在地区不能为空");
+                }
+                // 校验经纬度
+                String lngAndLat = authPartyRow.getCell(3).getStringCellValue();
+                if (StringUtils.isEmpty(lngAndLat)) {
+                    return ResponseJson.error("第" + i + 1 + "行经纬度不能为空");
+                }
+                String[] split = lngAndLat.split(",");
+                if (2 != split.length) {
+                    return ResponseJson.error("第" + i + 1 + "行经纬度格式错误");
+                }
+                BigDecimal lng = new BigDecimal(split[0]);
+                BigDecimal lat = new BigDecimal(split[1]);
+                // 校验联系电话
+                String mobile = authPartyRow.getCell(4).getStringCellValue();
+                if (StringUtils.isEmpty(mobile)) {
+                    return ResponseJson.error("第" + i + 1 + "行联系电话不能为空");
+                }
+                // 校验员工人数
+                Integer empNum = null;
+                String empNumStr = authPartyRow.getCell(5).getStringCellValue();
+                if (StringUtils.isEmpty(empNumStr)) {
+                    return ResponseJson.error("第" + i + 1 + "行员工人数不能为空");
+                }
+                try {
+                    empNum = Integer.parseInt(empNumStr);
+                } catch (Exception e) {
+                    return ResponseJson.error("第" + i + 1 + "行员工人数格式错误");
+                }
+                // 校验店铺备注
+                String remarks = authPartyRow.getCell(6).getStringCellValue();
+                Integer customFlag = 0;
+                if (StringUtils.isNotEmpty(remarks)) {
+                    customFlag = 1;
+                }
+                CmBrandAuthPo authPo = new CmBrandAuthPo();
+                authPo.setAuthParty(authParty);
+                authPo.setProvinceId(provinceId);
+                authPo.setCityId(cityId);
+                authPo.setTownId(townId);
+                authPo.setAddress(address);
+                authPo.setLng(lng);
+                authPo.setLat(lat);
+                authPo.setMobile(mobile);
+                authPo.setEmpNum(empNum);
+                authPo.setCustomFlag(customFlag);
+                authPo.setRemarks(remarks);
+                authImportList.add(authPo);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseJson.error("导入失败,请检查表格数据");
+        } finally {
+            // 删除临时数据
+            File tempFile = new File(filePath);
+            boolean delete = tempFile.delete();
+            log.info("【图片上传】>>>>>>>>>>>>>>>>删除临时表格:" + delete);
+        }
+        // 保存授权数据
+        authImportList.forEach(authPo -> {
+            // 保存授权机构
+            CmBrandAuthPo auth = new CmBrandAuthPo();
+            auth.setAuthUserId(authUserId);
+            auth.setCreateBy(createBy);
+            // 导入数据
+            ResponseJson responseJson = saveAuth(auth, null, true, 1);
+        });
+        return ResponseJson.success("导入成功");
+    }
+
+    /**
+     * 已停用
+     */
+    private ResponseJson saveExcelDataBak(String filePath, Integer authUserId, Integer createBy) {
+        //判断是否为excel类型文件
+        if (!filePath.endsWith(".xls") && !filePath.endsWith(".xlsx")) {
+            System.out.println("文件不是excel类型");
+        }
+        // 获取供应商品牌
+        List<String> shopBrands = shopService.getShopBrands(authUserId);
+
         // 授权列表
         List<AuthImportPo> authImportList = new ArrayList<>();
 

+ 52 - 0
src/main/java/com/caimei/service/auth/impl/AuthTemplateServiceImpl.java

@@ -0,0 +1,52 @@
+package com.caimei.service.auth.impl;
+
+import com.caimei.mapper.cmMapper.AuthTemplateMapper;
+import com.caimei.model.ResponseJson;
+import com.caimei.model.vo.*;
+import com.caimei.service.auth.AuthTemplateService;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2022/7/6
+ */
+@Slf4j
+@Service
+public class AuthTemplateServiceImpl implements AuthTemplateService {
+
+    @Resource
+    private AuthTemplateMapper authTemplateMapper;
+
+    @Override
+    public ResponseJson<PageInfo<TemplateListVo>> getTemplateList(Integer listType, Integer authUserId, Integer pageNum, Integer pageSize) {
+        if (null == listType) {
+            return ResponseJson.error("列表类型不能为空", null);
+        }
+        if (2 == listType && null == authUserId) {
+            return ResponseJson.error("供应商用户id不能为空", null);
+        }
+        PageHelper.startPage(pageNum, pageSize);
+        List<TemplateListVo> templateList = authTemplateMapper.getTemplateList(listType, authUserId);
+        PageInfo<TemplateListVo> pageInfo = new PageInfo<>(templateList);
+        return ResponseJson.success(pageInfo);
+    }
+
+    @Override
+    public ResponseJson saveTemplate(Integer templateId, String templateImage, Integer authUserId, Integer status, String qrPosition) {
+        boolean insertFlag = null == templateId;
+        if (insertFlag) {
+            authTemplateMapper.insertTemplate(templateImage, authUserId);
+        } else {
+            authTemplateMapper.updateSelective(templateId, templateImage, authUserId, status, qrPosition);
+        }
+        return ResponseJson.success();
+    }
+}

+ 40 - 0
src/main/resources/mapper/AuthTemplateMapper.xml

@@ -0,0 +1,40 @@
+<?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.caimei.mapper.cmMapper.AuthTemplateMapper">
+    <insert id="insertTemplate">
+        insert into cm_brand_auth_template (authUserId, templateImage)
+        values (#{authUserId}, #{templateImage})
+    </insert>
+    <update id="updateSelective">
+        update cm_brand_auth_template
+        <set>
+            <if test="authUserId != null">
+                authUserId = #{authUserId},
+            </if>
+            <if test="templateImage != null and templateImage != ''">
+                templateImage = #{templateImage},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            <if test="qrPosition != null and qrPosition != ''">
+                qrPosition = #{qrPosition},
+            </if>
+        </set>
+        where id = #{templateId}
+    </update>
+
+    <select id="getTemplateList" resultType="com.caimei.model.vo.TemplateListVo">
+        select id as templateId,authUserId, templateImage, authFlag, productFlag, qrPosition, status, addTime
+        from cm_brand_auth_template
+        <where>
+            <if test="authUserId != null">
+                and authUserId = #{authUserId}
+            </if>
+            <if test="listType == 2">
+                and status = 1
+            </if>
+        </where>
+        order by addTime desc
+    </select>
+</mapper>