给客户信息页面增加分配用户相关的接口
This commit is contained in:
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.base.BaseController;
|
||||
import com.jsh.erp.base.TableDataInfo;
|
||||
import com.jsh.erp.datasource.entities.Supplier;
|
||||
import com.jsh.erp.datasource.entities.User;
|
||||
import com.jsh.erp.datasource.vo.SupplierSimple;
|
||||
import com.jsh.erp.service.SupplierService;
|
||||
import com.jsh.erp.service.SystemConfigService;
|
||||
@@ -25,6 +26,8 @@ import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
|
||||
import static com.jsh.erp.utils.ResponseJsonUtil.returnStr;
|
||||
@@ -347,6 +350,54 @@ public class SupplierController extends BaseController {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* 客户对应用户显示
|
||||
* @param type
|
||||
* @param oneValue
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getCustomerUser")
|
||||
@ApiOperation(value = "客户对应用户显示")
|
||||
public JSONArray findUserCustomer(@RequestParam("UBType") String type, @RequestParam("UBValue") String oneValue,
|
||||
HttpServletRequest request) throws Exception{
|
||||
JSONArray arr = new JSONArray();
|
||||
try {
|
||||
//获取权限信息
|
||||
List<Long> keyIdList = userBusinessService.getUBKeyIdByTypeAndOneValue(type, oneValue);
|
||||
Map<Long, Long> keyIdMap = keyIdList.stream().collect(Collectors.toMap(Function.identity(),Function.identity()));
|
||||
List<User> dataList = userService.getUser(request);
|
||||
//开始拼接json数据
|
||||
JSONObject outer = new JSONObject();
|
||||
outer.put("id", 0);
|
||||
outer.put("key", 0);
|
||||
outer.put("value", 0);
|
||||
outer.put("title", "用户列表");
|
||||
outer.put("attributes", "用户列表");
|
||||
//存放数据json数组
|
||||
JSONArray dataArray = new JSONArray();
|
||||
if (null != dataList) {
|
||||
for (User user : dataList) {
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", user.getId());
|
||||
item.put("key", user.getId());
|
||||
item.put("value", user.getId());
|
||||
item.put("title", user.getLoginName() + "(" + user.getUsername() + ")");
|
||||
item.put("attributes", user.getLoginName());
|
||||
if (keyIdMap.get(user.getId())!=null) {
|
||||
item.put("checked", true);
|
||||
}
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
outer.put("children", dataArray);
|
||||
arr.add(outer);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据客户或供应商查询期初、期初已收等信息
|
||||
* @param organId
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsh.erp.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.datasource.entities.UserBusiness;
|
||||
import com.jsh.erp.service.UserBusinessService;
|
||||
@@ -167,4 +168,32 @@ public class UserBusinessController {
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据KeyId和类型更新一个值
|
||||
* @param jsonObject
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/updateOneValueByKeyIdAndType")
|
||||
@ApiOperation(value = "根据KeyId和类型更新一个值")
|
||||
public BaseResponseInfo updateOneValueByKeyIdAndType(@RequestBody JSONObject jsonObject,
|
||||
HttpServletRequest request)throws Exception {
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
try {
|
||||
String type = jsonObject.getString("type");
|
||||
JSONArray keyIdArr = jsonObject.getJSONArray("keyIds");
|
||||
String oneValue = jsonObject.getString("oneValue");
|
||||
int back = userBusinessService.updateOneValueByKeyIdAndType(type, keyIdArr, oneValue);
|
||||
if(back > 0) {
|
||||
res.code = 200;
|
||||
res.data = "成功";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
res.code = 500;
|
||||
res.data = "更新权限失败";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,11 @@ public interface UserBusinessMapperEx {
|
||||
@Param("type") String type);
|
||||
|
||||
void updateValueByTypeAndKeyId(@Param("type") String type, @Param("keyId") String keyId, @Param("ubValue") String ubValue);
|
||||
|
||||
List<Long> getUBKeyIdByTypeAndOneValue(
|
||||
@Param("type") String type,
|
||||
@Param("oneValue") String oneValue);
|
||||
|
||||
List<UserBusiness> getOldListByType(
|
||||
@Param("type") String type);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.jsh.erp.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.BusinessConstants;
|
||||
import com.jsh.erp.datasource.entities.User;
|
||||
@@ -18,7 +19,9 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class UserBusinessService {
|
||||
@@ -172,4 +175,70 @@ public class UserBusinessService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Long> getUBKeyIdByTypeAndOneValue(String type, String oneValue) {
|
||||
return userBusinessMapperEx.getUBKeyIdByTypeAndOneValue(type, oneValue);
|
||||
}
|
||||
|
||||
public int updateOneValueByKeyIdAndType(String type, JSONArray keyIdArr, String oneValue) {
|
||||
int res = 0;
|
||||
try {
|
||||
Map<String, String> keyIdMap = new HashMap<>();
|
||||
List<UserBusiness> oldUbList = userBusinessMapperEx.getOldListByType(type);
|
||||
for(Object keyIdObj: keyIdArr) {
|
||||
String keyId = keyIdObj.toString();
|
||||
keyIdMap.put(keyId, keyId);
|
||||
List<UserBusiness> ubList = userBusinessMapperEx.getBasicDataByKeyIdAndType(keyId, type);
|
||||
if(ubList.size()>0) {
|
||||
String valueStr = ubList.get(0).getValue();
|
||||
Boolean flag = valueStr.contains("[" + oneValue + "]");
|
||||
if(flag) {
|
||||
//存在则忽略
|
||||
} else {
|
||||
//不存在则追加并更新
|
||||
valueStr = valueStr + "[" + oneValue + "]";
|
||||
UserBusiness userBusiness = new UserBusiness();
|
||||
userBusiness.setId(ubList.get(0).getId());
|
||||
userBusiness.setValue(valueStr);
|
||||
userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
|
||||
}
|
||||
} else {
|
||||
//新增数据
|
||||
UserBusiness userBusiness = new UserBusiness();
|
||||
userBusiness.setType(type);
|
||||
userBusiness.setKeyId(keyId);
|
||||
userBusiness.setValue("[" + oneValue + "]");
|
||||
userBusinessMapper.insertSelective(userBusiness);
|
||||
}
|
||||
}
|
||||
//检查被移除的keyId
|
||||
for(UserBusiness item: oldUbList) {
|
||||
String oldValue = item.getValue();
|
||||
String oldkeyId = item.getKeyId();
|
||||
if(keyIdMap.get(oldkeyId) == null) {
|
||||
//处理被删除的keyId
|
||||
String valueStr = "[" + oneValue + "]";
|
||||
if(oldValue.equals(valueStr)) {
|
||||
//说明value里面只有一条数据,需要进行逻辑删除
|
||||
UserBusiness userBusiness = new UserBusiness();
|
||||
userBusiness.setId(item.getId());
|
||||
userBusiness.setDeleteFlag("1");
|
||||
userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
|
||||
} else {
|
||||
//多条进行替换后再更新
|
||||
String newValue = oldValue.replace(valueStr, "");
|
||||
UserBusiness userBusiness = new UserBusiness();
|
||||
userBusiness.setId(item.getId());
|
||||
userBusiness.setValue(newValue);
|
||||
userBusinessMapper.updateByPrimaryKeySelective(userBusiness);
|
||||
}
|
||||
}
|
||||
}
|
||||
res = 1;
|
||||
} catch (Exception e) {
|
||||
res = 0;
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,4 +23,18 @@
|
||||
set value= #{ubValue}
|
||||
where type = #{type} and key_id = #{keyId}
|
||||
</update>
|
||||
|
||||
<select id="getUBKeyIdByTypeAndOneValue" resultType="java.lang.Long">
|
||||
select ub.key_id from jsh_user_business ub
|
||||
where ub.type='UserCustomer'
|
||||
<bind name="bindOneValue" value="'%['+oneValue+']%'"/>
|
||||
and ub.value like #{bindOneValue}
|
||||
and ifnull(ub.delete_flag,'0') !='1'
|
||||
</select>
|
||||
|
||||
<select id="getOldListByType" resultType="com.jsh.erp.datasource.entities.UserBusiness">
|
||||
select * from jsh_user_business ub
|
||||
where ub.type='UserCustomer'
|
||||
and ifnull(ub.delete_flag,'0') !='1'
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user