| New file |
| | |
| | | package org.springblade.modules.registerUnit.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiParam; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.common.cache.DictCache; |
| | | import org.springblade.common.enums.DictEnum; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.support.Kv; |
| | | import org.springblade.core.tool.utils.DigestUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springblade.modules.FTP.FtpUtil; |
| | | import org.springblade.modules.information.entity.Information; |
| | | import org.springblade.modules.information.service.IInformationService; |
| | | import org.springblade.modules.registerUnit.entity.RegisterUnit; |
| | | import org.springblade.modules.registerUnit.service.RegisterUnitService; |
| | | import org.springblade.modules.registerUnit.vo.RegisterUnitVo; |
| | | import org.springblade.modules.system.entity.Dept; |
| | | import org.springblade.modules.system.entity.Role; |
| | | import org.springblade.modules.system.entity.User; |
| | | import org.springblade.modules.system.service.IDeptService; |
| | | import org.springblade.modules.system.service.IRoleService; |
| | | import org.springblade.modules.system.service.IUserService; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; |
| | | |
| | | /** |
| | | * @author zhongrj |
| | | * @time 2022-01-11 |
| | | * @desc 企业注册控制层 |
| | | */ |
| | | @RestController |
| | | @AllArgsConstructor |
| | | @RequestMapping("/registerUnit") |
| | | public class RegisterUnitController { |
| | | |
| | | private final RegisterUnitService registerUnitService; |
| | | |
| | | private final IDeptService deptService; |
| | | |
| | | private final IInformationService informationService; |
| | | |
| | | private final IUserService userService; |
| | | |
| | | private final IRoleService roleService; |
| | | |
| | | |
| | | /** |
| | | * 自定义分页 |
| | | * |
| | | * @param query page,size |
| | | * @param registerUnit 企业注册信息对象 |
| | | */ |
| | | @GetMapping("/page") |
| | | public R<IPage<RegisterUnitVo>> page(RegisterUnitVo registerUnit, Query query) { |
| | | IPage<RegisterUnitVo> pages = registerUnitService.selectRegisterUnitPage(Condition.getPage(query), registerUnit); |
| | | return R.data(pages); |
| | | } |
| | | |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param registerUnit 企业注册信息对象 |
| | | */ |
| | | @PostMapping("/save") |
| | | @ApiOperation(value = "新增", notes = "传入registerUnit") |
| | | public R save(@RequestBody RegisterUnit registerUnit) { |
| | | //判断当前企业是否已注册 |
| | | RegisterUnit registerUnit1 = new RegisterUnit(); |
| | | registerUnit1.setDeptName(registerUnit.getDeptName()); |
| | | //待审核的 |
| | | registerUnit1.setAuditStatus("1"); |
| | | //查询 |
| | | RegisterUnit one = registerUnitService.getOne(Condition.getQueryWrapper(registerUnit1)); |
| | | if (null != one) { |
| | | throw new ServiceException("企业名称:[" + registerUnit.getDeptName() + "]已提交注册!请勿重新注册!"); |
| | | } |
| | | |
| | | //查询审核通过的 |
| | | RegisterUnit registerUnit2 = new RegisterUnit(); |
| | | registerUnit2.setDeptName(registerUnit.getDeptName()); |
| | | //审核通过的 |
| | | registerUnit2.setAuditStatus("2"); |
| | | //查询 |
| | | RegisterUnit registerUnit3 = registerUnitService.getOne(Condition.getQueryWrapper(registerUnit2)); |
| | | if (null != registerUnit3) { |
| | | //再查询是否已注销 |
| | | Dept dept = new Dept(); |
| | | dept.setDeptName(registerUnit.getDeptName()); |
| | | dept.setIsDeleted(0); |
| | | Dept one1 = deptService.getOne(Condition.getQueryWrapper(dept)); |
| | | if (null != one1) { |
| | | throw new ServiceException("企业名称:[" + registerUnit.getDeptName() + "]已存在!请勿重新注册!"); |
| | | } |
| | | } |
| | | |
| | | //检查已有单位 |
| | | Dept dept = new Dept(); |
| | | dept.setDeptName(registerUnit.getDeptName()); |
| | | dept.setIsDeleted(0); |
| | | Dept one1 = deptService.getOne(Condition.getQueryWrapper(dept)); |
| | | if (null != one1) { |
| | | throw new ServiceException("企业名称:[" + registerUnit.getDeptName() + "]已存在!请勿重新注册!"); |
| | | } |
| | | |
| | | return R.data(registerUnitService.save(registerUnit)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 修改 |
| | | * |
| | | * @param registerUnit 企业注册信息对象 |
| | | */ |
| | | @PostMapping("/update") |
| | | public R update(@RequestBody RegisterUnit registerUnit) { |
| | | return R.status(registerUnitService.updateById(registerUnit)); |
| | | } |
| | | |
| | | /** |
| | | * 新增或修改 |
| | | * |
| | | * @param registerUnit 企业注册信息对象 |
| | | */ |
| | | @PostMapping("/submit") |
| | | public R submit(@RequestBody RegisterUnit registerUnit) { |
| | | if (null == registerUnit.getId()) { |
| | | registerUnitService.save(registerUnit); |
| | | } else { |
| | | registerUnitService.updateById(registerUnit); |
| | | } |
| | | return R.data(registerUnit); |
| | | } |
| | | |
| | | /** |
| | | * 删除 |
| | | * |
| | | * @param ids 企业注册信息ids 数组 |
| | | */ |
| | | @PostMapping("/remove") |
| | | public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) { |
| | | return R.status(registerUnitService.removeByIds(Func.toLongList(ids))); |
| | | } |
| | | |
| | | /** |
| | | * 详情 |
| | | * |
| | | * @param registerUnit 企业注册信息对象 |
| | | */ |
| | | @GetMapping("/detail") |
| | | @ApiOperation(value = "详情", notes = "传入registerUnit") |
| | | public R<RegisterUnit> detail(RegisterUnit registerUnit) { |
| | | RegisterUnit detail = registerUnitService.getOne(Condition.getQueryWrapper(registerUnit)); |
| | | return R.data(detail); |
| | | } |
| | | |
| | | /** |
| | | * 审核 |
| | | * |
| | | * @param registerUnit 企业注册信息对象 |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @PostMapping("/audit") |
| | | public R audit(@RequestBody RegisterUnit registerUnit) { |
| | | registerUnit.setAuditTime(new Date()); |
| | | //如果审核通过 |
| | | if (registerUnit.getAuditStatus().equals("2")) { |
| | | RegisterUnit unit = registerUnitService.getById(registerUnit.getId()); |
| | | unit.setAuditUser(registerUnit.getAuditUser()); |
| | | //新增组织机构,公司信息,账号信息 |
| | | this.saveUnit(unit); |
| | | } |
| | | return R.status(registerUnitService.updateById(registerUnit)); |
| | | } |
| | | |
| | | /** |
| | | * 新增组织机构,公司信息,账号信息 |
| | | * 注意事务管理生效需要public 修饰,同一类方法调用的,父方法也需添加事务管理 |
| | | * @param registerUnit |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveUnit(RegisterUnit registerUnit) { |
| | | Dept dept = new Dept(); |
| | | //自招保安公司 |
| | | if (registerUnit.getStats().equals("0")) { |
| | | dept.setParentId(1420222768149966850L); |
| | | dept.setAncestors("0,1420222768149966850"); |
| | | } |
| | | //保安培训公司 |
| | | if (registerUnit.getStats().equals("1")) { |
| | | dept.setParentId(1418458374477549569L); |
| | | dept.setAncestors("0,1418458374477549569"); |
| | | } |
| | | //保安服务公司 |
| | | if (registerUnit.getStats().equals("2")) { |
| | | dept.setParentId(1413470343230877697L); |
| | | dept.setAncestors("0,1413470343230877697"); |
| | | } |
| | | //跨区域保安公司 |
| | | if (registerUnit.getStats().equals("4")) { |
| | | dept.setParentId(1425366663452196865L); |
| | | dept.setAncestors("0,1425366663452196865"); |
| | | } |
| | | dept.setTenantId("000000"); |
| | | dept.setDeptName(registerUnit.getDeptName()); |
| | | dept.setDeptCategory(1); |
| | | |
| | | //创建公司对象 |
| | | Information information = new Information(); |
| | | //新增组织机构 |
| | | if (deptService.submit(dept)) { |
| | | CacheUtil.clear(SYS_CACHE); |
| | | // 返回懒加载树更新节点所需字段 |
| | | Kv kv = Kv.create().set("id", String.valueOf(dept.getId())).set("tenantId", dept.getTenantId()) |
| | | .set("deptCategoryName", DictCache.getValue(DictEnum.ORG_CATEGORY, dept.getDeptCategory())); |
| | | String id = kv.get("id").toString(); |
| | | information.setDepartmentid(id); |
| | | } |
| | | information.setStats(registerUnit.getStats()); |
| | | information.setAddress(registerUnit.getAddress()); |
| | | information.setContacts(registerUnit.getLinkman()); |
| | | information.setContactscell(registerUnit.getPhone()); |
| | | if (null != registerUnit.getBusinessLicense() && !registerUnit.getBusinessLicense().equals("")) { |
| | | information.setBusinessLicense(registerUnit.getBusinessLicense()); |
| | | } |
| | | information.setJurisdiction(registerUnit.getJurisdiction()); |
| | | information.setCreateTime(new Date()); |
| | | information.setRegistration(registerUnit.getUnit()); |
| | | information.setEnterprisename(registerUnit.getDeptName()); |
| | | information.setCreateUserId(registerUnit.getAuditUser()); |
| | | |
| | | //公司新增 |
| | | boolean status = informationService.save(information); |
| | | |
| | | //公司新增成功则创建默认账户,公司名即为账号名,默认密码为 123456 |
| | | if (status) { |
| | | User user = new User(); |
| | | user.setAccount(registerUnit.getDeptName()); |
| | | user.setPassword(DigestUtil.encrypt("123456")); |
| | | Integer userCount = userService.selectCount(registerUnit.getDeptName()); |
| | | if (userCount > 0 && Func.isEmpty(user.getId())) { |
| | | throw new ServiceException(StringUtil.format("当前用户 [{}] 已存在!", user.getAccount())); |
| | | } |
| | | user.setDeptId(information.getDepartmentid()); |
| | | user.setTenantId("000000"); |
| | | user.setCreateUser(Long.parseLong(registerUnit.getAuditUser())); |
| | | user.setCreateTime(new Date()); |
| | | user.setUpdateTime(new Date()); |
| | | user.setStatus(1); |
| | | user.setIsDeleted(0); |
| | | //分配保安角色 |
| | | //如果是本市保安公司,分公司,自招保安公司,分配保安公司管理员角色,如果是培训学校,则分配的是培训公司管理员角色 |
| | | Role role = new Role(); |
| | | if (information.getStats().equals("1")) { |
| | | role.setRoleAlias("培训公司管理员"); |
| | | } else { |
| | | role.setRoleAlias("保安公司管理员"); |
| | | } |
| | | Role oneRole = roleService.getOne(Condition.getQueryWrapper(role)); |
| | | user.setRoleId(oneRole.getId().toString()); |
| | | //插入用户数据 |
| | | userService.save(user); |
| | | |
| | | Integer isDeleted = 0; |
| | | String s = "insert into sys_information(id,creditCode,enterpriseName,representative" + |
| | | ",registeredCapital,organizationCode,registrationNumber, enterprises, address," + |
| | | " business,region,registration,industry,departmentid,stats,jurisdiction,representativecell," + |
| | | "contacts,contactscell,create_time,create_user_id) " + |
| | | "values(" + "'" + information.getId() + "'" + |
| | | "," + "'" + information.getCreditcode() + "'" + |
| | | "," + "'" + information.getEnterprisename() + "'" + |
| | | "," + "'" + information.getRepresentative() + "'" + |
| | | "," + "'" + information.getRegisteredcapital() + "'" + |
| | | "," + "'" + information.getOrganizationcode() + "'" + |
| | | "," + "'" + information.getRegistrationnumber() + "'" + |
| | | "," + "'" + information.getEnterprises() + "'" + |
| | | "," + "'" + information.getAddress() + "'" + |
| | | "," + "'" + information.getBusiness() + "'" + |
| | | "," + "'" + information.getRegion() + "'" + |
| | | "," + "'" + information.getRegistration() + "'" + |
| | | "," + "'" + information.getIndustry() + "'" + |
| | | "," + "'" + information.getDepartmentid() + "'" + |
| | | "," + "'" + information.getStats() + "'" + |
| | | "," + "'" + information.getJurisdiction() + "'" + |
| | | "," + "'" + information.getRepresentativecell() + "'" + |
| | | "," + "'" + information.getContacts() + "'" + |
| | | "," + "'" + information.getContactscell() + "'" + |
| | | "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(information.getCreateTime()) + "'" + |
| | | "," + "'" + information.getCreateUserId() + "'" + ");" + |
| | | "insert into blade_dept(id,parent_id,tenant_id,dept_name,ancestors,dept_category,is_deleted) values(" + "'" + information.getDepartmentid() + "'" + "," + "'" + dept.getParentId() + "'" + "," |
| | | + "'" + dept.getTenantId() + "'" + |
| | | "," + "'" + information.getEnterprisename() + "'" + |
| | | "," + "'" + dept.getAncestors() + "'" + |
| | | "," + "'" + dept.getDeptCategory() + "'" + |
| | | "," + "'" + isDeleted + "'" + ");" + |
| | | "insert into blade_user(id,tenant_id,account,password,dept_id,create_user,create_time,update_time,status,is_deleted,role_id) " + |
| | | "values(" + "'" + user.getId() + "'" + |
| | | "," + "'" + user.getTenantId() + "'" |
| | | + "," + "'" + user.getAccount() + "'" + |
| | | "," + "'" + user.getPassword() + "'" + |
| | | "," + "'" + user.getDeptId() + "'" + |
| | | "," + "'" + user.getCreateUser() + "'" + |
| | | "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getCreateTime()) + "'" + |
| | | "," + "'" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(user.getUpdateTime()) + "'" + |
| | | "," + "'" + user.getStatus() + "'" + |
| | | "," + "'" + user.getIsDeleted() + "'" + |
| | | "," + "'" + user.getRoleId() + "'" + ")"; |
| | | FtpUtil.sqlFileUpload(s); |
| | | } |
| | | } |
| | | } |