Commit 8ce5cd65 by HlQ

[add]

1.添加合同相关接口
2.添加资源树
[chg]修改钉钉内处理工单,token 的获取逻辑
1 parent f7285cc0
Showing 38 changed files with 409 additions and 226 deletions
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="FacetManager">
<facet type="Spring" name="Spring">
<configuration>
<fileset id="fileset" name="Spring Application Context" removed="false">
<file>file://$MODULE_DIR$/src/main/resources/application-dev.properties</file>
<file>file://$MODULE_DIR$/src/main/resources/application-pro.properties</file>
</fileset>
</configuration>
</facet>
</component>
</module>
\ No newline at end of file
package vion.advice;
import cn.dev33.satoken.exception.NotLoginException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
......@@ -48,21 +49,27 @@ public class ResBodyAdvice implements ResponseBodyAdvice<Object> {
}
@ExceptionHandler(Exception.class)
public Object exceptionHandler(Exception e) {
public ResultVO exceptionHandler(Exception e) {
log.error("接口调用出错", e);
return ResultUtil.error(e.getMessage());
}
@ExceptionHandler(IllegalArgumentException.class)
public Object argExceptionHandler(Exception e) {
public ResultVO argExceptionHandler(Exception e) {
log.error("参数异常", e);
return ResultUtil.error(e.getMessage());
}
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
public Object methodArgExceptionHandler(Exception e) {
public ResultVO methodArgExceptionHandler(Exception e) {
log.error("方法参数异常", e);
return ResultUtil.error("Method parameter error.");
}
@ExceptionHandler(NotLoginException.class)
public ResultVO notLoginExceptionHandler(Exception e) {
log.error("未登录", e);
return ResultUtil.error(401, "请重新登录");
}
}
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import vion.dto.ContractDTO;
import vion.model.RContractStore;
import vion.service.IContractService;
import vion.service.IRContractStoreService;
import vion.vo.ContractVO;
import java.util.List;
/**
* 合同管理
......@@ -14,6 +22,31 @@ import vion.service.IContractService;
public class ContractController {
private final IContractService contractService;
private final IRContractStoreService contractStoreService;
private final Converter converter;
@GetMapping("/contract")
@SaCheckPermission(value = "contract:list", orRole="admin")
public Page<ContractVO> list(ContractDTO dto) {
return contractService.list(dto);
}
@GetMapping("/contract/{id}")
@SaCheckPermission(value = "contract:query", orRole="admin")
public ContractVO getById(@PathVariable Long id) {
return converter.convert(contractService.getById(id), new ContractVO());
}
@PostMapping("/contract/{id}")
@SaCheckPermission(value = "contract:edit", orRole="admin")
public String updateById(@PathVariable Long id, ContractDTO dto) {
return contractService.updateById(id, dto);
}
@PostMapping("/contract/store")
@SaCheckPermission(value = "contract:store", orRole="admin")
public String ss(List<RContractStore> contractStoreList) {
return contractStoreService.saveBatch(contractStoreList) ? "更新成功" : "更新失败";
}
}
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import vion.dto.ContractPaymentDTO;
import vion.model.ContractPayment;
import vion.service.IContractPaymentService;
import java.util.List;
/**
* 合同收款方式
*/
......@@ -14,6 +19,12 @@ import vion.service.IContractPaymentService;
public class ContractPaymentController {
private final IContractPaymentService contractPaymentService;
private final Converter converter;
@PostMapping("/contractPayment")
@SaCheckPermission(value = "contractPayment:edit", orRole="admin")
public String updPayment(List<ContractPaymentDTO> dtoList) {
return contractPaymentService.saveBatch(converter.convert(dtoList, ContractPayment.class)) ? "更新成功" : "更新失败";
}
}
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
......@@ -10,10 +11,11 @@ import vion.dto.RRoleResourceDTO;
import vion.model.RRoleResource;
import vion.service.IRRoleResourceService;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 角色资源关联
* 角色资源关联
*/
@RestController
@RequestMapping("/api")
......@@ -21,18 +23,14 @@ import java.util.Arrays;
public class RRoleResourceController {
private final IRRoleResourceService roleResourceService;
private final Converter converter;
@PostMapping("/rRoleRes")
@SaCheckPermission("role:resource:edit")
public String saveOrUpdateRUserRole(@RequestBody RRoleResourceDTO dto) {
roleResourceService.lambdaUpdate().eq(RRoleResource::getRoleId, dto.getRoleId()).remove();
Arrays.stream(dto.getResourceIds()).map(resourceId -> {
RRoleResource roleResource = new RRoleResource();
roleResource.setRoleId(resourceId);
roleResource.setResourceId(dto.getRoleId());
return roleResource;
}).forEach(roleResourceService::save);
return "创建成功";
public String saveOrUpdateRUserRole(@RequestBody List<RRoleResourceDTO> dto) {
List<Long> roleIdList = dto.stream().map(RRoleResourceDTO::getRoleId).collect(Collectors.toList());
roleResourceService.lambdaUpdate().in(RRoleResource::getRoleId, roleIdList).remove();
return roleResourceService.saveBatch(converter.convert(dto, RRoleResource.class)) ? "创建成功" : "创建失败";
}
}
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
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 org.springframework.web.bind.annotation.*;
import vion.dto.RUserRoleDTO;
import vion.model.RUserRole;
import vion.service.IRUserRoleService;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* 用户角色
* 用户角色关联
*/
@RestController
@RequestMapping("/api")
......@@ -21,17 +20,13 @@ import java.util.Arrays;
public class RUserRoleController {
private final IRUserRoleService rUserRoleService;
private final Converter converter;
@PostMapping("/rUserRole")
@SaCheckPermission("user:role:edit")
public String saveOrUpdateRUserRole(@RequestBody RUserRoleDTO dto) {
rUserRoleService.lambdaUpdate().eq(RUserRole::getUserId, dto.getUserId()).remove();
Arrays.stream(dto.getRoleIds()).map(roleId -> {
RUserRole rUserRole = new RUserRole();
rUserRole.setUserId(dto.getUserId());
rUserRole.setRoleId(roleId);
return rUserRole;
}).forEach(rUserRoleService::save);
return "创建成功";
public String saveOrUpdateRUserRole(@RequestBody List<RUserRoleDTO> dto) {
List<Long> userIdList = dto.stream().map(RUserRoleDTO::getUserId).collect(Collectors.toList());
rUserRoleService.lambdaUpdate().in(RUserRole::getUserId, userIdList).remove();
return rUserRoleService.saveBatch(converter.convert(dto, RUserRole.class)) ? "创建成功" : "创建失败";
}
}
package vion.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -11,6 +12,8 @@ import vion.model.Resource;
import vion.service.IResourceService;
import vion.vo.ResourceVO;
import java.util.List;
/**
* 资源管理
*
......@@ -29,6 +32,12 @@ public class ResourceController {
return resourceService.list(dto);
}
@GetMapping("/resource/tree")
@SaCheckPermission
public List<Tree<Long>> listTree(Long id) {
return resourceService.listTree(id);
}
@GetMapping("/resource/{id}")
@SaCheckPermission(value = "resource:query", orRole="admin")
public ResourceVO getRoleById(@PathVariable Long id) {
......
......@@ -6,9 +6,17 @@ import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import vion.dto.RoleDTO;
import vion.model.RUserRole;
import vion.model.Role;
import vion.model.User;
import vion.service.IRUserRoleService;
import vion.service.IRoleService;
import vion.service.IUserService;
import vion.vo.RoleVO;
import vion.vo.UserVO;
import java.util.List;
import java.util.stream.Collectors;
/**
* 角色管理
......@@ -20,6 +28,8 @@ import vion.vo.RoleVO;
public class RoleController {
private final IRoleService roleService;
private final IRUserRoleService userRoleService;
private final IUserService userService;
private final Converter converter;
@GetMapping("/role")
......@@ -55,4 +65,13 @@ public class RoleController {
private String remove(@PathVariable Long id) {
return roleService.removeById(id) ? "删除成功" : "删除失败";
}
@GetMapping("/role/user/{id}")
@SaCheckPermission(value = "role:user", orRole="admin")
public List<UserVO> listUserById(@PathVariable Long id) {
List<RUserRole> userRoleList = userRoleService.lambdaQuery().eq(RUserRole::getRoleId, id).list();
List<Long> userIdList = userRoleList.stream().map(RUserRole::getUserId).collect(Collectors.toList());
List<User> userList = userService.lambdaQuery().in(User::getId, userIdList).list();
return converter.convert(userList, UserVO.class);
}
}
......@@ -9,12 +9,18 @@ import org.springframework.web.bind.annotation.*;
import vion.Global;
import vion.dto.StatusDTO;
import vion.dto.StoreDTO;
import vion.model.Contract;
import vion.model.RContractStore;
import vion.model.Store;
import vion.service.IContractService;
import vion.service.IRContractStoreService;
import vion.service.IStoreService;
import vion.vo.ContractVO;
import vion.vo.StoreVO;
import vion.vo.UserVO;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping(Global.BASE_URL)
......@@ -23,6 +29,8 @@ import java.util.List;
public class StoreController {
private final IStoreService storeService;
private final IContractService contractService;
private final IRContractStoreService contractStoreService;
private final Converter converter;
......@@ -67,4 +75,14 @@ public class StoreController {
public Object updateStoreStage(StatusDTO statusDTO, @RequestHeader String token) {
return storeService.updateStoreStage(statusDTO, token);
}
@GetMapping("/store/contract/{id}")
@SaCheckPermission(value = "store:contract", orRole="admin")
// todo 权限未加库
public List<ContractVO> listContractById(@PathVariable Long id) {
List<RContractStore> contractStoreList = contractStoreService.lambdaQuery().eq(RContractStore::getStoreId, id).list();
List<Long> contractIdList = contractStoreList.stream().map(RContractStore::getContractId).collect(Collectors.toList());
List<Contract> contractList = contractService.lambdaQuery().in(Contract::getId, contractIdList).list();
return converter.convert(contractList, ContractVO.class);
}
}
......@@ -4,23 +4,30 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import vion.Global;
import vion.third.DingMod;
import vion.third.WechatMod;
import vion.dto.BaseDTO;
import vion.dto.DingDTO;
import vion.dto.UserDTO;
import vion.model.RUserRole;
import vion.model.Role;
import vion.model.TaskTemp;
import vion.model.User;
import vion.service.IRUserRoleService;
import vion.service.IRoleService;
import vion.service.ITaskTempService;
import vion.service.IUserService;
import vion.third.DingMod;
import vion.third.WechatMod;
import vion.vo.RoleVO;
import vion.vo.UserVO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.stream.Collectors;
@RestController
......@@ -31,13 +38,18 @@ public class UserController {
private final IUserService userService;
private final ITaskTempService taskTempService;
private final IRUserRoleService userRoleService;
private final IRoleService roleService;
private final Converter converter;
private final DingMod dingMod;
private final WechatMod wechatMod;
@GetMapping("/users")
@SaCheckPermission(value = "user:list", orRole="admin")
public Page<User> getUserList(BaseDTO dto) {
return userService.page(Page.of(dto.getPageNum(), dto.getPageSize()));
public Page<User> getUserList(UserDTO dto) {
return userService.lambdaQuery(converter.convert(dto, new User()))
.orderByDesc(User::getModifyTime)
.page(Page.of(dto.getPageNum(), dto.getPageSize()));
}
@GetMapping("/user")
......@@ -63,6 +75,15 @@ public class UserController {
return userService.getOrgTree(deptId);
}
@GetMapping("/user/role/{id}")
@SaCheckPermission(value = "user:role", orRole="admin")
// todo 权限未加库
public List<RoleVO> listRoleById(@PathVariable Long id) {
List<RUserRole> userRoleList = userRoleService.lambdaQuery().eq(RUserRole::getUserId, id).list();
List<Long> roleIdList = userRoleList.stream().map(RUserRole::getRoleId).collect(Collectors.toList());
List<Role> roleList = roleService.lambdaQuery().in(Role::getId, roleIdList).list();
return converter.convert(roleList, RoleVO.class);
}
@GetMapping("/ding/callback/{target}")
public Object dingCallback(@PathVariable String target, DingDTO dto, HttpServletResponse res) {
......
......@@ -3,6 +3,7 @@ package vion.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.web.multipart.MultipartFile;
import java.math.BigDecimal;
import java.util.Date;
......@@ -112,4 +113,7 @@ public class ContractDTO extends BaseDTO {
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date modifyTime;
private MultipartFile[] files;
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ public class ContractPaymentDTO {
/**
* 付款比例
*/
private BigDecimal paymentRatios;
private BigDecimal paymentRatio;
/**
* 创建者
......
......@@ -10,7 +10,6 @@ import lombok.Setter;
@Getter
@Setter
public class RRoleResourceDTO extends BaseDTO {
private Long id;
/**
* 角色id
......@@ -22,6 +21,5 @@ public class RRoleResourceDTO extends BaseDTO {
*/
private Long resourceId;
private Long[] resourceIds;
}
\ No newline at end of file
......@@ -20,6 +20,4 @@ public class RUserRoleDTO extends BaseDTO {
* 角色id
*/
private Long roleId;
private Long[] roleIds;
}
\ No newline at end of file
package vion.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import java.util.Date;
/**
* 用户信息
*/
@Getter
@Setter
public class UserDTO extends BaseDTO {
private Long id;
private String userid;
private String username;
private String password;
private String phone;
private Long deptId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date createTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date modifyTime;
private String remark;
/** 是否是预工单处理人 0:不是 1:是 */
private Integer preWorkOrder;
/** 员工状态 2:试用期 3:正式 5:待离职 -1:无状态 */
private Integer employeeStatus;
/* 状态 0:正常 1:禁用 */
private Integer status;
}
\ No newline at end of file
package vion.enums;
public enum ResultEnum {
/**
* 登录失败
*/
LOGIN_ERROR(503, "Login Failed"),
/**
* 数据重复(目前没用)
*/
DATA_ERROR(502, "The data is incorrect. There may be duplicate data. Please check the data"),
/**
* atoken校验失败
*/
ATOKEN_ERROR(501, "atoken verification failed"),
/**
* 错误
*/
ERROR(505, "Failed to update or add"),
/**
* 插入或更新时有失败的数据
*/
SAVE_OR_UPDATE_ERROR(500, "Failed to save or update"),
/**
* 成功
*/
SUCCESS(200, "success"),
/**
* 查询数据为空或是查询出错
*/
SELECT_ERROR(506, "Data does not exist or search error"),
/**
* 查询分钟数据不是同一天
*/
ISNOTSAMEDAY(507, "The time interval between entries is not one day"),
/**
* 参数不全或参数错误提示
*/
FALSEPARAM(508, "Parameter error, please enter correct parameter"),
ILLEGALPARAM(513, "The parameter contains illegal characters"),
NOTVALIDMODIFYTIME(509, "The modification entered is not in the valid range"),
TIMEOUTOFWEEKS(511, "The interval between start date and end date exceeds 7 days"),
FREQUENCYERROR(512, "Interface requests are too frequent"),
MARK_ERROR(514, "Mark failed"),
IMAGE_ERROR(515, "The picture does not fit");
private final Integer code;
private final String message;
ResultEnum(Integer code, String message) {
this.code = code;
this.message = message;
}
public Integer getCode() {
return code;
}
public String getMessage() {
return message;
}
}
package vion.interceptor;
import cn.hutool.core.lang.Opt;
import cn.hutool.json.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import vion.Global;
import vion.enums.ResultEnum;
import vion.vo.UserVO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
@Component
public class Interceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
String url = request.getRequestURI();
if (url.indexOf("login") >= 0) {
return true;
}
UserVO user = Opt.ofBlankAble(request.getHeader("token")).map(Global.USERNAME_MAP::get).orElse(null);
if (user == null) {
response.reset();
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json;charset=UTF-8");
PrintWriter pw = response.getWriter();
JSONObject jsonObject = new JSONObject();
jsonObject.set("code", ResultEnum.ATOKEN_ERROR.getCode());
jsonObject.set("msg", "请先登陆再访问!");
pw.write(jsonObject.toString());
pw.flush();
pw.close();
return false;
} else {
request.setAttribute("start", System.currentTimeMillis());
return true;
}
}
}
......@@ -2,18 +2,12 @@ package vion.interceptor;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import javax.annotation.Resource;
@Configuration
// @Configuration
public class InterceptorConfig implements WebMvcConfigurer {
@Resource
private Interceptor interceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new SaInterceptor(handle -> {
......
......@@ -38,8 +38,8 @@ public class ContractPayment {
/**
* 付款比例
*/
@TableField(value = "payment_ratios")
private BigDecimal paymentRatios;
@TableField(value = "payment_ratio")
private BigDecimal paymentRatio;
/**
* 创建者
......
......@@ -24,7 +24,7 @@ public class FileInfo {
private Long storeId;
/** 文件扩展名 */
private String type;
/** 文件来源(1项目、2工单预处理,3工单操作,4巡检) */
/** 文件来源(1项目、2工单预处理,3工单操作,4巡检,5合同) */
private Integer sourceType;
/** 文件来源id */
private Long sourceId;
......
......@@ -57,8 +57,4 @@ public class Role {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date updateTime;
}
/**
* @author HlQ
* @date 2023/11/28
*/
}
\ No newline at end of file
......@@ -33,8 +33,10 @@ public class Task {
/** 故障说明 */
private String faultDescription;
/** 报修人 */
@TableField(condition = SqlCondition.LIKE)
private String repairPeople;
/** 报修人联系方式 */
@TableField(condition = SqlCondition.LIKE)
private String repairPhone;
/** 状态 */
@OrderBy(asc = true, sort = 1)
......
......@@ -23,6 +23,7 @@ public class TaskTemp {
/** 项目id */
private Long storeId;
/** 项目名称 */
@TableField(condition = SqlCondition.LIKE)
private String storeName;
/** 报修时间 */
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
......@@ -33,8 +34,10 @@ public class TaskTemp {
/** 故障说明 */
private String faultDescription;
/** 报修人 */
@TableField(condition = SqlCondition.LIKE)
private String repairPeople;
/** 联系方式 */
@TableField(condition = SqlCondition.LIKE)
private String repairPhone;
/** 状态(1待确认、2进行中、3已确认) */
@OrderBy(asc = true, sort = 1)
......
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import io.github.linpeilie.annotations.AutoMapper;
import io.github.linpeilie.annotations.AutoMappers;
import lombok.Data;
import vion.dto.UserDTO;
import vion.vo.UserVO;
import java.util.Date;
......@@ -15,12 +16,14 @@ import java.util.Date;
@Data
@TableName(value="tbl_user_info")
@AutoMappers({
@AutoMapper(target = UserDTO.class),
@AutoMapper(target = UserVO.class),
})
public class User {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private String userid;
@TableField(condition = SqlCondition.LIKE)
private String username;
private String password;
private String phone;
......
package vion.service;
import vion.model.ContractPayment;
import com.baomidou.mybatisplus.extension.service.IService;
/**
import vion.model.Contract;
import vion.model.ContractPayment;
/**
* @author HlQ
* @date 2023/11/29
*/
public interface IContractPaymentService extends IService<ContractPayment>{
public interface IContractPaymentService extends IService<ContractPayment> {
void calMoney(Contract contract);
}
package vion.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import vion.dto.ContractDTO;
import vion.model.Contract;
import com.baomidou.mybatisplus.extension.service.IService;
/**
import vion.vo.ContractVO;
/**
* @author HlQ
* @date 2023/11/29
*/
public interface IContractService extends IService<Contract>{
Page<ContractVO> list(ContractDTO dto);
String updateById(Long id, ContractDTO dto);
}
......@@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @author HlQ
* @date 2023/11/29
*/
public interface RContractStoreService extends IService<RContractStore>{
public interface IRContractStoreService extends IService<RContractStore>{
}
package vion.service;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import vion.dto.ResourceDTO;
import vion.model.Resource;
import vion.vo.ResourceVO;
import java.util.List;
/**
* @author HlQ
* @date 2023/11/28
......@@ -13,4 +16,6 @@ import vion.vo.ResourceVO;
public interface IResourceService extends IService<Resource>{
Page<ResourceVO> list(ResourceDTO dto);
List<Tree<Long>> listTree(Long id);
}
package vion.service.impl;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.NumberUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import vion.model.ContractPayment;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.mapper.ContractPaymentMapper;
import vion.model.Contract;
import vion.model.ContractPayment;
import vion.service.IContractPaymentService;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author HlQ
* @date 2023/11/29
*/
@Service
@RequiredArgsConstructor
public class ContractPaymentServiceImpl extends ServiceImpl<ContractPaymentMapper, ContractPayment> implements IContractPaymentService {
@Override
public void calMoney(Contract contract) {
List<ContractPayment> contractPaymentList = this.lambdaQuery().eq(ContractPayment::getContractId, contract.getId()).list();
Map<Integer, BigDecimal> type2RatioMap = contractPaymentList.stream().collect(Collectors.toMap(ContractPayment::getPaymentType, ContractPayment::getPaymentRatio));
Integer status = contract.getStatus();
BigDecimal sumRatio = new BigDecimal(0);
for (int i = 1; i <= status; i++) {
BigDecimal ratio = type2RatioMap.get(i);
NumberUtil.add(ratio, sumRatio);
}
BigDecimal totalAmount = contract.getTotalAmount();
BigDecimal curAmount = NumberUtil.mul(totalAmount, sumRatio);
BigDecimal recAmount = NumberUtil.sub(curAmount, contract.getPaidAmount());
BigDecimal outsideAmount = NumberUtil.sub(totalAmount, recAmount);
contract.setReceivableAmount(recAmount);
contract.setOutstandingAmount(outsideAmount);
}
}
package vion.service.impl;
import org.springframework.stereotype.Service;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import vion.dto.ContractDTO;
import vion.mapper.ContractMapper;
import vion.model.Contract;
import vion.model.FileInfo;
import vion.service.IContractPaymentService;
import vion.service.IContractService;
import vion.service.IFileService;
import vion.vo.ContractVO;
import vion.vo.UserVO;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
* @author HlQ
* @date 2023/11/29
*/
@Service
@RequiredArgsConstructor
public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract> implements IContractService {
private final IFileService fileService;
private final IContractPaymentService contractPaymentService;
private final Converter converter;
@Value("${fileUrl:}")
private String fileUrl;
@Override
public Page<ContractVO> list(ContractDTO dto) {
Page<Contract> contractList = this.lambdaQuery(converter.convert(dto, new Contract()))
.page(Page.of(dto.getPageNum(), dto.getPageSize()));
List<ContractVO> contractVOList = converter.convert(contractList.getRecords(), ContractVO.class);
return Page.<ContractVO>of(contractList.getCurrent(), contractList.getSize(), contractList.getTotal()).setRecords(contractVOList);
}
@Override
public String updateById(Long id, ContractDTO dto) {
Contract exitContract = this.getById(id);
Contract contract = converter.convert(dto, new Contract());
contract.setId(id);
if (ObjUtil.notEqual(contract.getStatus(), exitContract.getStatus())) {
contractPaymentService.calMoney(contract);
}
this.updateById(contract);
UserVO userVO = (UserVO) StpUtil.getTokenSession().get("curLoginUser");
Opt.ofNullable(dto.getFiles())
.ifPresent(fileList ->
Arrays.stream(fileList).forEach(infile -> {
//上传url地址
String orgName = infile.getOriginalFilename();
String fileName = orgName.substring(0, orgName.lastIndexOf("."));
String fileExt = orgName.substring(orgName.lastIndexOf("."));
String filename = fileName + "_" + DateUtil.format(new Date(), "yyyyMMdd_HHmmss") + fileExt;
String path = fileUrl + FileUtil.FILE_SEPARATOR + "contract" + FileUtil.FILE_SEPARATOR + contract.getId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
} catch (IOException e) {
log.error("保存文件出错", e);
}
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(contract.getId());
fileInfo.setSourceType(5);
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader(userVO.getUsername());
fileService.save(fileInfo);
}));
return "更新成功";
}
}
package vion.service.impl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import vion.mapper.RContractStoreMapper;
import vion.model.RContractStore;
import vion.service.RContractStoreService;
import vion.service.IRContractStoreService;
/**
* @author HlQ
* @date 2023/11/29
*/
@Service
public class RContractStoreServiceImpl extends ServiceImpl<RContractStoreMapper, RContractStore> implements RContractStoreService{
public class RContractStoreServiceImpl extends ServiceImpl<RContractStoreMapper, RContractStore> implements IRContractStoreService {
}
package vion.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.linpeilie.Converter;
......@@ -11,7 +18,9 @@ import vion.model.Resource;
import vion.service.IResourceService;
import vion.vo.ResourceVO;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author HlQ
......@@ -31,4 +40,37 @@ public class ResourceServiceImpl extends ServiceImpl<ResourceMapper, Resource> i
List<ResourceVO> resourceVOList = converter.convert(resourcePage.getRecords(), ResourceVO.class);
return Page.<ResourceVO>of(resourcePage.getCurrent(), resourcePage.getSize(), resourcePage.getTotal()).setRecords(resourceVOList);
}
@Override
public List<Tree<Long>> listTree(Long id) {
List<Resource> resourceList = this.list();
List<TreeNode<Long>> nodeList = CollUtil.newArrayList();
resourceList.forEach(v -> {
TreeNode<Long> node = new TreeNode<>(v.getId(), v.getParentId(), v.getName(), 1);
Map<String, Object> map = MapUtil.<String, Object>builder()
.put("path", v.getPath())
.put("component", v.getComponent())
.put("perm", v.getPerm())
.put("sortCode", v.getSortCode())
.put("type", v.getType())
.put("remark", v.getRemark())
.put("createTime", DateUtil.formatDateTime(v.getCreateTime()))
.put("updateTime", DateUtil.formatDateTime(v.getUpdateTime()))
.build();
node.setExtra(map);
nodeList.add(node);
});
List<Tree<Long>> wholeTree = TreeUtil.build(nodeList, 0L);
return Opt.ofNullable(id).map(d -> {
List<Tree<Long>> resTree = new ArrayList<>();
wholeTree.forEach(t ->
t.walk(tmp -> {
if (tmp.getId().equals(d)) {
resTree.add(tmp);
}
}));
return resTree;
}).orElse(wholeTree);
}
}
......@@ -7,11 +7,17 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.dto.RoleDTO;
import vion.mapper.RoleMapper;
import vion.model.RUserRole;
import vion.model.Role;
import vion.model.User;
import vion.service.IRUserRoleService;
import vion.service.IRoleService;
import vion.service.IUserService;
import vion.vo.RoleVO;
import vion.vo.UserVO;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author HlQ
......
......@@ -40,7 +40,6 @@ public class StoreServiceImpl extends ServiceImpl<StoreMapper, Store> implements
private final IFileService fileService;
private final Converter converter;
@Value("${fileUrl:}")
private String fileUrl;
......
......@@ -32,14 +32,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IU
List<TreeNode<String>> nodeList = CollUtil.newArrayList();
deptList.forEach(v -> {
TreeNode<String> node = new TreeNode<>(v.getDeptId().toString(), v.getParentId().toString(), v.getDeptName(), 1);
node.setExtra(MapUtil.of("type", "dept"));
node.setExtra(MapUtil.of("pkId", v.getId()));
node.setExtra(MapUtil.<String, Object>builder().put("type", "dept").put("pkId", v.getId()).build());
nodeList.add(node);
});
userList.forEach(v -> {
TreeNode<String> node = new TreeNode<>(v.getUserid(), v.getDeptId().toString(), v.getUsername(), 2);
node.setExtra(MapUtil.of("type", "user"));
node.setExtra(MapUtil.of("pkId", v.getId()));
node.setExtra(MapUtil.<String, Object>builder().put("type", "user").put("pkId", v.getId()).build());
nodeList.add(node);
});
List<Tree<String>> wholeTree = TreeUtil.build(nodeList, "1");
......
......@@ -7,7 +7,6 @@ import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.lang.Opt;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
......@@ -240,7 +239,7 @@ public class DingMod {
}
Long id = userVO.getId();
List<RUserRole> userRoleList = userRoleService.lambdaQuery().eq(RUserRole::getUserId, id).list();
Opt.ofEmptyAble(userRoleList)
List<RRoleResource> roleResourceList = Opt.ofEmptyAble(userRoleList)
.map(urList -> urList.stream().map(RUserRole::getRoleId).collect(Collectors.toList()))
.map(roleIdList -> {
// 获取用户关联的角色
......@@ -248,10 +247,11 @@ public class DingMod {
List<RoleVO> roleVOS = converter.convert(roles, RoleVO.class);
userVO.setRoleVOList(roleVOS);
return roleResourceService.lambdaQuery().select(RRoleResource::getResourceId).in(RRoleResource::getRoleId, roleIdList).list();
})
}).orElse(ListUtil.empty());
// 获取角色关联的资源
Opt.ofEmptyAble(roleResourceList)
.map(rrList -> rrList.stream().map(RRoleResource::getResourceId).collect(Collectors.toList()))
.ifPresent(resourceIdList -> {
// 获取角色关联的资源
List<Resource> resourceList = resourceService.listByIds(resourceIdList);
List<String> permCodeList = resourceList.stream().map(Resource::getPerm).collect(Collectors.toList());
userVO.setPermCodeList(permCodeList);
......@@ -265,8 +265,7 @@ public class DingMod {
StpUtil.getTokenSession().set("curLoginUser", userVO);
Global.USERNAME_MAP.put(token, userVO);
// todo 返回权限码合集
return user;
return userVO;
} else if (StrUtil.equals(target, "inside")) {
String response = HttpUtil.post(buildSignUrl(), "{\"tmp_auth_code\":\"" + dto.getCode() + "\"}");
JSONObject userInfoObj = JSONUtil.parseObj(response);
......@@ -286,8 +285,12 @@ public class DingMod {
User user = userService.lambdaQuery().select(User::getId, User::getUserid, User::getUsername, User::getPhone, User::getStatus).eq(User::getUserid, userid).one();
UserVO userVO = converter.convert(user, new UserVO());
String token = IdUtil.simpleUUID();
StpUtil.login(userVO.getId());
String token = StpUtil.getTokenValue();
userVO.setToken(token);
StpUtil.getTokenSession().set("curLoginUser", userVO);
Global.USERNAME_MAP.put(token, userVO);
try {
if (ObjUtil.isAllNotEmpty(dto.getStoreId(), dto.getTaskId())) {
......
package vion.utils;
import vion.enums.ResultEnum;
import vion.vo.ResultVO;
public class ResultUtil {
public static ResultVO<Object> success(Object o) {
ResultVO<Object> resultVO = new ResultVO<Object>();
resultVO.setCode(ResultEnum.SUCCESS.getCode());
resultVO.setMsg(ResultEnum.SUCCESS.getMessage());
resultVO.setCode(200);
resultVO.setMsg("success");
resultVO.setData(o);
return resultVO;
}
public static ResultVO<Object> error(ResultEnum e) {
public static ResultVO<Object> error(Integer code, String o) {
ResultVO<Object> resultVO = new ResultVO<Object>();
resultVO.setCode(e.getCode());
resultVO.setMsg(e.getMessage());
resultVO.setCode(code);
resultVO.setMsg(o);
resultVO.setData(null);
return resultVO;
}
public static ResultVO<Object> error(Object o) {
ResultVO<Object> resultVO = new ResultVO<Object>();
resultVO.setCode(500);
resultVO.setMsg("error");
resultVO.setData(o);
return resultVO;
}
public static ResultVO<Object> success() {
return success(null);
public static ResultVO<Object> error(String o) {
return error(500, o);
}
public static ResultVO<Object> error() {
return error(null);
return error(500, "error");
}
public static ResultVO<Object> success() {
return success(null);
}
}
......@@ -28,7 +28,7 @@ public class ContractPaymentVO {
/**
* 付款比例
*/
private BigDecimal paymentRatios;
private BigDecimal paymentRatio;
/**
* 创建者
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!