| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- package titemgroup;
- import baseclass.PaoCust;
- import baseclass.tools.GetFieldsName;
- import openapi.base.SQLFactory;
- import openapi.base.data.Row;
- import openapi.base.data.Rows;
- import openapi.base.data.db.DBConnect;
- import p2.p2server.P2Server;
- import p2.pao.PaoRemote;
- import p2.pao.PaoSet;
- import p2.pao.PaoSetRemote;
- import p2.util.P2AppException;
- import p2.util.P2Exception;
- import java.util.ArrayList;
- public class titemgroup extends PaoCust {
- public titemgroup(PaoSet arg0) {
- super(arg0);
- }
- @Override
- public void init() throws P2Exception {
- super.init();
- if (!toBeAdded() && getBoolean("fisused")) {
- setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true);
- }
- if (!toBeAdded() && !getPaoSet("titem_group").isEmpty()) {
- setFieldFlag("fsaleclsnum", READONLY, true);
- setFieldFlag("fieldname", READONLY, true);
- }
- }
- @Override
- public void add() throws P2Exception {
- super.add();
- setValue("fgroupnum", getBillNum(getThisPaoSet().getApp()));
- }
- @Override
- protected void save() throws P2Exception {
- super.save();
- if ("".equals(getString("fitemno")) && !getPaoSet("titem_group").isEmpty()) {
- setValue("fitemno", getPaoSet("titem_group").getPao(0).getString("fitemno"), 11L);
- }
- }
- @Override
- public void canDelete() throws P2Exception {
- super.canDelete();
- if (getBoolean("fisused")) {
- throw new P2AppException("", "已启用,不可删除");
- }
- if (!getPaoSet("titem_group").isEmpty()) {
- throw new P2AppException("", "已绑定商品,不可删除");
- }
- }
- @Override
- public void usedvalidate(boolean isused) throws P2Exception {
- super.usedvalidate(isused);
- }
- @Override
- public void used(boolean isused) throws P2Exception {
- setValue("fisused", isused, 11L);
- }
- public void additems(PaoSetRemote titemSet) throws P2Exception {
- PaoSetRemote titem_groupSet = getPaoSet("titem_group");
- BatchAdd(titemSet, new String[]{"fitemno", "$" + getString("fgroupnum")}, titem_groupSet, new String[]{"fitemno", "fgroupnum"}, true);
- reflashSaleclsnum();
- }
- /**
- * 刷新商品组营销分类
- *
- * @throws P2Exception
- */
- public void reflashSaleclsnum() throws P2Exception {
- PaoSetRemote titem_groupSet = getPaoSet("titem_group");
- PaoSetRemote titemgroup_saleclsnumSet = getPaoSet("titemgroup_saleclsnum");
- String[] fsaleclsnums = getStrings(titemgroup_saleclsnumSet, "fsaleclsnum");//已存在的营销类别
- String[] fitemnos = getStrings(titem_groupSet, "fitemno");//已存在的商品编号
- SQLFactory sqlFactory = new SQLFactory(this, "商品营销分类查询");
- sqlFactory.addParameter("siteid", getString("siteid"));
- sqlFactory.addParameter_in("fitemno", fitemnos);
- DBConnect dbConnect = new DBConnect();
- Rows fsaleclsnumrows = dbConnect.runSqlQuery(sqlFactory.getSQL());//需要授权的营销类别
- for (Row fsaleclsnumrow : fsaleclsnumrows) {
- boolean isadd = true;
- for (String fsaleclsnum : fsaleclsnums) {
- if (fsaleclsnumrow.getString("fsaleclsnum").equals(fsaleclsnum)) {
- isadd = false;
- break;
- }
- }
- if (isadd) {
- PaoRemote pao = titemgroup_saleclsnumSet.addAtEnd();
- pao.setValue("fsaleclsnum", fsaleclsnumrow.getString("fsaleclsnum"), 2L);
- }
- }
- ArrayList<PaoRemote> deletepaolist = new ArrayList<>();
- int i = 0;
- while (titemgroup_saleclsnumSet.getPao(i) != null) {
- boolean isdelete = true;
- for (Row fsaleclsnumrow : fsaleclsnumrows) {
- if (titemgroup_saleclsnumSet.getPao(i).getString("fsaleclsnum").equals(fsaleclsnumrow.getString("fsaleclsnum"))) {
- isdelete = false;
- }
- }
- if (isdelete) {
- deletepaolist.add(titemgroup_saleclsnumSet.getPao(i));
- }
- i++;
- }
- for (PaoRemote deletepao : deletepaolist) {
- deletepao.delete();
- }
- }
- @Override
- public void fieldValidate(Object paoField, String fieldname) throws P2Exception {
- super.fieldValidate(paoField, fieldname);
- if ("FGROUPNAME".equals(fieldname)) {
- //distinctfieldcheck("FGROUPNAME");
- }
- }
- @Override
- public void fieldAction(Object paoField, String fieldname) throws P2Exception {
- super.fieldAction(paoField, fieldname);
- if ("FSALECLSNUM".equals(fieldname)) {
- String fsaleclsnum = getString("fsaleclsnum");
- if ("".equals(fsaleclsnum)) {
- setValue("flongsaleclsnum", "", 11L);
- } else {
- String flongsaleclsnum = fsaleclsnum;
- boolean hasup = true;
- while (hasup) {
- PaoSetRemote titemclass = P2Server.getP2Server().getPaoSet("titemclass", getUserInfo());
- titemclass.setWhere("fitemclsnum='" + fsaleclsnum + "' and fclasstype='营销类别' and fupclass is not null");
- titemclass.reset();
- if (titemclass.isEmpty()) {
- hasup = false;
- } else {
- fsaleclsnum = titemclass.getPao(0).getString("fupclass");
- flongsaleclsnum = fsaleclsnum + "/" + flongsaleclsnum;
- }
- }
- setValue("flongsaleclsnum", flongsaleclsnum, 11L);
- }
- }
- }
- }
|