Browse Source

Merge remote-tracking branch 'origin/master'

liulingchao 4 years ago
parent
commit
08803d8059
17 changed files with 346 additions and 19 deletions
  1. 121 0
      dgtly-api/src/main/java/com/dgtly/api/controller/CommonController.java
  2. 62 2
      dgtly-api/src/main/java/com/dgtly/api/controller/SysCompanyController.java
  3. 2 1
      dgtly-api/src/main/java/com/dgtly/api/controller/SysNoticeInterface.java
  4. 2 2
      dgtly-api/src/main/resources/application-test.yml
  5. 8 2
      dgtly-goods/dgtly-goods-admin/src/main/java/com/dgtly/goods/controller/GoodsTypeController.java
  6. 3 4
      dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/type/add.html
  7. 23 0
      dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/type/type.html
  8. 9 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/mapper/GoodsInfoMapper.java
  9. 9 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/IGoodsInfoService.java
  10. 12 0
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsInfoServiceImpl.java
  11. 24 1
      dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsTypeServiceImpl.java
  12. 12 0
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsInfoMapper.xml
  13. 1 1
      dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsTypeMapper.xml
  14. 1 0
      dgtly-member/dgtly-member-api/src/main/java/com/dgtly/member/controller/CaptchaController.java
  15. 1 0
      dgtly-member/dgtly-member-api/src/main/java/com/dgtly/member/controller/MemberInfoController.java
  16. 7 1
      dgtly-system/src/main/java/com/dgtly/system/service/ISysCompanyService.java
  17. 49 5
      dgtly-system/src/main/java/com/dgtly/system/service/impl/SysCompanyServiceImpl.java

+ 121 - 0
dgtly-api/src/main/java/com/dgtly/api/controller/CommonController.java

@@ -0,0 +1,121 @@
+package com.dgtly.api.controller;
+
+import com.dgtly.common.annotation.ApiNoCheckSign;
+import com.dgtly.common.annotation.ApiPassToken;
+import com.dgtly.common.config.Global;
+import com.dgtly.common.config.ServerConfig;
+import com.dgtly.common.constant.Constants;
+import com.dgtly.common.core.domain.AjaxResult;
+import com.dgtly.common.utils.StringUtils;
+import com.dgtly.common.utils.file.FileUploadUtils;
+import com.dgtly.common.utils.file.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 通用请求处理
+ * 
+ * @author ruoyi
+ */
+@ApiNoCheckSign
+@ApiPassToken
+@RestController("/common")
+public class CommonController
+{
+    private static final Logger log = LoggerFactory.getLogger(CommonController.class);
+
+    @Autowired
+    private ServerConfig serverConfig;
+
+    /**
+     * 通用下载请求
+     * 
+     * @param fileName 文件名称
+     * @param delete 是否删除
+     */
+    @GetMapping("download")
+    public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
+    {
+        try
+        {
+            if (!FileUtils.isValidFilename(fileName))
+            {
+                throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
+            }
+            String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
+            String filePath = Global.getDownloadPath() + fileName;
+
+            response.setCharacterEncoding("utf-8");
+            response.setContentType("multipart/form-data");
+            response.setHeader("Content-Disposition",
+                    "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, realFileName));
+            FileUtils.writeBytes(filePath, response.getOutputStream());
+            if (delete)
+            {
+                FileUtils.deleteFile(filePath);
+            }
+        }
+        catch (Exception e)
+        {
+            log.error("下载文件失败", e);
+        }
+    }
+
+    /**
+     * 通用上传请求
+     */
+    @PostMapping("/upload")
+    @ResponseBody
+    public AjaxResult uploadFile(MultipartFile file) throws Exception
+    {
+        try
+        {
+            // 上传文件路径
+            String filePath = Global.getUploadPath();
+            // 上传并返回新文件名称
+            String fileName = FileUploadUtils.upload(filePath, file);
+            String url = serverConfig.getUrl() + fileName;
+            AjaxResult ajax = AjaxResult.success();
+            ajax.putKV("fileName", fileName);
+            ajax.putKV("url", url);
+            return ajax;
+        }
+        catch (Exception e)
+        {
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
+
+    /**
+     * 本地资源通用下载
+     */
+    @GetMapping("/download/resource")
+    public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
+            throws Exception
+    {
+        // 本地资源路径
+        String localPath = Global.getProfile();
+        // 数据库资源地址
+        String downloadPath = localPath + StringUtils.substringAfter(resource, Constants.RESOURCE_PREFIX);
+        // 下载名称
+        String downloadName = StringUtils.substringAfterLast(downloadPath, "/");
+        response.setCharacterEncoding("utf-8");
+        response.setContentType("multipart/form-data");
+        response.setHeader("Content-Disposition",
+                "attachment;fileName=" + FileUtils.setFileDownloadHeader(request, downloadName));
+        FileUtils.writeBytes(downloadPath, response.getOutputStream());
+    }
+}

+ 62 - 2
dgtly-api/src/main/java/com/dgtly/api/controller/SysCompanyController.java

@@ -1,6 +1,8 @@
 package com.dgtly.api.controller;
 
+import com.dgtly.apiframework.util.TokenUtil;
 import com.dgtly.common.annotation.ApiPassToken;
+import com.dgtly.common.constant.UserConstants;
 import com.dgtly.common.core.controller.ApiBaseController;
 import com.dgtly.common.core.domain.AjaxResult;
 import com.dgtly.common.core.domain.ParameterObject;
@@ -8,8 +10,12 @@ import com.dgtly.common.core.domain.ResultType;
 import com.dgtly.companyext.domain.CompanyExtInfo;
 import com.dgtly.companyext.service.ICompanyExtInfoService;
 import com.dgtly.goods.domain.GoodsInfo;
+import com.dgtly.member.domain.MemberFollow;
+import com.dgtly.member.service.IMemberFollowService;
 import com.dgtly.system.domain.SysCompany;
+import com.dgtly.system.domain.SysUser;
 import com.dgtly.system.service.ISysCompanyService;
+import com.dgtly.system.service.ISysUserService;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -20,7 +26,7 @@ import org.springframework.web.bind.annotation.RestController;
 import java.util.List;
 
 @RestController
-@RequestMapping("/company/")
+@RequestMapping("/company")
 @ApiPassToken/* 不用验证token  方法上可用*/
 public class SysCompanyController extends ApiBaseController {
 
@@ -28,6 +34,12 @@ public class SysCompanyController extends ApiBaseController {
     @Autowired
     private ISysCompanyService companyService;
 
+    @Autowired
+    private ISysUserService userService;
+
+    @Autowired
+    private IMemberFollowService memberFollowService;
+
     @Autowired
     private ICompanyExtInfoService companyExtInfoService;
 
@@ -39,8 +51,20 @@ public class SysCompanyController extends ApiBaseController {
         obj.checkParameterNotNull("id");
         Long companyId = obj.getLong(" id");
         CompanyExtInfo  companyExtInfo =  companyExtInfoService.selectCompanyExtInfoByCompanyId(companyId);
+        int isFollow = 0;
+        /*判断用户是否关注商户*/
+        String memberId = TokenUtil.getTokenUserId();
+        if(memberId!=null){
+            MemberFollow mf= new MemberFollow();
+            mf.setCompanyId(companyId);
+            mf.setMemberId(Long.parseLong(memberId));
+            List<MemberFollow> mfList=  memberFollowService.selectMemberFollowList(mf);
+            if(mfList.size()>0){
+                isFollow=1;
+            }
+        }
         if(companyExtInfo!=null){
-            return AjaxResult.success(companyExtInfo);
+            return AjaxResult.success(companyExtInfo).putKV("isFollow",isFollow);
         }else{
             return AjaxResult.error(ResultType.NUll);
         }
@@ -55,4 +79,40 @@ public class SysCompanyController extends ApiBaseController {
         return AjaxResult.success().putKV("list",goodsInfos);
     }
 
+
+    @ApiOperation(value = "商家入驻")
+    @ApiImplicitParam(name = "params" , paramType = "body")
+    @PostMapping("/enter")
+    public Object enter(){
+        ParameterObject obj =  getParameterObject();
+        obj.checkParameterNotNull("loginName,phonenumber,companyName");
+
+        SysUser sysUser  = obj.parseBean(SysUser.class);
+
+        if (UserConstants.USER_NAME_NOT_UNIQUE.equals(userService.checkLoginNameUnique(sysUser.getLoginName())))
+        {
+            return AjaxResult.error(300,"新增用户'" + sysUser.getLoginName() + "'失败,登录账号已存在");
+        }
+        else if (UserConstants.USER_PHONE_NOT_UNIQUE.equals(userService.checkPhoneUnique(sysUser)))
+        {
+            return AjaxResult.error(301,"新增用户'" + sysUser.getLoginName() + "'失败,手机号码已存在");
+        }
+        else if (sysUser.getPassword().length() < UserConstants.PASSWORD_MIN_LENGTH
+                || sysUser.getPassword().length() > UserConstants.PASSWORD_MAX_LENGTH)
+        {
+            return  AjaxResult.error(302,"密码长度为6-19,请重新设置!!");
+        }
+
+
+
+        SysCompany sysCompany  = obj.parseBean(SysCompany.class);
+        CompanyExtInfo cei  = obj.parseBean(CompanyExtInfo.class);
+
+        companyService.apiAddCompany(sysUser,sysCompany,cei);
+
+
+
+        return AjaxResult.success();
+    }
+
 }

+ 2 - 1
dgtly-api/src/main/java/com/dgtly/api/controller/SysNoticeInterface.java

@@ -1,5 +1,6 @@
 package com.dgtly.api.controller;
 
+import com.dgtly.common.core.controller.ApiBaseController;
 import com.dgtly.common.core.controller.BaseController;
 import com.dgtly.common.core.domain.AjaxResult;
 import com.dgtly.common.utils.StringUtils;
@@ -23,7 +24,7 @@ import java.util.List;
   */
 @RestController
 @RequestMapping("/interface/notice")
-public class SysNoticeInterface extends BaseController {
+public class SysNoticeInterface extends ApiBaseController {
 
     @Autowired
     private ISysNoticeService sysNoticeService;

+ 2 - 2
dgtly-api/src/main/resources/application-test.yml

@@ -25,10 +25,10 @@ security:
 # 开发环境配置
 server:
   # 服务器的HTTP端口,默认为80
-  port: 8888
+  port: 9002
   servlet:
     # 应用的访问路径
-    context-path: /steelfurnitureAPI
+    context-path: /
   tomcat:
     # tomcat的URI编码
     uri-encoding: UTF-8

+ 8 - 2
dgtly-goods/dgtly-goods-admin/src/main/java/com/dgtly/goods/controller/GoodsTypeController.java

@@ -7,6 +7,8 @@ import com.dgtly.common.constant.UserConstants;
 import com.dgtly.common.core.domain.Ztree;
 import com.dgtly.common.utils.StringUtils;
 import com.dgtly.framework.util.ShiroUtils;
+import com.dgtly.goods.domain.GoodsInfo;
+import com.dgtly.goods.service.IGoodsInfoService;
 import com.dgtly.system.domain.SysDept;
 import com.dgtly.system.domain.SysMenu;
 import com.dgtly.system.domain.SysUser;
@@ -42,6 +44,9 @@ public class GoodsTypeController extends BaseController
     @Autowired
     private IGoodsTypeService goodsTypeService;
 
+    @Autowired
+    private IGoodsInfoService goodsInfoService;
+
 
 
     @RequiresPermissions("goods:type:view")
@@ -172,10 +177,11 @@ public class GoodsTypeController extends BaseController
         {
             return AjaxResult.error(300,"存在子菜单,不允许删除");
         }
-       /* if (menuService.selectCountRoleMenuByMenuId(id) > 0)
+
+        if (goodsInfoService.selectGoodsInfoCountByTypeId(id) > 0)
         {
             return AjaxResult.error(300,"分类已有商品,不允许删除");
-        }*/
+        }
         return toAjax(goodsTypeService.deleteGoodsTypeById(id));
     }
 

+ 3 - 4
dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/type/add.html

@@ -5,9 +5,9 @@
 </head>
 <body class="white-bg">
     <div class="wrapper wrapper-content animated fadeInRight ibox-content">
-        <input name="parentId" type="hidden" id="treeId" th:value="${type.id}"/>
         <form class="form-horizontal m" id="form-type-add" >
-            <div class="form-group">    
+            <div class="form-group">
+                <input name="parentId" type="hidden" id="treeId" th:value="${type.id}"/>
                 <label class="col-sm-3 control-label"><span style="color: red; ">*</span>类型名称:</label>
                 <div class="col-sm-8">
                     <input name="name" class="form-control" type="text" required>
@@ -100,8 +100,7 @@
                 $.operate.save(prefix + "/add", data);
             }
         }
-        function addAttribute() {
-        }
+
     </script>
 </body>
 </html>

+ 23 - 0
dgtly-goods/dgtly-goods-admin/src/main/resources/templates/goods/type/type.html

@@ -17,6 +17,7 @@
                             <li>
                                 <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                 <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
+
                             </li>
                         </ul>
                     </div>
@@ -33,6 +34,9 @@
                 <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="goods:type:remove">
                     <i class="fa fa-remove"></i> 删除
                 </a>
+                <a class="btn btn-info" id="expandAllBtn">
+                    <i class="fa fa-exchange"></i> 展开/折叠
+                </a>
             </div>
             <div class="col-sm-12 select-table table-striped">
                 <table id="bootstrap-tree-table"></table>
@@ -100,6 +104,25 @@
             };
             $.treeTable.init(options);
         });
+
+        // tree表格树 展开/折叠
+        var expandFlag;
+        $("#expandAllBtn").click(function() {
+            var dataExpand = $.common.isEmpty($.table._option.expandAll) ? true : $.table._option.expandAll;
+            expandFlag = $.common.isEmpty(expandFlag) ? dataExpand : expandFlag;
+            if (!expandFlag) {
+                $.bttTable.bootstrapTreeTable('expandAll');
+            } else {
+                $.bttTable.bootstrapTreeTable('collapseAll');
+            }
+            expandFlag = expandFlag ? false: true;
+        })
+        // 按下ESC按钮关闭弹层
+        $('body', document).on('keyup', function(e) {
+            if (e.which === 27) {
+                $.modal.closeAll();
+            }
+        });
     </script>
 </body>
 </html>

+ 9 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/mapper/GoodsInfoMapper.java

@@ -65,4 +65,13 @@ public interface GoodsInfoMapper
      * @return 结果
      */
     public List<GoodsInfo> selectGoodsInfoHotList();
+
+    /**
+     * @descption: 根据分类id查询商品数量包括小雷的
+     * @param:
+     * @return:
+     * @auther: qxp
+     * @date: 2020-2-25
+     */
+    public int selectGoodsInfoCountByTypeId(Long typeId);
 }

+ 9 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/IGoodsInfoService.java

@@ -66,4 +66,13 @@ public interface IGoodsInfoService
      * @return 结果
      */
     public List<GoodsInfo> selectGoodsInfoHotList();
+
+    /**
+     * @descption: 根据分类id查询商品数量包括小雷的
+     * @param:
+     * @return:
+     * @auther: qxp
+     * @date: 2020-2-25
+     */
+    public int selectGoodsInfoCountByTypeId(Long id);
 }

+ 12 - 0
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsInfoServiceImpl.java

@@ -144,4 +144,16 @@ public class GoodsInfoServiceImpl implements IGoodsInfoService
     public List<GoodsInfo> selectGoodsInfoHotList() {
         return goodsInfoMapper.selectGoodsInfoHotList();
     }
+
+    /**
+     * @descption: 根据分类id查询商品数量包括小雷的
+     * @param:
+     * @return:
+     * @auther: qxp
+     * @date: 2020-2-25
+     */
+    @Override
+    public int selectGoodsInfoCountByTypeId(Long id) {
+        return goodsInfoMapper.selectGoodsInfoCountByTypeId(id);
+    }
 }

+ 24 - 1
dgtly-goods/dgtly-goods-common/src/main/java/com/dgtly/goods/service/impl/GoodsTypeServiceImpl.java

@@ -3,10 +3,13 @@ package com.dgtly.goods.service.impl;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.dgtly.common.constant.UserConstants;
 import com.dgtly.common.core.domain.Ztree;
+import com.dgtly.common.exception.BusinessException;
 import com.dgtly.common.utils.DateUtils;
 import com.dgtly.goods.domain.GoodsTypeAttribute;
 import com.dgtly.goods.mapper.GoodsTypeAttributeMapper;
+import com.dgtly.system.domain.SysDept;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.dgtly.goods.mapper.GoodsTypeMapper;
@@ -69,7 +72,27 @@ public class GoodsTypeServiceImpl implements IGoodsTypeService
     {
         goodsType.setCreateTime(DateUtils.getNowDate());
         int i = goodsTypeMapper.insertGoodsType(goodsType);
-        goodsTypeAttributeMapper.batchAttribute(goodsType.getGoodsTypeAttributes(),goodsType.getId());
+        GoodsType type = goodsTypeMapper.selectGoodsTypeById(goodsType.getParentId());
+        GoodsType upType = new GoodsType();
+        if(i<1){
+            throw new RuntimeException("新增类型失败");
+        }
+        if(type!=null){
+            upType.setAncestors(type.getAncestors()+","+goodsType.getId());
+        }else{
+            upType.setAncestors(0+","+goodsType.getId());
+        }
+        upType.setId(goodsType.getId());
+        i = goodsTypeMapper.updateGoodsType(upType);
+        if(i<1){
+            throw new RuntimeException("新增类型失败");
+        }
+        if(goodsType.getGoodsTypeAttributes()!=null&&goodsType.getGoodsTypeAttributes().size()>0){
+            int num =goodsTypeAttributeMapper.batchAttribute(goodsType.getGoodsTypeAttributes(),goodsType.getId());
+            if(num<goodsType.getGoodsTypeAttributes().size()){
+                throw new RuntimeException("新增类型失败");
+            }
+        }
         return i  ;
     }
 

+ 12 - 0
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsInfoMapper.xml

@@ -196,5 +196,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by gi.create_time
         limit 0,10
     </select>
+
+
+    <select id="selectGoodsInfoCountByTypeId" parameterType="GoodsInfo" resultType="Integer">
+        select count(1)
+        from goods_info gi
+        left join goods_type gt on gt.id =gi.type_id
+        where
+            find_in_set(#{typeId} ,gt.ancestors )
+            and gi.del_flag = "0"
+            and gi.putaway_flag = "1"
+
+    </select>
     
 </mapper>

+ 1 - 1
dgtly-goods/dgtly-goods-common/src/main/resources/mapper/goods/GoodsTypeMapper.xml

@@ -103,7 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <where>
             <if test="name != null  and name != ''"> and name = #{name}</if>
             <if test="parentId != null "> and parent_id = #{parentId}</if>
-            <if test="ancestors != null  and ancestors != ''"> and ancestors like concat('%', #{ancestors}, '%')</if>
+            <if test="ancestors != null  and ancestors != ''"> and  find_in_set(#{ancestors} ,ancestors ) </if>
         </where>
     </select>
     

+ 1 - 0
dgtly-member/dgtly-member-api/src/main/java/com/dgtly/member/controller/CaptchaController.java

@@ -68,6 +68,7 @@ public class CaptchaController extends BaseController
                 bi = captchaProducer.createImage(capStr);
             }*/
             session.setAttribute(Constants.KAPTCHA_SESSION_KEY, code);
+            System.out.println("注册sessionId:"+session.getId());
             out = response.getOutputStream();
             ImageIO.write(bi, "jpg", out);
             out.flush();

+ 1 - 0
dgtly-member/dgtly-member-api/src/main/java/com/dgtly/member/controller/MemberInfoController.java

@@ -78,6 +78,7 @@ public class MemberInfoController extends ApiBaseController {
     @PostMapping("/memberLogin")
     public Object memberLogin(){
         ParameterObject obj =  getParameterObject();
+        System.out.println("登录sessionId:"+getSession().getId());
         MemberInfo memberInfo = obj.parseBean(MemberInfo.class);
        //获取验证码
         HttpServletRequest request = getRequest();

+ 7 - 1
dgtly-system/src/main/java/com/dgtly/system/service/ISysCompanyService.java

@@ -1,6 +1,7 @@
 package com.dgtly.system.service;
 
 import com.dgtly.common.core.domain.Ztree;
+import com.dgtly.companyext.domain.CompanyExtInfo;
 import com.dgtly.system.domain.SysCompany;
 import com.dgtly.system.domain.SysUser;
 
@@ -84,5 +85,10 @@ public interface ISysCompanyService
      */
     public List<SysCompany> selectCompanyHotList();
 
-
+    /**
+     * api商家入驻
+     * @param
+     * @return
+     */
+    public int apiAddCompany(SysUser sysUser, SysCompany sysCompany, CompanyExtInfo cei);
 }

+ 49 - 5
dgtly-system/src/main/java/com/dgtly/system/service/impl/SysCompanyServiceImpl.java

@@ -11,6 +11,8 @@ import com.dgtly.common.utils.DateUtils;
 import com.dgtly.common.utils.ShiroSaltUtil;
 import com.dgtly.common.utils.StringUtils;
 import com.dgtly.common.utils.security.EncryptPassWordClass;
+import com.dgtly.companyext.domain.CompanyExtInfo;
+import com.dgtly.companyext.mapper.CompanyExtInfoMapper;
 import com.dgtly.system.domain.SysDept;
 import com.dgtly.system.domain.SysUser;
 import com.dgtly.system.service.ISysConfigService;
@@ -44,6 +46,9 @@ public class SysCompanyServiceImpl implements ISysCompanyService
     @Autowired
     private ISysConfigService sysConfigService;
 
+    @Autowired
+    private CompanyExtInfoMapper companyExtInfoMapper;
+
     /**
      * 查询公司表
      * 
@@ -118,6 +123,7 @@ public class SysCompanyServiceImpl implements ISysCompanyService
         return sysCompanyMapper.deleteSysCompanyById(id);
     }
 
+
     @Override
     @Transactional
     public int addCompany(SysCompany sysCompany,SysUser user){
@@ -136,7 +142,7 @@ public class SysCompanyServiceImpl implements ISysCompanyService
         dept.setCompanyId(sysCompany.getId());
         dept.setDeptName(sysCompany.getCompanyName());
         /*父节点为100 总体结构*/
-        dept.setParentId(100L);
+        dept.setParentId(Long.parseLong(sysConfigService.selectConfigByKey("sys.dept.parentId")));
         dept.setCreateBy(sysCompany.getCreateBy());
         sysDeptService.insertDept(dept);
         //创建管理员账号
@@ -144,7 +150,7 @@ public class SysCompanyServiceImpl implements ISysCompanyService
         Long[] roles = {Long.parseLong(sysConfigService.selectConfigByKey("company.manager.roleId"))};
         user.setRoleIds(roles);
         user.setDeptId(dept.getDeptId());
-        user.setCompanyId(sysCompany.getId()+0l);
+        user.setCompanyId(sysCompany.getId());
         user.setSalt(ShiroSaltUtil.randomSalt());
         user.setPassword(EncryptPassWordClass.encryptPassword(user.getLoginName(), user.getPassword(), user.getSalt()));
         user.setCreateBy(sysCompany.getCreateBy());
@@ -155,7 +161,6 @@ public class SysCompanyServiceImpl implements ISysCompanyService
     @Override
     public List<Ztree> selectSysCompanyTree(SysCompany sysCompany) {
         List<SysCompany> companies=sysCompanyMapper.selectSysCompanyList(sysCompany);
-
         return initZtree(companies);
     }
 
@@ -169,9 +174,9 @@ public class SysCompanyServiceImpl implements ISysCompanyService
         return sysCompanyMapper.selectCompanyHotList();
     }
 
+
     public List<Ztree> initZtree(List<SysCompany> companies)
     {
-
         List<Ztree> ztrees = new ArrayList<Ztree>();
         for (SysCompany company : companies)
         {
@@ -182,10 +187,49 @@ public class SysCompanyServiceImpl implements ISysCompanyService
                 ztree.setpId(0L);
                 ztree.setName(company.getCompanyName());
                 ztree.setTitle(company.getCompanyName());
-
                 ztrees.add(ztree);
             }
         }
         return ztrees;
     }
+
+
+    /**
+     * API商户入驻
+     * @param
+     * @return
+     */
+    @Override
+    @Transactional
+    public int apiAddCompany(SysUser sysUser, SysCompany sysCompany, CompanyExtInfo companyExtInfo) {
+
+        sysCompanyMapper.insertSysCompany(sysCompany);
+        //创建公司主体部门
+        SysDept dept = new SysDept();
+        dept.setCompanyId(sysCompany.getId());
+        dept.setDeptName(sysCompany.getCompanyName());
+        /*父节点为100 总体结构*/
+        dept.setParentId(Long.parseLong(sysConfigService.selectConfigByKey("sys.dept.parentId")));
+        sysDeptService.insertDept(dept);
+        //创建管理员账号
+
+        if(sysUser.getSex()==null){
+            sysUser.setSex("1");
+        }
+        Long[] roles = {Long.parseLong(sysConfigService.selectConfigByKey("company.manager.roleId"))};
+        sysUser.setRoleIds(roles);
+        sysUser.setDeptId(dept.getDeptId());
+        sysUser.setCompanyId(sysCompany.getId());
+        sysUser.setSalt(ShiroSaltUtil.randomSalt());
+        sysUser.setPassword(EncryptPassWordClass.encryptPassword(sysUser.getLoginName(), sysUser.getPassword(), sysUser.getSalt()));
+        sysUserService.insertUser(sysUser);
+
+        companyExtInfo.setCompanyId(sysCompany.getId());
+        companyExtInfoMapper.insertCompanyExtInfo(companyExtInfo);
+        /*新增待审核记录*/
+
+
+        return 1;
+    }
+
 }