修复进销存合并
This commit is contained in:
@@ -1,152 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zsw.erp.datasource.entities.Account;
|
||||
import com.zsw.erp.datasource.vo.AccountVo4InOutList;
|
||||
import com.zsw.erp.service.account.AccountService;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.utils.ErpInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zsw.erp.utils.ResponseJsonUtil.returnJson;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/account")
|
||||
@Api(tags = {"账户管理"})
|
||||
public class AccountController {
|
||||
private Logger logger = LoggerFactory.getLogger(AccountController.class);
|
||||
|
||||
@Resource
|
||||
private AccountService accountService;
|
||||
|
||||
/**
|
||||
* 查找结算账户信息-下拉框
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/findBySelect")
|
||||
@ApiOperation(value = "查找结算账户信息-下拉框")
|
||||
public String findBySelect(HttpServletRequest request) throws Exception {
|
||||
String res = null;
|
||||
try {
|
||||
List<Account> dataList = accountService.findBySelect();
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if (null != dataList) {
|
||||
for (Account account : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("Id", account.getId());
|
||||
//结算账户名称
|
||||
item.put("AccountName", account.getName());
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
res = dataArray.toJSONString();
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
res = "获取数据失败";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有结算账户
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getAccount")
|
||||
@ApiOperation(value = "获取所有结算账户")
|
||||
public R getAccount(HttpServletRequest request) throws Exception {
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
List<Account> accountList = accountService.getAccount();
|
||||
map.put("accountList", accountList);
|
||||
return R.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 账户流水信息
|
||||
* @param currentPage
|
||||
* @param pageSize
|
||||
* @param accountId
|
||||
* @param initialAmount
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/findAccountInOutList")
|
||||
@ApiOperation(value = "账户流水信息")
|
||||
public R findAccountInOutList(@RequestParam("currentPage") Integer currentPage,
|
||||
@RequestParam("pageSize") Integer pageSize,
|
||||
@RequestParam("accountId") Long accountId,
|
||||
@RequestParam("initialAmount") BigDecimal initialAmount,
|
||||
HttpServletRequest request) throws Exception{
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
List<AccountVo4InOutList> dataList = accountService.findAccountInOutList(accountId, (currentPage-1)*pageSize, pageSize);
|
||||
int total = accountService.findAccountInOutListCount(accountId);
|
||||
map.put("total", total);
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if (null != dataList) {
|
||||
for (AccountVo4InOutList aEx : dataList) {
|
||||
String timeStr = aEx.getOperTime().toString();
|
||||
BigDecimal balance = accountService.getAccountSum(accountId, timeStr, "date").add(accountService.getAccountSumByHead(accountId, timeStr, "date"))
|
||||
.add(accountService.getAccountSumByDetail(accountId, timeStr, "date")).add(accountService.getManyAccountSum(accountId, timeStr, "date")).add(initialAmount);
|
||||
aEx.setBalance(balance);
|
||||
aEx.setAccountId(accountId);
|
||||
dataArray.add(aEx);
|
||||
}
|
||||
}
|
||||
map.put("rows", dataArray);
|
||||
return R.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新默认账户
|
||||
* @param object
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping(value = "/updateIsDefault")
|
||||
@ApiOperation(value = "更新默认账户")
|
||||
public String updateIsDefault(@RequestBody JSONObject object,
|
||||
HttpServletRequest request) throws Exception{
|
||||
Long accountId = object.getLong("id");
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
int res = accountService.updateIsDefault(accountId);
|
||||
if(res > 0) {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算账户的统计
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getStatistics")
|
||||
@ApiOperation(value = "结算账户的统计")
|
||||
public R getStatistics(@RequestParam("name") String name,
|
||||
@RequestParam("serialNo") String serialNo,
|
||||
HttpServletRequest request) throws Exception {
|
||||
|
||||
Map<String, Object> map = accountService.getStatistics(name, serialNo);
|
||||
return R.success(map);
|
||||
}
|
||||
}
|
||||
@@ -5,8 +5,8 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.datasource.dto.BomDto;
|
||||
import com.zsw.erp.dto.bom.BomConvert;
|
||||
import com.zsw.erp.service.zyh.BomService;
|
||||
import com.zsw.erp.utils.DozerUtils;
|
||||
import com.zsw.pos.product.dto.AdminStoreProductDTO;
|
||||
import com.zsw.pos.product.entity.Product;
|
||||
import com.zsw.pos.product.entity.ProductSku;
|
||||
@@ -29,17 +29,13 @@ import java.util.List;
|
||||
@RequestMapping("/bom")
|
||||
@Slf4j
|
||||
public class BomController {
|
||||
|
||||
@Resource
|
||||
private DozerUtils dozerUtils;
|
||||
|
||||
@DubboReference
|
||||
// @DubboReference
|
||||
private ProductService productService;
|
||||
|
||||
@DubboReference
|
||||
// @DubboReference
|
||||
private ProductSkuService productSkuService;
|
||||
|
||||
@DubboReference
|
||||
// @DubboReference
|
||||
private StoreService storeService;
|
||||
|
||||
@Resource
|
||||
@@ -60,7 +56,7 @@ public class BomController {
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("列举全部BOM")
|
||||
public R<List<BomDto>> list(){
|
||||
List<BomDto> rs = dozerUtils.convertList(bomService.list(), BomDto.class);
|
||||
List<BomDto> rs = BomConvert.INSTANCE.convertList2Dto(bomService.list());
|
||||
return R.success(rs);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -34,8 +34,8 @@ import static com.zsw.erp.utils.ResponseJsonUtil.returnJson;
|
||||
@RestController
|
||||
@RequestMapping(value = "/material")
|
||||
@Api(tags = {"商品管理"})
|
||||
public class MaterialController {
|
||||
private Logger logger = LoggerFactory.getLogger(MaterialController.class);
|
||||
public class BxgProductController {
|
||||
private Logger logger = LoggerFactory.getLogger(BxgProductController.class);
|
||||
|
||||
@Resource
|
||||
private MaterialService materialService;
|
||||
@@ -7,7 +7,6 @@ import com.zsw.erp.datasource.entities.DepotEx;
|
||||
import com.zsw.erp.datasource.entities.MaterialInitialStock;
|
||||
import com.zsw.erp.service.depot.DepotService;
|
||||
import com.zsw.erp.service.material.MaterialService;
|
||||
import com.zsw.erp.service.userBusiness.UserBusinessService;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.utils.ErpInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -33,9 +32,6 @@ public class DepotController {
|
||||
@Resource
|
||||
private DepotService depotService;
|
||||
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
|
||||
@Resource
|
||||
private MaterialService materialService;
|
||||
|
||||
@@ -66,7 +62,6 @@ public class DepotController {
|
||||
JSONArray arr = new JSONArray();
|
||||
try {
|
||||
//获取权限信息
|
||||
List<Long> ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
|
||||
List<Depot> dataList = depotService.findUserDepot();
|
||||
//开始拼接json数据
|
||||
JSONObject outer = new JSONObject();
|
||||
@@ -85,10 +80,7 @@ public class DepotController {
|
||||
item.put("value", depot.getId());
|
||||
item.put("title", depot.getName());
|
||||
item.put("attributes", depot.getName());
|
||||
Boolean flag = ubValue.contains(depot.getId());
|
||||
if (flag) {
|
||||
item.put("checked", true);
|
||||
}
|
||||
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.zsw.erp.controller;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zsw.base.R;
|
||||
@@ -14,7 +16,7 @@ import com.zsw.erp.datasource.vo.DepotHeadVo4InDetail;
|
||||
import com.zsw.erp.datasource.vo.DepotHeadVo4InOutMCount;
|
||||
import com.zsw.erp.datasource.vo.DepotHeadVo4List;
|
||||
import com.zsw.erp.datasource.vo.DepotHeadVo4StatementAccount;
|
||||
import com.zsw.erp.service.account.AccountService;
|
||||
import com.zsw.erp.dto.depot.DepotConvert;
|
||||
import com.zsw.erp.service.accountHead.AccountHeadService;
|
||||
import com.zsw.erp.service.depot.DepotService;
|
||||
import com.zsw.erp.service.depotHead.DepotHeadService;
|
||||
@@ -54,7 +56,8 @@ public class DepotHeadController {
|
||||
private AccountHeadService accountHeadService;
|
||||
|
||||
@Resource
|
||||
private AccountService accountService;
|
||||
private AdminUserService adminUserService;
|
||||
|
||||
|
||||
@Resource
|
||||
private SupplierService supplierService;
|
||||
@@ -464,15 +467,15 @@ public class DepotHeadController {
|
||||
body.setInfo(head);
|
||||
|
||||
List<DepotItem> list = depotItemService.getListByHeaderId(head.getId());
|
||||
List<DepotItemDto> listRs = BeanUtil.copyToList(list, DepotItemDto.class);
|
||||
List<DepotItemDto> listRs = DepotConvert.INSTANCE.convertList(list);
|
||||
body.setRows(listRs);
|
||||
body.setId(head.getId());
|
||||
String sub = no.substring(0, 4).toUpperCase();
|
||||
logger.info("sub:{}",sub);
|
||||
|
||||
Supplier supplier = supplierService.getSupplier(head.getOrganId());
|
||||
Account acc = accountService.getAccount(head.getAccountId());
|
||||
|
||||
AdminUserDO user = adminUserService.getUser(head.getAccountId());
|
||||
|
||||
model.addObject("supplier",supplier.getSupplier());
|
||||
model.addObject("create_time", DateUtil.format(head.getCreateTime(), DatePattern.NORM_DATETIME_PATTERN));
|
||||
@@ -482,7 +485,7 @@ public class DepotHeadController {
|
||||
model.addObject("discount_money",head.getDiscountMoney());
|
||||
model.addObject("discount_last_money",head.getDiscountLastMoney());
|
||||
model.addObject("other_money",head.getOtherMoney());
|
||||
model.addObject("account",acc.getName());
|
||||
model.addObject("account",user.getNickname());
|
||||
model.addObject("total_price",head.getTotalPrice());
|
||||
model.addObject("debt",head.getDiscountLastMoney().subtract(head.getChangeAmount()));
|
||||
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import static com.zsw.erp.utils.ResponseJsonUtil.returnJson;
|
||||
|
||||
@RestController
|
||||
@Api(tags = {"资源接口"})
|
||||
public class ResourceController {
|
||||
public class ErpController {
|
||||
|
||||
@Resource
|
||||
private CommonQueryManager configResourceManager;
|
||||
+4
-21
@@ -16,8 +16,6 @@ import com.zsw.erp.config.QiniuConfigProperty;
|
||||
import com.zsw.erp.datasource.entities.SystemConfig;
|
||||
import com.zsw.erp.service.depot.DepotService;
|
||||
import com.zsw.erp.service.systemConfig.SystemConfigService;
|
||||
import com.zsw.erp.service.user.UserService;
|
||||
import com.zsw.erp.service.userBusiness.UserBusinessService;
|
||||
import com.zsw.erp.utils.StringUtil;
|
||||
import com.zsw.erp.utils.Tools;
|
||||
import io.swagger.annotations.Api;
|
||||
@@ -53,30 +51,21 @@ import java.util.List;
|
||||
@RequestMapping(value = "/systemConfig")
|
||||
@Api(tags = {"系统参数"})
|
||||
@EnableConfigurationProperties(QiniuConfigProperty.class)
|
||||
public class SystemConfigController {
|
||||
private Logger logger = LoggerFactory.getLogger(SystemConfigController.class);
|
||||
public class ErpSystemConfigController {
|
||||
private Logger logger = LoggerFactory.getLogger(ErpSystemConfigController.class);
|
||||
|
||||
@Resource
|
||||
QiniuConfigProperty qiniuConfigProperty;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private DepotService depotService;
|
||||
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
|
||||
|
||||
@Resource
|
||||
private SystemConfigService systemConfigService;
|
||||
|
||||
@Value(value="${spring.servlet.multipart.max-file-size}")
|
||||
private Long maxFileSize;
|
||||
|
||||
@Value(value="${spring.servlet.multipart.max-request-size}")
|
||||
private Long maxRequestSize;
|
||||
|
||||
/**
|
||||
* 获取当前租户的配置信息
|
||||
* @param request
|
||||
@@ -104,13 +93,7 @@ public class SystemConfigController {
|
||||
@ApiOperation(value = "获取文件大小限制")
|
||||
public R fileSizeLimit(HttpServletRequest request) throws Exception {
|
||||
|
||||
Long limit = 0L;
|
||||
if(maxFileSize<maxRequestSize) {
|
||||
limit = maxFileSize;
|
||||
} else {
|
||||
limit = maxRequestSize;
|
||||
}
|
||||
return R.success(limit);
|
||||
return R.success("");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,241 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.zsw.erp.datasource.entities.BtnDto;
|
||||
import com.zsw.erp.datasource.entities.Function;
|
||||
import com.zsw.erp.datasource.entities.UserBusiness;
|
||||
import com.zsw.erp.service.functions.FunctionService;
|
||||
import com.zsw.erp.service.userBusiness.UserBusinessService;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.utils.Tools;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/function")
|
||||
@Api(tags = {"功能管理"})
|
||||
public class FunctionController {
|
||||
private Logger logger = LoggerFactory.getLogger(FunctionController.class);
|
||||
|
||||
@Resource
|
||||
private FunctionService functionService;
|
||||
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
|
||||
/**
|
||||
* 根据父编号查询菜单
|
||||
* @param jsonObject
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping(value = "/findMenuByPNumber")
|
||||
@ApiOperation(value = "根据父编号查询菜单")
|
||||
public JSONArray findMenuByPNumber(@RequestBody JSONObject jsonObject,
|
||||
HttpServletRequest request)throws Exception {
|
||||
String pNumber = jsonObject.getStr("pNumber");
|
||||
Long userId = jsonObject.getLong("userId");
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
try {
|
||||
Long roleId = 0L;
|
||||
List<Long> fc = Lists.newArrayList();
|
||||
UserBusiness role = userBusinessService.getBasicData(userId, "UserRole");
|
||||
roleId = role.getValue().get(0).longValue();
|
||||
//当前用户所拥有的功能列表,格式如:[1][2][5]
|
||||
// List<UserBusiness> funList = userBusinessService.getBasicData(roleId.toString(), "RoleFunctions");
|
||||
// if(funList!=null && funList.size()>0){
|
||||
// fc = funList.get(0).getValue();
|
||||
// }
|
||||
// List<Function> dataList = functionService.getRoleFunction(pNumber);
|
||||
List<Function> dataList;
|
||||
if (roleId == 1L){
|
||||
logger.info("当前是系统管理员,给予全部菜单和权限。");
|
||||
dataList = functionService.getRoleFunction(pNumber);
|
||||
fc = functionService.getFunction().stream().map(Function::getId).collect(Collectors.toList());
|
||||
}else{
|
||||
dataList = functionService.getRoleFunction(pNumber);
|
||||
UserBusiness fun = userBusinessService.getBasicData(roleId, "RoleFunctions");
|
||||
fc = fun.getValue().stream().map(Number::longValue).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (dataList.size() != 0) {
|
||||
dataArray = getMenuByFunction(dataList, fc);
|
||||
//增加首页菜单项
|
||||
JSONObject homeItem = new JSONObject();
|
||||
homeItem.set("id", 0);
|
||||
homeItem.set("text", "首页");
|
||||
homeItem.set("icon", "home");
|
||||
homeItem.set("url", "/dashboard/analysis");
|
||||
homeItem.set("component", "/layouts/TabLayout");
|
||||
dataArray.add(0,homeItem);
|
||||
}
|
||||
} catch (DataAccessException e) {
|
||||
logger.error(">>>>>>>>>>>>>>>>>>>查找异常", e);
|
||||
}
|
||||
return dataArray;
|
||||
}
|
||||
|
||||
public JSONArray getMenuByFunction(List<Function> dataList, List<Long> fc) throws Exception {
|
||||
|
||||
dataList = dataList.stream()
|
||||
.filter(function -> fc.contains(function.getId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
JSONArray dataArray = new JSONArray();
|
||||
for (Function function : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
List<Function> newList = functionService.getRoleFunction(function.getNumber());
|
||||
item.set("id", function.getId());
|
||||
item.set("text", function.getName());
|
||||
item.set("icon", function.getIcon());
|
||||
item.set("url", function.getUrl());
|
||||
item.set("component", function.getComponent());
|
||||
if (newList.size()>0) {
|
||||
JSONArray childrenArr = getMenuByFunction(newList, fc);
|
||||
if(childrenArr.size()>0) {
|
||||
item.put("children", childrenArr);
|
||||
dataArray.add(item);
|
||||
}
|
||||
} else {
|
||||
if (fc.contains(function.getId())) {
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
return dataArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 角色对应功能显示
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/findRoleFunction")
|
||||
@ApiOperation(value = "角色对应功能显示")
|
||||
public JSONArray findRoleFunction(@RequestParam("UBType") String type, @RequestParam("UBKeyId") Long keyId,
|
||||
HttpServletRequest request)throws Exception {
|
||||
JSONArray arr = new JSONArray();
|
||||
try {
|
||||
List<Function> dataListFun = functionService.findRoleFunction("0");
|
||||
//开始拼接json数据
|
||||
JSONObject outer = new JSONObject();
|
||||
outer.set("id", 0);
|
||||
outer.set("key", 0);
|
||||
outer.set("value", 0);
|
||||
outer.set("title", "功能列表");
|
||||
outer.set("attributes", "功能列表");
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if (null != dataListFun) {
|
||||
//根据条件从列表里面移除"系统管理"
|
||||
List<Function> dataList = new ArrayList<>();
|
||||
for (Function fun : dataListFun) {
|
||||
String token = request.getHeader("X-Access-Token");
|
||||
Long tenantId = Tools.getTenantIdByToken(token);
|
||||
if (tenantId!=0L) {
|
||||
if(!("系统管理").equals(fun.getName())) {
|
||||
dataList.add(fun);
|
||||
}
|
||||
} else {
|
||||
//超管
|
||||
dataList.add(fun);
|
||||
}
|
||||
}
|
||||
dataArray = getFunctionList(dataList, type, keyId);
|
||||
outer.set("children", dataArray);
|
||||
}
|
||||
arr.add(outer);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public JSONArray getFunctionList(List<Function> dataList, String type, Long keyId) throws Exception {
|
||||
JSONArray dataArray = new JSONArray();
|
||||
//获取权限信息
|
||||
List<Long> ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
|
||||
if (null != dataList) {
|
||||
for (Function function : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.set("id", function.getId());
|
||||
item.set("key", function.getId());
|
||||
item.set("value", function.getId());
|
||||
item.set("title", function.getName());
|
||||
item.set("attributes", function.getName());
|
||||
List<Function> funList = functionService.findRoleFunction(function.getNumber());
|
||||
if(funList.size()>0) {
|
||||
JSONArray funArr = getFunctionList(funList, type, keyId);
|
||||
item.set("children", funArr);
|
||||
} else {
|
||||
if (ubValue == null){
|
||||
item.set("checked", false);
|
||||
}else {
|
||||
Boolean flag = ubValue.contains(function.getId());
|
||||
item.set("checked", flag);
|
||||
}
|
||||
}
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
return dataArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id列表查找功能信息
|
||||
* @param roleId
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/findRoleFunctionsById")
|
||||
@ApiOperation(value = "根据id列表查找功能信息")
|
||||
public R findByIds(@RequestParam("roleId") Long roleId,
|
||||
HttpServletRequest request)throws Exception {
|
||||
|
||||
UserBusiness ub = userBusinessService.getBasicData(roleId, "RoleFunctions");
|
||||
//按钮
|
||||
Map<Long,String> btnMap = new HashMap<>();
|
||||
List<BtnDto> btnStr = ub.getBtnStr();
|
||||
if(ObjectUtil.isNotEmpty(btnStr)) {
|
||||
for(BtnDto obj: btnStr) {
|
||||
if(obj.getFunId()!=null && obj.getBtnStr()!=null) {
|
||||
btnMap.put(obj.getFunId(), obj.getBtnStr());
|
||||
}
|
||||
}
|
||||
}
|
||||
//菜单
|
||||
List<Long> funIds = ub.getValue().stream().map(Number::longValue).collect(Collectors.toList());
|
||||
List<Function> dataList = functionService.findByIds(funIds);
|
||||
JSONObject outer = new JSONObject();
|
||||
outer.set("total", dataList.size());
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if (ObjectUtil.isNotEmpty(dataList)) {
|
||||
for (Function function : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.set("id", function.getId());
|
||||
item.set("name", function.getName());
|
||||
item.set("pushBtn", function.getPushBtn());
|
||||
item.set("btnStr", ObjectUtil.isEmpty(btnMap.get(function.getId()))?"":btnMap.get(function.getId()));
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
outer.set("rows", dataArray);
|
||||
return R.success(outer);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import com.zsw.base.R;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class IndexController {
|
||||
|
||||
@RequestMapping("/")
|
||||
public R<String> index(){
|
||||
return R.success("","欢迎访问回乡进销存系统");
|
||||
}
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zsw.erp.datasource.entities.PlatformConfig;
|
||||
import com.zsw.erp.service.platformConfig.PlatformConfigService;
|
||||
import com.zsw.erp.service.user.UserService;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.utils.ErpInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zsw.erp.utils.ResponseJsonUtil.returnJson;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/platformConfig")
|
||||
@Api(tags = {"平台参数"})
|
||||
public class PlatformConfigController {
|
||||
private Logger logger = LoggerFactory.getLogger(PlatformConfigController.class);
|
||||
|
||||
@Value("${demonstrate.open}")
|
||||
private boolean demonstrateOpen;
|
||||
|
||||
@Resource
|
||||
private PlatformConfigService platformConfigService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
private static final String TEST_USER = "jsh";
|
||||
|
||||
/**
|
||||
* 获取平台名称
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getPlatform/name")
|
||||
@ApiOperation(value = "获取平台名称")
|
||||
public String getPlatformName(HttpServletRequest request)throws Exception {
|
||||
String res;
|
||||
try {
|
||||
String platformKey = "platform_name";
|
||||
PlatformConfig platformConfig = platformConfigService.getPlatformConfigByKey(platformKey);
|
||||
res = platformConfig.getPlatformValue();
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
res = "ERP系统";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取官方网站地址
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getPlatform/url")
|
||||
@ApiOperation(value = "获取官方网站地址")
|
||||
public String getPlatformUrl(HttpServletRequest request)throws Exception {
|
||||
String res;
|
||||
try {
|
||||
String platformKey = "platform_url";
|
||||
PlatformConfig platformConfig = platformConfigService.getPlatformConfigByKey(platformKey);
|
||||
res = platformConfig.getPlatformValue();
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
res = "#";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据platformKey更新platformValue
|
||||
* @param object
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/updatePlatformConfigByKey")
|
||||
@ApiOperation(value = "根据platformKey更新platformValue")
|
||||
public String updatePlatformConfigByKey(@RequestBody JSONObject object,
|
||||
HttpServletRequest request)throws Exception {
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
String platformKey = object.getString("platformKey");
|
||||
String platformValue = object.getString("platformValue");
|
||||
int res = platformConfigService.updatePlatformConfigByKey(platformKey, platformValue);
|
||||
if(res > 0) {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据platformKey查询信息
|
||||
* @param platformKey
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getPlatformConfigByKey")
|
||||
@ApiOperation(value = "根据platformKey查询信息")
|
||||
public R getPlatformConfigByKey(@RequestParam("platformKey") String platformKey,
|
||||
HttpServletRequest request)throws Exception {
|
||||
|
||||
PlatformConfig platformConfig = platformConfigService.getPlatformConfigByKey(platformKey);
|
||||
return R.success(platformConfig);
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zsw.erp.datasource.entities.Role;
|
||||
import com.zsw.erp.service.role.RoleService;
|
||||
import com.zsw.erp.service.userBusiness.UserBusinessService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/role")
|
||||
@Api(tags = {"角色管理"})
|
||||
public class RoleController {
|
||||
private Logger logger = LoggerFactory.getLogger(RoleController.class);
|
||||
|
||||
@Resource
|
||||
private RoleService roleService;
|
||||
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
|
||||
/**
|
||||
* 角色对应应用显示
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/findUserRole")
|
||||
@ApiOperation(value = "查询用户的角色")
|
||||
public JSONArray findUserRole(@RequestParam("UBType") String type, @RequestParam("UBKeyId") Long keyId,
|
||||
HttpServletRequest request)throws Exception {
|
||||
JSONArray arr = new JSONArray();
|
||||
try {
|
||||
//获取权限信息
|
||||
List<Long> ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
|
||||
List<Role> dataList = roleService.findUserRole();
|
||||
if (null != dataList) {
|
||||
for (Role role : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", role.getId());
|
||||
item.put("text", role.getName());
|
||||
Boolean flag = ubValue.contains(role.getId());
|
||||
if (flag) {
|
||||
item.put("checked", true);
|
||||
}
|
||||
arr.add(item);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/allList")
|
||||
@ApiOperation(value = "查询全部角色列表")
|
||||
public List<Role> allList(HttpServletRequest request)throws Exception {
|
||||
return roleService.allList();
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,8 @@ import com.zsw.erp.datasource.entities.Supplier;
|
||||
import com.zsw.erp.dto.supplier.SupplierVo;
|
||||
import com.zsw.erp.service.supplier.SupplierService;
|
||||
import com.zsw.erp.service.systemConfig.SystemConfigService;
|
||||
import com.zsw.erp.service.tenant.TenantService;
|
||||
import com.zsw.erp.service.user.UserService;
|
||||
import com.zsw.erp.service.userBusiness.UserBusinessService;
|
||||
import cn.iocoder.yudao.framework.security.core.LoginUser;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.utils.ErpInfo;
|
||||
import com.zsw.erp.utils.ExportExecUtil;
|
||||
@@ -41,17 +40,10 @@ public class SupplierController {
|
||||
@Resource
|
||||
private SupplierService supplierService;
|
||||
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
|
||||
@Resource
|
||||
private SystemConfigService systemConfigService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
|
||||
@GetMapping(value = "/checkIsNameAndTypeExist")
|
||||
@ApiOperation(value = "检查名称和类型是否存在")
|
||||
@@ -162,19 +154,15 @@ public class SupplierController {
|
||||
}
|
||||
//2、获取客户信息
|
||||
String type = "UserCustomer";
|
||||
Long userId = userService.getUserId(request);
|
||||
List<Long> ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, userId);
|
||||
LoginUser userInfo = SecurityFrameworkUtils.getLoginUser();
|
||||
List<Supplier> customerList = supplierService.findBySelectCus();
|
||||
if (null != customerList) {
|
||||
boolean customerFlag = systemConfigService.getCustomerFlag();
|
||||
for (Supplier supplier : customerList) {
|
||||
JSONObject item = new JSONObject();
|
||||
Boolean flag = ubValue.contains(supplier.getId());
|
||||
if (!customerFlag || flag) {
|
||||
item.put("id", supplier.getId());
|
||||
item.put("supplier", supplier.getSupplier() + "[客户]"); //客户名称
|
||||
dataArray.add(item);
|
||||
}
|
||||
item.put("id", supplier.getId());
|
||||
item.put("supplier", supplier.getSupplier() + "[客户]"); //客户名称
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
arr = dataArray;
|
||||
@@ -248,7 +236,6 @@ public class SupplierController {
|
||||
JSONArray arr = new JSONArray();
|
||||
try {
|
||||
//获取权限信息
|
||||
List<Long> ubValue = userBusinessService.getUBValueByTypeAndKeyId(type, keyId);
|
||||
List<Supplier> dataList = supplierService.findUserCustomer();
|
||||
//开始拼接json数据
|
||||
JSONObject outer = new JSONObject();
|
||||
@@ -267,10 +254,7 @@ public class SupplierController {
|
||||
item.put("value", supplier.getId());
|
||||
item.put("title", supplier.getSupplier());
|
||||
item.put("attributes", supplier.getSupplier());
|
||||
Boolean flag = ubValue.contains(supplier.getId());
|
||||
if (flag) {
|
||||
item.put("checked", true);
|
||||
}
|
||||
item.put("checked", true);
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zsw.erp.service.tenant.TenantService;
|
||||
import com.zsw.erp.utils.ErpInfo;
|
||||
import com.zsw.erp.utils.ResponseCode;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zsw.erp.utils.ResponseJsonUtil.returnJson;
|
||||
import static com.zsw.erp.utils.ResponseJsonUtil.success;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/tenant")
|
||||
@Api(tags = {"租户管理"})
|
||||
public class TenantController {
|
||||
private Logger logger = LoggerFactory.getLogger(TenantController.class);
|
||||
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
|
||||
/**
|
||||
* 批量设置状态-启用或者禁用
|
||||
* @param jsonObject
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/batchSetStatus")
|
||||
@ApiOperation(value = "批量设置状态")
|
||||
public String batchSetStatus(@RequestBody JSONObject jsonObject,
|
||||
HttpServletRequest request)throws Exception {
|
||||
Boolean status = jsonObject.getBoolean("status");
|
||||
String ids = jsonObject.getString("ids");
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
int res = tenantService.batchSetStatus(status, ids);
|
||||
if(res > 0) {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/listAllTenant")
|
||||
@ApiOperation("列举全部租户")
|
||||
public ResponseCode listAllTenant() throws Exception {
|
||||
return success(tenantService.getTenant());
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.jwt.model.TenantAuthInfo;
|
||||
import com.zsw.pos.authority.dto.auth.LoginParamDTO;
|
||||
import com.zsw.pos.oauth.service.LoginService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@Slf4j
|
||||
@Validated
|
||||
public class TestController {
|
||||
|
||||
@DubboReference
|
||||
private LoginService loginService;
|
||||
|
||||
@GetMapping("/test/login")
|
||||
public R test(@RequestParam String username, @RequestParam String password){
|
||||
|
||||
LoginParamDTO dto = new LoginParamDTO();
|
||||
dto.setAccount(username);
|
||||
dto.setPassword(password);
|
||||
dto.setGrantType("password");
|
||||
R<TenantAuthInfo> rs = loginService.grant(dto);
|
||||
log.debug("login result : {}",rs.getData());
|
||||
return rs;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.zsw.erp.datasource.dto.BtnStrDto;
|
||||
import com.zsw.erp.datasource.entities.UserBusiness;
|
||||
import com.zsw.erp.service.user.UserService;
|
||||
import com.zsw.erp.service.userBusiness.UserBusinessService;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.utils.ErpInfo;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.zsw.erp.utils.ResponseJsonUtil.returnJson;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/userBusiness")
|
||||
@Api(tags = {"用户角色模块的关系"})
|
||||
public class UserBusinessController {
|
||||
private Logger logger = LoggerFactory.getLogger(UserBusinessController.class);
|
||||
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
/**
|
||||
* 获取信息
|
||||
* @param keyId
|
||||
* @param type
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping(value = "/getBasicData")
|
||||
@ApiOperation(value = "获取信息")
|
||||
public R getBasicData(@RequestParam(value = "KeyId") Long keyId,
|
||||
@RequestParam(value = "Type") String type,
|
||||
HttpServletRequest request)throws Exception {
|
||||
|
||||
UserBusiness list = userBusinessService.getBasicData(keyId, type);
|
||||
Map<String, List> mapData = new HashMap<String, List>();
|
||||
mapData.put("userBusinessList", Lists.newArrayList(list));
|
||||
return R.success(mapData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验存在
|
||||
* @param type
|
||||
* @param keyId
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping(value = "/checkIsValueExist")
|
||||
@ApiOperation(value = "校验存在")
|
||||
public String checkIsValueExist(@RequestParam(value ="type", required = false) String type,
|
||||
@RequestParam(value ="keyId", required = false) String keyId,
|
||||
HttpServletRequest request)throws Exception {
|
||||
Map<String, Object> objectMap = new HashMap<String, Object>();
|
||||
Long id = userBusinessService.checkIsValueExist(type, keyId);
|
||||
if(id != null) {
|
||||
objectMap.put("id", id);
|
||||
} else {
|
||||
objectMap.put("id", null);
|
||||
}
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新角色的按钮权限
|
||||
* @param jsonObject
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/updateBtnStr")
|
||||
@ApiOperation(value = "更新角色的按钮权限")
|
||||
public R updateBtnStr(@RequestBody BtnStrDto dto,
|
||||
HttpServletRequest request)throws Exception {
|
||||
|
||||
String roleId = dto.getRoleId();
|
||||
// JSONArray btnStrArray = jsonObject.getJSONArray("btnStr");
|
||||
// List<BtnDto> btnStr = btnStrArray.toJavaList(BtnDto.class);
|
||||
String keyId = roleId;
|
||||
String type = "RoleFunctions";
|
||||
int back = userBusinessService.updateBtnStr(keyId, type, dto.getBtnStr());
|
||||
if(back > 0) {
|
||||
return R.success("成功");
|
||||
}else {
|
||||
return R.fail("更新失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,483 +0,0 @@
|
||||
package com.zsw.erp.controller;
|
||||
|
||||
import cn.hutool.core.date.*;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.jwt.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.zsw.erp.constants.BusinessConstants;
|
||||
import com.zsw.erp.constants.ExceptionConstants;
|
||||
import com.zsw.erp.datasource.entities.BtnDto;
|
||||
import com.zsw.erp.datasource.dto.UserLoginDto;
|
||||
import com.zsw.erp.datasource.entities.Tenant;
|
||||
import com.zsw.erp.datasource.entities.User;
|
||||
import com.zsw.erp.datasource.entities.UserEx;
|
||||
import com.zsw.erp.datasource.vo.TreeNodeEx;
|
||||
import com.zsw.erp.exception.BusinessParamCheckingException;
|
||||
import com.zsw.erp.service.inventorySeason.InventorySeasonService;
|
||||
import com.zsw.erp.service.log.LogService;
|
||||
import com.zsw.erp.service.redis.RedisService;
|
||||
import com.zsw.erp.service.tenant.TenantService;
|
||||
import com.zsw.erp.service.user.UserService;
|
||||
import com.zsw.base.R;
|
||||
import com.zsw.erp.utils.*;
|
||||
import com.zsw.jwt.model.AuthInfo;
|
||||
import com.zsw.jwt.model.TenantAuthInfo;
|
||||
import com.zsw.pos.authority.dto.auth.LoginParamDTO;
|
||||
import com.zsw.pos.oauth.service.LoginService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
|
||||
import static com.zsw.erp.utils.ResponseJsonUtil.returnJson;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/user")
|
||||
@Api(tags = {"用户管理"})
|
||||
public class UserController {
|
||||
private Logger logger = LoggerFactory.getLogger(UserController.class);
|
||||
|
||||
@Value("${manage.roleId}")
|
||||
private Integer manageRoleId;
|
||||
|
||||
@Value("${demonstrate.open}")
|
||||
private boolean demonstrateOpen;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@Resource
|
||||
private TenantService tenantService;
|
||||
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
@Resource
|
||||
private InventorySeasonService inventorySeasonService;
|
||||
|
||||
@DubboReference
|
||||
private LoginService loginService;
|
||||
|
||||
@Value("${tenant.userNumLimit}")
|
||||
private Integer systemLimit;
|
||||
|
||||
private static final String TEST_USER = "jsh";
|
||||
private static String SUCCESS = "操作成功";
|
||||
private static String ERROR = "操作失败";
|
||||
private static final String HTTP = "http://";
|
||||
private static final String CODE_OK = "200";
|
||||
private static final String BASE_CHECK_CODES = "qwertyuiplkjhgfdsazxcvbnmQWERTYUPLKJHGFDSAZXCVBNM1234567890";
|
||||
|
||||
@PostMapping(value = "/login")
|
||||
@ApiOperation(value = "登录")
|
||||
public R login(@RequestBody User userParam,
|
||||
HttpServletRequest request)throws Exception {
|
||||
logger.info("============用户登录 login 方法调用开始==============");
|
||||
String msgTip = "";
|
||||
User user=null;
|
||||
|
||||
String loginName = userParam.getLoginName().trim();
|
||||
String password = userParam.getPassword().trim();
|
||||
|
||||
String posTenantCode = null;
|
||||
JWTPayload payload = new JWTPayload();
|
||||
|
||||
// 登录zsw-admin
|
||||
LoginParamDTO dto = new LoginParamDTO();
|
||||
dto.setAccount(loginName);
|
||||
dto.setPassword(password);
|
||||
R<TenantAuthInfo> result = loginService.grant(dto);
|
||||
logger.error("result:{}",result);
|
||||
if (result.getIsSuccess()){
|
||||
// 检查系统里是否存在租户和账户 没有准备走注册流程
|
||||
posTenantCode = result.getData().getTenantCode();
|
||||
// 在这里带了太多的门店ID
|
||||
payload.setPayload("loginName",loginName);
|
||||
payload.setPayload("tenantId",posTenantCode);
|
||||
}
|
||||
|
||||
//获取用户状态
|
||||
//int userStatus = -1;
|
||||
redisService.deleteObjectBySession(request,"userId");
|
||||
UserLoginDto loginDto = userService.validateUser(loginName, password);
|
||||
|
||||
switch (loginDto.getUserStatus()) {
|
||||
case ExceptionCodeConstants.UserExceptionCode.USER_NOT_EXIST:
|
||||
msgTip = "user is not exist";
|
||||
if (posTenantCode != null){
|
||||
// 用户不存在 但是用户不存在 可能报错。
|
||||
UserEx ex = new UserEx();
|
||||
ex.setLoginName(loginName);
|
||||
ex.setPassword(password);
|
||||
ex.setTenantId(Long.parseLong(posTenantCode));
|
||||
LocalDateTime time = LocalDateTimeUtil.offset(LocalDateTime.now(), 10, ChronoUnit.YEARS);
|
||||
DateTimeFormatter formater = DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN);
|
||||
String t = time.format(formater);
|
||||
ex.setExpireTime(t);
|
||||
user = this.registerUser(ex,request);
|
||||
payload.setPayload("userId",user.getId());
|
||||
payload.setPayload("loginName",loginName);
|
||||
payload.setPayload("tenantId",posTenantCode);
|
||||
msgTip = "user can login";
|
||||
}
|
||||
break;
|
||||
case ExceptionCodeConstants.UserExceptionCode.USER_PASSWORD_ERROR:
|
||||
msgTip = "user password error";
|
||||
break;
|
||||
case ExceptionCodeConstants.UserExceptionCode.BLACK_USER:
|
||||
msgTip = "user is black";
|
||||
break;
|
||||
case ExceptionCodeConstants.UserExceptionCode.USER_ACCESS_EXCEPTION:
|
||||
msgTip = "access service error";
|
||||
break;
|
||||
case ExceptionCodeConstants.UserExceptionCode.BLACK_TENANT:
|
||||
msgTip = "tenant is black";
|
||||
break;
|
||||
case ExceptionCodeConstants.UserExceptionCode.EXPIRE_TENANT:
|
||||
msgTip = "tenant is expire";
|
||||
break;
|
||||
case ExceptionCodeConstants.UserExceptionCode.USER_CONDITION_FIT:
|
||||
msgTip = "user can login";
|
||||
user = loginDto.getUser();
|
||||
payload.setPayload("userId",user.getId());
|
||||
payload.setPayload("loginName",loginName);
|
||||
payload.setPayload("tenantId",user.getTenantId());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// 1个月过期
|
||||
DateTime exAt = DateUtil.offset(new Date(), DateField.MONTH, 1);
|
||||
payload.setExpiresAt(exAt);
|
||||
String token = JWTUtil.createToken(payload.getClaimsJson(), "88888888".getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("msgTip", msgTip);
|
||||
if(user!=null){
|
||||
redisService.storageObjectBySession(token,"userId",user.getId());
|
||||
String roleType = userService.getRoleTypeByUserId(user.getId()); //角色类型
|
||||
if (roleType == null){
|
||||
logger.error("角色错误!");
|
||||
}
|
||||
redisService.storageObjectBySession(token,"roleType",roleType);
|
||||
redisService.storageObjectBySession(token,"clientIp", Tools.getLocalIp(request));
|
||||
logService.insertLogWithUserId(user.getId(), user.getTenantId(), "用户",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_LOGIN).append(user.getLoginName()).toString(),
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
List<BtnDto> btnStrArr = userService.getBtnStrArrById(user.getId());
|
||||
data.put("token", token);
|
||||
data.put("user", user);
|
||||
LocalUser.setTenantId(user.getTenantId());
|
||||
LocalUser.setUserId(user.getId());
|
||||
data.put("season",inventorySeasonService.getNow());
|
||||
//用户的按钮权限
|
||||
if(!"admin".equals(user.getLoginName())){
|
||||
data.put("userBtn", btnStrArr);
|
||||
}
|
||||
data.put("roleType", roleType);
|
||||
logger.info("===============用户登录 login 方法调用结束===============");
|
||||
return R.success(data);
|
||||
}else{
|
||||
return R.fail("用户名或者密码错误");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@GetMapping(value = "/getUserSession")
|
||||
@ApiOperation(value = "获取用户信息")
|
||||
public R getSessionUser(HttpServletRequest request)throws Exception {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
|
||||
User user = userService.getUser(userId);
|
||||
user.setPassword(null);
|
||||
data.put("user", user);
|
||||
return R.success(data);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/logout")
|
||||
@ApiOperation(value = "退出")
|
||||
public R logout(HttpServletRequest request, HttpServletResponse response)throws Exception {
|
||||
redisService.deleteObjectBySession(request,"userId");
|
||||
return R.success();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/resetPwd")
|
||||
@ApiOperation(value = "重置密码")
|
||||
public String resetPwd(@RequestBody JSONObject jsonObject,
|
||||
HttpServletRequest request) throws Exception {
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
Long id = jsonObject.getLong("id");
|
||||
String password = "123456";
|
||||
String md5Pwd = Tools.md5Encryp(password);
|
||||
int update = userService.resetPwd(md5Pwd, id);
|
||||
if(update > 0) {
|
||||
return returnJson(objectMap, SUCCESS, ErpInfo.OK.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ERROR, ErpInfo.ERROR.code);
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping(value = "/updatePwd")
|
||||
@ApiOperation(value = "更新密码")
|
||||
public String updatePwd(@RequestBody JSONObject jsonObject, HttpServletRequest request)throws Exception {
|
||||
Integer flag = 0;
|
||||
Map<String, Object> objectMap = new HashMap<String, Object>();
|
||||
try {
|
||||
String info = "";
|
||||
Long userId = jsonObject.getLong("userId");
|
||||
String oldpwd = jsonObject.getString("oldpassword");
|
||||
String password = jsonObject.getString("password");
|
||||
User user = userService.getUser(userId);
|
||||
//必须和原始密码一致才可以更新密码
|
||||
if(demonstrateOpen && user.getLoginName().equals(TEST_USER)){
|
||||
flag = 3; //jsh用户不能修改密码
|
||||
info = "jsh用户不能修改密码";
|
||||
} else if (oldpwd.equalsIgnoreCase(user.getPassword())) {
|
||||
user.setPassword(password);
|
||||
flag = userService.updateUserByObj(user); //1-成功
|
||||
info = "修改成功";
|
||||
} else {
|
||||
flag = 2; //原始密码输入错误
|
||||
info = "原始密码输入错误";
|
||||
}
|
||||
objectMap.put("status", flag);
|
||||
if(flag > 0) {
|
||||
return returnJson(objectMap, info, ErpInfo.OK.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ERROR, ErpInfo.ERROR.code);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(">>>>>>>>>>>>>修改用户ID为 : " + jsonObject.getLong("userId") + "密码信息失败", e);
|
||||
flag = 3;
|
||||
objectMap.put("status", flag);
|
||||
return returnJson(objectMap, ERROR, ErpInfo.ERROR.code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部用户数据列表
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getAllList")
|
||||
@ApiOperation(value = "获取全部用户数据列表")
|
||||
public R getAllList(HttpServletRequest request)throws Exception {
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
List<User> dataList = userService.getUser();
|
||||
if(dataList!=null) {
|
||||
data.put("userList", dataList);
|
||||
}
|
||||
return R.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户列表,用于用户下拉框
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@GetMapping(value = "/getUserList")
|
||||
@ApiOperation(value = "用户列表")
|
||||
public JSONArray getUserList(HttpServletRequest request)throws Exception {
|
||||
JSONArray dataArray = new JSONArray();
|
||||
try {
|
||||
List<User> dataList = userService.getUser();
|
||||
if (null != dataList) {
|
||||
for (User user : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", user.getId());
|
||||
item.put("userName", user.getUsername());
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return dataArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 新增用户及机构和用户关系
|
||||
* create time: 2019/3/8 16:06
|
||||
* @Param: beanJson
|
||||
* @return java.lang.Object
|
||||
*/
|
||||
@PostMapping("/addUser")
|
||||
@ApiOperation(value = "新增用户")
|
||||
@ResponseBody
|
||||
public Object addUser(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception{
|
||||
JSONObject result = ExceptionConstants.standardSuccess();
|
||||
// 系统的人数限制
|
||||
Object limit = redisService.getObjectFromSessionByKey(request, "userNumLimit");
|
||||
Long userNumLimit = ObjectUtil.isNotEmpty(limit)
|
||||
? Long.parseLong(limit.toString())
|
||||
: systemLimit;
|
||||
Long count = userService.countUser(null,null);
|
||||
if(count>= userNumLimit) {
|
||||
throw new BusinessParamCheckingException(ExceptionConstants.USER_OVER_LIMIT_FAILED_CODE,
|
||||
ExceptionConstants.USER_OVER_LIMIT_FAILED_MSG);
|
||||
} else {
|
||||
UserEx ue= JSONObject.parseObject(obj.toJSONString(), UserEx.class);
|
||||
userService.addUserAndOrgUserRel(ue, request);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* create by: cjl
|
||||
* description:
|
||||
* 修改用户及机构和用户关系
|
||||
* create time: 2019/3/8 16:06
|
||||
* @Param: beanJson
|
||||
* @return java.lang.Object
|
||||
*/
|
||||
@PutMapping("/updateUser")
|
||||
@ApiOperation(value = "修改用户")
|
||||
@ResponseBody
|
||||
public Object updateUser(@RequestBody JSONObject obj, HttpServletRequest request)throws Exception{
|
||||
JSONObject result = ExceptionConstants.standardSuccess();
|
||||
UserEx ue= JSONObject.parseObject(obj.toJSONString(), UserEx.class);
|
||||
userService.updateUserAndOrgUserRel(ue, request);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册用户
|
||||
* @param ue
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@PostMapping(value = "/registerUser")
|
||||
@ApiOperation(value = "注册用户")
|
||||
public UserEx registerUser(@RequestBody UserEx ue,
|
||||
HttpServletRequest request)throws Exception{
|
||||
logger.error("用户注册开始...");
|
||||
JSONObject result = ExceptionConstants.standardSuccess();
|
||||
ue.setUsername(ue.getLoginName());
|
||||
userService.checkUserNameAndLoginName(ue); //检查用户名和登录名
|
||||
ue = userService.registerUser(ue,manageRoleId,request);
|
||||
return ue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取机构用户树
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@RequestMapping("/getOrganizationUserTree")
|
||||
@ApiOperation(value = "获取机构用户树")
|
||||
public JSONArray getOrganizationUserTree()throws Exception{
|
||||
JSONArray arr=new JSONArray();
|
||||
List<TreeNodeEx> organizationUserTree= userService.getOrganizationUserTree();
|
||||
if(organizationUserTree!=null&&organizationUserTree.size()>0){
|
||||
for(TreeNodeEx node:organizationUserTree){
|
||||
String str=JSON.toJSONString(node);
|
||||
JSONObject obj=JSON.parseObject(str);
|
||||
arr.add(obj) ;
|
||||
}
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的角色类型
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/getRoleTypeByCurrentUser")
|
||||
@ApiOperation(value = "获取当前用户的角色类型")
|
||||
public R getRoleTypeByCurrentUser(HttpServletRequest request) {
|
||||
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
String roleType = redisService.getObjectFromSessionByKey(request,"roleType").toString();
|
||||
data.put("roleType", roleType);
|
||||
return R.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取随机校验码
|
||||
* @param response
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/randomImage/{key}")
|
||||
@ApiOperation(value = "获取随机校验码")
|
||||
public R randomImage(HttpServletResponse response,@PathVariable String key) throws IOException {
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
String codeNum = Tools.getCharAndNum(4);
|
||||
String base64 = RandImageUtil.generate(codeNum);
|
||||
data.put("codeNum", codeNum);
|
||||
data.put("base64", base64);
|
||||
return R.success(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量设置状态-启用或者禁用
|
||||
* @param jsonObject
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/batchSetStatus")
|
||||
@ApiOperation(value = "批量设置状态")
|
||||
public String batchSetStatus(@RequestBody JSONObject jsonObject,
|
||||
HttpServletRequest request)throws Exception {
|
||||
Byte status = jsonObject.getByte("status");
|
||||
String ids = jsonObject.getString("ids");
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
int res = userService.batchSetStatus(status, ids);
|
||||
if(res > 0) {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的用户数量和租户信息
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/infoWithTenant")
|
||||
@ApiOperation(value = "获取当前用户的用户数量和租户信息")
|
||||
public R randomImage(HttpServletRequest request){
|
||||
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
|
||||
User user = userService.getUser(userId);
|
||||
//获取当前用户数
|
||||
Long userCurrentNum = userService.countUser(null, null);
|
||||
Tenant tenant = tenantService.getTenantByTenantId(user.getTenantId());
|
||||
data.put("type", tenant.getType()); //租户类型,0免费租户,1付费租户
|
||||
data.put("expireTime", Tools.parseDateToStr(tenant.getExpireTime()));
|
||||
data.put("userCurrentNum", userCurrentNum);
|
||||
data.put("userNumLimit", tenant.getUserNumLimit());
|
||||
return R.success(data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user