| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.common.annotation.OperationLog; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | import com.vincent.rsf.server.common.domain.KeyValVo; |
| | | import com.vincent.rsf.server.common.domain.PageParam; |
| | | import com.vincent.rsf.server.manager.entity.Companys; |
| | | import com.vincent.rsf.server.manager.entity.Warehouse; |
| | | import com.vincent.rsf.server.manager.service.CompanysService; |
| | | import com.vincent.rsf.server.system.controller.BaseController; |
| | | import io.swagger.annotations.Api; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | |
| | | @Api(tags = "往来企业") |
| | | @RestController |
| | | public class CompanysController extends BaseController { |
| | | |
| | |
| | | @OperationLog("Create 字典数据集") |
| | | @PostMapping("/companys/save") |
| | | public R save(@RequestBody Companys companys) { |
| | | if (Objects.isNull(companys.getName())) { |
| | | throw new CoolException("企业名称不能为空!!"); |
| | | } |
| | | if (Objects.isNull(companys.getBreifCode())) { |
| | | throw new CoolException("企业助记码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(companys.getType())) { |
| | | throw new CoolException("企业类型不能为空!!"); |
| | | } |
| | | |
| | | List<Companys> warehouses = companysService.list(new LambdaQueryWrapper<Companys>().eq(Companys::getName, companys.getName())); |
| | | if (!warehouses.isEmpty()) { |
| | | throw new CoolException("企业名称已存在!!"); |
| | | } |
| | | if (!companysService.list(new LambdaQueryWrapper<Companys>().eq(Companys::getCode, companys.getBreifCode())).isEmpty()) { |
| | | throw new CoolException("编码已存在!!"); |
| | | } |
| | | |
| | | companys.setCreateBy(getLoginUserId()); |
| | | companys.setCreateTime(new Date()); |
| | | companys.setUpdateBy(getLoginUserId()); |
| | | companys.setUpdateTime(new Date()); |
| | | if (!companysService.save(companys)) { |
| | | return R.error("Save Fail"); |
| | | } |
| | |
| | | @PostMapping("/companys/update") |
| | | public R update(@RequestBody Companys companys) { |
| | | companys.setUpdateBy(getLoginUserId()); |
| | | companys.setUpdateTime(new Date()); |
| | | if (Objects.isNull(companys.getName())) { |
| | | throw new CoolException("名称不能为空!!"); |
| | | } |
| | | if (Objects.isNull(companys.getBreifCode())) { |
| | | throw new CoolException("助记码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(companys.getType())) { |
| | | throw new CoolException("类型不能为空!!"); |
| | | } |
| | | Companys companys1 = companysService.getById(companys.getId()); |
| | | if (!companys.getName().equals(companys1.getName())) { |
| | | List<Companys> areasList = companysService.list(new LambdaQueryWrapper<Companys>().eq(Companys::getName, companys.getName())); |
| | | if (!areasList.isEmpty()) { |
| | | throw new CoolException("企业名已存在!!"); |
| | | } |
| | | } |
| | | if (!companys.getBreifCode().equals(companys1.getBreifCode())) { |
| | | List<Companys> areasList = companysService.list(new LambdaQueryWrapper<Companys>().eq(Companys::getBreifCode, companys.getBreifCode())); |
| | | if (!areasList.isEmpty()) { |
| | | throw new CoolException("编码已存在!!"); |
| | | } |
| | | } |
| | | |
| | | if (!companysService.updateById(companys)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | |
| | | @PreAuthorize("hasAuthority('manager:companys:list')") |
| | | @PostMapping("/companys/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(companysService.list(), Companys.class), response); |
| | | List<Companys> companies = new ArrayList<>(); |
| | | if (!Objects.isNull(map.get("ids"))) { |
| | | companies = companysService.list(new LambdaQueryWrapper<Companys>().in(Companys::getId, map.get("ids"))); |
| | | } else { |
| | | companies = companysService.list(); |
| | | } |
| | | ExcelUtil.build(ExcelUtil.create(companies, Companys.class), response); |
| | | } |
| | | |
| | | } |