changhaoning 1 年間 前
コミット
65938b1abd

+ 24 - 0
src/main/java/com/dk/mdm/controller/mst/WxUserController.java

@@ -0,0 +1,24 @@
+package com.dk.mdm.controller.mst;
+
+import com.dk.mdm.model.pojo.mst.WxUser;
+import com.dk.common.controller.BaseController;
+import com.dk.common.service.BaseService;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RestController;
+import io.swagger.annotations.Api;
+import com.dk.mdm.service.mst.WxUserService;
+
+@Api(tags = "微信用户API接口")
+@RestController
+@RequestMapping("/wxUser")
+public class WxUserController{
+
+    public BaseService<WxUser> getService() {
+        return wxUserService;
+    }
+
+    @Autowired
+    private WxUserService wxUserService;
+
+}

+ 31 - 0
src/main/java/com/dk/mdm/mapper/mst/WxUserMapper.java

@@ -0,0 +1,31 @@
+package com.dk.mdm.mapper.mst;
+
+import com.dk.mdm.model.pojo.mst.WxUser;
+import com.dk.common.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+*  微信用户 Mapper
+*/
+@Repository
+public interface WxUserMapper extends BaseMapper<WxUser>{
+
+    /**
+     * @desc   : 通过手机号查询
+     * @author : 常皓宁
+     * @date   : 2024/4/30 17:06
+     */
+    WxUser getByPhone(@Param("userPhone") String userPhone);
+
+    /**
+     * @desc   : 更新微信用的公司
+     * @author : 常皓宁
+     * @date   : 2024/4/30 17:06
+     */
+    int updateCpid(@Param("userId") String userId, @Param("currentCp") Integer currentCp,@Param("joinedCps") List<Integer> joinedCps);
+
+}
+

+ 189 - 0
src/main/java/com/dk/mdm/mapper/mst/WxUserMapper.xml

@@ -0,0 +1,189 @@
+<?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.dk.mdm.mapper.mst.WxUserMapper">
+
+    <!-- 通用设置 -->
+    <!-- 通用查询列 -->
+    <sql id="Base_Column_List">
+        user_id, user_wxid, user_name, user_phone, user_pwd, current_cp, joined_cps, flg_valid, remarks, op_create_time, op_create_user_id, op_update_time, op_update_user_id, op_app_code, op_timestamp, op_db_user
+    </sql>
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.dk.mdm.model.pojo.mst.WxUser">
+        <id column="user_id" property="userId"/>
+                <result column="user_wxid" property="userWxid"/>
+                <result column="user_name" property="userName"/>
+                <result column="user_phone" property="userPhone"/>
+                <result column="user_pwd" property="userPwd"/>
+                <result column="current_cp" property="currentCp"/>
+                <result column="joined_cps" property="joinedCps" typeHandler="IntListTypeHandler"/>
+                <result column="flg_valid" property="flgValid"/>
+                <result column="remarks" property="remarks"/>
+            <result column="op_create_time" property="opCreateTime" typeHandler="TimestampTypeHandler"/>
+                <result column="op_create_user_id" property="opCreateUserId"/>
+            <result column="op_update_time" property="opUpdateTime" typeHandler="TimestampTypeHandler"/>
+                <result column="op_update_user_id" property="opUpdateUserId"/>
+                <result column="op_app_code" property="opAppCode"/>
+            <result column="op_timestamp" property="opTimestamp" typeHandler="TimestampTypeHandler"/>
+                <result column="op_db_user" property="opDbUser"/>
+    </resultMap>
+
+    <!-- 通用条件列 -->
+    <sql id="Condition">
+        <where>
+            <if test="userWxid != null and userWxid != ''">
+                AND user_wxid = #{userWxid}
+            </if>
+            <if test="userName != null and userName != ''">
+                AND user_name = #{userName}
+            </if>
+            <if test="userPhone != null and userPhone != ''">
+                AND user_phone = #{userPhone}
+            </if>
+            <if test="userPwd != null and userPwd != ''">
+                AND user_pwd = #{userPwd}
+            </if>
+            <if test="currentCp != null">
+                AND current_cp = #{currentCp}
+            </if>
+            <if test="joinedCps != null">
+                AND joined_cps = #{joinedCps}
+            </if>
+            <if test="flgValid != null">
+                AND flg_valid = #{flgValid}
+            </if>
+            <if test="remarks != null and remarks != ''">
+                AND remarks = #{remarks}
+            </if>
+            <if test="opCreateTime != null">
+                AND op_create_time = #{opCreateTime}
+            </if>
+            <if test="opCreateUserId != null">
+                AND op_create_user_id = #{opCreateUserId}
+            </if>
+            <if test="opUpdateTime != null">
+                AND op_update_time = #{opUpdateTime}
+            </if>
+            <if test="opUpdateUserId != null">
+                AND op_update_user_id = #{opUpdateUserId}
+            </if>
+            <if test="opAppCode != null and opAppCode != ''">
+                AND op_app_code = #{opAppCode}
+            </if>
+            <if test="opTimestamp != null">
+                AND op_timestamp = #{opTimestamp}
+            </if>
+            <if test="opDbUser != null and opDbUser != ''">
+                AND op_db_user = #{opDbUser}
+            </if>
+        </where>
+    </sql>
+
+    <sql id="idsForeach">
+        <!-- 根据主键userId批量操作 -->
+        WHERE user_id in
+        <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
+    </sql>
+
+    <!-- 查询表t_wx_user,(条件查询+分页)列表 -->
+    <select id="selectByCond" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_wx_user
+        <include refid="Condition"/>
+        <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
+            limit #{end} offset #{start}
+        </if>
+    </select>
+
+    <!-- 查询表t_wx_user,(条件查询)个数 -->
+    <select id="countByCond" resultType="Long">
+        SELECT
+        count(1)
+        FROM t_wx_user
+        <include refid="Condition"/>
+    </select>
+
+    <!-- 根据主键查询表t_wx_user的一行数据 -->
+    <select id="selectById" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_wx_user
+        WHERE user_id = #{userId}::uuid
+    </select>
+
+    <!-- 根据主键锁定表t_wx_user的一行数据 -->
+    <select id="selectByIdForUpdate" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_wx_user
+        WHERE user_id = #{userId}
+        for update
+    </select>
+
+    <!-- 根据主键锁定表t_wx_user的多行数据 -->
+    <select id="selectByIdsForUpdate" resultMap="BaseResultMap">
+        SELECT
+        <include refid="Base_Column_List"/>
+        FROM t_wx_user
+        <include refid="idsForeach"/>
+        for update
+    </select>
+
+    <insert id="insertBatch">
+        insert into t_wx_user
+        (
+        <trim suffixOverrides=",">
+            user_wxid,
+            user_name,
+            user_phone,
+            user_pwd,
+            current_cp,
+            joined_cps,
+            remarks,
+            op_app_code,
+        </trim>
+        )
+        values
+        <foreach collection="list" index="index" item="item" separator=",">
+            (
+            <trim suffixOverrides=",">
+                #{item.userWxid},
+                #{item.userName},
+                #{item.userPhone},
+                #{item.userPwd},
+                #{item.currentCp},
+                #{item.joinedCps},
+                #{item.remarks},
+                #{item.opAppCode},
+            </trim>
+            )
+        </foreach>
+    </insert>
+
+    <!-- 根据电话号码获取用户信息 -->
+    <select id="getByPhone" resultMap="BaseResultMap">
+        SELECT txu.user_id,
+               txu.user_wxid,
+               txu.user_name,
+               txu.user_phone,
+               txu.user_pwd,
+               txu.current_cp,
+               txu.flg_valid,
+               txu.joined_cps
+        FROM dkic_a.t_wx_user txu
+        where txu.user_phone = #{userPhone}
+          AND txu.flg_valid
+    </select>
+
+    <!--更新微信用的公司-->
+    <update id="updateCpid">
+        update dkic_a.t_wx_user set current_cp = #{currentCp}
+        <if test="joinedCps != null">
+            ,joined_cps = #{joinedCps,typeHandler=IntListTypeHandler}
+        </if>
+        where user_id = #{userId}::uuid
+    </update>
+</mapper>

+ 190 - 0
src/main/java/com/dk/mdm/model/pojo/mst/WxUser.java

@@ -0,0 +1,190 @@
+package com.dk.mdm.model.pojo.mst;
+
+import cn.afterturn.easypoi.excel.annotation.Excel;
+import com.baomidou.mybatisplus.annotation.*;
+import java.io.Serializable;
+
+import com.dk.common.infrastructure.annotaiton.ExportTitle;
+import com.dk.common.infrastructure.handler.*;
+import com.dk.common.model.pojo.PageInfo;
+import com.dk.mdm.model.response.mst.CompanyResponse;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.AllArgsConstructor;
+import lombok.NoArgsConstructor;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import com.alibaba.fastjson.JSONObject;
+
+import java.util.List;
+import java.time.LocalDateTime;
+
+/**
+ *  微信用户
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+@ExportTitle("微信用户")
+@TableName(value = "t_wx_user", autoResultMap = true)
+@ApiModel(value="实体类:微信用户", description="表名:t_wx_user")
+public class WxUser extends PageInfo<WxUser> implements Serializable {
+
+    /*
+     * 数据库字段
+     */
+
+    /**
+     * 用户ID
+     */
+    @TableId(value = "user_id", type = IdType.AUTO)
+    @ApiModelProperty(value = "用户ID")
+    @TableField(typeHandler = UuidTypeHandler.class)
+    private String userId;
+
+
+    /**
+     * 微信ID
+     */
+    @Excel(name = "微信ID")
+    @ApiModelProperty(value = "微信ID")
+    private String userWxid;
+
+
+    /**
+     * 用户名称 (首次登录为微信名,可以修改)
+     */
+    @Excel(name = "用户名称 (首次登录为微信名,可以修改)")
+    @ApiModelProperty(value = "用户名称 (首次登录为微信名,可以修改)")
+    private String userName;
+
+
+    /**
+     * 用户电话 (web端登录用(电话+密码),小程序登录更新)
+     */
+    @Excel(name = "用户电话 (web端登录用(电话+密码),小程序登录更新)")
+    @ApiModelProperty(value = "用户电话 (web端登录用(电话+密码),小程序登录更新)")
+    private String userPhone;
+
+
+    /**
+     * 登录密码 (web端登录用(电话+密码),小程序登录不验证)
+     */
+    @Excel(name = "登录密码 (web端登录用(电话+密码),小程序登录不验证)")
+    @ApiModelProperty(value = "登录密码 (web端登录用(电话+密码),小程序登录不验证)")
+    private String userPwd;
+
+
+    /**
+     * 当前公司
+     */
+    @Excel(name = "当前公司")
+    @ApiModelProperty(value = "当前公司")
+    private Integer currentCp;
+
+
+    /**
+     * 加入的公司
+     */
+    @Excel(name = "加入的公司")
+    @ApiModelProperty(value = "加入的公司")
+    @TableField(typeHandler = IntListTypeHandler.class)
+    private List<Integer> joinedCps;
+
+
+    /**
+     * 有效标识 (1:正常 0:停用)
+     */
+    @Excel(name = "有效标识 (1:正常 0:停用)")
+    @ApiModelProperty(value = "有效标识 (1:正常 0:停用)")
+    private Boolean flgValid;
+
+
+    /**
+     * 备注
+     */
+    @Excel(name = "备注")
+    @ApiModelProperty(value = "备注")
+    private String remarks;
+
+
+    /**
+     * 创建时间 (触发器自动处理)
+     */
+    @Excel(name = "创建时间 (触发器自动处理)", format = "yyyy-MM-dd HH:mm:ss", width = 20)
+    @ApiModelProperty(value = "创建时间 (触发器自动处理)")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField(typeHandler = TimestampTypeHandler.class)
+    private LocalDateTime opCreateTime;
+
+
+    /**
+     * 创建用户 (触发器自动处理)
+     */
+    @Excel(name = "创建用户 (触发器自动处理)")
+    @ApiModelProperty(value = "创建用户 (触发器自动处理)")
+    private Long opCreateUserId;
+
+
+    /**
+     * 修改时间 (触发器自动处理)
+     */
+    @Excel(name = "修改时间 (触发器自动处理)", format = "yyyy-MM-dd HH:mm:ss", width = 20)
+    @ApiModelProperty(value = "修改时间 (触发器自动处理)")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField(typeHandler = TimestampTypeHandler.class)
+    private LocalDateTime opUpdateTime;
+
+
+    /**
+     * 修改用户 (触发器自动处理)
+     */
+    @Excel(name = "修改用户 (触发器自动处理)")
+    @ApiModelProperty(value = "修改用户 (触发器自动处理)")
+    private Long opUpdateUserId;
+
+
+    /**
+     * 数据操作应用 (触发器自动处理)
+     */
+    @Excel(name = "数据操作应用 (触发器自动处理)")
+    @ApiModelProperty(value = "数据操作应用 (触发器自动处理)")
+    private String opAppCode;
+
+
+    /**
+     * 数据时间戳 (触发器自动处理)
+     */
+    @Excel(name = "数据时间戳 (触发器自动处理)")
+    @ApiModelProperty(value = "数据时间戳 (触发器自动处理)")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    @TableField(typeHandler = TimestampTypeHandler.class)
+    private LocalDateTime opTimestamp;
+
+
+    /**
+     * 数据操作数据库用户 (触发器自动处理)
+     */
+    @Excel(name = "数据操作数据库用户 (触发器自动处理)")
+    @ApiModelProperty(value = "数据操作数据库用户 (触发器自动处理)")
+    private String opDbUser;
+
+
+    /*
+     * 相关属性
+     * @TableField(exist = false)
+     */
+
+    /*
+     * 关联属性 + 查询条件
+     * @TableField(exist = false)
+     */
+
+
+    private static final long serialVersionUID = 1L;
+
+}

+ 45 - 33
src/main/java/com/dk/mdm/service/mst/CompanyService.java

@@ -18,11 +18,13 @@ import com.dk.common.response.ResponseResultVO;
 import com.dk.common.util.HaipHttpUtils;
 import com.dk.mdm.mapper.mst.OrgMapper;
 import com.dk.mdm.mapper.mst.UserMapper;
+import com.dk.mdm.mapper.mst.WxUserMapper;
 import com.dk.mdm.model.pojo.mst.Company;
 import com.dk.mdm.mapper.mst.CompanyMapper;
 import com.dk.common.service.BaseService;
 import com.dk.common.mapper.BaseMapper;
 import com.dk.mdm.model.pojo.mst.Org;
+import com.dk.mdm.model.pojo.mst.WxUser;
 import com.dk.mdm.model.query.mst.CompanyQuery;
 import com.dk.mdm.model.response.mst.CompanyResponse;
 import org.apache.commons.collections4.CollectionUtils;
@@ -57,7 +59,7 @@ public class CompanyService extends BaseService<Company> {
 	private CompanyMapper companyMapper;
 
 	@Autowired
-	private UserMapper userMapper;
+	private WxUserMapper wxuserMapper;
 
 	@Resource
 	private HaipHttpUtils haipHttpUtils;
@@ -153,38 +155,48 @@ public class CompanyService extends BaseService<Company> {
 
 
 		//新建微信用户
-
-		// 更新 创建商户用户的公司id
-		Integer cpId = company.getCpId();
-		List<Integer> cpIds = new ArrayList<>();
-		cpIds.add(cpId);
-		// 当天的userid可能 存在加入公司
-		//if (userLogin.getJoinedCps()!=null && userLogin.getJoinedCps().size() > 0){
-		//	cpIds.addAll(userLogin.getJoinedCps()) ;
-		//}
-		//userMapper.updateCpid(userLogin.getUserId(), cpId, cpIds);
-		//
-		//// 生成员工
-		//UserLogin userLogin = userMapper.selectById(company.getOwner());
-		//StaffVO staffVO = new StaffVO();
-		//staffVO.setWxUserId(userLogin.getUserId());
-		//staffVO.setCpId(company.getCpId());
-		//staffVO.setStaffName(userLogin.getUserPhone());
-		//staffVO.setStaffPhone(userLogin.getUserPhone());
-		//staffVO.setOrgId(orgResponse.getOrgId());
-		//
-		//// 注册商户时候插入员工
-		//StaffResponse staffResponse = new StaffResponse();
-		//JSONObject staffJsonObject = haipHttpUtils.doPostRequest(requestUrl, staffVO);
-		//// 如果没有成功返回,状态设置为待审
-		//if (staffJsonObject.get("code") == null || !ResponseCodeEnum.SUCCESS.getCode().equals(staffJsonObject.get("code"))) {
-		//	// 无用户
-		//	throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
-		//			ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
-		//} else {
-		//	Object data = staffJsonObject.get("data");
-		//	staffResponse = JSONObject.parseObject(JSONObject.toJSONString(data),StaffResponse.class);
-		//}
+		WxUser wxUser = wxuserMapper.getByPhone(company.getCpPhone());
+		WxUser newWxUser = new WxUser();
+		if (wxUser == null) {
+			//注册
+			List<Integer> joinedCps = new ArrayList<>();
+			joinedCps.add(company.getCpId());
+			newWxUser.setCurrentCp(company.getCpId());
+			newWxUser.setJoinedCps(joinedCps);
+			newWxUser.setUserName(company.getCpManager());
+			newWxUser.setUserPhone(company.getCpPhone());
+			wxuserMapper.insert(newWxUser);
+		} else {
+			// 更新 户用户的公司id
+			Integer cpId = company.getCpId();
+			List<Integer> cpIds = new ArrayList<>();
+			cpIds.add(cpId);
+			if (wxUser.getJoinedCps()!=null && wxUser.getJoinedCps().size() > 0){
+				cpIds.addAll(wxUser.getJoinedCps()) ;
+			}
+			wxuserMapper.updateCpid(wxUser.getUserId(), cpId, cpIds);
+		}
+		// 生成员工
+		StaffVO staffVO = new StaffVO();
+		//TODO: 获取新建或者更新的ID 得想想怎么弄
+		staffVO.setWxUserId(wxUser.getUserId());
+		staffVO.setCpId(company.getCpId());
+		staffVO.setStaffName(company.getCpManager());
+		staffVO.setStaffPhone(company.getCpPhone());
+		staffVO.setOrgId(orgResponse.getOrgId());
+
+		// 注册商户时候插入员工
+		StaffResponse staffResponse = new StaffResponse();
+		JSONObject staffJsonObject = haipHttpUtils.doPostRequest(requestUrl, staffVO);
+		// 如果没有成功返回,状态设置为待审
+		if (staffJsonObject.get("code") == null || !ResponseCodeEnum.SUCCESS.getCode().equals(staffJsonObject.get("code"))) {
+			// 无用户
+			throw new BaseBusinessException(ErrorCodeEnum.USER_REGISTER_ERROR.getCode(),
+					ErrorCodeEnum.USER_REGISTER_ERROR.getMessage());
+		} else {
+			Object data = staffJsonObject.get("data");
+			staffResponse = JSONObject.parseObject(JSONObject.toJSONString(data),StaffResponse.class);
+		}
 
 
 		// 生成员工权限 角色 仓库 等等。

+ 23 - 0
src/main/java/com/dk/mdm/service/mst/WxUserService.java

@@ -0,0 +1,23 @@
+package com.dk.mdm.service.mst;
+
+import com.dk.mdm.model.pojo.mst.WxUser;
+import com.dk.mdm.mapper.mst.WxUserMapper;
+import com.dk.common.service.BaseService;
+import com.dk.common.mapper.BaseMapper;
+import org.springframework.stereotype.Service;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+public class WxUserService extends BaseService<WxUser> {
+
+	@Override
+	public BaseMapper<WxUser> getRepository() {
+		return wxUserMapper;
+	}
+
+	@Autowired
+	private WxUserMapper wxUserMapper;
+
+}