master
dengjun 2024-11-18 15:52:49 +08:00
parent d8acbfb9bc
commit 31972e4e67
18 changed files with 208 additions and 33 deletions

View File

@ -14,4 +14,5 @@ import org.springframework.web.bind.annotation.RestController;
@Menu(code = "0301", name = "对外开放接口")
@Tag(name = "对外开放接口")
public class ApiController extends BaseController<HelpApiService, HelpApi, BaseQuery> {
}

View File

@ -32,10 +32,10 @@ public class BrandController extends BaseDictController<DictBrandService, DictBr
return ResultData.fail("名称已存在");
}
exists = service.lambdaQuery().eq(DictBrand::getCode, entity.getCode()).ne(entity.getId() != null, DictBrand::getId, entity.getId()).exists();
if (exists) {
return ResultData.fail("编码已存在");
}
// exists = service.lambdaQuery().eq(DictBrand::getCode, entity.getCode()).ne(entity.getId() != null, DictBrand::getId, entity.getId()).exists();
// if (exists) {
// return ResultData.fail("编码已存在");
// }
return super.save(entity);
}

View File

@ -0,0 +1,109 @@
package com.wsnet.cargo.controller;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.wsnet.cargo.entity.DictCity;
import com.wsnet.cargo.excel.CityExcel;
import com.wsnet.cargo.service.DictCityService;
import com.wsnet.core.annotation.Menu;
import com.wsnet.core.enums.StatusEnums;
import com.wsnet.core.response.ResultData;
import com.wsnet.excel.utils.ExcelUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;
import jakarta.validation.ValidatorFactory;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/city")
@Menu(code = "0212", name = "城市管理")
@Tag(name = "城市管理")
public class CityController {
@Resource
private DictCityService cityService;
@Operation(summary = "城市导入", operationId = "01")
@PostMapping("/import")
public ResultData<String> importExcel(MultipartFile file) throws IOException {
ValidatorFactory vf = Validation.buildDefaultValidatorFactory();
Validator validator = vf.getValidator();
// 错误信息
List<JSONObject> errors = new ArrayList<>();
// 获取所有的城市列表
Map<String, DictCity> cityMap = cityService.lambdaQuery().eq(DictCity::getStatus, StatusEnums.active).list()
.stream().collect(Collectors.toMap(s -> s.getCode()+"#$#"+s.getName(), s -> s));
ExcelUtils.readExcel(file.getInputStream(), CityExcel.class, (rowData) -> {
// 这里只验证格式是否正确,并不验证数据的有效性
// 对数据进行检验
Set<ConstraintViolation<CityExcel>> set = validator.validate(rowData);
if (!CollectionUtils.isEmpty(set)) { // 验证失败的
JSONObject o = JSONObject.from(rowData);
o.put("status", set.stream().map(p -> p.getMessage()).collect(Collectors.joining(",")));
errors.add(o);
}
return true;
}, (rowDataList) -> {
if (CollectionUtils.isNotEmpty(errors)) { // 有错误信息,不做处理
return;
}
List<DictCity> cityList = rowDataList.stream().map(s -> {
if (cityMap.containsKey(s.getAdCode()+"#$#"+s.getName())) {
DictCity city = cityMap.get(s.getAdCode()+"#$#"+s.getName());
city.setName(s.getName());
city.setStatus(StatusEnums.active);
return city;
} else {
DictCity city = new DictCity();
city.setName(s.getName());
city.setCode(s.getAdCode());
city.setStatus(StatusEnums.active);
return city;
}
}).collect(Collectors.toList());
cityService.saveOrUpdateBatch(cityList);
});
if (CollectionUtils.isNotEmpty(errors)) {
return ResultData.fail(JSON.toJSONString(errors));
}
return ResultData.success("success");
}
@Operation(summary = "城市级联", operationId = "02")
@GetMapping("/list")
public ResultData<List<DictCity>> getCityList(@RequestParam(required = false,name = "id") @Parameter(description = "id为空时则省") Long id) {
if (id == null) {
List<DictCity> list = cityService.lambdaQuery().eq(DictCity::getStatus, StatusEnums.active)
.likeLeft(DictCity::getCode, "0000").orderByAsc(DictCity::getCode).list();
return ResultData.success(list);
} else {
DictCity city = cityService.getById(id);
if (city == null) {
return ResultData.fail("城市不存在");
}
String adCode = StringUtils.substring(city.getCode(), 0, 2);
List<DictCity> list = cityService.lambdaQuery().eq(DictCity::getStatus, StatusEnums.active)
.ne(DictCity::getId, id)
.likeLeft(DictCity::getCode, "00")
.likeRight(DictCity::getCode, adCode)
.orderByAsc(DictCity::getCode).list();
return ResultData.success(list);
}
}
}

View File

@ -25,7 +25,9 @@ public class EmployeeController extends BaseDictController<DictEmployeeService,
@Override
public ResultData<Page<DictEmployee>> page(@RequestBody EmployeeQuery query) {
CargoApiUser user = (CargoApiUser) UserContext.getUser();
query.setEnterpriseId(user.getEnterpriseId());
if (query.getEnterpriseId() == null) {
query.setEnterpriseId(user.getEnterpriseId());
}
query.setFields("*+enterprise@name+wharf@name");

View File

@ -43,7 +43,6 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.YearMonth;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -125,8 +124,7 @@ public class EnterpriseController extends BaseDictController<DictEnterpriseServi
@NotBlank(message = "文件编号不能为空") String no,
MultipartFile file) throws IOException {
// 按年月创建目录
YearMonth ym = YearMonth.now();
String foldPath = StringUtils.join(path, File.separator, ym.getYear(), File.separator, ym.getMonthValue());
String foldPath = StringUtils.join(path);
// 创建文件目录
File fold = new File(foldPath);
@ -157,6 +155,10 @@ public class EnterpriseController extends BaseDictController<DictEnterpriseServi
CargoApiUser user = (CargoApiUser) UserContext.getUser();
DictEnterprise enterprise = enterpriseService.getById(user.getEnterpriseId());
if (enterprise == null) {
return ResultData.fail("非企业账号,不能添加员工");
}
// 添加员工
// 如果企业类型为港口码头,则必须指定码头
if (enterprise.getEnterpriseType() == EnterpriseTypeEnums.PORT) {
@ -218,6 +220,7 @@ public class EnterpriseController extends BaseDictController<DictEnterpriseServi
}
}
@Operation(summary = "获取身份证图片", operationId = "13")
@GetMapping("/image/id/{id}")
public ResponseEntity<org.springframework.core.io.Resource> getIdImage(@PathVariable Long id) {

View File

@ -232,7 +232,7 @@ public class ManifestController extends BaseController<BusManifestService, BusMa
BusManifest manifest = PoMapper.instance.manifestExcelToEntity(rowData);
manifest.setScheduleId(scheduleId);
manifest.setBrandId(brand.get().getId());
manifest.setGoodsStatus(GoodsStatusEnums.RIVER);
manifest.setGoodsStatus(GoodsStatusEnums.PLAN);
saveDataList.add(manifest);
}

View File

@ -434,7 +434,7 @@ public class SailScheduleController extends BaseController<BusSailScheduleServic
schedule.setLoadWharfId(loadWharf.get().getId());
schedule.setDischargePortId(dischargePort.get().getId());
schedule.setDischargeWharfId(dischargeWharf.get().getId());
schedule.setShipStatus(ShipStatusEnums.SEA);
schedule.setShipStatus(ShipStatusEnums.PLAN);
saveDataList.add(schedule);
}
@ -508,4 +508,15 @@ public class SailScheduleController extends BaseController<BusSailScheduleServic
}).collect(Collectors.toList());
return ResultData.success(rst);
}
@Operation(summary = "历史分页列表", operationId = "17")
@PostMapping("/history/page")
public ResultData<Page<BusSailSchedule>> historyPage(@RequestBody SailScheduleQuery query) {
// 我订阅的码头
CargoApiUser user = (CargoApiUser) UserContext.getUser();
// 订阅的码头ID
query.setLoadWharfId(user.getWharfId());
query.setFields("*+enterprise@name+ship@name+route@name+loadWharf@name+dischargeWharf@name+loadPort@name+dischargePort@name");
return super.page(query);
}
}

View File

@ -34,10 +34,10 @@ public class VehicleTypeController extends BaseDictController<DictVehicleTypeSer
return ResultData.fail("名称已存在");
}
exists = service.lambdaQuery().eq(DictVehicleType::getCode, entity.getCode()).ne(entity.getId() != null, DictVehicleType::getId, entity.getId()).exists();
if (exists) {
return ResultData.fail("编码已存在");
}
// exists = service.lambdaQuery().eq(DictVehicleType::getCode, entity.getCode()).ne(entity.getId() != null, DictVehicleType::getId, entity.getId()).exists();
// if (exists) {
// return ResultData.fail("编码已存在");
// }
return super.save(entity);
}
}

View File

@ -34,10 +34,10 @@ public class VehicleTypeDetailController extends BaseDictController<DictVehicleT
return ResultData.fail("名称已存在");
}
exists = service.lambdaQuery().eq(DictVehicleTypeDetail::getCode, entity.getCode()).ne(entity.getId() != null, DictVehicleTypeDetail::getId, entity.getId()).exists();
if (exists) {
return ResultData.fail("编码已存在");
}
// exists = service.lambdaQuery().eq(DictVehicleTypeDetail::getCode, entity.getCode()).ne(entity.getId() != null, DictVehicleTypeDetail::getId, entity.getId()).exists();
// if (exists) {
// return ResultData.fail("编码已存在");
// }
return super.save(entity);
}
}

View File

@ -34,7 +34,7 @@ public class DictBrand extends BaseEntity implements Serializable {
*/
@TableField(value = "code")
@Schema(description = "品牌编码")
@NotBlank(message = "品牌编码不能为空")
// @NotBlank(message = "品牌编码不能为空")
private String code;
/**
@ -42,7 +42,7 @@ public class DictBrand extends BaseEntity implements Serializable {
*/
@TableField(value = "en_name")
@Schema(description = "品牌英文名称")
@NotBlank(message = "品牌英文名称不能为空")
// @NotBlank(message = "品牌英文名称不能为空")
private String enName;
/**

View File

@ -1,12 +1,10 @@
package com.wsnet.cargo.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.wsnet.core.db.annos.DbDict;
import com.wsnet.core.db.entity.BaseEntity;
import java.io.Serializable;
import java.util.Date;
import com.wsnet.core.enums.StatusEnums;
import lombok.Data;
@ -17,6 +15,7 @@ import lombok.Data;
*/
@TableName(value ="dict_city")
@Data
@DbDict
public class DictCity extends BaseEntity implements Serializable {
/**
*

View File

@ -75,7 +75,6 @@ public class DictEmployee extends BaseEntity implements Serializable {
private Long userId;
@Schema(description = "密码")
@NotBlank(message = "密码不能为空")
@TableField(exist = false)
private String password;

View File

@ -2,9 +2,11 @@ package com.wsnet.cargo.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.wsnet.core.db.annos.DbBean;
import com.wsnet.core.db.entity.BaseEntity;
import java.io.Serializable;
import com.wsnet.core.enums.StatusEnums;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
@ -47,7 +49,22 @@ public class DictShipRoutePort extends BaseEntity implements Serializable {
@TableField(value = "status")
@Schema(description = "状态")
@NotNull(message = "状态不能为空")
private Integer status;
private StatusEnums status;
@TableField(exist = false)
@Schema(description = "码头")
@DbBean(ref = "wharfId")
private DictWharf wharf;
@TableField(exist = false)
@Schema(description = "港口")
@DbBean(ref = "portId")
private DictPort port;
@TableField(exist = false)
@Schema(description = "航线")
@DbBean(ref = "routeId")
private DictShipRoute route;
@TableField(exist = false)
private static final long serialVersionUID = 1L;

View File

@ -34,7 +34,7 @@ public class DictVehicleType extends BaseEntity implements Serializable {
*/
@TableField(value = "code")
@Schema(description = "车型编码")
@NotBlank(message = "车型编码不能为空")
// @NotBlank(message = "车型编码不能为空")
private String code;
/**
@ -42,7 +42,7 @@ public class DictVehicleType extends BaseEntity implements Serializable {
*/
@TableField(value = "en_name")
@Schema(description = "车型英文名称")
@NotBlank(message = "车型英文名称不能为空")
// @NotBlank(message = "车型英文名称不能为空")
private String enName;
/**

View File

@ -35,7 +35,7 @@ public class DictVehicleTypeDetail extends BaseEntity implements Serializable {
*/
@TableField(value = "code")
@Schema(description = "编码")
@NotBlank(message = "编码不能为空")
// @NotBlank(message = "编码不能为空")
private String code;
/**
@ -43,7 +43,7 @@ public class DictVehicleTypeDetail extends BaseEntity implements Serializable {
*/
@TableField(value = "en_name")
@Schema(description = "英文名称")
@NotBlank(message = "英文名称不能为空")
// @NotBlank(message = "英文名称不能为空")
private String enName;
/**

View File

@ -5,8 +5,10 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.apache.commons.lang3.StringUtils;
public enum GoodsStatusEnums {
SEA("1", "海港"),
RIVER("2", "河港")
PLAN("1", "有计划"),
REACH("2", "已靠港"),
WORK("3", "作业中"),
LEAVE("4", "已离港")
;
@EnumValue

View File

@ -5,8 +5,10 @@ import com.fasterxml.jackson.annotation.JsonValue;
import org.apache.commons.lang3.StringUtils;
public enum ShipStatusEnums {
SEA("1", "海港"),
RIVER("2", "河港")
PLAN("1", "有计划"),
REACH("2", "已靠港"),
WORK("3", "作业中"),
LEAVE("4", "已离港")
;
@EnumValue

View File

@ -0,0 +1,30 @@
package com.wsnet.cargo.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
@Schema(title = "城市导入")
public class CityExcel implements Serializable {
/**
*
*/
@ExcelProperty(value = "中文名")
@NotNull(message = "中文名不能为空")
private String name;
/**
*
*/
@ExcelProperty(value = "adcode")
@NotNull(message = "adcode不能为空")
private String adCode;
}