Commit 0587e349 by kangxiaoshan

权限处理

parent 43e6bd00
......@@ -203,7 +203,12 @@ public class ContractController {
@RequestMapping(value = "find/body", method = RequestMethod.GET)
@ResponseBody
public ResultModel findBody(@CurrentAccount User loginAccount,@PathVariable String platform) {
public ResultModel findBody(@CurrentAccount User loginAccount,@PathVariable String platform,String dropall) {
if("all".equals(dropall)){
platform = dropall;
}
return ResultModel.OK(service.findBody(platform));
}
......
package common.controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.*;
@RestController
public class ContractSaveController {
@RequestMapping(value = "txt2db",method = RequestMethod.GET)
void saveTxtData2Db(){
BufferedReader reader = null;
try {
File txt = ResourceUtils.getFile("classpath:hisdata.txt");
reader = new BufferedReader(new FileReader(txt));
String tempString = null;
while ((tempString = reader.readLine()) != null) {
// 显示行号
System.out.println(tempString);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
}
}
......@@ -62,6 +62,9 @@ public class LoginController {
if(null != user.getRoleType()){
user.setRoleTypeName(roleTypeRepository.getName(user.getRoleType()));
}
Cookie cookie = new Cookie("TOKEN", token);
cookie.setPath("/");
cookie.setMaxAge(60 * 60 * 24 * 7);
......
......@@ -78,6 +78,7 @@ public class UserController {
@RequestMapping(value = "/find/role", method = RequestMethod.GET)
@ResponseBody
public ResultModel findRole(@CurrentAccount User loginAccount) {
return ResultModel.OK(roleRepository.findAll());
}
......
......@@ -13,6 +13,8 @@ public class Auth {
private Long user;
private String auth;
private String authExtend;
private Long modifyAccount;
private Long createAccount;
private Date modifyTime;
......@@ -45,6 +47,14 @@ public class Auth {
this.auth = auth;
}
public String getAuthExtend() {
return authExtend;
}
public void setAuthExtend(String authExtend) {
this.authExtend = authExtend;
}
public Long getModifyAccount() {
return modifyAccount;
}
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class AuthDic {
private Long id;
private String dicName;
private int index;
private int type;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getDicName() {
return dicName;
}
public void setDicName(String dicName) {
this.dicName = dicName;
}
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
......@@ -19,6 +19,7 @@ public class User {
private Long roleType;
private String roleTypeName;
private String auth;
private String authExtend;
private Boolean status;
private Long parent;
......@@ -128,6 +129,15 @@ public class User {
this.auth = auth;
}
@Transient
public String getAuthExtend() {
return authExtend;
}
public void setAuthExtend(String authExtend) {
this.authExtend = authExtend;
}
public Boolean getStatus() {
return status;
}
......
......@@ -13,4 +13,7 @@ public interface ContractBodyRepository extends JpaRepository<ContractBody, Long
@Query(value = "select * from contract_body where platform = ?1 ",nativeQuery = true)
List<ContractBody> findByPlatform(String platform);
@Query(value = "select distinct * from contract_body",nativeQuery = true)
List<ContractBody> findAllDis();
}
......@@ -82,4 +82,16 @@ public interface ContractRepository extends JpaRepository<Contract, Long> {
@Query(value = "select * from contract where contract_code =?2 and platform = ?1 ",nativeQuery = true)
Contract findOneByCode(String platform, String contractId);
@Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and customer_body in ?4 and id in ?5 and status!='del' order by ds desc",nativeQuery = true)
List<Contract> findByDsContractBody(String startDate, String endDate, List<String> platforms, List bodyids, List<String> ids);
@Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and customer_body in ?4 and status!='del' order by ds desc",nativeQuery = true)
List<Contract> findByDsContractBody(String startDate, String endDate, String platform, List bodyids);
@Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and sale in ?4 and status!='del' order by ds desc",nativeQuery = true)
List<Contract> findByDsContractSalse(String startDate, String endDate, String platform, List salseid);
@Query(value = "select * from contract where start_date >= ?1 and start_date <= ?2 and platform in ?3 and sale in ?4 and id in ?5 and status!='del' order by ds desc",nativeQuery = true)
List<Contract> findByDsContractSalse(String startDate, String endDate, List<String> platforms, List salseid, List<String> ids);
}
......@@ -189,10 +189,15 @@ public class ContractServiceImpl implements ContractService {
@Override
public List<ContractBody> findBody(String platform) {
List<ContractBody> common = contractBodyRepository.findByPlatform("common");
List<ContractBody> byPlatform = contractBodyRepository.findByPlatform(platform);
common.addAll(byPlatform);
return common;
if("all".equals(platform)){
List<ContractBody> all = contractBodyRepository.findAllDis();
return all;
}else{
List<ContractBody> common = contractBodyRepository.findByPlatform("common");
List<ContractBody> byPlatform = contractBodyRepository.findByPlatform(platform);
common.addAll(byPlatform);
return common;
}
}
......@@ -1073,42 +1078,81 @@ public class ContractServiceImpl implements ContractService {
List<String> ids = new ArrayList<>(idsDic.keySet());
if (loginAccount.getRole().equals(RoleEnum.SOUTH_BUSSINUSS.getKey()) || loginAccount.getRole().equals(RoleEnum.NORTH_BUSSINUSS.getKey())) {
List<User> userList = userService.findAllSons(loginAccount.getId());
List<Long> idList = new ArrayList<>();
idList.add(loginAccount.getId());
for (User u : userList) {
idList.add(u.getId());
if(RoleEnum.FINANCE.getKey().equals(loginAccount.getRole())){
//财务 按签约主体查看
List bodyids = Arrays.asList(loginAccount.getAuthExtend().split(","));
if (!StringUtils.isEmpty(contractId)) {
if (ids != null && ids.size() > 0) {
contractList = contractRepository.findByDsContractBody(startDate, endDate, platforms,bodyids,ids);
}
} else {
contractList = contractRepository.findByDsContractBody(startDate, endDate, platform,bodyids);
}
// contractList = contractRepository.findByDsAndRoile(startDate, endDate, platfrom, idList);
}else if(RoleEnum.SALSEMAN.getKey().equals(loginAccount.getRole())){
//销售 按签约合同人查看
List salseid = Arrays.asList(loginAccount.getAuthExtend().split(","));
if (!StringUtils.isEmpty(contractId)) {
//查看关联合同
if (ids != null && ids.size() > 0) {
contractList = contractRepository.findByDsAndRoileRelation(startDate, endDate, platforms, idList, ids);
contractList = contractRepository.findByDsContractSalse(startDate, endDate, platforms,salseid,ids);
}
} else {
contractList = contractRepository.findByDsAndRoile(startDate, endDate, platform, idList);
contractList = contractRepository.findByDsContractSalse(startDate, endDate, platform,salseid);
}
} else {
// contractList = contractRepository.findByDs(startDate, endDate, platform);
}else{
if (!StringUtils.isEmpty(contractId)) {
if (ids != null && ids.size() > 0) {
contractList = contractRepository.findByDsRelation(startDate, endDate, platforms, ids);
}
} else {
contractList = contractRepository.findByDs(startDate, endDate, platform);
}
}
// if (loginAccount.getRole().equals(RoleEnum.SOUTH_BUSSINUSS.getKey()) || loginAccount.getRole().equals(RoleEnum.NORTH_BUSSINUSS.getKey())) {
//
// List<User> userList = userService.findAllSons(loginAccount.getId());
// List<Long> idList = new ArrayList<>();
// idList.add(loginAccount.getId());
// for (User u : userList) {
// idList.add(u.getId());
// }
//
//// contractList = contractRepository.findByDsAndRoile(startDate, endDate, platfrom, idList);
//
//
// if (!StringUtils.isEmpty(contractId)) {
// //查看关联合同
// if (ids != null && ids.size() > 0) {
// contractList = contractRepository.findByDsAndRoileRelation(startDate, endDate, platforms, idList, ids);
// }
//
// } else {
// contractList = contractRepository.findByDsAndRoile(startDate, endDate, platform, idList);
// }
//
//
// } else {
//// contractList = contractRepository.findByDs(startDate, endDate, platform);
//
// if (!StringUtils.isEmpty(contractId)) {
// if (ids != null && ids.size() > 0) {
// contractList = contractRepository.findByDsRelation(startDate, endDate, platforms, ids);
// }
// } else {
// contractList = contractRepository.findByDs(startDate, endDate, platform);
// }
//
// }
Map<String, String> saleMap = new HashMap();
Map<String, PackageType> typeMap = new HashMap();
......@@ -1157,8 +1201,8 @@ public class ContractServiceImpl implements ContractService {
c.setPriceLevelName(packageBaseMap.get(c.getPriceLevel()) == null ? "" : packageBaseMap.get(c.getPriceLevel()).getPackageName());
}
// c.setCreateName(saleMap.containsKey(c.getCreateAccount()) ? saleMap.get(c.getCreateAccount()) : "");
c.setCreateName(saleMap.containsKey(c.getCreateAccount()) ? saleMap.get(c.getCreateAccount()) : "");
result.add(c);
}
}
......
......@@ -65,15 +65,15 @@ public class UserServiceImpl implements UserService {
resource.setStatus(true);
User save = userRepository.save(resource);
if(resource.getRole().equals(RoleEnum.SOUTH_BUSSINUSS.getKey())){
bussinussManService.create(login.getEmail(), save.getEmail(), save.getName(),"华北");
salesManService.create(login.getEmail(), save.getEmail(), save.getName());
ioSalesManService.create(login.getEmail(), save.getEmail(), save.getName());
} else if(resource.getRole().equals(RoleEnum.NORTH_BUSSINUSS.getKey())){
bussinussManService.create(login.getEmail(), save.getEmail(), save.getName(),"华南");
salesManService.create(login.getEmail(), save.getEmail(), save.getName());
ioSalesManService.create(login.getEmail(), save.getEmail(), save.getName());
}
// if(resource.getRole().equals(RoleEnum.SOUTH_BUSSINUSS.getKey())){
// bussinussManService.create(login.getEmail(), save.getEmail(), save.getName(),"华北");
// salesManService.create(login.getEmail(), save.getEmail(), save.getName());
// ioSalesManService.create(login.getEmail(), save.getEmail(), save.getName());
// } else if(resource.getRole().equals(RoleEnum.NORTH_BUSSINUSS.getKey())){
// bussinussManService.create(login.getEmail(), save.getEmail(), save.getName(),"华南");
// salesManService.create(login.getEmail(), save.getEmail(), save.getName());
// ioSalesManService.create(login.getEmail(), save.getEmail(), save.getName());
// }
//auth
......@@ -81,6 +81,7 @@ public class UserServiceImpl implements UserService {
auth.setCreateTime(new Date());
auth.setCreateAccount(login.getId());
auth.setAuth(resource.getAuth());
auth.setAuthExtend(resource.getAuthExtend());
auth.setUser(save.getId());
authRepository.save(auth);
return save;
......@@ -107,46 +108,50 @@ public class UserServiceImpl implements UserService {
auth.setModifyTime(new Date());
auth.setModifyAccount(login.getId());
auth.setAuth(resource.getAuth());
auth.setAuthExtend(resource.getAuthExtend());
auth.setUser(save.getId());
Auth authSave = authRepository.save(auth);
if(null != save.getRoleType() && save.getRoleType().equals(RoleTypeEnum.COMMON.getKey())){
JSONArray rootArr = JSONArray.fromObject(authSave.getAuth());
List<String> authList = new ArrayList<>();
if(ValidateUtil.isValid(rootArr)){
for (int i = 0; i < rootArr.size(); i++) {
JSONObject obj = rootArr.getJSONObject(i);
authList.add(obj.getString("id"));
}
}
List<User> userList = findSonsAlive(save.getId());
if(ValidateUtil.isValid(userList)){
List<Long> ids = new ArrayList<>();
for(User u : userList){
ids.add(u.getId());
}
List<Auth> list = authRepository.findAllByUsers(ids);
if(ValidateUtil.isValid(list)){
List<Auth> authListSave = new ArrayList<>();
for(Auth a : list){
String authStr = a.getAuth();
JSONArray arrSave = new JSONArray();
JSONArray arr = JSONArray.fromObject(authStr);
if(ValidateUtil.isValid(arr)){
for (int i = 0; i < arr.size(); i++) {
JSONObject obj = arr.getJSONObject(i);
if(authList.contains(obj.getString("id"))){
arrSave.add(obj);
}
}
}
a.setAuth(arrSave.toString());
authListSave.add(a);
}
authRepository.save(authSave);
}
}
}
// if(null != save.getRoleType() && save.getRoleType().equals(RoleTypeEnum.COMMON.getKey())){
// JSONArray rootArr = JSONArray.fromObject(authSave.getAuth());
// List<String> authList = new ArrayList<>();
// if(ValidateUtil.isValid(rootArr)){
// for (int i = 0; i < rootArr.size(); i++) {
// JSONObject obj = rootArr.getJSONObject(i);
// authList.add(obj.getString("id"));
// }
// }
// List<User> userList = findSonsAlive(save.getId());
// if(ValidateUtil.isValid(userList)){
// List<Long> ids = new ArrayList<>();
// for(User u : userList){
// ids.add(u.getId());
// }
// List<Auth> list = authRepository.findAllByUsers(ids);
// if(ValidateUtil.isValid(list)){
// List<Auth> authListSave = new ArrayList<>();
// for(Auth a : list){
// String authStr = a.getAuth();
// JSONArray arrSave = new JSONArray();
// JSONArray arr = JSONArray.fromObject(authStr);
// if(ValidateUtil.isValid(arr)){
// for (int i = 0; i < arr.size(); i++) {
// JSONObject obj = arr.getJSONObject(i);
// if(authList.contains(obj.getString("id"))){
// arrSave.add(obj);
// }
// }
// }
// a.setAuth(arrSave.toString());
// authListSave.add(a);
// }
//
// // 这是什么操作?
// authRepository.save(authSave);
// }
// }
// }
return save;
}
......
......@@ -6,9 +6,13 @@ package dic;
*/
public enum RoleEnum {
MANAGER(1L,"管理员"),
NORTH_BUSSINUSS(2L,"北区商务"),
SOUTH_BUSSINUSS(3L,"南区商务");
MANAGER(1L, "管理员"),
NORTH_BUSSINUSS(2L, "北区商务"),
SOUTH_BUSSINUSS(3L, "南区商务"),
SALSEMAN(3L, "销售"),
FINANCE(2L, "财务"),
PM(4L, "项目经理");
private Long key;
......
......@@ -59,6 +59,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
|| requestURL.indexOf("update/pwd") != -1
|| requestURL.indexOf("user/forget") != -1
|| requestURL.indexOf("user/code") != -1
|| requestURL.indexOf("txt2db") != -1
|| requestURL.indexOf("contract/build") != -1
|| requestURL.indexOf("accountmng/findSaleInfo") != -1){
return true;
......
......@@ -22,6 +22,7 @@ public class AccountServiceImpl implements AccountService {
@Autowired
AccountRepository accountRepository;
@Override
public Account update(Contract contract) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment