ZcglController.java 25.7 KB
Newer Older
yuquan.zhu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
package cn.timer.api.controller.zcgl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;

import cn.hutool.core.util.StrUtil;
import cn.timer.api.bean.yggl.YgglMainEmp;
import cn.timer.api.bean.zcgl.ZcglAdminZccrkgl;
import cn.timer.api.bean.zcgl.ZcglAssoZcda;
import cn.timer.api.bean.zcgl.ZcglAssoZcgh;
import cn.timer.api.bean.zcgl.ZcglAssoZcgx;
import cn.timer.api.bean.zcgl.ZcglAssoZcly;
import cn.timer.api.bean.zzgl.ZzglBmgwM;
import cn.timer.api.config.annotation.CurrentUser;
import cn.timer.api.config.annotation.UserBean;
import cn.timer.api.dao.zcgl.ZcglAdminZccrkglMapper;
import cn.timer.api.dao.zcgl.ZcglAssoZcdaMapper;
import cn.timer.api.dao.zcgl.ZcglAssoZcgxMapper;
import cn.timer.api.dto.zcgl.ZcglDetailsDto;
import cn.timer.api.dto.zcgl.ZcglLyDetailsDto;
import cn.timer.api.dto.zcgl.ZcglQueryDto;
import cn.timer.api.dto.zcgl.ZcglTjtDto;
import cn.timer.api.utils.Result;
import cn.timer.api.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 资产管理
 * 
 * @author dsc 2019-11-26
 */
@Api(tags = "6.0资产管理")
@RestController
@Transactional
@RequestMapping(value = "/zcgl", produces = { "application/json" })
public class ZcglController {

	@Autowired
	private ZcglAssoZcdaMapper zcdaMapper;

	@Autowired
	private ZcglAdminZccrkglMapper zccrkglMapper;

	@Autowired
	private ZcglAssoZcgxMapper zcglAssoZcgxMapper;

	// 寻找子节点
	private static ZcglAssoZcgx findChildren(ZcglAssoZcgx parent, List<ZcglAssoZcgx> listGoodsCategory) {
		for (ZcglAssoZcgx all : listGoodsCategory) {
			if (parent.getId().equals(all.getUpLbid())) {
				if (parent.getChildren() == null) {
					parent.setChildren(new ArrayList<ZcglAssoZcgx>());
				}
				parent.getChildren().add(findChildren(all, listGoodsCategory));
			}
		}
		return parent;
	}

	/**
	 * 查询资产名称列表
	 */
	@GetMapping(value = "/querylist")
	@ApiOperation(value = "查询资产名称列表", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryList(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		List<ZcglAssoZcgx> treeList = new ArrayList<>();
		QueryWrapper<ZcglAssoZcgx> queryWrapper = new QueryWrapper<ZcglAssoZcgx>();
		queryWrapper.eq("org_code", orgCode).select("id", "lbmc", "up_lbid", "org_code");

		List<ZcglAssoZcgx> list = ZcglAssoZcgx.builder().build().selectList(queryWrapper);
		for (ZcglAssoZcgx parent : list) { // 遍历
			if (parent.getUpLbid().equals(0)) { // 找到parentId为零的节点,即一级目录,
				treeList.add(findChildren(parent, list));
			}
		}
		return ResultUtil.data(treeList, "查询成了");
	}

	/**
	 * 根据名称查询详情(按资产类别查询)
	 */
	@GetMapping(value = "/queryDetails")
	@ApiOperation(value = "查询资产详情列表", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryDetails(@RequestParam(defaultValue = "1") Integer currentPage,
			@RequestParam(defaultValue = "10") Integer totalPage, @RequestParam(required = false) String query,
			@RequestParam Integer id, @CurrentUser UserBean userBean) {

		Page<ZcglDetailsDto> p = new Page<ZcglDetailsDto>(currentPage, totalPage);

		List<ZcglAssoZcda> list = zcdaMapper.queryDetails(p, userBean.getOrgCode(), id, query);
		if (list != null) {
			return ResultUtil.datas(list, p, "终于查到了,我太难了");
		}
		return ResultUtil.error("空类别id,查不到的");
	}

	/**
	 * 增/改资产档案
	 */
	@PostMapping(value = "/updatezc")
	@ApiOperation(value = "新增/修改资产档案", httpMethod = "POST", notes = "接口发布说明")
	public Result<ZcglAssoZcda> updatezc(@CurrentUser UserBean userBean, @RequestBody ZcglAssoZcda zcda) {
		Boolean a = zcda.getId() == null;
		if (a && zcda.getLrrid() == null) {
			ZcglAssoZcda zc = ZcglAssoZcda.builder().build().selectOne(new QueryWrapper<ZcglAssoZcda>()
					.eq("org_code", userBean.getOrgCode()).orderByDesc("id").select("id"));

			if (zc != null && zc.getId() != null) {
				zcda.setZdyid("ZC-" + String.format("%05d", zc.getId() + 1));
			} else {
				zcda.setZdyid("ZC-" + String.format("%05d", 1));
			}
			zcda.setLrrid(userBean.getEmpNum());
			zcda.setLrsjTime(new Date());
			zcda.setOrgCode(userBean.getOrgCode());
			zcda.insert();
			return ResultUtil.data(zcda, "添加成功");
		} else {
			zcda.updateById();
			return ResultUtil.data(zcda, "修改成功");
		}

	}

	/**
	 * 新增入库
	 */
	@PostMapping(value = "/addrk")
	@ApiOperation(value = "新增入库管理", httpMethod = "POST", notes = "接口发布说明")
	public Result<ZcglAdminZccrkgl> addrk(@CurrentUser UserBean userBean, @RequestBody ZcglAdminZccrkgl zccrkgl) {
		Boolean a = zccrkgl.getId() == null;
		if (a && zccrkgl.getCkryid() == null) {
			zccrkgl.setCkryid(userBean.getEmpNum());
			zccrkgl.setOrgCode(userBean.getOrgCode());
			zccrkgl.setStatus(0);
			zccrkgl.setGrsjTime(new Date());
			zccrkgl.insert();

			Integer zcid = zccrkgl.getZcid();
			// 修改资产数量
			ZcglAssoZcda.builder().id(zcid)
					.xzsl(zccrkgl.getZcsl()
							+ new ZcglAssoZcda().selectOne(new QueryWrapper<ZcglAssoZcda>().eq("id", zcid)).getXzsl())
					.build().updateById();

		}
		return ResultUtil.data(zccrkgl, "新增入库成功");

	}

	/**
	 * 新增出库
	 */
	@PostMapping(value = "/addck")
	@ApiOperation(value = "新增出库管理", httpMethod = "POST", notes = "接口发布说明")
	public Result<ZcglAdminZccrkgl> addck(@CurrentUser UserBean userBean, @RequestBody ZcglAdminZccrkgl zccrkgl) {
		zccrkgl.setCkryid(userBean.getEmpNum());
		zccrkgl.setOrgCode(userBean.getOrgCode());
		zccrkgl.setStatus(1);
		zccrkgl.setCksjTime(new Date());
		zccrkgl.insert();

		Integer zcid = zccrkgl.getZcid();
		// 修改资产数量

		ZcglAssoZcda.builder().id(zcid)
				.xzsl(new ZcglAssoZcda().selectOne(new QueryWrapper<ZcglAssoZcda>().eq("id", zcid)).getXzsl()
						- zccrkgl.getZcsl())
				.build().updateById();
		return ResultUtil.data(zccrkgl, "新增出库成功");

	}

	/**
	 * 新增/修改资产分类
	 */
	@PostMapping(value = "/updatezcfl")
	@ApiOperation(value = "新增/修改资产分类", httpMethod = "POST", notes = "接口发布说明")
	public Result<ZcglAssoZcgx> updatezcfl(@CurrentUser UserBean userBean, @RequestBody ZcglAssoZcgx zcgx) {
		Boolean a = zcgx.getId() == null;
		if (a) {
			zcgx.setOrgCode(userBean.getOrgCode());
			zcgx.insert();
			return ResultUtil.success("新增成功");
		} else {
			zcgx.updateById();
			return ResultUtil.success("修改成功");
		}
	}

	/**
	 * 删除资产分类(批量)
	 */
	@DeleteMapping(value = "/delzcfl")
	@ApiOperation(value = "删除资产分类", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<ZcglAssoZcgx> delzcfl(@CurrentUser UserBean userBean, @RequestBody List<Integer> ids) {
		zcglAssoZcgxMapper.deleteBatchIds(ids);
		return ResultUtil.success("删除成功");
	}

	/**
	 * 删除资产档案(按类别id批量)
	 */
	@DeleteMapping(value = "/delzcbypid")
	@ApiOperation(value = "删除资产档案(按父类名id批量)", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Integer> delzcbypid(@CurrentUser UserBean userBean, @RequestBody Integer id) {
		Integer rows = zcdaMapper.deleteDetails(userBean.getOrgCode(), id);
		return ResultUtil.success("成功删除了" + rows + "行资产档案!");
	}

	/**
	 * 删除分类名称(按类别id批量)
	 */
	@DeleteMapping(value = "/delzcbyLbmc")
	@ApiOperation(value = "删除资产分类名(按父类名id批量)", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Integer> delzcbyLbmc(@CurrentUser UserBean userBean, @RequestBody Integer id) {
		Integer rows = delzcLbmc(userBean, id);
		return ResultUtil.success("成功删除了" + rows + "行类名!");
	}

	// 根据父id批量删除类别名方法
	private Integer delzcLbmc(UserBean userBean, Integer id) {
		return zcglAssoZcgxMapper.deleteUpid(userBean.getOrgCode(), id);
	}

	/**
	 * 删除资产档案
	 */
	@DeleteMapping(value = "/delzc")
	@ApiOperation(value = "删除资产档案", httpMethod = "DELETE", notes = "接口发布说明")
	public Result<Integer> delzc(@CurrentUser UserBean userBean, @RequestBody List<Integer> ids) {
		// 加入记录 jlMapper.insertbydeldept(id, userBean.getEmpNum());
		if (ids != null) {
			zcdaMapper.deleteBatchIds(ids);
			return ResultUtil.success("删除成功");
		}
		return ResultUtil.error("没这个id");
	}

	/**
	 * 获取公司资产档案详情
	 */
	@GetMapping(value = "/getgszc")
	@ApiOperation(value = "获取全部公司资产档案", httpMethod = "GET", notes = "接口发布说明")
	public Result<List<ZcglAssoZcda>> getgszc(@CurrentUser UserBean userBean) {
		Integer orgCode = userBean.getOrgCode();
		QueryWrapper<ZcglAssoZcda> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("org_code", orgCode);
		List<ZcglAssoZcda> zcglAssoZcda = ZcglAssoZcda.builder().build().selectList(queryWrapper);
		return ResultUtil.data(zcglAssoZcda, "获取公司资产档案详情成功");
	}

	/**
	 * 获取个人资产档案、搜索、分页
	 */
	@GetMapping(value = "/getgrzc")
	@ApiOperation(value = "获取个人资产档案", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> getgrzc(@CurrentUser UserBean userBean, @RequestParam(required = false) String query,
			@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime,
			@RequestParam(required = false, defaultValue = "1") Integer currPage,
			@RequestParam(required = false, defaultValue = "10") Integer pageSize) {
		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();

		com.github.pagehelper.Page<Object> page = PageHelper.startPage(currPage, pageSize);

		List<ZcglAssoZcda> zcglAssoZcda = zcdaMapper.personalassets(orgCode, empNum, query, startTime, endTime);

		Long total = page.getTotal();

		return ResultUtil.pageData(zcglAssoZcda, total, "个人资产记录搜索成功");

	}

	/**
	 * 入库搜索分页
	 */
	@PostMapping(value = "/getrkjl")
	@ApiOperation(value = "搜索入库记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> rkquery(@CurrentUser UserBean userBean, @RequestBody ZcglQueryDto zcglQueryDto) {
		String s = zcglQueryDto.getStartTime();
		String e = zcglQueryDto.getEndTime();
		String q = zcglQueryDto.getQuery();
		Page<ZcglAdminZccrkgl> page = new Page<ZcglAdminZccrkgl>(
				zcglQueryDto.getCurrentPage() == null ? 1 : zcglQueryDto.getCurrentPage(),
				zcglQueryDto.getTotalPage() == null ? 10 : zcglQueryDto.getTotalPage());

		QueryWrapper<ZcglAdminZccrkgl> queryWrapper = new QueryWrapper<>();
311 312 313 314
		queryWrapper.eq("org_code", userBean.getOrgCode()).eq("status", 0)
				.between(!StrUtil.hasBlank(s) && !StrUtil.hasBlank(e), "grsj_time",
						!StrUtil.hasBlank(s) ? s : "1000-01-01 00:00:00",
						!StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
yuquan.zhu committed
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
				.and(!StrUtil.hasBlank(q),
						wq -> wq.like("zcmc", q).or().like("zcggxh", q).or().like("zcgys", q).or().like("zcbh", q));

		IPage<ZcglAdminZccrkgl> zPage = ZcglAdminZccrkgl.builder().build().selectPage(page, queryWrapper);
		List<ZcglAdminZccrkgl> zccrkgls = zPage.getRecords();
		zPage.getCurrent();
		zPage.getPages();
		zPage.getTotal();
		zPage.getSize();
		return ResultUtil.data(zPage, zccrkgls, "入库记录搜索成功");
	}

	/**
	 * 出库搜索分页
	 */
	@PostMapping(value = "/getckjl")
	@ApiOperation(value = "搜索出库记录", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> ckquery(@CurrentUser UserBean userBean, @RequestBody ZcglQueryDto zcglQueryDto) {
		String s = zcglQueryDto.getStartTime();
		String e = zcglQueryDto.getEndTime();
		String q = zcglQueryDto.getQuery();
		Page<ZcglAdminZccrkgl> page = new Page<ZcglAdminZccrkgl>(
				zcglQueryDto.getCurrentPage() == null ? 1 : zcglQueryDto.getCurrentPage(),
				zcglQueryDto.getTotalPage() == null ? 10 : zcglQueryDto.getTotalPage());

		QueryWrapper<ZcglAdminZccrkgl> queryWrapper = new QueryWrapper<>();
341 342 343 344
		queryWrapper.eq("org_code", userBean.getOrgCode()).eq("status", 1)
				.between(!StrUtil.hasBlank(s) && !StrUtil.hasBlank(e), "grsj_time",
						!StrUtil.hasBlank(s) ? s : "1000-01-01 00:00:00",
						!StrUtil.hasBlank(e) ? e : "9999-01-01 00:00:00")
yuquan.zhu committed
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522
				.and(!StrUtil.hasBlank(q),
						wq -> wq.like("zcmc", q).or().like("zcggxh", q).or().like("zcgys", q).or().like("zcbh", q));

		IPage<ZcglAdminZccrkgl> zPage = ZcglAdminZccrkgl.builder().build().selectPage(page, queryWrapper);
		List<ZcglAdminZccrkgl> zccrkgls = zPage.getRecords();
		zPage.getCurrent();
		zPage.getPages();
		zPage.getTotal();
		zPage.getSize();
		return ResultUtil.data(zPage, zccrkgls, "出库记录搜索成功");
	}

//	/**
//	 * 本月出、入库数量
//	 */
//	@GetMapping(value = "/getcrksl")
//	@ApiOperation(value = "本月出入库数量", httpMethod = "GET", notes = "接口发布说明")
//	public Result<Map<String, Integer>> getckrsl(@CurrentUser UserBean userBean) {
//
//		QueryWrapper<ZcglAdminZccrkgl> queryWrapper0 = new QueryWrapper<ZcglAdminZccrkgl>();
//		QueryWrapper<ZcglAdminZccrkgl> queryWrapper1 = new QueryWrapper<ZcglAdminZccrkgl>();
//		Date now = new Date();
//		Date begin = DateUtil.beginOfMonth(now);
//		Date end = DateUtil.endOfMonth(now);
//		queryWrapper0.eq("status", 0).between("cksj_time", begin, end);
//		queryWrapper1.eq("status", 1).between("cksj_time", begin, end);
//		Integer a = ZcglAdminZccrkgl.builder().build().selectCount(queryWrapper0);
//		Integer b = ZcglAdminZccrkgl.builder().build().selectCount(queryWrapper1);
//		Map<String, Integer> map = new HashMap<String, Integer>();
//		map.put("byrksl", a);
//		map.put("bycksl", b);
//		return ResultUtil.data(map, "查询成功");
//	}

	/**
	 * 设置报废资产
	 */
	@PostMapping(value = "/setScrap/{id}")
	@ApiOperation(value = "设置报废资产", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> setScrap(@CurrentUser UserBean userBean, @PathVariable Integer id, Integer bfsl) {

		QueryWrapper<ZcglAssoZcda> queryWrapper = new QueryWrapper<ZcglAssoZcda>();

		queryWrapper.eq("org_code", userBean.getOrgCode()).eq("id", id);

		ZcglAssoZcda zc = ZcglAssoZcda.builder().build().selectOne(queryWrapper);
		Integer xz = zc.getXzsl() - bfsl;
		Integer bf = zc.getBfsl() + bfsl;
		// 资产不为空 且 可报废数量大于等于0
		if (zc != null && xz >= 0) {

			zc.setXzsl(xz);
			zc.setBfsl(bf);

			UpdateWrapper<ZcglAssoZcda> updateWrapper = new UpdateWrapper<ZcglAssoZcda>();
			updateWrapper.eq("id", id);

			zc.update(updateWrapper);

			return ResultUtil.data(zc, "成功了");
		} else {
			return ResultUtil.error("请刷新!");
		}
	}

	/**
	 * 资产领用
	 */
	@PostMapping(value = "/zcly/{id}")
	@ApiOperation(value = "资产领用", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> zcly(@CurrentUser UserBean userBean, @RequestBody ZcglAssoZcly zcly,
			@PathVariable Integer id) {
		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();

		QueryWrapper<ZcglAssoZcly> query = new QueryWrapper<ZcglAssoZcly>();
		query.eq("org_code", orgCode).eq("lyrid", zcly.getLyrid()).eq("zcid", id);
		ZcglAssoZcly zcglAssoZcly = ZcglAssoZcly.builder().build().selectOne(query);
		Integer xzlysl = zcly.getLysl();// 新增领用数量
		// 已有领用的物品
		if (zcglAssoZcly != null) {
			Integer ylysl = zcglAssoZcly.getLysl();

			UpdateWrapper<ZcglAssoZcly> updateWrapper = new UpdateWrapper<ZcglAssoZcly>();
			updateWrapper.eq("id", zcglAssoZcly.getId());
			zcly.setLysl(ylysl + xzlysl);
			zcly.update(updateWrapper);

			return ResultUtil.success("增加数量成功");
		} else {
			// 根据id查询资产详情
			QueryWrapper<ZcglAssoZcda> queryWrapper = new QueryWrapper<ZcglAssoZcda>();
			queryWrapper.eq("org_code", orgCode).eq("id", id);
			ZcglAssoZcda zcda = ZcglAssoZcda.builder().build().selectOne(queryWrapper);

			Integer zclysl = zcda.getLysl();// 仓库已领用
			Integer zcxzsl = zcda.getXzsl();// 仓库闲置
			Integer lysl = zcly.getLysl();// 领用数量

			UpdateWrapper<ZcglAssoZcda> updateWrapper = new UpdateWrapper<ZcglAssoZcda>();
			updateWrapper.eq("id", id);
			zcda.setLysl(zclysl + lysl);
			zcda.setXzsl(zcxzsl - lysl);
			zcda.update(updateWrapper);

			zcly.setZcid(id);
			zcly.setOrgCode(orgCode);
			zcly.setLyclr(empNum);
			zcly.setLyrqTime(new Date());

			zcly.insert();
			return ResultUtil.success("新增领用成功");
		}

	}

	/**
	 * 资产领用详情
	 */
	@PostMapping(value = "/zclyDetail/{id}")
	@ApiOperation(value = "资产领用详情", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> zclyDetail(@CurrentUser UserBean userBean, @PathVariable Integer id) {
		QueryWrapper<ZcglAssoZcly> queryWrapper = new QueryWrapper<ZcglAssoZcly>();
		Integer orgCode = userBean.getOrgCode();
		queryWrapper.eq("org_code", orgCode).eq("zcid", id);
		List<ZcglAssoZcly> list = ZcglAssoZcly.builder().build().selectList(queryWrapper);
		List<ZcglLyDetailsDto> newList = new ArrayList<ZcglLyDetailsDto>();
		for (ZcglAssoZcly zcglAssoZcly : list) {
			ZcglLyDetailsDto zDto = new ZcglLyDetailsDto();
			Integer lyrid = zcglAssoZcly.getLyrid();
			Integer lyclr = zcglAssoZcly.getLyclr();
			String sybm = zcglAssoZcly.getSybm();
			QueryWrapper<YgglMainEmp> queryWrapper1 = new QueryWrapper<YgglMainEmp>();
			queryWrapper1.eq("org_code", orgCode).eq("emp_num", lyrid).select("name");
			YgglMainEmp yg1 = YgglMainEmp.builder().build().selectOne(queryWrapper1);
			if (yg1 != null && yg1.getName() != null) {
				zDto.setLyrid(yg1.getName());
			}

			QueryWrapper<YgglMainEmp> queryWrapper2 = new QueryWrapper<YgglMainEmp>();
			queryWrapper2.eq("org_code", orgCode).eq("emp_num", lyclr).select("name");
			YgglMainEmp yg2 = YgglMainEmp.builder().build().selectOne(queryWrapper2);
			if (yg2 != null && yg2.getName() != null) {
				zDto.setLyrid(yg2.getName());
			}

			QueryWrapper<ZzglBmgwM> queryWrapper3 = new QueryWrapper<ZzglBmgwM>();
			queryWrapper3.eq("org_code", orgCode).eq("id", sybm).select("name");
			ZzglBmgwM bm = ZzglBmgwM.builder().build().selectOne(queryWrapper3);
			if (bm != null && bm.getName() != null) {
				zDto.setSybm(bm.getName());
			}

			zDto.setGhrqTime(zcglAssoZcly.getGhrqTime());
			zDto.setLyhcfd(zcglAssoZcly.getLyhcfd());
			zDto.setLyrqTime(zcglAssoZcly.getLyrqTime());
			zDto.setLysl(zcglAssoZcly.getLysl());
			zDto.setOrgCode(orgCode);
			zDto.setSm(zcglAssoZcly.getSm());
			zDto.setZcid(id);
			zDto.setZtStatus(zcglAssoZcly.getZtStatus());
			newList.add(zDto);
		}

		return ResultUtil.data(newList, "查询成功");

	}

	/**
	 * 资产归还
	 */
	@PostMapping(value = "/zcback/{id}")
	@ApiOperation(value = "资产归还", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> zcback(@CurrentUser UserBean userBean, @RequestBody ZcglAssoZcgh zcgh,
			@PathVariable Integer id) {
		Integer orgCode = userBean.getOrgCode();
		Integer empNum = userBean.getEmpNum();

ilal committed
523
//		System.out.println(id);
yuquan.zhu committed
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
		// 根据id查询资产详情
		QueryWrapper<ZcglAssoZcda> queryWrapper = new QueryWrapper<ZcglAssoZcda>();
		queryWrapper.eq("org_code", orgCode).eq("id", id);
		ZcglAssoZcda zcda = ZcglAssoZcda.builder().build().selectOne(queryWrapper);

		// 查询领用详情
		QueryWrapper<ZcglAssoZcly> queryWrapper2 = new QueryWrapper<ZcglAssoZcly>();
		queryWrapper2.eq("org_code", orgCode).eq("zcid", id).eq("lyrid", empNum);
		ZcglAssoZcly zcly = ZcglAssoZcly.builder().build().selectOne(queryWrapper2);

		// 仓库的已领用数量和闲置数量
		Integer lysl = zcda.getLysl();
		Integer xzsl = zcda.getXzsl();
		// 归还的数量
		Integer ghsl = zcgh.getGhsl();
		// 归还后的仓库已领用数量和闲置数量
		lysl = lysl - ghsl;
		xzsl = xzsl + ghsl;

		// 归还后的个人领用数量更新
		Integer grly = zcly.getLysl() - ghsl;

		// 更新數量
		if (ghsl > 0 && lysl >= 0 && grly >= 0) {

			UpdateWrapper<ZcglAssoZcda> updateWrapper = new UpdateWrapper<ZcglAssoZcda>();
			updateWrapper.eq("id", id);
			zcda.setLysl(lysl);
			zcda.setXzsl(xzsl);
			zcda.update(updateWrapper);

			UpdateWrapper<ZcglAssoZcly> updateWrapper2 = new UpdateWrapper<ZcglAssoZcly>();
			updateWrapper2.eq("lyrid", empNum).eq("zcid", id);
			zcly.setLysl(grly);
			if (grly == 0) {
				zcly.setZtStatus(1);
			}
			zcly.update(updateWrapper2);

ilal committed
563
//			System.out.println(id);
yuquan.zhu committed
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719

			// 插入资产归还表
			zcgh.setZcid(id);
			zcgh.setOrgCode(orgCode);
			zcgh.setGhrid(empNum);
			zcgh.setGhrqTime(new Date());
			zcgh.insert();
			// 更新仓库及个人领用

			return ResultUtil.data(zcgh, "归还成功");
		}
		return ResultUtil.error("归还失败,请确认归还数量是否正确!");

	}

	/********************** 手机端接口 ***************************/
	/**
	 * @param currPage 当前页
	 * @param pageSize 页码
	 * @return
	 */
	@GetMapping(value = "/queryGdzc")
	@ApiOperation(value = "固定资产查询(手机端)", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryGdzc(@CurrentUser UserBean userBean, @RequestParam(required = false) Integer currPage,
			@RequestParam(required = false) Integer pageSize) {
		if (currPage == null) {
			currPage = 1;
		}
		if (pageSize == null) {
			pageSize = 10;
		}
		List<ZcglDetailsDto> list = zcdaMapper.queryGdzc(userBean.getOrgCode(), (currPage - 1) * pageSize, pageSize);
		return ResultUtil.data(list, "查询成功");
	}

	@GetMapping(value = "/queryXhzc")
	@ApiOperation(value = "消耗资产查询(手机端)", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryXhzc(@CurrentUser UserBean userBean, @RequestParam(required = false) Integer currPage,
			@RequestParam(required = false) Integer pageSize) {
		if (currPage == null) {
			currPage = 1;
		}
		if (pageSize == null) {
			pageSize = 10;
		}
		List<ZcglDetailsDto> list = zcdaMapper.queryXhzc(userBean.getOrgCode(), (currPage - 1) * pageSize, pageSize);
		return ResultUtil.data(list, "查询成功");
	}

	/********************** 资产统计图 ***************************/
	/**
	 * 资产管理总资产、分类资产查询统计图查询
	 * 
	 * @param userBean
	 * @return
	 */
	@GetMapping(value = "/zcglzzc")
	@ApiOperation(value = "总资产、分类资产查询", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryZcglCartogram(@CurrentUser UserBean userBean, Integer id) {
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		/**
		 * 查全部
		 */
		List<ZcglDetailsDto> zcdas = zcdaMapper.queryZczj(userBean.getOrgCode(), 0);
		Double zzc = 0D;
		for (ZcglDetailsDto zcglDetailsDto : zcdas) {
			Integer a = zcglDetailsDto.getXzsl();
			Integer b = zcglDetailsDto.getLysl();
			Double c = zcglDetailsDto.getZcdj();
			Double zj = (a + b) * c;
			zzc += zj;
		}

		/**
		 * 分类查
		 */
		List<ZcglDetailsDto> assoZcdas = zcdaMapper.queryZczj(userBean.getOrgCode(), id);
		for (ZcglDetailsDto zcglDetailsDto : assoZcdas) {
			Integer a = zcglDetailsDto.getXzsl();
			Integer b = zcglDetailsDto.getLysl();
			Double c = zcglDetailsDto.getZcdj();
			Double d = (a + b) * c;
			Map<String, Object> map = new HashMap<>();
			map.put("name", zcglDetailsDto.getMc());
			map.put("value", d);
			list.add(map);
		}

		return ResultUtil.datas(list, zzc, "查询成功");

	}

	/**
	 * 资产管理出入库数量按时间查询
	 * 
	 * @param userBean
	 * @param year
	 * @param yearMonth
	 * @return
	 */
	@PostMapping(value = "/zcglcrk")
	@ApiOperation(value = "出库、入库数量按时间查询", httpMethod = "POST", notes = "接口发布说明")
	public Result<Object> queryByDate(@CurrentUser UserBean userBean, @RequestBody ZcglTjtDto zcglTjtDto) {
		Integer orgCode = userBean.getOrgCode();
		Integer year = zcglTjtDto.getYear();
		Integer yearMonth = zcglTjtDto.getYearMonth();
		List<ZcglTjtDto> a = zccrkglMapper.queryRkByYear(orgCode);
		List<ZcglTjtDto> b = zccrkglMapper.queryCkByYear(orgCode);
		List<ZcglTjtDto> c = zccrkglMapper.queryRkByMonth(orgCode, year);
		List<ZcglTjtDto> d = zccrkglMapper.queryCkByMonth(orgCode, year);
		List<ZcglTjtDto> e = zccrkglMapper.queryRkByDay(orgCode, yearMonth);
		List<ZcglTjtDto> f = zccrkglMapper.queryCkByDay(orgCode, yearMonth);

		List<List<ZcglTjtDto>> list = new ArrayList<List<ZcglTjtDto>>();
		list.add(a);
		list.add(b);
		list.add(c);
		list.add(d);
		list.add(e);
		list.add(f);

		return ResultUtil.data(list, "查询成功");

	}

	/**
	 * 资产数量查询
	 * 
	 * @param userBean
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/zcglzcsl")
	@ApiOperation(value = "资分类数量查询", httpMethod = "GET", notes = "接口发布说明")
	public Result<Object> queryZcsl(@CurrentUser UserBean userBean, Integer id) {

		List<ZcglDetailsDto> list = zcdaMapper.queryZczj(userBean.getOrgCode(), id);
		List<Object> l = new ArrayList<Object>();

		for (ZcglDetailsDto zcglDetailsDto : list) {
			Map<String, Object> map = new HashMap<>();
			String mc = zcglDetailsDto.getMc();
			Integer a = zcglDetailsDto.getXzsl();
			Integer b = zcglDetailsDto.getLysl();
			Integer c = zcglDetailsDto.getBfsl();
			map.put("mc", mc);
			map.put("xz", a);
			map.put("ly", b);
			map.put("bf", c);
			l.add(map);
		}

		return ResultUtil.data(l, "查询成功");
	}

}