Commit f29b89bd by duanhq

技工注册完善 by duanht 2019/2/28

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@17430 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent f9b90d2b
package com.glsx.publicservice.controller;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.HttpUtils;
import com.glsx.publicservice.util.SmsUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -25,60 +31,66 @@ import com.glsx.publicservice.service.CommonService;
import com.glsx.publicservice.util.fastdfs.FastDFSClientWrapper;
/**
*
* @author zhanghj
* @version 1.0.0
* @Title CommonController.java
* @Package com.glsx.publicservice.controller
* @Description TODO
* @author zhanghj
* @date 2019年2月16日 下午5:41:40
* @version 1.0.0
*/
@RestController
@RequestMapping(value="/common")
public class CommonController
{
@RequestMapping(value = "/common")
public class CommonController {
private static final Logger logger = LoggerFactory.getLogger(CommonController.class);
@Autowired
private CommonService commonService;
@RequestMapping(value="/sendVerificationCode", method={RequestMethod.GET, RequestMethod.POST})
public ResultObject sendVerificationCode(HttpServletRequest request, String phone){
Map<String, Object> result = new HashMap<String, Object>();
try{
if (StringUtil.isEmpty(phone)){
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
String verifyCode = commonService.sendVerificationCode(phone);
logger.info("手机号:" + phone + "的短信验证码:"+ verifyCode);
//result.put("verifyCode", verifyCode);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
} catch(RedisSystemException e){
logger.error("获取验证码redis异常" + e.getMessage(), e);
/*
* 测试环境redis连接总被重试异常重试
private CommonService commonService;
@RequestMapping(value = "/sendVerificationCode", method = {RequestMethod.GET, RequestMethod.POST})
public ResultObject sendVerificationCode(HttpServletRequest request, String phone) {
Map<String, Object> result = new HashMap<String, Object>();
try {
if (StringUtil.isEmpty(phone)) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
String verifyCode = commonService.sendVerificationCode(phone);
logger.info("手机号:" + phone + "的短信验证码:" + verifyCode);
//result.put("verifyCode", verifyCode);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
} catch (RedisSystemException e) {
logger.error("获取验证码redis异常" + e.getMessage(), e);
/*
* 测试环境redis连接总被重试异常重试
*/
String verifyCode = commonService.sendVerificationCode(phone);
logger.info("手机号:" + phone + "的短信验证码:"+ verifyCode);
result.put("verifyCode", verifyCode);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}catch(Exception e){
logger.error("获取验证码失败" + e.getMessage(), e);
return new ResultObject(ResultCodeEnum.ERROR.getCode(), ResultCodeEnum.ERROR.getMsg());
}
}
@AuthCheck
@RequestMapping(value="/uploadFile" , method = RequestMethod.POST)
public ResultObject uploadImage(@RequestParam("file")MultipartFile file, HttpServletRequest request) throws IOException{
String path = FastDFSClientWrapper.uploadFile(file);
logger.info("上传文件路径==" + path);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), path);
}
@RequestMapping(value="/upload", method=RequestMethod.GET)
public ModelAndView get(ModelAndView mv){
mv.setViewName("fileUpload");
return mv;
}
String verifyCode = commonService.sendVerificationCode(phone);
logger.info("手机号:" + phone + "的短信验证码:" + verifyCode);
result.put("verifyCode", verifyCode);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
} catch (Exception e) {
logger.error("获取验证码失败" + e.getMessage(), e);
return new ResultObject(ResultCodeEnum.ERROR.getCode(), ResultCodeEnum.ERROR.getMsg());
}
}
@AuthCheck
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public ResultObject uploadImage(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws IOException {
String path = FastDFSClientWrapper.uploadFile(file);
logger.info("上传文件路径==" + path);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), path);
}
@RequestMapping(value = "/upload", method = RequestMethod.GET)
public ModelAndView get(ModelAndView mv) {
mv.setViewName("fileUpload");
return mv;
}
@AuthCheck
@RequestMapping(value = "/sendSms", method = RequestMethod.POST)
public void sendSms(@RequestParam("phone") String phone) throws IOException {
SmsUtil smsUtil = new SmsUtil();
String msgContent = MessageFormat.format("您本次操作验证码为:{0},一分钟内有效。",phone);
smsUtil.send(phone, msgContent);
}
}
......@@ -129,7 +129,7 @@ public class UserController extends BaseController {
Map<String, Object> result = new HashMap<String, Object>(16);
PageHelper.startPage(page.getPageIndex(), page.getPageSize(), true);
//测试
userQueryVo.setUserId(0);
userQueryVo.setUserId(UserUtils.getUserId(request));
List<SysMechanic> list = sysUserService.getSysMechanicList(userQueryVo);
com.github.pagehelper.Page<SysMechanic> pages = (com.github.pagehelper.Page<SysMechanic>) list;
page.setTotalCount((int) pages.getTotal());
......@@ -251,7 +251,7 @@ public class UserController extends BaseController {
sysMechanic.setUserType(3);
sysMechanic.setUpdateBy(UserUtils.getUserName(request));
sysMechanic.setUpdateTime(DateUtil.getCurrentTime());
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), sysUserService.saveSysMechanic(sysMechanic));
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), sysUserService.saveSysMechanic(sysMechanic,UserUtils.getUserId(request)));
}
......
......@@ -58,4 +58,6 @@ public interface SysUserMapper {
List<SysOrganization> getAllLevel(@Param("id") Integer id);
List<SysUser> getMechanicByOrgId(UserQueryVo userQueryVo);
int insertServiceMechanic(@Param("currentUserId")Integer currentUserId, @Param("userId")Integer userId);
}
\ No newline at end of file
package com.glsx.usercenter.mapper;
import com.glsx.usercenter.pojo.user.SysUserServices;
import com.glsx.usercenter.pojo.user.SysUserServicesExample;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface SysUserServicesMapper {
long countByExample(SysUserServicesExample example);
int deleteByExample(SysUserServicesExample example);
int deleteByPrimaryKey(Integer id);
int insert(SysUserServices record);
int insertSelective(SysUserServices record);
List<SysUserServices> selectByExample(SysUserServicesExample example);
SysUserServices selectByPrimaryKey(Integer id);
int updateByExampleSelective(@Param("record") SysUserServices record, @Param("example") SysUserServicesExample example);
int updateByExample(@Param("record") SysUserServices record, @Param("example") SysUserServicesExample example);
int updateByPrimaryKeySelective(SysUserServices record);
int updateByPrimaryKey(SysUserServices record);
int deleteByUserIdAndServiceId(@Param(value = "userId") int userId, @Param(value = "item") String item);
}
\ No newline at end of file
......@@ -55,6 +55,11 @@ public class SysMechanic extends SysUser{
private Integer serviceType;
/**
*服务商Id (适用于技工手机注册)
*/
private Integer serviceId;
/**
*身份证号
*/
@NotBlank(message = "{param.not.null}", groups = {Default.class, GroupA.class})
......@@ -142,4 +147,12 @@ public class SysMechanic extends SysUser{
public void setSysUserImageList(List<SysUserImage> sysUserImageList) {
this.sysUserImageList = sysUserImageList;
}
public Integer getServiceId() {
return serviceId;
}
public void setServiceId(Integer serviceId) {
this.serviceId = serviceId;
}
}
......@@ -6,6 +6,7 @@ import com.glsx.usercenter.pojo.GroupA;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.groups.Default;
import java.io.Serializable;
import java.util.ArrayList;
......@@ -44,6 +45,7 @@ public class SysUser extends BaseModel implements Serializable{
* 手机号
*/
@NotBlank(message="{param.not.null}", groups={Default.class, GroupA.class})
@Size(min=11,max=11,message="手机格式不正确")
private String phoneNumber;
/**
......@@ -83,6 +85,11 @@ public class SysUser extends BaseModel implements Serializable{
private String serviceKey;
/**
*服务项信息
*/
private List<SysUserServices> userService = new ArrayList<>();
/**
*角色id
*/
@NotNull(message="{param.not.null}", groups={Default.class, GroupA.class})
......@@ -233,5 +240,13 @@ public class SysUser extends BaseModel implements Serializable{
public void setServiceKey(String serviceKey) {
this.serviceKey = serviceKey;
}
public List<SysUserServices> getUserService() {
return userService;
}
public void setUserService(List<SysUserServices> userService) {
this.userService = userService;
}
}
package com.glsx.usercenter.pojo.user;
import javax.validation.constraints.Size;
public class SysUserServices {
private Integer id;
private Integer userId;
/**
* 服务项key
*/
private String serviceKey;
/**
* 安装时间
*/
@Size(min=11,max=11,message="手机格式不正确")
private Integer installTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getServiceKey() {
return serviceKey;
}
public void setServiceKey(String serviceKey) {
this.serviceKey = serviceKey == null ? null : serviceKey.trim();
}
public Integer getInstallTime() {
return installTime;
}
public void setInstallTime(Integer installTime) {
this.installTime = installTime;
}
}
\ No newline at end of file
......@@ -95,13 +95,13 @@ public interface SysUserService {
int saveSysMerchant(SysMerchant sysMerchant);
/**
* @param sysMechanic
* @param sysMechanic,currentUserId
* @return int
* @author duanht
* @Title: save
* @Description: TODO 保存技工信息
*/
int saveSysMechanic(SysMechanic sysMechanic);
int saveSysMechanic(SysMechanic sysMechanic,Integer currentUserId);
/**
......
......@@ -10,7 +10,6 @@ import com.glsx.usercenter.mapper.*;
import com.glsx.usercenter.pojo.user.*;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.LockedAccountException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.crypto.hash.Md5Hash;
......@@ -193,6 +192,7 @@ public class SysUserServiceImpl implements SysUserService {
if (sysUser.getUserType() == 1) {
updateServiceItem(userId, sysUser);
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
......@@ -301,7 +301,7 @@ public class SysUserServiceImpl implements SysUserService {
@Override
@Transactional(rollbackFor = Exception.class)
public int saveSysMechanic(SysMechanic sysMechanic) {
public int saveSysMechanic(SysMechanic sysMechanic,Integer currentUserId) {
try {
Integer userId = null;
if (sysMechanic.getId() == null || sysMechanic.getId() == 0) {
......@@ -311,6 +311,8 @@ public class SysUserServiceImpl implements SysUserService {
sysMechanic.setMechanicStatus(1);
sysUserMapper.insertSysMechanic(sysMechanic);
userId = sysMechanic.getUserId();
//绑定服务商
sysUserMapper.insertServiceMechanic(currentUserId,userId);
} else {
//更新主表
sysUserMapper.updateByPrimaryKeySelective(sysMechanic);
......@@ -326,11 +328,6 @@ public class SysUserServiceImpl implements SysUserService {
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
//审核通过后发送短信给技工
if (sysMechanic.getMechanicStatus() == 2) {
String msgContent = MessageFormat.format("您本次操作验证码为:{0},一分钟内有效。",sysMechanic.getPhoneNumber());
//smsUtil.send(sysMechanic.getPhoneNumber(), msgContent);
}
return 1;
}
......@@ -359,15 +356,16 @@ public class SysUserServiceImpl implements SysUserService {
private void updateServiceItem(Integer userId, SysUser sysUser) {
logger.info(sysUser.getName() + "开始更新服务项");
//如果是更新角色和数据需要先删除原有的连接数据
for (String item : sysUser.getServiceKey().split(",")) {
for (SysUserServices sysUserServices : sysUser.getUserService()) {
if (userId == null) {
//根据user_id和服务项删除数据
sysUserServicesMapper.deleteByUserIdAndServiceId(sysUser.getUserId(), item);
sysUserServicesMapper.deleteByUserIdAndServiceId(sysUser.getUserId(), sysUserServices.getServiceKey());
}
SysUserServices sysUserServices = new SysUserServices();
sysUserServices.setUserId(sysUser.getUserId());
sysUserServices.setServiceKey(item);
sysUserServicesMapper.insert(sysUserServices);
SysUserServices userServices = new SysUserServices();
userServices.setUserId(sysUser.getUserId());
userServices.setServiceKey(sysUserServices.getServiceKey());
userServices.setInstallTime(sysUserServices.getInstallTime());
sysUserServicesMapper.insert(userServices);
}
logger.info("服务项更新成功");
}
......
......@@ -849,4 +849,9 @@
</if>
</select>
<insert id="insertServiceMechanic">
INSERT INTO sys_service_mechanic (service_id, mechanic_id)
VALUES (#{currentUserId,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER})
</insert>
</mapper>
\ No newline at end of file
<?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.glsx.usercenter.mapper.SysUserServicesMapper">
<resultMap id="BaseResultMap" type="com.glsx.usercenter.pojo.user.SysUserServices">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="user_id" jdbcType="INTEGER" property="userId" />
<result column="service_key" jdbcType="VARCHAR" property="serviceKey" />
<result column="install_time" jdbcType="INTEGER" property="installTime" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, user_id, service_key, install_time
</sql>
<select id="selectByExample" parameterType="com.glsx.usercenter.pojo.user.SysUserServicesExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
'false' as QUERYID,
<include refid="Base_Column_List" />
from sys_user_services
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from sys_user_services
where id = #{id,jdbcType=INTEGER}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from sys_user_services
where id = #{id,jdbcType=INTEGER}
</delete>
<delete id="deleteByExample" parameterType="com.glsx.usercenter.pojo.user.SysUserServicesExample">
delete from sys_user_services
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.glsx.usercenter.pojo.user.SysUserServices">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into sys_user_services (user_id, service_key, install_time
)
values (#{userId,jdbcType=INTEGER}, #{serviceKey,jdbcType=VARCHAR}, #{installTime,jdbcType=INTEGER}
)
</insert>
<insert id="insertSelective" parameterType="com.glsx.usercenter.pojo.user.SysUserServices">
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Integer">
SELECT LAST_INSERT_ID()
</selectKey>
insert into sys_user_services
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">
user_id,
</if>
<if test="serviceKey != null">
service_key,
</if>
<if test="installTime != null">
install_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">
#{userId,jdbcType=INTEGER},
</if>
<if test="serviceKey != null">
#{serviceKey,jdbcType=VARCHAR},
</if>
<if test="installTime != null">
#{installTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.glsx.usercenter.pojo.user.SysUserServicesExample" resultType="java.lang.Long">
select count(*) from sys_user_services
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update sys_user_services
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=INTEGER},
</if>
<if test="record.userId != null">
user_id = #{record.userId,jdbcType=INTEGER},
</if>
<if test="record.serviceKey != null">
service_key = #{record.serviceKey,jdbcType=VARCHAR},
</if>
<if test="record.installTime != null">
install_time = #{record.installTime,jdbcType=INTEGER},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update sys_user_services
set id = #{record.id,jdbcType=INTEGER},
user_id = #{record.userId,jdbcType=INTEGER},
service_key = #{record.serviceKey,jdbcType=VARCHAR},
install_time = #{record.installTime,jdbcType=INTEGER}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.glsx.usercenter.pojo.user.SysUserServices">
update sys_user_services
<set>
<if test="userId != null">
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="serviceKey != null">
service_key = #{serviceKey,jdbcType=VARCHAR},
</if>
<if test="installTime != null">
install_time = #{installTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<update id="updateByPrimaryKey" parameterType="com.glsx.usercenter.pojo.user.SysUserServices">
update sys_user_services
set user_id = #{userId,jdbcType=INTEGER},
service_key = #{serviceKey,jdbcType=VARCHAR},
install_time = #{installTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="deleteByUserIdAndServiceId">
DELETE FROM sys_user_services
WHERE user_id = #{userId,jdbcType=INTEGER} AND service_key = #{item,jdbcType=VARCHAR}
</delete>
</mapper>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!