NewGoodsController.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.SqlClient;
  5. using System.IO;
  6. using Common.Model;
  7. using Common.Wechat;
  8. using CoreEntity.DAL;
  9. using CoreEntity.Entity;
  10. using JCSoft.WX.Framework.Api;
  11. using Microsoft.AspNetCore.Hosting;
  12. using Microsoft.AspNetCore.Mvc;
  13. using Microsoft.Extensions.Caching.Memory;
  14. using Newtonsoft.Json;
  15. using Newtonsoft.Json.Serialization;
  16. using Npoi.Mapper;
  17. using PublicLibrary.Model;
  18. using SupplierWeb.Codes.mvc;
  19. using ZcPeng.PublicLibrary;
  20. namespace SupplierWeb.Controllers
  21. {
  22. [Route("web/newgoods")]
  23. [ApiController]
  24. public class NewGoodsController : BaseController
  25. {
  26. [AuthPermission]
  27. [HttpPost]
  28. [Route("getData")]
  29. public JsonResult GetData(string[] filters, int pageIndex, int pageSize,
  30. string sortField, Int32 sortDirection, string[] sumFields, [FromBody] dynamic data)
  31. {
  32. List<QueryFilter> filterList = new List<QueryFilter>();
  33. if (data != null)
  34. {
  35. if (data.filters.Count > 0)
  36. {
  37. var list = JsonConvert.SerializeObject(data.filters);
  38. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  39. }
  40. pageIndex = data.pageIndex;
  41. pageSize = data.pageSize;
  42. sortField = data.sortField;
  43. sortDirection = data.sortDirection;
  44. sumFields = data.sumFields.ToObject<string[]>();
  45. }
  46. var isAce = sortDirection == 0;
  47. var direction = " asc ";
  48. if (isAce)
  49. direction = " desc ";
  50. var queryCondition = string.Empty;
  51. var param = new List<SqlParameter>();
  52. var start = (pageIndex - 1) * pageSize;
  53. var end = start + 1 + pageSize;
  54. var dt = new DataTable();
  55. if (filterList != null)
  56. {
  57. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(),out param,new Temp(),"");
  58. }
  59. //var sql =
  60. // $"select * from (select row_number() over (order by A.GoodsId {(isAce ? "asc" : "desc")}) as rowNum,A.*,B.StdCode,B.FirstSupp,B.ApprovalNo from GOODSDOC A left join GOODSATTR B on A.GoodsId = B.GoodsId) C where c.rowNum > {start} and c.rowNum < {end} {queryCondition}";
  61. var sql =
  62. $"select * from " +
  63. $"(select *," +
  64. $"row_number() over (order by C.{sortField} {direction}) as rowNum from (" +
  65. $"select A.goodsId,A.goodsName,'有编码' as goodsCode,A.goodsSpec,A.manufacturer," +
  66. $"B.StdCode,B.FirstSupp,B.ApprovalNo " +
  67. $"from GOODSDOC A " +
  68. $"left join GOODSATTR B on A.GoodsId = B.GoodsId and B.EntId = A.EntId " +
  69. $"where 1 = 1 {queryCondition}) C " +
  70. $") R where rowNum > {start} and rowNum < {end}";
  71. DataAccess.GetValues(sql, ref dt, param.ToArray(), out var msg);
  72. IList<Temp> result = new List<Temp>();
  73. if (dt != null && dt.Rows.Count > 0)
  74. {
  75. result = ModelConvertHelper<Temp>.ConvertToModel(dt);
  76. }
  77. var jsonData = JsonConvert.SerializeObject(result);
  78. var countSql =
  79. $"select count(1) from (select * from (select A.*,B.StdCode,B.FirstSupp,B.ApprovalNo " +
  80. $"from GOODSDOC A " +
  81. $"left join GOODSATTR B on A.GoodsId = B.GoodsId and B.EntId = A.EntId " +
  82. $"where 1 = 1 {queryCondition}) C ) R";
  83. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out _);
  84. return Json(new
  85. {
  86. items = result,
  87. sum = new { },
  88. totalCount = count,
  89. msg = msg
  90. });
  91. }
  92. [AuthPermission]
  93. [HttpPost]
  94. [Route("add")]
  95. public JsonResult Add(string staffid, [FromBody] Temp entity)
  96. {
  97. var userid = getStaffUserid(staffid);
  98. //判断参数是否合法
  99. if (string.IsNullOrEmpty(userid))
  100. {
  101. return Json(new
  102. {
  103. success = 0,
  104. msg = "没有登陆"
  105. });
  106. }
  107. var sql0 = "select * from sup_Account where id = @userid";
  108. var param0 = new List<SqlParameter>();
  109. param0.Add(new SqlParameter("userid", int.Parse(userid)));
  110. var dt0 = new DataTable();
  111. DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  112. var userName = string.Empty;
  113. if (dt0 != null && dt0.Rows.Count > 0)
  114. {
  115. userName = dt0.Rows[0]["AccountRealName"].ToString();
  116. }
  117. //Object GoodsCode = null;
  118. //var param11 = new List<SqlParameter>();
  119. //param11.Add(new SqlParameter("GoodsId", entity.goodsId));
  120. //DataAccess.GetOneValue("select GoodsCode from GoodsDoc where GoodsId = @GoodsId", param11.ToArray(), out GoodsCode, out _);
  121. var sql1 = "select * from NEWGOOD where GoodsId=@GoodsId and GoodsSpec=@GoodsSpec and State = 1 and userid = @userid";
  122. var param1 = new List<SqlParameter>();
  123. var oneparam = entity.goodsId == null ? new SqlParameter("GoodsId", DBNull.Value ): new SqlParameter("GoodsId", entity.goodsId.ToString());
  124. param1.Add(oneparam);
  125. param1.Add(new SqlParameter("GoodsName", entity.goodsName));
  126. param1.Add(new SqlParameter("GoodsSpec", entity.goodsSpec));
  127. param1.Add(new SqlParameter("userid", int.Parse(userid)));
  128. var dt = new DataTable();
  129. DataAccess.GetValues(sql1, ref dt, param1.ToArray(), out _);
  130. if (dt != null && dt.Rows.Count > 0)
  131. {
  132. return Json(new
  133. {
  134. success = false,
  135. msg = "已提交过该商品"
  136. });
  137. }
  138. if (!string.IsNullOrEmpty(entity.goodsId))
  139. {
  140. var sql3 = "select * from k_contactsp " +
  141. "left join CONTACTDOC on k_contactsp.ContactId=CONTACTDOC.ContactId and k_contactsp.EntId = CONTACTDOC.EntId " +
  142. "where UserId= @UserId and GoodsId=@GoodsId";
  143. var param3 = new List<SqlParameter>();
  144. param3.Add(new SqlParameter("GoodsId", entity.goodsId));
  145. param3.Add(new SqlParameter("UserId", int.Parse(userid)));
  146. var dt3 = new DataTable();
  147. DataAccess.GetValues(sql3, ref dt3, param3.ToArray(), out _);
  148. if (dt3 != null && dt3.Rows.Count > 0)
  149. {
  150. return Json(new
  151. {
  152. success = false,
  153. msg = "已提交过该商品"
  154. });
  155. }
  156. }
  157. var sql2 = "select GoodsCode from GoodsDoc where GoodsId = @GoodsId ";
  158. var param2 = new List<SqlParameter>();
  159. param2.Add(new SqlParameter("GoodsId", entity.goodsId));
  160. var result2 = "";
  161. DataAccess.GetOneValue(sql2, param2.ToArray(), out var obj,out result2);
  162. if (obj != null)
  163. {
  164. string goodscode = obj.ToString();
  165. entity.goodsCode = goodscode;
  166. }
  167. var sql =
  168. $"insert into NEWGOOD (GoodsCode,GoodsName, GoodsSpec, Manufacturer, ApprovalNo, Cnum, Price , UserID, UserName, CreateDate ,State ,Comment4sup,SuppliersId,GoodsId,EntId" +
  169. $") values (@GoodsCode,@GoodsName, @GoodsSpec, @Manufacturer, @ApprovalNo, @Cnum, @Price,@UserID,@UserName,@CreateDate,@State,@Comment4sup,@SuppliersId,@GoodsId,@EntId)";
  170. var param = new List<SqlParameter>();
  171. if (string.IsNullOrEmpty(entity.goodsCode))
  172. {
  173. entity.goodsCode = "";
  174. }
  175. string comment = entity.Comment4sup == null ? "" : entity.Comment4sup;
  176. param.Add(new SqlParameter("GoodsCode", entity.goodsCode));
  177. param.Add(new SqlParameter("GoodsName", entity.goodsName));
  178. param.Add(new SqlParameter("GoodsSpec", entity.goodsSpec));
  179. param.Add(new SqlParameter("Manufacturer", entity.manufacturer));
  180. param.Add(new SqlParameter("ApprovalNo", entity.approvalNo));
  181. param.Add(new SqlParameter("Cnum", entity.stockNum));
  182. param.Add(new SqlParameter("Price", entity.SaleP));
  183. param.Add(new SqlParameter("UserID", int.Parse(userid)));
  184. param.Add(new SqlParameter("UserName", userName));
  185. param.Add(new SqlParameter("CreateDate", DateTime.Now));
  186. param.Add(new SqlParameter("State", 1));
  187. param.Add(new SqlParameter("Comment4sup", comment));
  188. param.Add(new SqlParameter("SuppliersId", entity.SuppliersId == null ? "" : entity.SuppliersId));
  189. var oneparam1 = entity.goodsId == null ? new SqlParameter("GoodsId", DBNull.Value) : new SqlParameter("GoodsId", entity.goodsId.ToString());
  190. param.Add(oneparam1);
  191. param.Add(new SqlParameter("EntId", "E1WB67UEYPG"));
  192. int success = DataAccess.ExecuteCommand(sql, param, out var msg);
  193. return Json(new
  194. {
  195. success = success,
  196. msg = msg
  197. });
  198. }
  199. [AuthPermission]
  200. [HttpPost]
  201. [Route("edit")]
  202. public JsonResult Edit(string staffid, [FromBody] Temp entity)
  203. {
  204. var userid = getStaffUserid(staffid);
  205. //判断参数是否合法
  206. if (string.IsNullOrEmpty(userid))
  207. {
  208. return Json(new
  209. {
  210. success = 0,
  211. msg = "没有登陆"
  212. });
  213. }
  214. var sql =
  215. $"update NEWGOOD set Cnum=@Cnum,Price=@Price where id = @id";
  216. var param = new List<SqlParameter>();
  217. param.Add(new SqlParameter("Cnum", entity.Cnum));
  218. param.Add(new SqlParameter("Price", entity.Price));
  219. param.Add(new SqlParameter("id", entity.Id));
  220. var success = DataAccess.ExecuteCommand(sql, param, out var msg);
  221. return Json(new
  222. {
  223. success = true,
  224. msg
  225. });
  226. }
  227. [AuthPermission]
  228. [HttpPost]
  229. [Route("getNewGoodsList")]
  230. public JsonResult GetNewGoodsList(string staffid, [FromBody] dynamic data)
  231. {
  232. var userid = getStaffUserid(staffid);
  233. //判断参数是否合法
  234. if (string.IsNullOrEmpty(userid))
  235. {
  236. return Json(new
  237. {
  238. success = 0,
  239. msg = "没有登陆"
  240. });
  241. }
  242. List<QueryFilter> filterList = new List<QueryFilter>();
  243. int pageIndex = 1;
  244. int pageSize = 15;
  245. string sortField = " Id ";
  246. int sortDirection = 0;
  247. string[] sumFields;
  248. if (data != null)
  249. {
  250. if (data.filters.Count > 0)
  251. {
  252. var list = JsonConvert.SerializeObject(data.filters);
  253. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  254. }
  255. pageIndex = data.pageIndex;
  256. pageSize = data.pageSize;
  257. sortField = data.sortField;
  258. sortDirection = data.sortDirection;
  259. sumFields = data.sumFields.ToObject<string[]>();
  260. }
  261. var isAce = sortDirection == 0;
  262. string direction = "asc";
  263. if (isAce)
  264. direction = "desc";
  265. var queryCondition = string.Empty;
  266. var param = new List<SqlParameter>();
  267. var start = (pageIndex - 1) * pageSize;
  268. var end = (start + 1 + pageSize);
  269. var dt = new DataTable();
  270. if (filterList != null)
  271. {
  272. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(), out param,new Temp2(),"A.");
  273. queryCondition = queryCondition.Replace("A.Suppliers", "B.BusinessName");
  274. }
  275. sortField = "A." + sortField;
  276. sortField = sortField.Replace("A.Suppliers", "B.BusinessName");
  277. var sql =
  278. $"select * from ";
  279. var sql1 = $"(select A.Id,A.approvalNo,A.goodsName,case A.GoodsCode when 0 then '0' else '有编码'end as goodsCode1,A.goodsSpec,A.manufacturer,A.SuppliersId,A.Price,A.Cnum,A.Comment4sup,A.CreateDate," +
  280. $"B.BusinessName as Suppliers,row_number() over (order by {sortField} {direction}) as rowNum " +
  281. $"from NEWGOOD A " +
  282. $"left join BUSINESSDOC B on B.BusinessId=A.SuppliersId " +
  283. $"where 1 = 1 and A.userid = @userid and A.state = 1 {queryCondition}" +
  284. $") R";
  285. var sql2 = $" where rowNum > {start} and rowNum < {end}";
  286. param.Add(new SqlParameter("userid", int.Parse(userid)));
  287. DataAccess.GetValues(sql + sql1 + sql2, ref dt, param.ToArray(), out var msg);
  288. IList<Temp2> result = new List<Temp2>();
  289. if (dt != null && dt.Rows.Count > 0)
  290. {
  291. result = ModelConvertHelper<Temp2>.ConvertToModel(dt);
  292. }
  293. var countSql =
  294. $"select count(1) from "+ sql1;
  295. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out _);
  296. var setting = new JsonSerializerSettings
  297. {
  298. ContractResolver = new DefaultContractResolver()
  299. };
  300. //JsonConvert.DefaultSettings = new Func<JsonSerializerSettings>(() =>
  301. //{
  302. // //日期类型默认格式化处理
  303. // //setting.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
  304. // //setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
  305. // //空值处理
  306. // //setting.NullValueHandling = NullValueHandling.Ignore;
  307. // //高级用法九中的Bool类型转换 设置
  308. // //setting.Converters.Add(new BoolConvert("是,否"));
  309. // IsoDateTimeConverter timejson = new IsoDateTimeConverter
  310. // {
  311. // DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
  312. // };
  313. // setting.Converters.Add(timejson);
  314. // return setting;
  315. //});
  316. var jsonData = JsonConvert.SerializeObject(result, setting);
  317. return Json(new
  318. {
  319. items = JsonConvert.DeserializeObject(jsonData),
  320. sum = new { },
  321. totalCount = count
  322. });
  323. }
  324. [AuthPermission]
  325. [HttpPost]
  326. [Route("getPurNewGoodsList")]
  327. public JsonResult GetPurNewGoodsList(string staffid, [FromBody] dynamic data)
  328. {
  329. var userid = getStaffUserid(staffid);
  330. var RoleId = getStaff("roleid");
  331. //判断参数是否合法
  332. if (string.IsNullOrEmpty(userid))
  333. {
  334. return Json(new
  335. {
  336. success = 0,
  337. msg = "没有登陆",
  338. timeout = 1
  339. });
  340. }
  341. List<QueryFilter> filterList = new List<QueryFilter>();
  342. int pageIndex = 1;
  343. int pageSize = 15;
  344. string sortField;
  345. int sortDirection = 0;
  346. string[] sumFields;
  347. if (data != null)
  348. {
  349. if (data.filters.Count > 0)
  350. {
  351. var list = JsonConvert.SerializeObject(data.filters);
  352. filterList = JsonConvert.DeserializeObject<List<QueryFilter>>(list);
  353. }
  354. pageIndex = data.pageIndex;
  355. pageSize = data.pageSize;
  356. sortField = data.sortField;
  357. sortDirection = data.sortDirection;
  358. sumFields = data.sumFields.ToObject<string[]>();
  359. }
  360. var isAce = sortDirection == 0;
  361. var queryCondition = string.Empty;
  362. var param = new List<SqlParameter>();
  363. var start = (pageIndex - 1) * pageSize;
  364. var end = (start + 1 + pageSize);
  365. var dt = new DataTable();
  366. if (filterList != null)
  367. {
  368. queryCondition = QueryFilter.getFilterSqlParam(filterList.ToArray(),out param,new Temp2(),"B.");
  369. }
  370. queryCondition = queryCondition.Replace("B.Suppliers", "B1.BusinessName");
  371. string StaffDocId = StaffDocDAL.GetStaffId(userid);
  372. string filterPurRole = ((RoleId == "1" || RoleId == "6" || RoleId == "7" || RoleId == "8") ? "" :
  373. (" and B.userid in" +
  374. " (SELECT A1.userid FROM K_contactsp K1 LEFT JOIN ContactDoc A1 ON K1.ContactId = A1.ContactId " +
  375. "where K1.SaleManId = '" + StaffDocId + "' and A1.Beactive = 'Y') "));
  376. var sql =
  377. $"select * from ";
  378. var sql1 = $"(select B1.BusinessName " +
  379. $" as Suppliers ," +
  380. $" case when B.PurPrice is not null " +
  381. $" then B.PurPrice else D.PurP end as LastPrice," +
  382. $" ID ,B.GoodsName ,B.GoodsSpec ,B.Manufacturer ,B.ApprovalNo , Cnum , Price, UserId,UserName, B.CreateDate, State, " +
  383. $"B.GoodsCode, LastModifyDate,LastModifyUser,Comment4sup,Comment4pur,SuppliersId," +
  384. $" row_number() over (order by id desc) as rowNum " +
  385. $"from NEWGOOD B " +
  386. $" left join BUSINESSDOC B1 on B1.BusinessId=B.SuppliersId and B1.EntId='E1WB67UEYPG'" +
  387. $" left join GoodsDoc C on convert(varchar,B.GoodsCode)=C.GoodsCode and C.EntId='E1WB67UEYPG'" +
  388. $" left join GOODSATTR D on C.GoodsId=D.GoodsId and D.EntId = C.EntId " +
  389. $" where 1 = 1 and state = 1 {queryCondition} " + filterPurRole + ") R";
  390. var sql2 = $" where rowNum > {start} and rowNum < {end}";
  391. string result1 = "";
  392. DataAccess.GetValues(sql + sql1 + sql2, ref dt, param.ToArray(), out result1);
  393. IList<Temp2> result = new List<Temp2>();
  394. if (dt != null && dt.Rows.Count > 0)
  395. {
  396. result = ModelConvertHelper<Temp2>.ConvertToModel(dt);
  397. }
  398. var countSql =
  399. $"select count(1) from " +sql1 ;
  400. string result2 = "";
  401. var count = DataAccess.GetRowCountDefine(countSql, param.ToArray(), out result2);
  402. return Json(new
  403. {
  404. items = result,
  405. sum = new { },
  406. totalCount = count
  407. });
  408. }
  409. [AuthPermission]
  410. [HttpPost]
  411. [Route("updateprice")]
  412. public JsonResult updateprice(string staffid, [FromBody] dynamic data)
  413. {
  414. var userid = getStaffUserid(staffid);
  415. //判断参数是否合法
  416. if (string.IsNullOrEmpty(userid))
  417. {
  418. return Json(new
  419. {
  420. success = 0,
  421. msg = "没有登陆"
  422. });
  423. }
  424. var sql0 = "select * from sup_Account where id = @userid";
  425. var param0 = new List<SqlParameter>();
  426. param0.Add(new SqlParameter("userid", int.Parse(userid)));
  427. var dt0 = new DataTable();
  428. DataAccess.GetValues(sql0, ref dt0, param0.ToArray(), out _);
  429. var userName = string.Empty;
  430. if (dt0 != null && dt0.Rows.Count > 0)
  431. {
  432. userName = dt0.Rows[0]["AccountRealName"].ToString();
  433. }
  434. var sql = "update newgood set PurPrice=@PurPrice , LastModifyDate=@LastModifyDate ,LastModifyUser=@LastModifyUser ,Comment4pur=@Comment4pur ,SuppliersId=@SuppliersId where id=@id";
  435. var param = new List<SqlParameter>();
  436. int id = data.id;
  437. string purPrice = data.purPrice;
  438. string comment = data.comment4pur==null? "":data.comment4pur;
  439. string suppliersId = data.suppliersId;
  440. param.Add(new SqlParameter("id", id));
  441. param.Add(new SqlParameter("LastModifyDate", DateTime.Now));
  442. param.Add(new SqlParameter("LastModifyUser", userName));
  443. param.Add(new SqlParameter("PurPrice", purPrice));
  444. param.Add(new SqlParameter("Comment4pur", comment));
  445. param.Add(new SqlParameter("SuppliersId", suppliersId));
  446. var dt = new DataTable();
  447. string result = "";
  448. var infectRow = DataAccess.ExecuteCommand(sql, param.ToArray(), out result);
  449. if (infectRow > 0)
  450. {
  451. return Json(new
  452. {
  453. success = true
  454. });
  455. }
  456. return Json(new
  457. {
  458. success = false,
  459. msg = result
  460. });
  461. }
  462. [AuthPermission]
  463. [HttpGet]
  464. [Route("getsup")]
  465. public string getsup(string staffid)
  466. {
  467. var userid = getStaffUserid(staffid);
  468. //判断参数是否合法
  469. if (string.IsNullOrEmpty(userid))
  470. {
  471. return "";
  472. }
  473. var sql =
  474. $"select userid,b.BusinessName as lab,b.BusinessId as value from contactdoc A " +
  475. $"left join BUSINESSDOC B on a.BusinessId=b.BusinessId " +
  476. //$"left join supplydoc C on b.BusinessCode=c.gysbh " +
  477. $"where B.BusinessId is not null and userid=@userid";
  478. var param = new List<SqlParameter>();
  479. var dt = new DataTable();
  480. var id = int.Parse(userid);
  481. param.Add(new SqlParameter("userid", id));
  482. DataAccess.GetValues(sql, ref dt, param.ToArray(), out _);
  483. IList<SupDrow> result = new List<SupDrow>();
  484. if (dt != null && dt.Rows.Count > 0)
  485. {
  486. result = ModelConvertHelper<SupDrow>.ConvertToModel(dt);
  487. }
  488. return JsonConvert.SerializeObject(result);
  489. }
  490. [AuthPermission]
  491. [HttpGet]
  492. [Route("getallsup")]
  493. public string getallsup(string staffid)
  494. {
  495. var userid = getStaffUserid(staffid);
  496. //判断参数是否合法
  497. if (string.IsNullOrEmpty(userid))
  498. {
  499. return "";
  500. }
  501. var sql =
  502. $"select distinct userid,b.BusinessName as lab,b.BusinessId as value from contactdoc A " +
  503. $"left join BUSINESSDOC B on a.BusinessId=b.BusinessId " +
  504. //$"left join supplydoc C on b.BusinessCode=c.gysbh " +
  505. $"where b.BusinessId is not null";
  506. var param = new List<SqlParameter>();
  507. var dt = new DataTable();
  508. var id = int.Parse(userid);
  509. param.Add(new SqlParameter("userid", id));
  510. DataAccess.GetValues(sql, ref dt, param.ToArray(), out _);
  511. IList<SupDrow> result = new List<SupDrow>();
  512. if (dt != null && dt.Rows.Count > 0)
  513. {
  514. result = ModelConvertHelper<SupDrow>.ConvertToModel(dt);
  515. }
  516. return JsonConvert.SerializeObject(result);
  517. }
  518. public class SupDrow
  519. {
  520. public string lab { get; set; }
  521. public string label { get => lab; }
  522. public string value { get; set; }
  523. public bool disabled { get; set; }
  524. }
  525. public NewGoodsController(IMemoryCache cache, IApiClient client) : base(cache, client)
  526. {
  527. }
  528. public class Temp
  529. {
  530. public int Id { get; set; }
  531. public string goodsCode { get; set; }
  532. public string goodsId { get; set; }
  533. public string approvalNo { get; set; }
  534. public string goodsName { get; set; }
  535. public string goodsSpec { get; set; }
  536. public string manufacturer { get; set; }
  537. public string stdCode { get; set; }
  538. public decimal SaleP { get; set; }
  539. public int stockNum { get; set; }
  540. public string FirstSupp { get; set; }
  541. public decimal Price { get; set; }
  542. public int Cnum { get; set; }
  543. public decimal PurPrice { get; set; }
  544. public DateTime LastModifyDate { get; set; }
  545. public string LastModifyUser { get; set; }
  546. public DateTime CreateDate { get; set; }
  547. public string UserName { get; set; }
  548. public string Comment4sup { get; set; }
  549. public string Comment4pur { get; set; }
  550. public string SuppliersId { get; set; }
  551. public string Suppliers { get; set; }
  552. public string EntId { get; set; }
  553. public string A_EntId { get; set; }
  554. public string C_EntId { get; set; }
  555. }
  556. public class Temp2
  557. {
  558. public int Id { get; set; }
  559. public int goodsCode { get; set; }
  560. public string goodsCode1 { get; set; }
  561. public string goodsId { get; set; }
  562. public string approvalNo { get; set; }
  563. public string goodsName { get; set; }
  564. public string goodsSpec { get; set; }
  565. public string manufacturer { get; set; }
  566. public string stdCode { get; set; }
  567. public decimal SaleP { get; set; }
  568. public int stockNum { get; set; }
  569. public string FirstSupp { get; set; }
  570. public decimal Price { get; set; }
  571. public int Cnum { get; set; }
  572. public decimal PurPrice { get; set; }
  573. public DateTime LastModifyDate { get; set; }
  574. public string LastModifyUser { get; set; }
  575. public DateTime CreateDate { get; set; }
  576. public string UserName { get; set; }
  577. public string Comment4sup { get; set; }
  578. public string Comment4pur { get; set; }
  579. public string SuppliersId { get; set; }
  580. public string Suppliers { get; set; }
  581. public decimal LastPrice { get; set; }
  582. public string C_EntId { get; set; }
  583. }
  584. public class NewGoodsExcel
  585. {
  586. private string _Contact;
  587. private string _GoodsCode;
  588. private string _GoodsName;
  589. private string _GoodsSpec;
  590. private string _Unit;
  591. private decimal _PurPrice;
  592. private decimal _ActPrice;
  593. private string _manufacturer;
  594. private string _suppliers;
  595. private DateTime _createDate;
  596. //private string _BusinessName;
  597. //private string _ApprovalNo;
  598. public string contact { get => _Contact; set => _Contact = value; }
  599. public string goodsCode { get => _GoodsCode; set => _GoodsCode = value; }
  600. public string goodsName { get => _GoodsName; set => _GoodsName = value; }
  601. public string goodsSpec { get => _GoodsSpec; set => _GoodsSpec = value; }
  602. public string unit { get => _Unit; set => _Unit = value; }
  603. public decimal purPrice { get => _PurPrice; set => _PurPrice = value; }
  604. public decimal actPrice { get => _ActPrice; set => _ActPrice = value; }
  605. public string manufacturer { get => _manufacturer; set => _manufacturer = value; }
  606. public string ApprovalNo { get; set; }
  607. public string Suppliers { get => _suppliers; set => _suppliers = value; }
  608. public DateTime createDate { get => _createDate; set => _createDate = value; }
  609. }
  610. [HttpPost, Route("exportexcel")]
  611. public ActionResult exportExcel([FromServices]IHostingEnvironment env, string staffId, string filter)
  612. {
  613. string userids;
  614. userids = getStaffUserid(staffId);
  615. //判断参数是否合法
  616. if (string.IsNullOrEmpty(userids))
  617. {
  618. return Json(new
  619. {
  620. success = false,
  621. msg = "没有登陆"
  622. });
  623. }
  624. #region 获取新品
  625. DataTable dt = new DataTable();
  626. string result;
  627. string direct = " desc ";
  628. if (0 != 1)
  629. direct = " asc";
  630. List<SqlParameter> parameters1;
  631. //filter参数
  632. QueryFilter[] filters = JsonConvert.DeserializeObject<QueryFilter[]>(filter);
  633. String filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new Temp(), "A.");
  634. filterstr = filterstr.Replace("A.Suppliers", "B.BusinessName");
  635. filterstr = filterstr.Replace("A.unit", "C.unit");
  636. filterstr = filterstr.Replace("A.EntId", "C.EntId");
  637. //filterstr += " and C.GoodsCode is NOT NULL ";
  638. string commandText0 = "select * from (";
  639. string commandText1 = "select A.UserName as contact,convert(varchar(20),isnull(A.goodsCode,0)) as goodsCode," +
  640. "A.goodsName,A.goodsSpec,A.manufacturer," +
  641. "'盒' as unit ," +
  642. "A.Price as purPrice,A.purPrice as actPrice,A.approvalNo," +
  643. //"C.GoodsCode," +
  644. "B.BusinessName as Suppliers," +
  645. "A.createDate as createDate," +
  646. " row_number() over" +
  647. "( order by SuppliersId " + direct + " ) as rownum from "
  648. + "NewGood A " +
  649. " left join BusinessDoc B on A.SuppliersId = B.BusinessId " +
  650. " left join GoodsDoc C on CONVERT(varchar(50), A.GoodsCode) = C.GoodsCode " +
  651. " where 1=1 " +
  652. filterstr +
  653. ")AAA ";
  654. string commandText = commandText0 + commandText1;
  655. bool success = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
  656. //result = DataAccess.GetDataTable(Config.TablePrefix + "PushFeedback", "Id", "*", fieldFilter, "", sortField + direct, pageIndex, pageSize != 0 ? pageSize : Config.PageSize);
  657. // 把DataTable转换为IList<UserInfo>
  658. IList<NewGoodsExcel> users = new List<NewGoodsExcel>();
  659. if (dt != null && dt.Rows.Count > 0)
  660. {
  661. // 把DataTable转换为IList<UserInfo>
  662. users = ModelConvertHelper<NewGoodsExcel>.ConvertToModel(dt);
  663. }
  664. #endregion
  665. var mapper = new Mapper();
  666. var fileName = Path.Combine("excel", "_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");
  667. mapper
  668. .Map<NewGoodsExcel>("联系人", o => o.contact)
  669. .Map<NewGoodsExcel>("商品编号", o => o.goodsCode)
  670. .Map<NewGoodsExcel>("商品名称", o => o.goodsName)
  671. .Map<NewGoodsExcel>("商品规格", o => o.goodsSpec)
  672. .Map<NewGoodsExcel>("单位", o => o.unit)
  673. .Map<NewGoodsExcel>("标准进价", o => o.purPrice/*, null,(column, source) => // tryPut resolver : Custom logic to put property value into cell.
  674. {
  675. // Custom logic to set the cell value.
  676. var sample = (NewGoodsExcel)source;
  677. var index = column.Attribute.Index;
  678. if ((index == 6))
  679. {
  680. column.CurrentValue = sample.purPrice.ToString();
  681. return true;
  682. }
  683. return true;
  684. }*/)
  685. .Map<NewGoodsExcel>("实际进价", o => o.actPrice/*, null, (column, source) => // tryPut resolver : Custom logic to put property value into cell.
  686. {
  687. // Custom logic to set the cell value.
  688. var sample = (NewGoodsExcel)source;
  689. var index = column.Attribute.Index;
  690. if ((index == 7))
  691. {
  692. column.CurrentValue = sample.actPrice.ToString();
  693. return true;
  694. }
  695. return true;
  696. }*/)
  697. .Map<NewGoodsExcel>("生产厂家", o => o.manufacturer)
  698. .Map<NewGoodsExcel>("批准文号", o => o.ApprovalNo)
  699. .Map<NewGoodsExcel>("供应商", o => o.Suppliers)
  700. .Map<NewGoodsExcel>("创建时间", o => o.createDate)
  701. .Save(Path.Combine(env.WebRootPath, fileName), users, "newSheet", overwrite: true,xlsx:false);
  702. byte[] fileBytes = System.IO.File.ReadAllBytes(Path.Combine(env.WebRootPath, fileName));
  703. System.IO.File.Delete(Path.Combine(env.WebRootPath, fileName));
  704. return File(fileBytes, "application/ms-excel", DateTime.Now.ToString("MMddHHmmss") + ".xls");
  705. }
  706. [AuthPermission]
  707. [HttpPost]
  708. [Route("editgoods")]
  709. public JsonResult EditGoods(string staffid, [FromBody] Temp entity)
  710. {
  711. var userid = getStaffUserid(staffid);
  712. //判断参数是否合法
  713. if (string.IsNullOrEmpty(userid))
  714. {
  715. return Json(new
  716. {
  717. success = 0,
  718. msg = "没有登陆"
  719. });
  720. }
  721. var sql = "";
  722. var param = new List<SqlParameter>();
  723. if (entity.goodsCode == "0")
  724. {
  725. sql =
  726. $"update NEWGOOD set goodsName=@goodsName,approvalNo=@approvalNo,goodsSpec=@goodsSpec,manufacturer=@manufacturer," +
  727. $"Cnum=@Cnum,Price=@Price,suppliersId=@suppliersId,comment4sup=@comment4sup where id = @id";
  728. param.Add(new SqlParameter("goodsName", entity.goodsName));
  729. param.Add(new SqlParameter("approvalNo", entity.approvalNo));
  730. param.Add(new SqlParameter("goodsSpec", entity.goodsSpec));
  731. param.Add(new SqlParameter("manufacturer", entity.manufacturer));
  732. param.Add(new SqlParameter("Cnum", entity.Cnum));
  733. param.Add(new SqlParameter("Price", entity.Price));
  734. param.Add(new SqlParameter("suppliersId", entity.SuppliersId));
  735. param.Add(new SqlParameter("comment4sup", entity.Comment4sup));
  736. param.Add(new SqlParameter("id", entity.Id));
  737. }
  738. else {
  739. sql =
  740. $"update NEWGOOD set Cnum=@Cnum,Price=@Price,suppliersId=@suppliersId,comment4sup=@comment4sup where id = @id";
  741. param.Add(new SqlParameter("Cnum", entity.Cnum));
  742. param.Add(new SqlParameter("Price", entity.Price));
  743. param.Add(new SqlParameter("suppliersId", entity.SuppliersId));
  744. param.Add(new SqlParameter("comment4sup", entity.Comment4sup));
  745. param.Add(new SqlParameter("id", entity.Id));
  746. }
  747. //DataAccess.ExecuteCommand(sql, param, out var msg);
  748. List<DataAccessCommand> list = new List<DataAccessCommand>(1);
  749. list.Add(new DataAccessCommand(sql, param,CommandType.Text,false));
  750. bool success = DataAccess.ExecuteBatchCommands(list, out var msg);
  751. return Json(new
  752. {
  753. success = success,
  754. msg
  755. });
  756. }
  757. }
  758. }