feature : (WIP) Invoicing page for customer

pull/6221/head
Gauthier LO 2023-09-06 14:26:33 +02:00
parent 061657d9bd
commit fd35ea1c3e
17 changed files with 262 additions and 6 deletions

View File

@ -0,0 +1,65 @@
package org.jeecg.modules.business.controller.admin;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.business.entity.Client;
import org.jeecg.modules.business.entity.PlatformOrder;
import org.jeecg.modules.business.entity.PlatformOrderContent;
import org.jeecg.modules.business.entity.Shop;
import org.jeecg.modules.business.service.IPlatformOrderService;
import org.jeecg.modules.business.service.IShopService;
import org.jeecg.modules.business.service.IUserClientService;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@Api(tags = "UserClient")
@RestController
@RequestMapping("/userClient")
@Slf4j
public class UserClientController {
@Autowired
private IUserClientService userClientService;
@Autowired
private ISysUserRoleService sysUserRoleService;
@Autowired
private IShopService shopService;
@Autowired
private IPlatformOrderService platformOrderService;
/**
* Checks if the user is a client and then lists orders of erp_status 1
* @return
*/
@GetMapping(value = "/getClient")
public Result<?> getClientByUserId() {
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
String userId = loginUser.getId();
userId = "1698676211346821122";
Client client = userClientService.getClientByUserId(userId);
if(client == null) {
List<SysRole> sysRoles = sysUserRoleService.getUserRole(userId);
boolean isAllowed = false;
for(SysRole sysRole: sysRoles) {
if(sysRole.getRoleCode().equals("admin") || sysRole.getRoleCode().equals("dev")) {
isAllowed = true;
break;
}
}
if(isAllowed)
return Result.OK("Permission Granted", "admin");
else
return Result.error(403, "Access Denied.");
}
return Result.ok(client);
}
}

View File

@ -61,6 +61,8 @@ public class InvoiceController {
@Autowired
private PlatformOrderMapper platformOrderMapper;
@Autowired
private IPlatformOrderService platformOrderService;
@Autowired
private PlatformOrderContentMapper platformOrderContentMap;
@Autowired
private IShippingInvoiceService iShippingInvoiceService;
@ -285,7 +287,7 @@ public class InvoiceController {
* @param req
* @return sku prices available code : 200 = success
*/
@PostMapping(value = "/preShipping/ordersBetweenOrderDates")
@PostMapping(value = "/preShipping/ordersBetweenOrderDates")
public Result<?> getOrdersBetweenOrderDates(PlatformOrder platformOrder, @RequestBody ShippingInvoiceParam param, HttpServletRequest req) {
QueryWrapper<PlatformOrder> queryWrapper = QueryGenerator.initQueryWrapper(platformOrder, req.getParameterMap());
LambdaQueryWrapper<PlatformOrder> lambdaQueryWrapper = queryWrapper.lambda();
@ -310,6 +312,19 @@ public class InvoiceController {
return checkSkuPrices(args);
}
@GetMapping(value = "/preShipping/orderByShops")
public Result<?> getOrdersByShops(@RequestParam("shopIds") String shopIds) {
log.info("User : {} is requesting uninvoiced orders for shops : [{}]",
((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername(),
shopIds);
List<String> shopIdList = Arrays.asList(shopIds.split(","));
List<PlatformOrder> orders = platformOrderService.findUninvoicedOrdersByShopForClient(shopIdList);
IPage<PlatformOrder> page = new Page<>();
page.setRecords(orders);
page.setTotal(orders.size());
return Result.OK(page);
}
/**
* Checks if all sku of order from shops between 2 dates are available
* @param platformOrder

View File

@ -0,0 +1,72 @@
package org.jeecg.modules.business.entity;
import java.io.Serializable;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.jeecg.common.aspect.annotation.Dict;
import org.springframework.format.annotation.DateTimeFormat;
import org.jeecgframework.poi.excel.annotation.Excel;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/**
* @Description: user_client
* @Author: jeecg-boot
* @Date: 2023-08-22
* @Version: V1.0
*/
@Data
@TableName("user_client")
@ApiModel(value = "user_client对象", description = "user_client")
public class UserClient implements Serializable {
private static final long serialVersionUID = 1L;
/**
*
*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private java.lang.String id;
/**
*
*/
@ApiModelProperty(value = "创建人")
private java.lang.String createBy;
/**
*
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private java.util.Date createTime;
/**
*
*/
@ApiModelProperty(value = "更新人")
private java.lang.String updateBy;
/**
*
*/
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "更新日期")
private java.util.Date updateTime;
/**
* ID
*/
@Excel(name = "系统用户ID", width = 15, dictTable = "client WHERE active = '1'", dicText = "internal_code", dicCode = "id")
@Dict(dictTable = "client WHERE active = '1'", dicText = "internal_code", dicCode = "id")
@ApiModelProperty(value = "客户ID")
private java.lang.String client_id;
/**
* ID
*/
@Excel(name = "系统用户ID", width = 15, dictTable = "sys_user WHERE del_flag = 0", dicText = "username", dicCode = "id")
@Dict(dictTable = "sys_user WHERE del_flag = 0", dicText = "username", dicCode = "id")
@ApiModelProperty(value = "系统用户ID")
private java.lang.String user_id;
}

View File

@ -1,7 +1,9 @@
package org.jeecg.modules.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.business.entity.Client;
import org.jeecg.modules.business.entity.UserClient;
import org.springframework.stereotype.Repository;
/**
@ -11,7 +13,7 @@ import org.springframework.stereotype.Repository;
* @Version: V1.0
*/
@Repository
public interface ClientUserMapper {
public interface ClientUserMapper extends BaseMapper<UserClient> {
/**
* Find client information for current system user
*

View File

@ -53,6 +53,7 @@ public interface PlatformOrderContentMapper extends BaseMapper<PlatformOrderCont
@Param("begin") Date begin,
@Param("end") Date end
);
List<PlatformOrderContent> findUninvoicedOrderContents(@Param("orderIds") List<String> orderIds);
/**
* Find all uninvoiced order content for specified shop between order time period with specified status ([1,2] or [1,2,3])

View File

@ -4,7 +4,9 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.jeecg.modules.business.domain.api.mabang.getorderlist.Order;
import org.jeecg.modules.business.entity.PlatformOrder;
import org.jeecg.modules.business.entity.PlatformOrderContent;
import org.jeecg.modules.business.entity.PlatformOrderShopSync;
import org.jeecg.modules.business.entity.Shop;
import org.jeecg.modules.business.vo.clientPlatformOrder.ClientPlatformOrderPage;
import org.jeecg.modules.business.vo.clientPlatformOrder.section.OrderQuantity;
import org.springframework.stereotype.Repository;
@ -12,6 +14,7 @@ import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @Description:
@ -183,4 +186,6 @@ public interface PlatformOrderMapper extends BaseMapper<PlatformOrder> {
void insertPlatformOrdersArchives(@Param("orders") List<PlatformOrder> platformOrders);
void cancelInvoice(@Param("invoiceNumber") String invoiceNumber);
void cancelBatchInvoice(@Param("invoiceNumbers") List<String> invoiceNumbers);
List<PlatformOrder> findUninvoicedOrdersByShopForClient(@Param("shopIds") List<String> shopIds);
}

View File

@ -5,7 +5,8 @@
resultType="org.jeecg.modules.business.entity.Client">
SELECT c.*
FROM user_client
JOIN client c
ON c.id = user_client.client_id
WHERE user_id = #{userId} </select>
JOIN client c
ON c.id = user_client.client_id
WHERE user_id = #{userId}
</select>
</mapper>

View File

@ -128,6 +128,20 @@
AND po.shipping_invoice_number IS NULL
AND poc.erp_status = 3
</select>
<select id="findUninvoicedOrderContents" resultType="org.jeecg.modules.business.entity.PlatformOrderContent">
SELECT poc.*
FROM platform_order_content poc
WHERE platform_order_id IN
<foreach
collection="orderIds"
index="index"
item="orderId"
open="("
close=")"
separator=",">
#{orderId}
</foreach>
</select>
<select id="findUninvoicedOrderContentsForShopsAndStatus" resultType="org.jeecg.modules.business.entity.PlatformOrderContent">
SELECT poc.*
FROM platform_order_content poc

View File

@ -540,6 +540,23 @@
WHERE erp_status IN (4,5)
AND order_time &lt; #{endDate};
</select>
<select id="findUninvoicedOrdersByShopForClient" resultType="org.jeecg.modules.business.entity.PlatformOrder">
SELECT *
FROM platform_order
WHERE erp_status = 1
AND shipping_invoice_number IS NULL
AND shop_id IN
<foreach
collection="shopIds"
separator=","
open="("
close=")"
index="index"
item="shopId"
>
#{shopId}
</foreach>;
</select>
<insert id="insertPlatformOrdersArchives" parameterType="list">
INSERT INTO platform_order_delete(id, create_by,
create_time, update_by,

View File

@ -176,4 +176,12 @@ public interface IPlatformOrderService extends IService<PlatformOrder> {
* @param invoiceNumbers
*/
void cancelBatchInvoice(List<String> invoiceNumbers);
/**
* Find all order that can be invoiced by small clients (type 2) themselves.
* Invoices of erp_status 1
* @param shopIds list of shop id
* @return list of orders
*/
List<PlatformOrder> findUninvoicedOrdersByShopForClient(List<String> shopIds);
}

View File

@ -0,0 +1,9 @@
package org.jeecg.modules.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.business.entity.Client;
import org.jeecg.modules.business.entity.UserClient;
public interface IUserClientService extends IService<UserClient> {
Client getClientByUserId(String userId);
}

View File

@ -393,4 +393,9 @@ public class PlatformOrderServiceImpl extends ServiceImpl<PlatformOrderMapper, P
public void cancelBatchInvoice(List<String> invoiceNumbers) {
platformOrderMap.cancelBatchInvoice(invoiceNumbers);
}
@Override
public List<PlatformOrder> findUninvoicedOrdersByShopForClient(List<String> shopIds) {
return platformOrderMap.findUninvoicedOrdersByShopForClient(shopIds);
}
}

View File

@ -0,0 +1,19 @@
package org.jeecg.modules.business.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.business.entity.Client;
import org.jeecg.modules.business.entity.UserClient;
import org.jeecg.modules.business.mapper.ClientUserMapper;
import org.jeecg.modules.business.service.IUserClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserClientServiceImpl extends ServiceImpl<ClientUserMapper, UserClient> implements IUserClientService {
@Autowired
private ClientUserMapper clientUserMapper;
@Override
public Client getClientByUserId(String userId) {
return clientUserMapper.selectClientByUserId(userId);
}
}

View File

@ -3,8 +3,10 @@ package org.jeecg.modules.system.mapper;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.entity.SysUserRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.stereotype.Repository;
/**
* <p>
@ -14,6 +16,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
* @Author scott
* @since 2018-12-21
*/
@Repository
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
/**
@ -32,4 +35,5 @@ public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {
@Select("select id from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
List<String> getRoleIdByUserName(@Param("username") String username);
List<SysRole> getRoleByUserId(@Param("userId") String userId);
}

View File

@ -0,0 +1,11 @@
<?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="org.jeecg.modules.system.mapper.SysUserRoleMapper">
<select id="getRoleByUserId" parameterType="java.lang.String" resultType="org.jeecg.modules.system.entity.SysRole">
SELECT sr.role_code, sr.id
FROM sys_user_role sur
JOIN sys_role sr
ON sr.id = sur.role_id
WHERE sur.user_id = #{userId};
</select>
</mapper>

View File

@ -1,7 +1,9 @@
package org.jeecg.modules.system.service;
import java.util.List;
import java.util.Map;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.entity.SysUserRole;
import com.baomidou.mybatisplus.extension.service.IService;
@ -15,4 +17,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
* @since 2018-12-21
*/
public interface ISysUserRoleService extends IService<SysUserRole> {
List<SysRole> getUserRole(String userId);
}

View File

@ -26,5 +26,10 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
*/
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
@Autowired
SysUserRoleMapper sysUserRoleMapper;
@Override
public List<SysRole> getUserRole(String userId) {
return sysUserRoleMapper.getRoleByUserId(userId);
}
}