فهرست منبع

新增合作社的同时给合作社代表创建一个登陆后台的管理账号

李书文 1 سال پیش
والد
کامیت
4cffbcf04f

+ 8 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterface.java

@@ -82,4 +82,12 @@ public interface AdminInterface {
     @PostMapping("AppUser/rpc/createAppAccount")
     public void createAccount(@RequestBody AppUserCreateDTO createDTO);
 
+
+    /**
+     * 创建合作社代表后台管理账号
+     * @param dto
+     */
+    @PostMapping("admin/rpc/createAdmin")
+    public void createAdmin(@RequestBody AdminCreateDto dto);
+
 }

+ 5 - 0
sp-core/sp-api/src/main/java/com/pj/api/client/admin/AdminInterfaceFallback.java

@@ -80,6 +80,11 @@ public class AdminInterfaceFallback implements FallbackFactory<AdminInterface> {
 
             }
 
+            @Override
+            public void createAdmin(AdminCreateDto dto) {
+
+            }
+
         };
     }
 

+ 70 - 0
sp-core/sp-api/src/main/java/com/pj/api/dto/AdminCreateDto.java

@@ -0,0 +1,70 @@
+package com.pj.api.dto;
+
+import java.io.Serializable;
+
+public class AdminCreateDto implements Serializable {
+
+    /**
+     * 账号
+     */
+    private String name;
+    /**
+     * 所属互市ID
+     */
+    private Long tradeAreaId;
+
+    /**
+     * 类型(00=运营管理者,01=合作社)
+     */
+    private String type;
+
+
+    /**
+     * 密码,发短信生成
+     */
+    private String password;
+
+    /** 所属角色id */
+    public Integer roleId;
+
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public Long getTradeAreaId() {
+        return tradeAreaId;
+    }
+
+    public void setTradeAreaId(Long tradeAreaId) {
+        this.tradeAreaId = tradeAreaId;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+    public void setType(String type) {
+        this.type = type;
+    }
+
+    public Integer getRoleId() {
+        return roleId;
+    }
+
+    public void setRoleId(Integer roleId) {
+        this.roleId = roleId;
+    }
+}

+ 17 - 0
sp-service/level-one-server/src/main/java/com/pj/tb_cooperative/TbCooperativeService.java

@@ -1,11 +1,15 @@
 package com.pj.tb_cooperative;
 
+import cn.hutool.core.util.RandomUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.pj.api.consts.FeignFactory;
+import com.pj.api.dto.AdminCreateDto;
 import com.pj.api.dto.CooperativeDto;
 import com.pj.api.dto.HtCooperativeDto;
+import com.pj.current.config.SystemObject;
 import com.pj.current.satoken.StpUserUtil;
 import com.pj.enummj.DeleteStatus;
 import com.pj.tb_trade_area.TbTradeArea;
@@ -103,6 +107,19 @@ public class TbCooperativeService extends ServiceImpl<TbCooperativeMapper, TbCoo
             tbCooperative.setCreateTime(new Date());
             //新增
             boolean save = this.save(tbCooperative);
+            //新增的同时给合作社代表创建一个登陆后台的管理账号
+            if(save){
+                //随机生成6位密码
+                String code = RandomUtil.randomNumbers(6);
+                SystemObject.smsFactory.handler().sendSMS(cooperativeDto.getCorrepTel(), "您的密码是" + code + "。请及时修改密码");
+                AdminCreateDto dto=new AdminCreateDto();
+                dto.setTradeAreaId(Long.parseLong(cooperativeDto.getFieldCode()));
+                dto.setPassword(code);
+                dto.setName(cooperativeDto.getCorrepTel());
+                dto.setRoleId(99); //所属角色ID,当前是99
+                dto.setType("01");//类型(00=运营管理者,01=合作社)
+                FeignFactory.adminInterface.createAdmin(dto);
+            }
             return save;
         }
         tbCooperative.setName(cooperativeDto.getCorrepName());

+ 13 - 0
sp-service/sp-admin/src/main/java/com/pj/project4sp/admin/SpAdminController.java

@@ -2,7 +2,10 @@ package com.pj.project4sp.admin;
 
 import java.util.List;
 
+import com.pj.api.dto.AdminCreateDto;
+import com.pj.current.config.SystemObject;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -44,6 +47,16 @@ public class SpAdminController {
     }
 
     /**
+     *
+     * @param dto
+     * @return
+     */
+    @PostMapping("rpc/createAdmin")
+    AjaxJson createAdmin(AdminCreateDto dto) {
+        return AjaxJson.toAjax(spAdminService.createAdmin(dto));
+    }
+
+    /**
      * 删
      */
     @RequestMapping("delete")

+ 24 - 0
sp-service/sp-admin/src/main/java/com/pj/project4sp/admin/SpAdminService.java

@@ -1,5 +1,6 @@
 package com.pj.project4sp.admin;
 
+import com.pj.api.dto.AdminCreateDto;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -24,6 +25,29 @@ public class SpAdminService {
 	
 	@Autowired
 	SpAdminPasswordService spAdminPasswordService;
+
+
+	/**
+	 * 创建合作社代表后台管理账号
+	 * @param dto
+	 * @return
+	 */
+	boolean createAdmin(AdminCreateDto dto){
+		SpAdmin admin=spAdminMapper.getByName(dto.getName());
+		if(admin==null){
+			admin.setName(dto.getName());
+			admin.setType(dto.getType());//合作社
+			admin.setTradeAreaId(dto.getTradeAreaId());
+			admin.setRoleId(dto.getRoleId());//合作社角色ID
+			spAdminMapper.add(admin);
+			// 获取主键
+			long id = SP.publicMapper.getPrimarykey();
+			// 更改密码(md5与明文)
+			spAdminPasswordService.updatePassword(id,dto.getPassword());
+			return true;
+		}
+		return false;
+	}
 	
 	
 	/**