Commit b4522db4 authored by ysongq's avatar ysongq

修改 添加用户

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