TenantService.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package com.yihu.hos.tenant.service;
  2. import com.yihu.hos.tenant.dao.TenantDao;
  3. import com.yihu.hos.tenant.model.TenantModel;
  4. import com.yihu.hos.web.framework.model.Result;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.stereotype.Service;
  7. import org.springframework.transaction.annotation.Transactional;
  8. import java.util.Date;
  9. import java.util.List;
  10. import java.util.Map;
  11. import java.util.UUID;
  12. /**
  13. * @author HZY
  14. * @vsrsion 1.0
  15. * Created at 2016/12/2.
  16. */
  17. @Service("TenantService")
  18. public class TenantService {
  19. public static final String BEAN_ID = "TenantService";
  20. @Autowired
  21. private TenantDao tenantDao;
  22. public TenantModel findTenantByName(String name) throws Exception {
  23. List<TenantModel> list = tenantDao.getTenantList(name);
  24. if (list!=null && !list.isEmpty()){
  25. return list.get(0);
  26. }
  27. return null;
  28. }
  29. public Result getTenantList(Map<String, Object> params) throws Exception {
  30. return tenantDao.getTenantList(params);
  31. }
  32. public TenantModel getTenantById(Long id) throws Exception {
  33. return tenantDao.getEntity(TenantModel.class,id);
  34. }
  35. public Result addTenant(TenantModel obj) throws Exception {
  36. String code = UUID.randomUUID().toString();
  37. obj.setCode(code);
  38. obj.setCreated(new Date());
  39. obj.setCreatedUnix(0);
  40. obj.setUpdated(new Date());
  41. obj.setUpdatedUnix(0);
  42. tenantDao.saveEntity(obj);
  43. return Result.success("保存成功");
  44. }
  45. @Transactional
  46. public Result updateTenant(TenantModel obj) throws Exception {
  47. TenantModel tenant = tenantDao.getEntity(TenantModel.class, obj.getId());
  48. tenant.setName(obj.getName());
  49. tenant.setLoginName(obj.getLoginName());
  50. tenant.setSchema(obj.getSchema());
  51. tenant.setPassword(obj.getPassword());
  52. tenant.setValid(obj.getValid());
  53. tenant.setUpdated(new Date());
  54. tenant.setUpdatedUnix(1);
  55. tenantDao.updateEntity(tenant);
  56. return Result.success("更新成功");
  57. }
  58. @Transactional
  59. public Result deleteTenant(Long id) throws Exception {
  60. TenantModel systemApp = tenantDao.getEntity(TenantModel.class, id);
  61. tenantDao.deleteEntity(systemApp);
  62. return Result.success("删除成功");
  63. }
  64. }