¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.controller; |
| | | |
| | | import com.yuanchu.mom.pojo.Department; |
| | | import com.yuanchu.mom.service.DepartmentService; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.stereotype.Controller; |
| | | |
| | | /** |
| | | * <p> |
| | | * é¨é¨æç» å端æ§å¶å¨ |
| | | * </p> |
| | | * |
| | | * @author æ±èéµ·éç½ç»ç§ææéå
¬å¸ |
| | | * @since 2024-04-15 04:01:48 |
| | | */ |
| | | @Api(tags = "人åæç»") |
| | | @AllArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/department") |
| | | public class DepartmentController { |
| | | |
| | | DepartmentService departmentService; |
| | | |
| | | @ApiOperation(value = "æ·»å é¨é¨") |
| | | @PostMapping("/addDepartment") |
| | | public Result addDepartment(@RequestBody Department department){ |
| | | return Result.success(departmentService.addDepartment(department)); |
| | | } |
| | | |
| | | @ApiOperation(value = "è·åé¨é¨æ ") |
| | | @GetMapping("/selectDepartment") |
| | | public Result selectDepartment(){ |
| | | return Result.success(departmentService.selectDepartment()); |
| | | } |
| | | |
| | | @ApiOperation(value = "å é¤é¨é¨") |
| | | @PostMapping("/delDepartment") |
| | | public Result delDepartment(Integer id){ |
| | | return Result.success(departmentService.delDepartment(id)); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.dto; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | @Data |
| | | @AllArgsConstructor |
| | | public class DepartmentDto { |
| | | |
| | | private Integer id; |
| | | |
| | | private String name; |
| | | |
| | | private Integer fatherId; |
| | | |
| | | private List<DepartmentDto> children; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.mapper; |
| | | |
| | | import com.yuanchu.mom.dto.DepartmentDto; |
| | | import com.yuanchu.mom.pojo.Department; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * é¨é¨æç» Mapper æ¥å£ |
| | | * </p> |
| | | * |
| | | * @author æ±èéµ·éç½ç»ç§ææéå
¬å¸ |
| | | * @since 2024-04-15 04:01:48 |
| | | */ |
| | | public interface DepartmentMapper extends BaseMapper<Department> { |
| | | |
| | | |
| | | //è·åé¨é¨æ |
| | | List<Department> selectDepartment(); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.pojo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.FieldFill; |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import java.io.Serializable; |
| | | import java.time.LocalDateTime; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Getter; |
| | | import lombok.Setter; |
| | | |
| | | /** |
| | | * <p> |
| | | * é¨é¨æç» |
| | | * </p> |
| | | * |
| | | * @author æ±èéµ·éç½ç»ç§ææéå
¬å¸ |
| | | * @since 2024-04-15 04:01:48 |
| | | */ |
| | | @Getter |
| | | @Setter |
| | | @ApiModel(value = "Department对象", description = "é¨é¨æç»") |
| | | public class Department implements Serializable { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | |
| | | @ApiModelProperty("åç§°") |
| | | private String name; |
| | | |
| | | @ApiModelProperty("ç¶çº§id") |
| | | private Integer fatherId; |
| | | |
| | | private Integer createUser; |
| | | |
| | | @TableField(fill = FieldFill.INSERT) |
| | | private LocalDateTime createTime; |
| | | |
| | | private Integer updateUser; |
| | | |
| | | @TableField(fill = FieldFill.INSERT_UPDATE) |
| | | private LocalDateTime updateTime; |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.service; |
| | | |
| | | import com.yuanchu.mom.dto.DepartmentDto; |
| | | import com.yuanchu.mom.pojo.Department; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | | * é¨é¨æç» æå¡ç±» |
| | | * </p> |
| | | * |
| | | * @author æ±èéµ·éç½ç»ç§ææéå
¬å¸ |
| | | * @since 2024-04-15 04:01:48 |
| | | */ |
| | | public interface DepartmentService extends IService<Department> { |
| | | |
| | | //æ·»å é¨é¨ |
| | | int addDepartment(Department department); |
| | | |
| | | //è·åé¨é¨æ |
| | | List<DepartmentDto> selectDepartment(); |
| | | |
| | | //å é¤é¨é¨ |
| | | boolean delDepartment(Integer id); |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.yuanchu.mom.dto.DepartmentDto; |
| | | import com.yuanchu.mom.pojo.Department; |
| | | import com.yuanchu.mom.mapper.DepartmentMapper; |
| | | import com.yuanchu.mom.service.DepartmentService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.var; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.sql.Connection; |
| | | import java.sql.PreparedStatement; |
| | | import java.sql.SQLException; |
| | | import java.sql.Wrapper; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | | * é¨é¨æç» æå¡å®ç°ç±» |
| | | * </p> |
| | | * |
| | | * @author æ±èéµ·éç½ç»ç§ææéå
¬å¸ |
| | | * @since 2024-04-15 04:01:48 |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService { |
| | | |
| | | DepartmentMapper departmentMapper; |
| | | |
| | | |
| | | //æ·»å é¨é¨ |
| | | @Override |
| | | public int addDepartment(Department department) { |
| | | departmentMapper.insert(department); |
| | | return department.getId(); |
| | | } |
| | | |
| | | //è·åé¨é¨æ |
| | | @Override |
| | | public List<DepartmentDto> selectDepartment() { |
| | | List<Department> departments = departmentMapper.selectDepartment(); |
| | | // å设 resultSet æ¯ä»æ°æ®åºæ¥è¯¢è¿åçç»æé |
| | | List<DepartmentDto> departmentDtos = new ArrayList<>(); |
| | | Map<Integer, DepartmentDto> departmentMap = new HashMap<>(); |
| | | |
| | | for (Department department : departments) { |
| | | DepartmentDto departmentDto = new DepartmentDto(department.getId(), department.getName(), department.getFatherId(), new ArrayList<DepartmentDto>()); |
| | | departmentMap.put(department.getId(), departmentDto); |
| | | if (department.getFatherId() == null) { |
| | | // æ ¹é¨é¨ |
| | | departmentDtos.add(departmentDto); |
| | | } else { |
| | | // å°å½åé¨é¨æ·»å å°ç¶é¨é¨ç children åè¡¨ä¸ |
| | | DepartmentDto parent = departmentMap.get(department.getFatherId()); |
| | | if (parent != null) { |
| | | parent.getChildren().add(departmentDto); |
| | | } |
| | | } |
| | | } |
| | | return departmentDtos; |
| | | } |
| | | |
| | | //å é¤é¨é¨ |
| | | @Override |
| | | public boolean delDepartment(Integer id) { |
| | | //夿æ¯å¦æåç±»,ç´å°æ²¡æä¸ºæ¢ |
| | | List<Department> department = getDepartment(id); |
| | | return removeBatchByIds(department); |
| | | } |
| | | |
| | | |
| | | //夿æ¯å¦æåç±»,ç´å°æ²¡æä¸ºæ¢ |
| | | public List<Department> getDepartment(Integer id){ |
| | | List<Department> list = new ArrayList<>(); |
| | | Department depart = baseMapper.selectById(id); |
| | | list.add(depart); |
| | | List<Department> departments = baseMapper.selectList(Wrappers.<Department>lambdaQuery().eq(Department::getFatherId, id)); |
| | | if (ObjectUtils.isNotEmpty(departments)){ |
| | | list.addAll(departments); |
| | | for (Department department : departments){ |
| | | list.addAll(getDepartment(department.getId())); |
| | | } |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | <?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.yuanchu.mom.mapper.DepartmentMapper"> |
| | | <select id="selectDepartment" resultType="com.yuanchu.mom.pojo.Department"> |
| | | WITH RECURSIVE DepartmentHierarchy AS ( |
| | | SELECT id, name, father_id |
| | | FROM department |
| | | WHERE father_id IS NULL |
| | | |
| | | UNION ALL |
| | | |
| | | SELECT d.id, d.name, d.father_id |
| | | FROM department d |
| | | JOIN DepartmentHierarchy dh ON d.father_id = dh.id |
| | | ) |
| | | SELECT id, name, father_id |
| | | FROM DepartmentHierarchy; |
| | | </select> |
| | | </mapper> |
| | |
| | | // æ¼ç¤ºä¾åï¼æ§è¡ main æ¹æ³æ§å¶å°è¾å
¥æ¨¡å表åå车èªå¨çæå¯¹åºé¡¹ç®ç®å½ä¸ |
| | | public class CodeGenerator { |
| | | |
| | | public static String database_url = "jdbc:mysql://192.168.110.209:3306/mom_ocean?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai"; |
| | | public static String database_username = "user"; |
| | | public static String database_url = "jdbc:mysql://114.132.189.42:9004/center-lims?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8"; |
| | | public static String database_username = "root"; |
| | | public static String database_password= "123456"; |
| | | public static String author = "æ±èéµ·éç½ç»ç§ææéå
¬å¸"; |
| | | public static String model_name = "/inspect-server"; // å¦æä¸ºåå¸å¼å¡«å模ååç§°ï¼å¦æä¸æ¯åå¸å¼ä¸ºç©ºå³å¯ |
| | | public static String model_name = "/cnas-server"; // å¦æä¸ºåå¸å¼å¡«å模ååç§°ï¼å¦æä¸æ¯åå¸å¼ä¸ºç©ºå³å¯ |
| | | public static String setParent = "com.yuanchu.mom"; // å
è·¯å¾ |
| | | public static void main(String[] args) { |
| | | String projectPath = System.getProperty("user.dir"); |
| | |
| | | datasource: |
| | | type: com.alibaba.druid.pool.DruidDataSource |
| | | driverClassName: com.mysql.cj.jdbc.Driver |
| | | #url: jdbc:mysql://localhost:3306/center_lims?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 |
| | | url: jdbc:mysql://114.132.189.42:9004/center-lims?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT%2B8 |
| | | username: root |
| | | password: 123456 |
| | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.util.DigestUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | |
| | | private String code; |
| | | |
| | | /** |
| | | * ç¾åç
§çå°å |
| | | */ |
| | | @ValueTableShow(value = 12,name = "ç¾åç
§çå°å") |
| | | private String signatureUrl; |
| | | |
| | | /** |
| | | * èªèº«ç
§çå°å |
| | | */ |
| | | @ValueTableShow(value = 13,name = "èªèº«ç
§çå°å") |
| | | private String pictureUrl; |
| | | |
| | | } |
| | |
| | | package com.yuanchu.mom.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | | import com.yuanchu.mom.pojo.User; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.yuanchu.mom.common.GetLook; |
| | | import com.yuanchu.mom.common.PrintChina; |
| | | import com.yuanchu.mom.dto.UserPageDto; |
| | |
| | | import com.yuanchu.mom.service.UserService; |
| | | import com.yuanchu.mom.utils.Jwt; |
| | | import com.yuanchu.mom.utils.QueryWrappers; |
| | | import com.yuanchu.mom.vo.Result; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.DigestUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class UserServiceImp implements UserService { |
| | | |
| | | @Resource |
| | | UserMapper userMapper; |
| | | |
| | | @Resource |
| | | Jwt jwt; |
| | | |
| | | @Resource |
| | | private GetLook getLook; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public User selectUserByPwd(String account, String password) { |
| | | QueryWrapper<User> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("account", account).eq("password", DigestUtils.md5DigestAsHex(password.getBytes())).eq("state", 1); |
| | | List<User> list = userMapper.selectList(wrapper); |
| | | return list.size()>0?list.get(0):null; |
| | | return list.size() > 0 ? list.get(0) : null; |
| | | } |
| | | |
| | | //æ ¹æ®ç¨æ·idæ¥è¯¢ç¨æ·å |
| | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("head", PrintChina.printChina(UserPageDto.class)); |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectUserList"); |
| | | if(map1.get("look")==1) user.setCreateUser(map1.get("userId")); |
| | | if (map1.get("look") == 1) user.setCreateUser(map1.get("userId")); |
| | | map.put("body", userMapper.selectUserDtoPageList(page, QueryWrappers.queryWrappers(user))); |
| | | return map; |
| | | } |
| | |
| | | @Override |
| | | public User getUserNow() { |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId(null); |
| | | return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getId, map1.get("userId")).eq(User::getIsCustom, 1).select(User::getId,User::getCompany,User::getName,User::getCode)); |
| | | return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getId, map1.get("userId")).eq(User::getIsCustom, 1).select(User::getId, User::getCompany, User::getName, User::getCode)); |
| | | } |
| | | |
| | | @Override |
| | | public User getUserInfo() { |
| | | Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId(null); |
| | | return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getId, map1.get("userId")).select(User::getId,User::getCompany,User::getName,User::getCode)); |
| | | return userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getId, map1.get("userId")).select(User::getId, User::getCompany, User::getName, User::getCode)); |
| | | } |
| | | |
| | | @Override |
| | | public int upUserPassword(String oldPassword, String newPassWord) { |
| | | Map<String, Integer> map = getLook.selectPowerByMethodAndUserId(null); |
| | | User user = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getId, map.get("userId")).eq(User::getPassword, DigestUtils.md5DigestAsHex(oldPassword.getBytes())).select(User::getId)); |
| | | if(BeanUtil.isEmpty(user)){ |
| | | if (BeanUtil.isEmpty(user)) { |
| | | throw new ErrorException("å¯ç 䏿£ç¡®"); |
| | | } |
| | | user.setPassword(DigestUtils.md5DigestAsHex(newPassWord.getBytes())); |
| | | return userMapper.updateById(user); |
| | | } |
| | | |
| | | } |
| | |
| | | <mapper namespace="com.yuanchu.mom.mapper.UserMapper"> |
| | | <select id="selectUserDtoPageList" resultType="com.yuanchu.mom.dto.UserPageDto"> |
| | | select * from ( |
| | | select u1.id, u1.account, u1.name, u1.state, u1.create_time, u1.update_time, u1.create_user, u1.update_user, u1.age, u1.email, u1.phone, u1.department, u1.company, u1.address, u1.is_custom, u1.role_id, u2.name create_user_name, u3.name update_user_name, r.name role_name |
| | | from user u1 |
| | | left join user u2 on u2.id = u1.create_user |
| | | left join user u3 on u3.id = u1.update_user |
| | | left join role r on u1.role_id = r.id |
| | | select u1.id, u1.account, u1.name, u1.state, u1.create_time, u1.update_time, u1.create_user, u1.update_user, |
| | | u1.age, u1.email, u1.phone, u1.department, u1.company, u1.address, u1.is_custom, u1.role_id, u2.name |
| | | create_user_name, u3.name update_user_name, r.name role_name,u1.signature_url,u1.picture_url |
| | | from user u1 |
| | | left join user u2 on u2.id = u1.create_user |
| | | left join user u3 on u3.id = u1.update_user |
| | | left join role r on u1.role_id = r.id |
| | | ) a |
| | | <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''"> |
| | | ${ew.customSqlSegment} |
| | | </if> |
| | | </select> |
| | | <select id="getDeviceManager" resultType="com.yuanchu.mom.dto.UserPageDto"> |
| | | select id,name from user where state=1 |
| | | select id, name |
| | | from user |
| | | where state = 1 |
| | | </select> |
| | | </mapper> |