hetong.entity.ts 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import { Entity, PrimaryColumn, Column, Index } from 'typeorm';
  2. import { z } from '@hono/zod-openapi';
  3. @Entity('hetong')
  4. export class Hetong {
  5. @PrimaryColumn({ name: 'id', type: 'varchar', length: 50 })
  6. id!: string;
  7. @Column({ name: 'contract_date', type: 'date' })
  8. contractDate!: Date;
  9. @Column({ name: 'user_id', type: 'varchar', length: 50 })
  10. userId!: string;
  11. @Column({ name: 'client_id', type: 'varchar', length: 50 })
  12. clientId!: string;
  13. @Column({ name: 'project_id', type: 'varchar', length: 50, nullable: true })
  14. projectId?: string;
  15. @Column({ name: 'amount', type: 'decimal', precision: 15, scale: 2 })
  16. amount!: number;
  17. @Column({ name: 'type', type: 'varchar', length: 50 })
  18. type!: string;
  19. @Column({ name: 'status', type: 'varchar', length: 50 })
  20. status!: string;
  21. @Column({ name: 'start_date', type: 'date' })
  22. startDate!: Date;
  23. @Column({ name: 'end_date', type: 'date' })
  24. endDate!: Date;
  25. @Column({ name: 'description', type: 'text', nullable: true })
  26. description?: string;
  27. @Column({ name: 'contract_number', type: 'varchar', length: 100 })
  28. contractNumber!: string;
  29. @Column({ name: 'currency', type: 'varchar', length: 20, default: 'CNY' })
  30. currency!: string;
  31. @Column({ name: 'exchange_rate', type: 'decimal', precision: 10, scale: 4, default: 1 })
  32. exchangeRate!: number;
  33. @Column({ name: 'foreign_amount', type: 'decimal', precision: 15, scale: 2, nullable: true })
  34. foreignAmount?: number;
  35. @Column({ name: 'file_path', type: 'varchar', length: 512, nullable: true })
  36. filePath?: string;
  37. @Column({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
  38. createdAt!: Date;
  39. @Column({
  40. name: 'updated_at',
  41. type: 'timestamp',
  42. default: () => 'CURRENT_TIMESTAMP',
  43. onUpdate: 'CURRENT_TIMESTAMP'
  44. })
  45. updatedAt!: Date;
  46. }
  47. export const HetongSchema = z.object({
  48. id: z.string().max(50).openapi({
  49. description: '合同ID',
  50. example: 'HT20230001'
  51. }),
  52. contractDate: z.date().openapi({
  53. description: '合同日期',
  54. example: '2023-01-15'
  55. }),
  56. userId: z.string().max(50).openapi({
  57. description: '关联用户ID',
  58. example: 'U1001'
  59. }),
  60. clientId: z.string().max(50).openapi({
  61. description: '客户ID',
  62. example: 'C2001'
  63. }),
  64. projectId: z.string().max(50).nullable().openapi({
  65. description: '项目ID',
  66. example: 'P3001'
  67. }),
  68. amount: z.number().multipleOf(0.01).openapi({
  69. description: '合同金额',
  70. example: 150000.00
  71. }),
  72. type: z.string().max(50).openapi({
  73. description: '合同类型',
  74. example: '服务合同'
  75. }),
  76. status: z.string().max(50).openapi({
  77. description: '合同状态:如生效中、已结束等',
  78. example: '生效中'
  79. }),
  80. startDate: z.date().openapi({
  81. description: '开始日期',
  82. example: '2023-02-01'
  83. }),
  84. endDate: z.date().openapi({
  85. description: '结束日期',
  86. example: '2024-01-31'
  87. }),
  88. description: z.string().nullable().openapi({
  89. description: '合同描述',
  90. example: '年度技术服务合同'
  91. }),
  92. contractNumber: z.string().max(100).openapi({
  93. description: '合同编号',
  94. example: 'HT-2023-0001'
  95. }),
  96. currency: z.string().max(20).openapi({
  97. description: '货币类型',
  98. example: 'CNY'
  99. }),
  100. exchangeRate: z.number().multipleOf(0.0001).openapi({
  101. description: '汇率',
  102. example: 1.0000
  103. }),
  104. foreignAmount: z.number().multipleOf(0.01).nullable().openapi({
  105. description: '外币金额',
  106. example: null
  107. }),
  108. filePath: z.string().max(512).nullable().openapi({
  109. description: '合同文件路径',
  110. example: '/uploads/contracts/2023/HT-2023-0001.pdf'
  111. }),
  112. createdAt: z.date().openapi({
  113. description: '创建时间',
  114. example: '2023-01-15T00:00:00Z'
  115. }),
  116. updatedAt: z.date().openapi({
  117. description: '更新时间',
  118. example: '2023-01-15T00:00:00Z'
  119. })
  120. });
  121. export const CreateHetongDto = z.object({
  122. id: z.string().max(50).openapi({
  123. description: '合同ID',
  124. example: 'HT20230001'
  125. }),
  126. contractDate: z.coerce.date().openapi({
  127. description: '合同日期',
  128. example: '2023-01-15'
  129. }),
  130. userId: z.string().max(50).openapi({
  131. description: '关联用户ID',
  132. example: 'U1001'
  133. }),
  134. clientId: z.string().max(50).openapi({
  135. description: '客户ID',
  136. example: 'C2001'
  137. }),
  138. projectId: z.string().max(50).nullable().optional().openapi({
  139. description: '项目ID',
  140. example: 'P3001'
  141. }),
  142. amount: z.coerce.number().multipleOf(0.01).openapi({
  143. description: '合同金额',
  144. example: 150000.00
  145. }),
  146. type: z.string().max(50).openapi({
  147. description: '合同类型',
  148. example: '服务合同'
  149. }),
  150. status: z.string().max(50).openapi({
  151. description: '合同状态:如生效中、已结束等',
  152. example: '生效中'
  153. }),
  154. startDate: z.coerce.date().openapi({
  155. description: '开始日期',
  156. example: '2023-02-01'
  157. }),
  158. endDate: z.coerce.date().openapi({
  159. description: '结束日期',
  160. example: '2024-01-31'
  161. }),
  162. description: z.string().nullable().optional().openapi({
  163. description: '合同描述',
  164. example: '年度技术服务合同'
  165. }),
  166. contractNumber: z.string().max(100).openapi({
  167. description: '合同编号',
  168. example: 'HT-2023-0001'
  169. }),
  170. currency: z.string().max(20).default('CNY').openapi({
  171. description: '货币类型',
  172. example: 'CNY'
  173. }),
  174. exchangeRate: z.coerce.number().multipleOf(0.0001).default(1).openapi({
  175. description: '汇率',
  176. example: 1.0000
  177. }),
  178. foreignAmount: z.coerce.number().multipleOf(0.01).nullable().optional().openapi({
  179. description: '外币金额',
  180. example: null
  181. }),
  182. filePath: z.string().max(512).nullable().optional().openapi({
  183. description: '合同文件路径',
  184. example: '/uploads/contracts/2023/HT-2023-0001.pdf'
  185. })
  186. });
  187. export const UpdateHetongDto = z.object({
  188. contractDate: z.coerce.date().optional().openapi({
  189. description: '合同日期',
  190. example: '2023-01-15'
  191. }),
  192. userId: z.string().max(50).optional().openapi({
  193. description: '关联用户ID',
  194. example: 'U1001'
  195. }),
  196. clientId: z.string().max(50).optional().openapi({
  197. description: '客户ID',
  198. example: 'C2001'
  199. }),
  200. projectId: z.string().max(50).nullable().optional().openapi({
  201. description: '项目ID',
  202. example: 'P3001'
  203. }),
  204. amount: z.coerce.number().multipleOf(0.01).optional().openapi({
  205. description: '合同金额',
  206. example: 150000.00
  207. }),
  208. type: z.string().max(50).optional().openapi({
  209. description: '合同类型',
  210. example: '服务合同'
  211. }),
  212. status: z.string().max(50).optional().openapi({
  213. description: '合同状态:如生效中、已结束等',
  214. example: '生效中'
  215. }),
  216. startDate: z.coerce.date().optional().openapi({
  217. description: '开始日期',
  218. example: '2023-02-01'
  219. }),
  220. endDate: z.coerce.date().optional().openapi({
  221. description: '结束日期',
  222. example: '2024-01-31'
  223. }),
  224. description: z.string().nullable().optional().openapi({
  225. description: '合同描述',
  226. example: '年度技术服务合同'
  227. }),
  228. contractNumber: z.string().max(100).optional().openapi({
  229. description: '合同编号',
  230. example: 'HT-2023-0001'
  231. }),
  232. currency: z.string().max(20).optional().openapi({
  233. description: '货币类型',
  234. example: 'CNY'
  235. }),
  236. exchangeRate: z.coerce.number().multipleOf(0.0001).optional().openapi({
  237. description: '汇率',
  238. example: 1.0000
  239. }),
  240. foreignAmount: z.coerce.number().multipleOf(0.01).nullable().optional().openapi({
  241. description: '外币金额',
  242. example: null
  243. }),
  244. filePath: z.string().max(512).nullable().optional().openapi({
  245. description: '合同文件路径',
  246. example: '/uploads/contracts/2023/HT-2023-0001.pdf'
  247. })
  248. });