hr 4 rokov pred
rodič
commit
a08ef759f6

+ 167 - 0
src/main/java/com/imed/costaccount/common/constants/CommonConstant.java

@@ -0,0 +1,167 @@
+package com.imed.costaccount.common.constants;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @Description: 分隔符公共类
+ */
+public final class CommonConstant {
+    public CommonConstant() {
+    }
+
+    /**
+     * 分割符-分号
+     */
+    public static final String SEPARATOR_SEMICOLON = ";";
+
+    /**
+     * 分割符-右箭头
+     */
+    public static final String RIGHT_ARROWS = "→";
+
+    /**
+     * 分割符-分号
+     */
+    public static final String SEPARATOR_SEMICOLON_C = ";";
+
+    /**
+     * 分割符-冒号
+     */
+    public static final String SEPARATOR_NUMBER = ":";
+
+    /**
+     * 分割符-冒号
+     */
+    public static final String SEPARATOR_NUMBER_C = ":";
+
+    /**
+     *  分割符-下划线
+     */
+    public static final String SEPARATOR_UNDERLINE = "_";
+    /**
+     * 分割符-竖线
+     */
+    public static final String SEPARATOR_VERTICALLINE="\\|";
+
+    /**
+     * 分割符-逗号
+     */
+    public static final String SEPARATOR_COMMA = ",";
+
+    /**
+     * 分割符-逗号
+     */
+    public static final String SEPARATOR_COMMA_C = ",";
+
+
+    /**
+     * 分割符-反斜杠
+     */
+    public static final String SEPARATOR_BACKSLASH = "/";
+
+    /**
+     * 分割符-反斜杠
+     */
+    public static final String SEPARATOR_BACKSLASH_C = "、";
+
+    /**
+     * 分割符-横杠
+     */
+    public static final String SEPARATOR_WHIPPTREE = "-";
+
+
+    /**
+     * 分割符-波浪号
+     */
+    public static final String SEPARATOR_WAVE = "~";
+
+    /**
+     * 分割符-分号
+     */
+    public static final String SEPARATOR_POINT = ".";
+
+    /**
+     * 分割符-分号
+     */
+    public static final String SEPARATOR_POINT_C = "。";
+
+    /**
+     * 分割符-空格
+     */
+    public static final String SEPARATOR_BlankSpace = " ";
+
+
+    /**
+     * 常量A
+     */
+    public static final String SEPARATOR_A = "A";
+    /**
+     * 左括号
+     */
+    public static final String LEFT_PARENTHESES = "(";
+    /**
+     * 左括号
+     */
+    public static final String LEFT_PARENTHESES_C = "(";
+    /**
+     * 右括号
+     */
+    public static final String RIGHT_PARENTHESES = ")";
+
+    /**
+     * 右括号
+     */
+    public static final String RIGHT_PARENTHESES_C = ")";
+    /**
+     * 导管表默认时间
+     */
+    public static final String ZERO_POINT = "0001-01-01 00:00:00";
+
+    /**
+     * 分隔符 - 乘号
+     */
+    public static final String MULTIPLICATION_SIGN = "×";
+
+
+    /**
+     * 分隔符 - 加号
+     */
+
+    public static final String MULTIPLICATION_PLUS = "\\+";
+
+    /**
+     * error
+     */
+    public static final String ERROR = "error";
+
+    /**
+     * UTF_8
+     */
+    public static final String UTF_8 = "UTF-8";
+
+    public static final String BLANK = " ";
+
+    /** 取消/作废 */
+    public static final Integer CANCEL = 1;
+    /** 正常 */
+    public static final Integer ENABLE = 0;
+
+    public static final String LIMIT_1 = "limit 1";
+
+    public static final String TOKEN = "token";
+
+    public static final String CHECK_PLAN_MSG_TITLE = "你有一个查核计划即将开始";
+
+    public static final String NULL = "";
+
+    public static final String X = "+";
+
+    public static final List<Integer> ADMIN = Arrays.asList(2, 5, 10);
+
+    public static final List<Integer> DEPT_MANAGER = Arrays.asList(1, 3, 12, 14, 16, 18);
+
+    public static final List<Integer> IMPROVER = Arrays.asList(4, 6, 7, 8, 9, 11, 13, 15);
+
+    public static final String NOT_APPLICABLE_NAME = "不适用";
+}

+ 43 - 0
src/main/java/com/imed/costaccount/common/constants/FileConstant.java

@@ -0,0 +1,43 @@
+package com.imed.costaccount.common.constants;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 文件名常量
+ */
+public final class FileConstant {
+    public FileConstant() {
+    }
+
+    /**
+     * 图片后缀名
+     */
+    public static final List<String> PIC_SUFFIX = Arrays.asList(new String[]{"jpeg", "gif", "png", "ico", "jpg"});
+    /**
+     * excel后缀名
+     */
+    public static final List<String> EXCEL_SUFFIX = Arrays.asList(new String[]{"xls", "xlsx"});
+    /**
+     * word后缀名
+     */
+    public static final List<String> WORD_SUFFIX = Arrays.asList(new String[]{"doc", "docx"});
+    /**
+     * ppt后缀名
+     */
+    public static final List<String> PPT_SUFFIX = Arrays.asList(new String[]{"ppt", "pptx"});
+    /**
+     * pdf后缀名
+     */
+    public static final String PDF_SUFFIX = "pdf";
+    /**
+     * txt后缀名
+     */
+    public static final String TXT_SUFFIX = "txt";
+
+    /**
+     * mp4后缀名
+     */
+    public static final String MP4_SUFFIX = "mp4";
+
+}

+ 100 - 0
src/main/java/com/imed/costaccount/common/constants/NumberConstant.java

@@ -0,0 +1,100 @@
+package com.imed.costaccount.common.constants;
+
+/**
+ * 数字设置
+ */
+public final class NumberConstant {
+    public NumberConstant() {
+    }
+
+    /**
+     * 零
+     */
+    public static final Integer ZERO = 0;
+
+    /**
+     * 一
+     */
+    public static final Integer ONE = 1;
+
+    /**
+     * 二
+     */
+    public static final Integer TWO = 2;
+
+    /**
+     * 三
+     */
+    public static final Integer THREE = 3;
+
+    /**
+     * 四
+     */
+    public static final Integer FOUR = 4;
+
+    /**
+     * 五
+     */
+    public static final Integer FIVE = 5;
+
+    /**
+     * 六
+     */
+    public static final Integer SIX = 6;
+
+    /**
+     * 七
+     */
+    public static final Integer SEVEN = 7;
+
+    /**
+     * 八
+     */
+    public static final Integer EIGHT = 8;
+
+    /**
+     * 九
+     */
+    public static final Integer NINE = 9;
+
+    /**
+     * 10
+     */
+    public static final Integer TEN = 10;
+
+    /**
+     * 二十四
+     */
+    public static final Integer TWENTY_FOUR = 24;
+
+    /**
+     * 三十
+     */
+    public static final Integer THIRTY = 30;
+
+    /**
+     * 五十八
+     */
+    public static final Integer FIFTY_EIGHT = 58;
+
+    /**
+     * 五十九
+     */
+    public static final Integer FIFTY_NINE = 59;
+
+    /**
+     * 一百
+     */
+    public static final Integer ONE_HUNDRED = 100;
+    /**
+     * 一千
+     */
+    public static final Integer ONE_THOUSAND = 1000;
+
+    /**
+     * 负一
+     */
+    public static final Integer NEGATIVE = -1;
+
+
+}

+ 10 - 0
src/main/java/com/imed/costaccount/common/constants/RedisKeyConstant.java

@@ -0,0 +1,10 @@
+package com.imed.costaccount.common.constants;
+
+/**
+ * @Description: redis key
+ */
+public final class RedisKeyConstant {
+    public RedisKeyConstant() {
+    }
+
+}

+ 32 - 0
src/main/java/com/imed/costaccount/common/exception/CostException.java

@@ -0,0 +1,32 @@
+package com.imed.costaccount.common.exception;
+
+import com.imed.costaccount.common.constants.CommonConstant;
+
+public class CostException extends RuntimeException{
+
+    private String code;
+
+    private String message;
+
+    public CostException(String code, String message) {
+        super(message);
+        this.code = code;
+        this.message = message;
+    }
+
+    public CostException(String message) {
+        super(message);
+        this.code = CommonConstant.ERROR;
+        this.message = message;
+    }
+
+
+    public String getCode() {
+        return code;
+    }
+
+    @Override
+    public String getMessage() {
+        return message;
+    }
+}

+ 69 - 0
src/main/java/com/imed/costaccount/common/exception/ExceptionHandle.java

@@ -0,0 +1,69 @@
+package com.imed.costaccount.common.exception;
+
+import com.imed.costaccount.common.constants.CommonConstant;
+import com.imed.costaccount.common.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.dao.DataAccessException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.converter.HttpMessageConversionException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.MissingServletRequestParameterException;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/**
+ * 自定义异常信息
+ * TODO 建议加上@ResponseStatus
+ */
+@ControllerAdvice
+@Slf4j
+public class ExceptionHandle {
+
+    @ResponseBody
+    @ExceptionHandler(value = MethodArgumentNotValidException.class)
+    public Result handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
+        String msg = e.getBindingResult().getFieldError().getField() + CommonConstant.SEPARATOR_NUMBER + e.getBindingResult().getFieldError().getDefaultMessage();
+        log.error("参数校验失败:[{}]", msg);
+        return Result.errorMsg(500, msg);
+    }
+
+    @ResponseBody
+    @ExceptionHandler(value = MissingServletRequestParameterException.class)
+    public Result handleMethodArgumentNotValidException(MissingServletRequestParameterException e) {
+        log.error("参数校验失败:[{}]", e.getParameterName());
+        return Result.errorMsg(500, "参数错误" + CommonConstant.SEPARATOR_NUMBER + e.getParameterName());
+    }
+
+    @ResponseBody
+    @ResponseStatus(HttpStatus.BAD_REQUEST)
+    @ExceptionHandler(value = HttpMessageConversionException.class)
+    public Result handleMissingServletRequestParameter(HttpMessageConversionException e) {
+        log.error("参数解析异常:{}", e.getMessage());
+        return Result.errorMsg(500, "参数解析异常");
+    }
+
+    @ExceptionHandler(value = CostException.class)
+    @ResponseBody
+    public Result handleCostException(CostException e) {
+        log.error("自定义异常:{}", e.getMessage(), e);
+        return Result.errorMsg(e.getMessage());
+    }
+
+    @ExceptionHandler(DataAccessException.class)
+    @ResponseBody
+    public Result handleDataAccessException(DataAccessException e) {
+        log.error("数据库错误:{}", e.getMessage(), e);
+        return Result.errorMsg("数据库错误");
+
+    }
+
+    @ExceptionHandler(Exception.class)
+    @ResponseBody
+    public Result handleException(Exception e) {
+        log.error("系统异常:{}", e.getMessage(), e);
+        return Result.errorMsg("系统异常");
+    }
+
+}

+ 1 - 1
src/main/java/com/imed/costaccount/common/shiro/ShiroConfig.java

@@ -38,7 +38,7 @@ public class ShiroConfig {
         filterMap.put("/webjars/**", "anon");
         filterMap.put("/druid/**", "anon");
         filterMap.put("/app/**", "anon");
-        filterMap.put("/sys/login", "anon");
+        filterMap.put("/costAccount/login", "anon");
         filterMap.put("/swagger/**", "anon");
         filterMap.put("/v2/api-docs", "anon");
         filterMap.put("/swagger-ui.html", "anon");

+ 24 - 0
src/main/java/com/imed/costaccount/model/dto/LoginDTO.java

@@ -0,0 +1,24 @@
+package com.imed.costaccount.model.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+@ApiModel("登录相关dto参数")
+public class LoginDTO {
+
+    @ApiModelProperty(name = "account", value = "账户")
+    @NotBlank(message = "账号不能为空")
+    private String account;
+
+    @ApiModelProperty(name = "password", value = "密码")
+    @NotBlank(message = "密码不能为空")
+    private String password;
+
+    @ApiModelProperty(name = "hospSign", value = "医院标识")
+    @NotBlank(message = "医院标识不为空")
+    private String hospSign;
+}

+ 4 - 0
src/main/java/com/imed/costaccount/model/vo/DemoVO.java

@@ -0,0 +1,4 @@
+package com.imed.costaccount.model.vo;
+
+public class DemoVO {
+}

+ 18 - 0
src/main/java/com/imed/costaccount/model/vo/LoginVO.java

@@ -0,0 +1,18 @@
+package com.imed.costaccount.model.vo;
+
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.*;
+
+@Getter
+@Setter
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+@ApiModel
+public class LoginVO {
+
+    @ApiModelProperty(name = "token",value = "登录返回jwt字符串")
+    private String token;
+}

+ 8 - 0
src/main/java/com/imed/costaccount/service/UserService.java

@@ -3,6 +3,8 @@ package com.imed.costaccount.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.LoginDTO;
+import com.imed.costaccount.model.vo.LoginVO;
 
 import java.util.Map;
 
@@ -16,5 +18,11 @@ import java.util.Map;
 public interface UserService extends IService<User> {
 
 
+    /**
+     * 登录接口
+     * @param loginDTO {@link LoginDTO} 登录相关参数
+     * @return
+     */
+    LoginVO login(LoginDTO loginDTO);
 }
 

+ 32 - 0
src/main/java/com/imed/costaccount/service/impl/UserServiceImpl.java

@@ -1,10 +1,20 @@
 package com.imed.costaccount.service.impl;
 
+import cn.hutool.crypto.SecureUtil;
+import cn.hutool.crypto.digest.MD5;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.imed.costaccount.common.exception.CostException;
+import com.imed.costaccount.common.token.JwtUtil;
 import com.imed.costaccount.common.util.PageUtils;
 import com.imed.costaccount.mapper.UserMapper;
 import com.imed.costaccount.model.User;
+import com.imed.costaccount.model.dto.LoginDTO;
+import com.imed.costaccount.model.vo.LoginVO;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import java.util.Map;
+import java.util.Objects;
+
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -14,6 +24,28 @@ import com.imed.costaccount.service.UserService;
 @Service("userService")
 public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
 
+    @Autowired
+    private JwtUtil jwtUtil;
 
+    @Override
+    public LoginVO login(LoginDTO loginDTO) {
+        String hospSign = loginDTO.getHospSign();
+        // todo 通过医院标识获取医院id
+        int hospId = 1;
+        User one = this.getOne(
+                new LambdaQueryWrapper<User>()
+                        .eq(User::getAccount, loginDTO.getAccount())
+                        .eq(User::getHospId, hospId)
+                        .last("limit 1")
+        );
+        if (Objects.isNull(one)) {
+            throw new CostException("用户不存在");
+        }
+        if (!SecureUtil.md5(loginDTO.getPassword()).equals(one.getPassword())) {
+            throw new CostException("密码错误");
+        }
+        String token = jwtUtil.createToken(one.getId());
 
+        return LoginVO.builder().token(token).build();
+    }
 }

+ 39 - 0
src/main/java/com/imed/costaccount/web/LoginController.java

@@ -0,0 +1,39 @@
+package com.imed.costaccount.web;
+
+import com.imed.costaccount.common.util.Result;
+import com.imed.costaccount.model.dto.LoginDTO;
+import com.imed.costaccount.model.vo.LoginVO;
+import com.imed.costaccount.service.UserService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.validation.Valid;
+
+@Api(tags = "登录相关模块")
+@RestController
+@RequestMapping("")
+public class LoginController {
+
+    private UserService userService;
+
+    public LoginController(UserService userService) {
+        this.userService = userService;
+    }
+
+
+    /**
+     * 登录接口
+     * @param loginDTO {@link LoginDTO} 登录相关参数
+     * @return
+     */
+    @PostMapping("/login")
+    @ApiOperation("登录操作")
+    public Result login(@RequestBody @Valid LoginDTO loginDTO) {
+        LoginVO loginVO = userService.login(loginDTO);
+        return Result.ok(loginVO);
+    }
+}