Commit b4522db4 authored by ysongq's avatar ysongq

修改 添加用户

parent 00cdbbef
...@@ -2,6 +2,7 @@ package com.jz.manage.moduls.controller.customer; ...@@ -2,6 +2,7 @@ package com.jz.manage.moduls.controller.customer;
import com.jz.common.bean.PageInfoResponse; import com.jz.common.bean.PageInfoResponse;
import com.jz.common.constant.Constants; import com.jz.common.constant.Constants;
import com.jz.common.constant.ResultMsg;
import com.jz.common.utils.Result; import com.jz.common.utils.Result;
import com.jz.common.utils.StatusCode; import com.jz.common.utils.StatusCode;
import com.jz.manage.moduls.controller.BaseController; import com.jz.manage.moduls.controller.BaseController;
...@@ -91,10 +92,11 @@ public class DepartmentController extends BaseController { ...@@ -91,10 +92,11 @@ public class DepartmentController extends BaseController {
@ApiModelProperty(value = "添加用户") @ApiModelProperty(value = "添加用户")
public Result add(@RequestBody SaveCustomerRequest saveCustomerRequest, HttpServletRequest req) throws Exception { public Result add(@RequestBody SaveCustomerRequest saveCustomerRequest, HttpServletRequest req) throws Exception {
if (saveCustomerRequest != null) { if (saveCustomerRequest != null) {
departmentService.add(saveCustomerRequest); Result result = departmentService.add(saveCustomerRequest);
return new Result<CompanyDetailsDto>(true, "添加用户成功!", StatusCode.OK); result.getMessage();
result.getCode();
return result;
} }
return new Result<CompanyDetailsDto>(false, "添加用户失败!", StatusCode.ERROR); return new Result<CompanyDetailsDto>(false, "添加用户失败!", StatusCode.ERROR);
} }
} }
\ No newline at end of file
package com.jz.manage.moduls.entity; package com.jz.manage.moduls.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
...@@ -19,6 +21,7 @@ public class MallCustomer implements Serializable { ...@@ -19,6 +21,7 @@ public class MallCustomer implements Serializable {
/** /**
* 用户id * 用户id
*/ */
@TableId(value = "customer_id", type = IdType.AUTO)
private Long customerId; private Long customerId;
/** /**
* 企业id * 企业id
......
package com.jz.manage.moduls.service; package com.jz.manage.moduls.service;
import com.jz.common.bean.PageInfoResponse; import com.jz.common.bean.PageInfoResponse;
import com.jz.common.utils.Result;
import com.jz.manage.moduls.controller.customer.bean.dto.CompanyDetailsDto; import com.jz.manage.moduls.controller.customer.bean.dto.CompanyDetailsDto;
import com.jz.manage.moduls.controller.customer.bean.dto.EnterpriseAuditDto; import com.jz.manage.moduls.controller.customer.bean.dto.EnterpriseAuditDto;
import com.jz.manage.moduls.controller.customer.bean.request.EnterpriseAuditRequest; import com.jz.manage.moduls.controller.customer.bean.request.EnterpriseAuditRequest;
...@@ -42,5 +43,5 @@ public interface DepartmentService { ...@@ -42,5 +43,5 @@ public interface DepartmentService {
* 添加用户 * 添加用户
* @param saveCustomerRequest * @param saveCustomerRequest
*/ */
void add(SaveCustomerRequest saveCustomerRequest); Result add(SaveCustomerRequest saveCustomerRequest);
} }
\ No newline at end of file
...@@ -9,8 +9,8 @@ import com.jz.common.constant.ResultCode; ...@@ -9,8 +9,8 @@ import com.jz.common.constant.ResultCode;
import com.jz.common.exception.ResponseException; import com.jz.common.exception.ResponseException;
import com.jz.common.utils.DateUtils; import com.jz.common.utils.DateUtils;
import com.jz.common.utils.Result;
import com.jz.manage.moduls.controller.customer.bean.dto.CompanyDetailsDto; import com.jz.manage.moduls.controller.customer.bean.dto.CompanyDetailsDto;
import com.jz.manage.moduls.controller.customer.bean.dto.CustomerDto;
import com.jz.manage.moduls.controller.customer.bean.dto.EnterpriseAuditDto; import com.jz.manage.moduls.controller.customer.bean.dto.EnterpriseAuditDto;
import com.jz.manage.moduls.controller.customer.bean.request.EnterpriseAuditRequest; import com.jz.manage.moduls.controller.customer.bean.request.EnterpriseAuditRequest;
...@@ -146,37 +146,44 @@ public class DepartmentServiceImpl implements DepartmentService { ...@@ -146,37 +146,44 @@ public class DepartmentServiceImpl implements DepartmentService {
* @param * @param
*/ */
@Override @Override
@Transactional @Transactional()
public void add(SaveCustomerRequest saveCustomerReq) { public Result add(SaveCustomerRequest saveCustomerReq) {
// 校验信息 // 校验信息
userCheck(saveCustomerReq); Result s = userCheck(saveCustomerReq);
boolean success = s.isSuccess();
if (!success) {
return Result.error("添加用户失败!");
}
// 保存企业信息 // 保存企业信息
saveCompany(saveCustomerReq); Long departmentId = saveCompany(saveCustomerReq);
if (departmentId != null) {
// 保存账号信息 // 保存账号信息
MallCustomer mallCustomer = new MallCustomer(); MallCustomer mallCustomer = new MallCustomer();
mallCustomer.setDepartmentId(departmentId);
mallCustomer.setCustomerAccount(saveCustomerReq.getCustomerAccount()); mallCustomer.setCustomerAccount(saveCustomerReq.getCustomerAccount());
mallCustomer.setCustomerPhone(saveCustomerReq.getCustomerPhone()); mallCustomer.setCustomerPhone(saveCustomerReq.getCustomerPhone());
mallCustomer.setPassword(saveCustomerReq.getPassword()); mallCustomer.setPassword(saveCustomerReq.getPassword());
mallCustomer.setCreTime(DateUtils.getToday()); mallCustomer.setCreTime(DateUtils.getToday());
mallCustomer.setCustomerPoint(0L);
mallCustomer.setCrePerson("1"); mallCustomer.setCrePerson("1");
mallCustomer.setDelFlag("N"); mallCustomer.setDelFlag("N");
mallCustomerDao.insert(mallCustomer); mallCustomerDao.insert(mallCustomer);
System.out.println(mallCustomer.getCustomerId());
// 如果充值金额不为空 // 如果充值金额不为空
if (saveCustomerReq.getBalanceMoney() != null) { if (saveCustomerReq.getBalanceMoney() != null) {
// 获取最新的企业id
Long departmentId = saveCustomerReq.getDepartmentId();
// 新增一条企业客户资产 // 新增一条企业客户资产
FinanceCustomerAssets assets = new FinanceCustomerAssets(); FinanceCustomerAssets assets = new FinanceCustomerAssets();
assets.setCrePerson(mallCustomer.getCustomerId() + "");
if (departmentId != null) { if (departmentId != null) {
try { try {
assets.setDepartmentId(departmentId); assets.setDepartmentId(departmentId);
assets.setUseMoney(saveCustomerReq.getBalanceMoney()); assets.setUseMoney(saveCustomerReq.getBalanceMoney());
assets.setTotalMoney(saveCustomerReq.getBalanceMoney()); assets.setTotalMoney(saveCustomerReq.getBalanceMoney());
assets.setCreTime(DateUtils.getToday()); assets.setCreTime(DateUtils.getToday());
assets.setCrePerson(String.valueOf(mallCustomer.getCustomerId())); assets.setCrePerson(mallCustomer.getCustomerId() + "");
int insert = financeCustomerAssetsDao.insert(assets); assets.setDelFlag("N");
System.out.println(insert); financeCustomerAssetsDao.insert(assets);
}catch (Exception e) { }catch (Exception e) {
throw ResponseException.of(ResultCode.FAILURE, "新增企业资产失败!"); throw ResponseException.of(ResultCode.FAILURE, "新增企业资产失败!");
} }
...@@ -189,9 +196,10 @@ public class DepartmentServiceImpl implements DepartmentService { ...@@ -189,9 +196,10 @@ public class DepartmentServiceImpl implements DepartmentService {
try{ try{
balance.setAssetsId(assetsId); balance.setAssetsId(assetsId);
balance.setBalanceMoney(saveCustomerReq.getBalanceMoney()); balance.setBalanceMoney(saveCustomerReq.getBalanceMoney());
balance.setCrePerson(String.valueOf(mallCustomer.getCustomerId())); balance.setCrePerson(mallCustomer.getCustomerId() + "");
balance.setCreTime(DateUtils.getToday()); balance.setCreTime(DateUtils.getToday());
balance.setAuditStatus("02"); balance.setAuditStatus("02");
balance.setDelFlag("N");
financeCustomerBalanceDao.insert(balance); financeCustomerBalanceDao.insert(balance);
}catch (Exception e) { }catch (Exception e) {
throw ResponseException.of(ResultCode.FAILURE, "新增充值记录失败!"); throw ResponseException.of(ResultCode.FAILURE, "新增充值记录失败!");
...@@ -199,12 +207,14 @@ public class DepartmentServiceImpl implements DepartmentService { ...@@ -199,12 +207,14 @@ public class DepartmentServiceImpl implements DepartmentService {
} }
} }
} }
return Result.of_success("添加用户成功!");
}
/** /**
* 保存企业信息 * 保存企业信息
* @param saveCustomerReq * @param saveCustomerReq
*/ */
private void saveCompany(SaveCustomerRequest saveCustomerReq) { private Long saveCompany(SaveCustomerRequest saveCustomerReq) {
Department department = new Department(); Department department = new Department();
// 添加创建人/创建时间 // 添加创建人/创建时间
department.setCrePerson("1"); department.setCrePerson("1");
...@@ -222,29 +232,39 @@ public class DepartmentServiceImpl implements DepartmentService { ...@@ -222,29 +232,39 @@ public class DepartmentServiceImpl implements DepartmentService {
department.setTelephone(saveCustomerReq.getTelephone()); department.setTelephone(saveCustomerReq.getTelephone());
// 已审核 // 已审核
department.setAuditStatus("02"); department.setAuditStatus("02");
tDepartmentDao.insert(department);
return department.getDepartmentId();
} }
/** /**
* 校验企业/账号是否存在 * 校验企业/账号是否存在
* @param saveCustomerReq * @param saveCustomerReq
*/ */
private void userCheck(SaveCustomerRequest saveCustomerReq) { private Result userCheck(SaveCustomerRequest saveCustomerReq) {
// 校验公司是否已存在 // 校验公司是否已存在
QueryWrapper queryWrapper = new QueryWrapper(); QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.eq("unified_credit_code", saveCustomerReq.getUnifiedCreditCode()); queryWrapper.eq("unified_credit_code", saveCustomerReq.getUnifiedCreditCode());
Department department = tDepartmentDao.selectOne(queryWrapper); Department department = tDepartmentDao.selectOne(queryWrapper);
// 如果为空 // 如果为空
if (department != null) { if (department != null) {
throw ResponseException.of(ResultCode.FAILURE, "公司已存在"); return Result.error("企业已存在!");
} }
// 校验账号信息 // 校验账号信息
Map<String, Object> map = new HashMap<>(); Map<String, Object> accountMap = new HashMap<>();
map.put("customerAccount", saveCustomerReq.getCustomerAccount()); accountMap.put("customerAccount", saveCustomerReq.getCustomerAccount());
map.put("customerPhone", saveCustomerReq.getCustomerPhone()); // 查询用户是否存在
MallCustomer accountUser = mallCustomerDao.selectByUser(accountMap);
if (accountUser != null) {
return Result.error("用户已存在!");
}
Map<String, Object> phoneMap = new HashMap<>();
phoneMap.put("customerPhone", saveCustomerReq.getCustomerPhone());
// 查询用户是否存在 // 查询用户是否存在
MallCustomer mallCustomer = mallCustomerDao.selectByUser(map); MallCustomer phoneUser = mallCustomerDao.selectByUser(phoneMap);
if (mallCustomer != null) { if (phoneUser != null) {
throw ResponseException.of(ResultCode.FAILURE, "用户已存在,请重新输入!"); return Result.error("用户已存在!");
} }
return Result.ok();
} }
} }
\ No newline at end of file
...@@ -91,11 +91,11 @@ ...@@ -91,11 +91,11 @@
</where> </where>
</select> </select>
<!--新增所有列--> <!--&lt;!&ndash;新增所有列&ndash;&gt;-->
<insert id="insert" keyProperty="customerId" useGeneratedKeys="true"> <!--<insert id="insert" keyProperty="customerId" useGeneratedKeys="true">-->
insert into t_mall_customer(department_id, password, customer_account, customer_name, customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag) <!--insert into t_mall_customer(department_id, password, customer_account, customer_name, customer_phone, customer_email, customer_address, customer_point, register_time, customer_level, identity_card, cre_time, upt_time, del_flag)-->
values (#{departmentId}, #{password}, #{customerAccount}, #{customerName}, #{customerPhone}, #{customerEmail}, #{customerAddress}, #{customerPoint}, #{registerTime}, #{customerLevel}, #{identityCard}, #{creTime}, #{uptTime}, #{delFlag}) <!--values (#{departmentId}, #{password}, #{customerAccount}, #{customerName}, #{customerPhone}, #{customerEmail}, #{customerAddress}, #{customerPoint}, #{registerTime}, #{customerLevel}, #{identityCard}, #{creTime}, #{uptTime}, #{delFlag})-->
</insert> <!--</insert>-->
<insert id="insertBatch" keyProperty="customerId" useGeneratedKeys="true"> <insert id="insertBatch" keyProperty="customerId" useGeneratedKeys="true">
insert into t_mall_customer(department_id, password, customer_account, customer_name, insert into t_mall_customer(department_id, password, customer_account, customer_name,
...@@ -175,13 +175,16 @@ ...@@ -175,13 +175,16 @@
customer_phone customer_phone
from t_mall_customer from t_mall_customer
where where
1=1 del_flag='N'
and del_flag='N' <if test="customerPhone != null and customerPhone != ''">
<if test="customerPhone != null">
and customer_phone = #{customerPhone} and customer_phone = #{customerPhone}
</if> </if>
<if test="customerAccount != null"> <if test="customerAccount != null and customerAccount != ''">
and customer_account = #{customerAccount}
</if>
<if test="customerPhone != null and customerAccount != null">
and customer_account = #{customerAccount} and customer_account = #{customerAccount}
and customer_phone = #{customerPhone}
</if> </if>
</select> </select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment