Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/jiwei/wlyy2.0 into dev

yeshijie 6 years ago
parent
commit
c57db04aac

+ 107 - 0
common/common-util/src/main/java/com/yihu/jw/util/security/RandomValidateCode.java

@ -0,0 +1,107 @@
package com.yihu.jw.util.security;
/**
 * Created by progr1mmer on 2018/2/5.
 */
import javax.imageio.ImageIO;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Random;
/**
 * @author Yingjie Chen
 * @date 2016/5/24
 */
public class RandomValidateCode {
    public static final String RANDOMCODEKEY = "RANDOMVALIDATECODEKEY";//放到session中的key
    private Random random = new Random();
    private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生的字符串
    private int width = 80;//图片宽
    private int height = 26;//图片高
    private int lineSize = 40;//干扰线数量
    private int stringNum = 4;//随机产生字符数量
    /*
     * 获得字体
     */
    private Font getFont(){
        return new Font("Fixedsys", Font.CENTER_BASELINE,18);
    }
    /*
     * 获得颜色
     */
    private Color getRandColor(int fc,int bc){
        if(fc > 255)
            fc = 255;
        if(bc > 255)
            bc = 255;
        int r = fc + random.nextInt(bc-fc-16);
        int g = fc + random.nextInt(bc-fc-14);
        int b = fc + random.nextInt(bc-fc-18);
        return new Color(r,g,b);
    }
    /**
     * 生成随机图片
     */
    public void getRandcode(HttpServletRequest request,
                            HttpServletResponse response) {
        HttpSession session = request.getSession();
        //BufferedImage类是具有缓冲区的Image类,Image类是用于描述图像信息的类
        BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_BGR);
        Graphics g = image.getGraphics();//产生Image对象的Graphics对象,改对象可以在图像上进行各种绘制操作
        g.fillRect(0, 0, width, height);
        g.setFont(new Font("Times New Roman",Font.ROMAN_BASELINE,18));
        g.setColor(getRandColor(110, 133));
        //绘制干扰线
        for(int i=0;i<=lineSize;i++){
            drowLine(g);
        }
        //绘制随机字符
        String randomString = "";
        for(int i = 1; i <= stringNum; i++){
            randomString= drowString(g, randomString,i);
        }
        session.removeAttribute(RANDOMCODEKEY);
        session.setAttribute(RANDOMCODEKEY, randomString);
        System.out.println(randomString);
        response.addCookie(new Cookie(RANDOMCODEKEY,randomString));
        g.dispose();
        try {
            ImageIO.write(image, "JPEG", response.getOutputStream());//将内存中的图片通过流动形式输出到客户端
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /*
     * 绘制字符串
     */
    private String drowString(Graphics g,String randomString,int i){
        g.setFont(getFont());
        g.setColor(new Color(random.nextInt(101),random.nextInt(111),random.nextInt(121)));
        String rand = String.valueOf(getRandomString(random.nextInt(randString.length())));
        randomString +=rand;
        g.translate(random.nextInt(3), random.nextInt(3));
        g.drawString(rand, 13*i, 16);
        return randomString;
    }
    /*
     * 绘制干扰线
     */
    private void drowLine(Graphics g){
        int x = random.nextInt(width);
        int y = random.nextInt(height);
        int xl = random.nextInt(13);
        int yl = random.nextInt(15);
        g.drawLine(x, y, x+xl, y+yl);
    }
    /*
     * 获取随机的字符
     */
    public String getRandomString(int num){
        return String.valueOf(randString.charAt(num));
    }
}

+ 48 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/LoginController.java

@ -7,6 +7,7 @@ import com.yihu.jw.healthyhouse.service.user.LoginService;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.util.security.RandomValidateCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -18,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.HashMap;
@ -60,6 +62,20 @@ public class LoginController extends EnvelopRestEndpoint {
    }
    @PostMapping("/captcha/check")
    @ApiOperation(value = "验证短信验证码")
    public Envelop checkCaptcha(
            HttpServletRequest request,
            @ApiParam(name = "clientId", value = "应用id", required = true)@RequestParam(required = true, name = "clientId") String clientId,
            @ApiParam(name = "username", value = "登录账号", required = true)@RequestParam(required = true, name = "username") String username,
            @ApiParam(name = "captcha", value = "短信验证码", required = true)@RequestParam(required = true, name = "captcha") String captcha) throws ManageException, ParseException {
        if (wlyyRedisVerifyCodeService.verification(clientId, username, captcha)) {
            return ObjEnvelop.getSuccess("验证码正确");
        } else {
            return ObjEnvelop.getError("验证码错误");
        }
    }
    @PostMapping("/mobile/login")
    @ApiOperation(value = "【普通用户】-手机登录注册")
    public ObjEnvelop<User> mobileLogin(
@ -146,5 +162,37 @@ public class LoginController extends EnvelopRestEndpoint {
        }
    }
    @GetMapping(value = "/getRandomImageCode")
    @ApiOperation(value = "修改密码时生成图形验证码",notes = "修改密码时生成图形验证码")
    public Envelop getImageCode (HttpServletRequest request, HttpServletResponse response)throws Exception{
        try {
            response.setContentType("image/jpeg");//设置相应类型,告诉浏览器输出的内容为图片
            response.setHeader("Pragma", "No-cache");//设置响应头信息,告诉浏览器不要缓存此内容
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expire", 0);
            RandomValidateCode randomValidateCode = new RandomValidateCode();
            randomValidateCode.getRandcode(request, response);//输出验证码图片方法
            return ObjEnvelop.getSuccess("获取验证码成功");
        } catch (Exception e) {
           return ObjEnvelop.getError("获取验证码失败");
        }
    }
    @PostMapping(value = "/checkRandomImageCode")
    @ApiOperation(value = "检验图片验证码",notes = "检验图片验证码")
    public Envelop checkImageCode(@ApiParam(name = "code",value = "输入的验证码")@RequestParam(value = "code",required = true)String code,
                                     HttpServletRequest request){
        if (StringUtils.isEmpty(code)){
            return ObjEnvelop.getError("请输入验证码!");
        }
        String codeRescource = String.valueOf(request.getSession().getAttribute(RandomValidateCode.RANDOMCODEKEY));
        if (code.toLowerCase().equals(codeRescource.toLowerCase())){
            request.getSession().removeAttribute(RandomValidateCode.RANDOMCODEKEY);
            return ObjEnvelop.getSuccess("验证码正确!");
        }else {
            return ObjEnvelop.getError("验证码错误!");
        }
    }
}

+ 1 - 2
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/facilities/FacilitiesController.java

@ -290,8 +290,7 @@ public class FacilitiesController extends EnvelopRestEndpoint {
    public ObjEnvelop importData(
            @ApiParam(name = "file", value = "文件", required = true)
            @RequestPart(value = "file") MultipartFile file,
            HttpServletRequest request,
            HttpServletResponse response) throws IOException, ManageException {
            HttpServletRequest request) throws IOException, ManageException {
        try {
            request.setCharacterEncoding("UTF-8");
            AExcelReader excelReader = new FacilityMsgReader();

+ 1 - 2
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/FacilityUsedRecordController.java

@ -201,8 +201,7 @@ public class FacilityUsedRecordController extends EnvelopRestEndpoint {
            //根据设施编码获取关联服务的名称
            String facilityCode = record.getFacilitieCode();
            List<FacilityServerRelation> facilityServerRelations = facilityServerRelationService.findByField("facilitieCode", facilityCode);
            List<String> services = facilityServerRelations.stream().map(FacilityServerRelation::getServiceName).collect(Collectors.toList());
            String servicesValue = Joiner.on("、").join(services);
            String servicesValue = facilityServerRelations.stream().map(FacilityServerRelation::getServiceName).collect(Collectors.joining("、"));
            record.setFacilityRelationServiceName(servicesValue);
            //根据记录获取评价记录
            NavigationServiceEvaluation comment = navigationServiceEvaluationService.findByUseRecordId(record.getId());

+ 45 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/controller/user/UserController.java

@ -2,6 +2,7 @@ package com.yihu.jw.healthyhouse.controller.user;
import com.yihu.jw.exception.business.ManageException;
import com.yihu.jw.healthyhouse.cache.WlyyRedisVerifyCodeService;
import com.yihu.jw.healthyhouse.constant.LoginInfo;
import com.yihu.jw.healthyhouse.model.facility.Facility;
import com.yihu.jw.healthyhouse.model.user.User;
import com.yihu.jw.healthyhouse.service.user.UserService;
@ -16,6 +17,7 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import jxl.write.Colour;
import jxl.write.WritableCellFormat;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.spi.ErrorCode;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
@ -159,6 +161,49 @@ public class UserController  extends EnvelopRestEndpoint {
        return ObjEnvelop.getSuccess("身份证认证完成!");
    }
    @GetMapping("/existence")
    @ApiOperation(value = "【管理员】-验证管理员是否存在")
    public Envelop existence(
            @ApiParam(name = "telephone", value = "管理员账号", required = true)@RequestParam(required = true, name = "telephone") String telephone  ) throws ManageException {
        boolean b = userService.checkManageUser(telephone);
        if (b) {
            return ObjEnvelop.getSuccess("该管理员账号存在!",b);
        }else {
            return ObjEnvelop.getSuccess("该管理员账号不存在!",b);
        }
    }
    @GetMapping("/findUserByPhoneOrName")
    @ApiOperation(value = "根据手机号或者用户查询用户",notes = "找回密码时验证")
    public Envelop findUserByPhoneOrName(
            @ApiParam(name = "loginName", value = "管理员登录账号", required = true)@RequestParam(required = true, name = "loginName") String loginName  ) throws ManageException {
        User user = userService.findByLoginCodeAndUserType(loginName, LoginInfo.USER_TYPE_SUPER_AdminManager);
        if (user != null) {
            return ObjEnvelop.getSuccess("该管理员账号存在!",user);
        }else {
            return ObjEnvelop.getSuccess("该管理员账号不存在!",user);
        }
    }
    @PostMapping(value = "/resetPassWord")
    @ApiOperation(value = "重设密码", notes = "根基传入的用户id和新的密码重设用户的密码")
    public ObjEnvelop resetPassWord(
            @ApiParam(name = "userId", value = "用户ID", defaultValue = "")
            @RequestParam(value = "userId") String userId,
            @ApiParam(name = "password", value = "密码", defaultValue = "")
            @RequestParam(value = "password") String password) {
        try {
            String resetPwd = userService.resetPwd(userId, password);
            return ObjEnvelop.getSuccess("重设密码成功",password);
        } catch (ManageException e) {
            return ObjEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping("/exportToExcel")
    @ApiOperation(value = "用户列表导出excel")

+ 1 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/dao/facility/FacilityDao.java

@ -18,7 +18,7 @@ public interface FacilityDao extends JpaRepository<Facility, String> {
    Facility findById(String id);
    Facility findByLongitudeAndLatitude(double longitude, double latitude);
    List<Facility> findByLongitudeAndLatitude(double longitude, double latitude);
    Facility findByCode(String code);

+ 20 - 0
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/model/user/User.java

@ -69,6 +69,10 @@ public class User extends UuidIdentityEntityWithOperator {
    @Column(name = "ijk_authentication")
    private String ijkAuthentication;//i健康认证
    @Column(name = "organization_code")
    private String organizationCode;//机构编码
    @Column(name = "organization_name")
    private String organizationName;//机构名称
    public String getLoginCode() {
        return loginCode;
@ -254,6 +258,22 @@ public class User extends UuidIdentityEntityWithOperator {
        this.ijkAuthentication = ijkAuthentication;
    }
    public String getOrganizationCode() {
        return organizationCode;
    }
    public void setOrganizationCode(String organizationCode) {
        this.organizationCode = organizationCode;
    }
    public String getOrganizationName() {
        return organizationName;
    }
    public void setOrganizationName(String organizationName) {
        this.organizationName = organizationName;
    }
    @Transient
    public String getAddress() {
        String address = "";

+ 3 - 2
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/facility/FacilityService.java

@ -57,8 +57,8 @@ public class FacilityService extends BaseJpaService<Facility, FacilityDao> {
    public boolean isHasFacility(double longitude,double latitude){
        boolean flag = false;
        Facility facility = facilityDao.findByLongitudeAndLatitude(longitude, latitude);
        if (facility!=null) {
        List<Facility> facilitys = facilityDao.findByLongitudeAndLatitude(longitude, latitude);
        if (facilitys!=null && facilitys.size()>0) {
            flag = true;
        }
        return flag;
@ -179,6 +179,7 @@ public class FacilityService extends BaseJpaService<Facility, FacilityDao> {
            facility.setCountyCode(townCode);
            facility.setCountyName(facilityMsg.getCounty());
            facility.setStreet(facilityMsg.getStreet());
            facility.setAddress( facilityMsg.getCity() + facilityMsg.getCounty() + facilityMsg.getStreet());
            facility.setStatus(facilityMsg.getStatus());
            facility.setOrgName(facilityMsg.getOrgName());
            facility.setServiceDay(facilityMsg.getServiceDate());

+ 43 - 1
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/UserService.java

@ -204,6 +204,13 @@ public class UserService extends BaseJpaService<User, UserDao> {
    }
    /**
     *  修改密码
     * @param userId    用户ID
     * @param oldPwd    原密码
     * @param newPwd    新密码
     * @throws ManageException
     */
    @Transactional
    public void updatePwd(String userId, String oldPwd,String newPwd) throws ManageException {
        User user = findById(userId);
@ -222,6 +229,26 @@ public class UserService extends BaseJpaService<User, UserDao> {
        userDao.save(user);
    }
    /**
     *  重设密码
     * @param userId    用户ID
     * @param newPwd    新密码
     * @throws ManageException
     */
    @Transactional
    public String resetPwd(String userId, String newPwd) throws ManageException {
        User user = findById(userId);
        if (user==null) {
            throw new ManageException("该账号不存在");
        }
        String password = MD5.GetMD5Code(newPwd + user.getSalt());
        user.setPassword(password);
        userDao.save(user);
        return newPwd;
    }
    @Transactional
    public void updateSecurePhone(String userId, String phone) throws ManageException {
        User user = findById(userId);
@ -276,7 +303,22 @@ public class UserService extends BaseJpaService<User, UserDao> {
        userDao.save(user1);
    }
   
    /**
     *  验证管理员是否存在
     * @param userCode   登录账号
     * @throws ManageException
     */
    public boolean checkManageUser(String userCode) throws ManageException {
        User user1 = findByLoginCodeAndUserType(userCode, LoginInfo.USER_TYPE_SUPER_AdminManager);
        if (user1==null) {
            return false;
        }else {
            return true;
        }
    }
    //excel中添加固定内容
    private void addStaticCell(Sheet sheet){
        //设置样式